PDA

View Full Version : Having problems with projections



profbalse
09-15-2003, 10:04 AM
Hi Wizards!!!,
I am in a great problem ...as I am not able to obtain the 2D projection[ Square] of a 3D Cube on the window...Is there a feasible way to do that...Can you guys give me a hint or can I get a sample code from any of you guys..Please reply me...I am in need of great help.....Many Thanks...Cheers

Orzech
09-15-2003, 10:37 AM
?

Hi. Honestly I don't really understand your problem. I'd like to help you but I don't how... http://www.opengl.org/discussion_boards/ubb/wink.gif

There is something interesting for me in your post... How can a projection on a window be not 2D? Meaby my monitor is weird but I didn't noticed any objects flying around me... http://www.opengl.org/discussion_boards/ubb/wink.gif

dorbie
09-15-2003, 10:47 AM
glMatrixMode(GL_PROJECTION);
glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);

Substitute your own cube diomensions to suit.

dorbie
09-15-2003, 10:50 AM
P.S. that assumes you have identity on the projection matrix to start with. And of course you'd only call it once. It would be safer to make the following call between the first matrixmode call and the ortho call.

glLoadIdentity();

Jan
09-15-2003, 01:52 PM
Do you mean, that your cube does not look like a cube, because its faces are not squares but rectangles?

In this case, you didnīt tell OpenGL, the aspect ratio of your window correctly:

glMatrixMode (GL_PROJECTION);
glLoadIdentity ();

float fRatio = ScreenResolutionX / ScreenResolutionY;

gluPerspective (m_fFOVAngle, fRatio, m_fNearPlane, m_fFarPlane);

glMatrixMode (GL_MODELVIEW);


For example if you have a 1024*768 window, fRatio will be 1.33, which simply means, that your screen is 1.33 times wider than it is high. If you do this, than your cube will look like a cube.

But maybe you meant something different ;-)

Jan.