News for hackers. Stuff that matters.
Re:Sphere Rendering by qingcharles on Wednesday June 05, 2024 @02:11AM (#40581853)
GPT gave me this, which seems to work when I ran it:

    public void DrawSphere(int centerX, int centerY, int radius, double angle)
    {
     for (int y = -radius; y <= radius; y++)
     {
      for (int x = -radius; x <= radius; x++)
      {
       if (x * x + y * y <= radius * radius)
       {
        double z = Math.Sqrt(radius * radius - x * x - y * y);
  
        double xRot = x * Math.Cos(angle) - z * Math.Sin(angle);
        double zRot = x * Math.Sin(angle) + z * Math.Cos(angle);
  
        double u = 0.5 + (Math.Atan2(zRot, xRot) / (2 * Math.PI));
        double v = 0.5 - (Math.Asin(y / (double)radius) / Math.PI);
        int textureX = (int)(u * _textureWidth) % _textureWidth;
        int textureY = (int)(v * _textureHeight) % _textureHeight;
  
        Rgba32 color = _texture[textureX, textureY];
        SetPixel(centerX + x, centerY + y, color);
       }
      }
     }
    }
Re:Sphere Rendering by qingcharles on Wednesday June 05, 2024 @08:58PM (#40592322)
Are all the downvotes because I used GPT to produce the code? The code worked just fine, so it's not bad code.