Thanks
I have a better grasp of how thing is supposed to work, but doing it in code is still a bit confusing.
Here is what I got so far
Init code:
void InitOpenGL (void){ glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glShadeModel(GL_SMOOTH); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); // Set up initial position/orientation using LookAt cam_pos.Set(0.0f, 0.0f, 0.0f); cam_target.Set(0.0f, 0.0f, 3.0f); cam_up.Set(0.0f, 1.0f, 0.0f); // glo = OpenGLObject instance glo.SetMode(OpenGLObject::MODE_6DOF); glo.LookAt(cam_pos, cam_target, cam_up); // Feed camera position/orientation into the modelview matrix glo.SetOpenGLViewMatrix(); glo.SetOpenGLModelMatrix();}
and here is the render:
void RenderFrame (void){ glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glo.SetOpenGLViewMatrix(); glo.ApplyPitch(rot_pitch); glo.MoveAlongForwardAxis(move_frwd); glo.SetOpenGLModelMatrix(); // this makes things happen //glo.MultOpenGLModelMatrix(); // this makes everything disappear // draw rectangle glTranslatef(0.0f, 0.0f, -8.0f); //glRotatef(angle, 0.0f, 0.0f, 1.0f); DrawTriangle();}
DrawRectangle just draws a simple rectangle.
When the rendering starts, I am positioned at 0,0,0 and have the rectangle right in front of me.
If I press the up-key, the rectangle start to rotate around me, which is good, but if I move myself(camera) away from 0,0,0, first, and then start to rotate, the rectange still rotate around 0,0,0, and not around me.
How do I make everything rotate around me and not around 0,0,0?
(Strictly speaking, I want to be the one rotating, but if I understand correct, its more common to have the world, and everything in it, rotate instead)
Im I supposed to reset(identity) all the matrices before every object I render?
The way its set up now, I never use any kind of Identity functions except at program init.
By the way, the projection matrix is set equal to the identity matrix at startup, is this correct?