0

So I have this randomly generated set of tiles that is wrapped in a circle and I'm not really sure how to scroll it around the circle. Basically it's a side-view planet that is in 2D and needs to be wrapped and moving at a controllable rate to give the illusion of planet rotation. I'll post my current render code below so you can get an idea of what I'm working with but I'm not really sure what to do to the x and y to make it scroll around. Here's what a planet looks like: https://i.stack.imgur.com/PzbKo.jpg

for (int x = 0; x < planet1.length; x++)
    {
        for (int y = 0; y < planet1[0].length; y++)
        {
            if (planet1[x][y] == 1 || planet1[x][y] == 2)
            {
                g.drawImage(water, x * 32, y * 32);
            } 
            else if (planet1[x][y] == 3)
            {
                g.drawImage(desert, x * 32, y * 32);
            }
            else if (planet1[x][y] == 4)
            {
                g.drawImage(plains, x * 32, y * 32);
            }
            else if (planet1[x][y] == 5)
            {
                g.drawImage(grassland, x * 32, y * 32);
            }
            else if (planet1[x][y] == 6)
            {
                g.drawImage(forest, x * 32, y * 32);
            }
            else if (planet1[x][y] == 7)
            {
                g.drawImage(hills, x * 32, y * 32);
            }
            else if (planet1[x][y] == 8)
            {
                g.drawImage(mountain, x * 32, y * 32);
            }
            else if (planet1[x][y] == 9)
            {
                g.drawImage(mountain, x * 32, y * 32);
            }
            else if (planet1[x][y] == -1)
            {

            }
        }
    }
  • You have to be more specific on what you expect the output to be. Simply scrolling and wrapping pixels in one direction? That'd have nothing to do with the projection of a sphere into two dimensions. For a solution in that direction you'll need some understanding of trigonometry and probably a better way to store the terrain data. – Ingo Bürk Jan 11 '15 at 10:08

1 Answers1

0

From the look of it you aren't drawing a sphere, rather a repeating rectangle clipped to a circle.

If you want it to actually appear to rotate, they you'll need make an orthographic projection of a sphere.
In which case, you'll need your tile data stored over θ,φ, and then create a constant map of on-screen xy into angles using φ= acos(length(x,y)/radius) θ= atan(y/x)
And then sample from the terrain data using [θ+roll,φ+pitch] (not exactly roll and pitch, but close enough)

Khlorghaal
  • 230
  • 2
  • 11