3 ms·
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 = -ra
by qingcharles 2y ago
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);
}
}
}
}
- qingcharles 2y agoAre all the downvotes because I used GPT to produce the code? The code worked just fine, so it's not bad code.