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.

6 Years
Discussion Span
Last Post by gusano79

Don't you have the x y z position and x y z rotation of your character (and gun)? Then just apply these to the camera with the offset so it is looking from the right height. That is if this is for a FPS.


I don't know anything about gltools, but if you have a position and orientation for the camera, you should at least be able to use glTranslate and glRotate to get the gun to match the camera.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.