05-15-2003, 03:18 PM

I have a question (or so) about gluProject. Everywhere I've read, it says that it gives me screen coordinates based on the object coordinates passed in, but I don't get the results I want.

For a slightly simplified case...

My projection matrix will always be the identity matrix, for now.

The viewport will be (0, 0, 640, 640).

The current modelview matrix is:

[ 0.0008787 0.0 0.0 0.0 ]

[ 0.0 0.0008787 0.0 0.0 ]

[ 0.0 0.0 -0.0004393 0.0 ]

[ 0.0 0.0 0.0 1.0 ]

Now, if I have a cube of "known space" which goes from (0, 0, 0) to (1315, 1280, 980), I want to find the screen coordinates of another cube that goes from (630, 630, 660) to (680, 650, 670).

In my program right now, I can see a square representing the dimensions of the known space as seen from the top, and a small cube in the middle being the object I'm interested in. The small cube is more or less visually centered both horizontally and vertically.

When I use gluProject on all of the eight points of the small cube, and find the minimum and maximum X and Y values, I get (497, 497) and (511,502). These are clearly not in the middle of the screen.

I became even more confused when I worked through the math myself. According to the documentation, for my given matrices and viewport, I should end up with the following equations for the window coordinates:

winX = 0 + 640 * (0.0008787 * X + 1) / 2

winY = 0 + 640 * (0.0008787 * Y + 1) / 2

Running the points for the small cube by hand obtains the same results as the function. However, these end formulas made me slightly suspicious. If I put (0,0,0) in these formulas, which should result in a point up near the corner, if not exactly on it, I end up with winX = 320 and winY = 320 - right in the middle of the screen.

Because of this, I'm pretty sure I've been making an unfounded assumption somewhere about what is going on. Any help pointing me in the right direction would be very much appreciated.

For a slightly simplified case...

My projection matrix will always be the identity matrix, for now.

The viewport will be (0, 0, 640, 640).

The current modelview matrix is:

[ 0.0008787 0.0 0.0 0.0 ]

[ 0.0 0.0008787 0.0 0.0 ]

[ 0.0 0.0 -0.0004393 0.0 ]

[ 0.0 0.0 0.0 1.0 ]

Now, if I have a cube of "known space" which goes from (0, 0, 0) to (1315, 1280, 980), I want to find the screen coordinates of another cube that goes from (630, 630, 660) to (680, 650, 670).

In my program right now, I can see a square representing the dimensions of the known space as seen from the top, and a small cube in the middle being the object I'm interested in. The small cube is more or less visually centered both horizontally and vertically.

When I use gluProject on all of the eight points of the small cube, and find the minimum and maximum X and Y values, I get (497, 497) and (511,502). These are clearly not in the middle of the screen.

I became even more confused when I worked through the math myself. According to the documentation, for my given matrices and viewport, I should end up with the following equations for the window coordinates:

winX = 0 + 640 * (0.0008787 * X + 1) / 2

winY = 0 + 640 * (0.0008787 * Y + 1) / 2

Running the points for the small cube by hand obtains the same results as the function. However, these end formulas made me slightly suspicious. If I put (0,0,0) in these formulas, which should result in a point up near the corner, if not exactly on it, I end up with winX = 320 and winY = 320 - right in the middle of the screen.

Because of this, I'm pretty sure I've been making an unfounded assumption somewhere about what is going on. Any help pointing me in the right direction would be very much appreciated.