world vertex to screen

Hi,

I have a primitive 3d engine I wrote using java. My matrix transformations are working ok (scale, rotate, translate), but when it comes time to perform the final perspective transform, things don’t quite look right.

For example, I used some cubes as a test, as I rotate them in place about the X axis, it looks like they somehow rotate at different speeds and that their edges aren’t parallel to one another.

Does anyone have a perspective function that they could pass a vertex through, so I could see if I get the same result with mine? I can’t think of how else to track down this bug.

Other than that, if someone has a tutorial showing how to get a world vertex to screen that would be great,

Thanks,
Mark

Hi Mark,

It’s difficult to tell what the problem is without the code. first of all, I’m not really sure shat the problem is…when using perspective projections and looking at rotated cubes the edges aren’t supposed to be parallel to each other, that’s only a property for orthographic and affine projections.

PS. Make sure you call glLoadIdentity before your call to gluPerspective/glFrustum when setting the GL_PROJECTION matrix.

Cheers,
Nico

Yeah, I could post the code but it is long (I’m not using opengl, I just wrote this renderer from scratch using java).

You can check out the applet here:
http://opennyc.com/test3d/

it might take a few seconds to load. I am just drawing two cubes. Notice the green cube which is twice as high as it is wide/deep. When you rotate it around the x-axis, its height seems to get swapped with the width!

I’ve built everything from clipping to z-buffering etc etc etc, and this is what’s broken! Unbelievable. I was just wondering if you guys think it is my persepective matrix?

Oh yeah you can just ignore the 2D junk at the top of the applet.

Thanks for any ideas,
Mark

You seem to have an incorrect order of scale and rotation matrix on the green cube.
Your projection setup look fine (as the red cube is not distorted).

zbuffer, what do you mean? I’m applying the transformations in my code in this applet like:

MatrixRotate();
MatrixScale();
MatrixRotate();
MatrixTranslate();

So is it wrong to do scaling after rotation (wrong in the sense that this is why I’m getting this wacky skewing)?

Thanks

well it is a typical OpenGL pitfall too : the last matrix operation is applied first.

http://www.juniata.edu/faculty/rhodes/graphics/opengltrans.htm

try this order :
MatrixRotate();
MatrixRotate();
MatrixScale();
MatrixTranslate();

ahh well I did:

Scale();
Rotate();
Rotate();
Translate();

and now it looks as expected. I can’t believe I made that mistake, thanks for your help, I otherwise probably would have wasted a lot of time ripping apart my frustrum class.