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.
Seeing some code would help me debug. Perhaps you could simplify your code to show how you are rendering.
Try doing the camera positioning after you draw the gun.
In general you should render like this:
1. draw protagonist (be it gun arm, full character or just the head of the character)
2. position camera.
3. draw scene.
4. draw user interface.
This of it like this; you always want your gun to draw in the same spot on the screen, positioning the camera moves where things will be drawn.