OpenGL Rotation?

It seems that 90deg rot. Around Y is going to have you looking at the side of a triangle with no depth.

It seems that 90deg rot. Around Y is going to have you looking at the side of a triangle with no depth. You should try rotating around the Z axis instead and see if you get something that makes more sense.

OpenGL has two matrices related to the display of geometry, the ModelView and the Projection. Both are applied to coordinates before the data becomes visible on the screen. First the ModelView matrix is applied, transforming the data from model space into view space.

Then the Projection matrix is applied with transforms the data from view space for "projection" on your 2D monitor. ModelView is used to position multiple objects to their locations in the "world", Projection is used to position the objects onto the screen. Your code seems fine, so I assume from reading the documentation you know what the nature of functions like glPushMatrix() is.

If rotating around Z still doesn't make sense, verify that you're editing the ModelView matrix by calling glMatrixMode.

IMPORTANT! See also Perry's answer below. – Ali Jan 7 at 20:46.

Ensure that you're modifying the modelview matrix by putting the following before the glRotatef call: glMatrixMode(GL_MODELVIEW); Otherwise, you may be modifying either the projection or a texture matrix instead.

When I had a first look at OpenGL, the NeHe tutorials (see the left menu) were invaluable.

I'd like to recommend a book: 3D Computer Graphics : A Mathematical Introduction with OpenGL by Samuel R. Buss It provides very clear explanations, and the mathematics are widely applicable to non-graphics domains. You'll also find a thorough description of orthographic projections vs. perspective transformations.

The "accepted answer" is not fully correct - rotating around the Z will not help you see this triangle unless you've done some strange things prior to this code. Removing a glOrtho(...) call might have corrected the problem in this case, but you still have a couple of other issues. Two major problems with the code as written: Have you positioned the camera previously?

In OpenGL, the camera is located at the origin, looking down the Z axis, with positive Y as up. In this case, the triangle is being drawn in the same plane as your eye, but up and to the right. Unless you have a very strange projection matrix, you won't see it.GluLookat() is the easiest command to do this, but any command that moves the current matrix (which should be MODELVIEW) can be made to work.

You are drawing the triangle in a left handed, or clockwise method, whereas the default for OpenGL is a right handed, or counterclockwise coordinate system. This means that, if you are culling backfaces (which you are probably not, but will likely move onto as you get more advanced), you would not see the triangle as expected. To see the problem, put your right hand in front of your face and, imagining it is in the X-Y plane, move your fingers in the order you draw the vertices (1,1) to (3,2) to (3,1).

When you do this, your thumb is facing away from your face, meaning you are looking at the back side of the triangle. You need to get into the habit of drawing faces in a right handed method, since that is the common way it is done in OpenGL. The best thing I can recommend is to use the NeHe tutorials - nehe.gamedev.net/.They begin by showing you how to set up OpenGL in several systems, move onto drawing triangles, and continue slowly and surely to more advanced topics.

They are very easy to follow.

Regarding Projection matrix, you can find a good source to start with here: msdn.microsoft.com/en-us/library/bb14730...).aspx It explains a bit about how to construct one type of projection matrix. Orthographic projection is the very basic/primitive form of such a matrix and basically what is does is taking 2 of the 3 axes coordinates and project them to the screen (you can still flip axes and scale them but there is no warp or perspective effect). Transformation of matrices is most likely one of the most important things when rendering in 3D and basically involves 3 matrix stages: Transform1 = Object coordinates system to World (for example - object rotation and scale) Transform2 = World coordinates system to Camera (placing the object in the right place) Transform3 = Camera coordinates system to Screen space (projecting to screen) Usually the 3 matrix multiplication result is referred to as the WorldViewProjection matrix (if you ever bump into this term), since it transforms the coordinates from Model space through World, then to Camera and finally to the screen representation.

Have fun.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions