Ok so on 2 other forums I posted this topic:
"I'm writing a game engine, but I've hit a mjor roadblock. You see I'm using GLtools and this allows you to easily move a camera around the 3D world, it also has a function that I believe returns the XYZ coordinates of the camera.
Only problem is that my character is supposed to have a gun, now in relation to the camera (and the direction the camera is facing) the gun is always in the same place.
The class GLFrame in gltools has some info on which way it's facing, I'm figuring I'll write a function that returns the vector.
So my chosen method of displaying the gun is essentially to convert (somehow) the new position of the camera AND the vector (the way the camera is facing) BACK to the default (namely 0,0,0 and 0,0, -1) and then REVERSE this on the constant position of the gun to receive the NEW gun location.
My question is, how do I this.
In other words how do I find the equation that will convert the coordinates."
The response I got from one guy was this:
"I believe this is the way most FPSs do it:
Image the world as consisting of three parts. The 3D scene, which contains the actual map; the 3D HUD, which contains the character's weapon; and the 2D HUD, which contains health and ammo gauges, etc. The 3D scene is rendered to the framebuffer as one unit based on the camera position, as you're thinking. Once that's done, the camera is set to a fixed point and direction (the 3D scene will be invisible at this point, so it doesn't matter where the point is) such that the weapon is visible, and this view is rendered on top of the previous one. The result is akin to having the character stand in front of a screen that displays the scene, which is why weapons don't clip through walls when you get really close to them. Finally, the 2D HUD is drawn directly onto the framebuffer without using the camera."
So my understanding of what he said is that one must first render the scene. Then set the new XYZ origin at the camera point then render the gun based on this new point and then paste this gun ON TOP of the map scene.
My question is, how would you paste one scene on top of another. Also, is there a way to set the new XYZ origin (with the -Z going in the direction of where the camera is facing) with GLtools or freeglut?