Drawing a cube in perspective (3)

1 Name: #!/usr/bin/anonymous : 2010-10-23 00:47 ID:IDiWkEUO

I am working on a game in which cubes fall from the sky. Right now my program draws orthogonal cubes. I would like them to appear in perspective, so they act more realistically.

To be more specific, when they are high in the sky, you should see the bottom face of the cubes. As they fall down they should appear to rotate so that you cannot see the bottom face once they are on level with your eye.

Right now I calculating the 2d polygon to draw on the screen in the following order:
0. (The cube begins as a unit cube centered at the origin)

  1. Apply rotation matrix to all vertices
  2. Scale all vertices
  3. Translate all vertices to appropriate location
  4. Calculate x, y values as such:
    x = x / (1 - z / eye.z)
    y = y / (1 - z / eye.z)

I thought that the formula in step 4 was all I needed for perspective, but the cubes still appear from the same angle no matter what their x or y location is on the screen. Perhaps I am doing something in the wrong order, or perhaps I am missing a step.

Any insight is appreciated. I can post more specific code examples if needed, though I like to keep things general.

2 Name: #!/usr/bin/anonymous : 2010-10-29 15:37 ID:KsKcINzI

What is the x and y values you are getting as the program is running? Also what is the calculations for steps 1-3?

3 Name: #!/usr/bin/anonymous : 2010-11-03 23:44 ID:MKe1cKC2

Thanks for the support, >>2. I actually solved my problem the day after I posted it. I was able to fix it by scaling before rotating (switching steps 1 and 2.) I'm still not exactly sure why this worked.

This thread has been closed. You cannot post in this thread any longer.