Dear community, I’m glad to write my first post today!
Unfortunately, this is about a struggle between me and opengl, which has lasted a few weeks now, and, even though I could have accomplished some results, I’m still far from my objectives.
I have implemented a basic opengl world, using the glfw libraries, which ( till now ) draws a simple ground plane ( a grid ), and a few squares around. A few days ago, I added support for the “camera”, using a vector to store its position, and a quaternion for its rotation. It’s taken a while, but it works pretty good.
Can you please confirm me that this is how things should be implemented?
- INIT ( enabling options, lighting, perspective, etc )
- CAMERA TRANSFORMS ( translation, rotation )
- WORLD OBJECTS
Once applied the transformations to the current MODELVIEW matrix to set the camera, I have to use glPushMatrix and glPopMatrix to draw things with respect to the default view, and not the current one ( the one of the camera ), am I right?
So, things should look like:
…
//Camera
glTranslated();
glRotatef();
//Object1
glPushMatrix();
glLoadIdentity();
//DRAW
glPopMatrix();
//Object2
glPushMatrix();
glLoadIdentity();
//DRAW
glPopMatrix();
…
This way everything seems to work. Now, I want to implement a simple HUD, which tells me the current camera orientation with respect to the initial ( default ) one. This can just be represented by three lines ( axis ) which are placed in a corner of my screen, and are rotated accordingly to the quaternion of my camera.
Now, I’m having a few problems trying to implement this. To draw the hud, shouldn’t it be enough to start drawing, without using glPushMatrix() and glPopMatrix()? It’s not working these way, objects are still drawn with respect to the identity matrix.
Thank you for your suggestions.