I'm developing some game in order to learn OpenGL.
I can make an object follow me around when I move forward, backward, left, right, up or down, by setting it's position right infront of the camera.
Problem starts when the camera rotates / tilts (looking up, down, left, right...).
The object is indeed sticks infront of the camera position (because I calculate a vector going out from the camera position and place it there), however I can't make the angle of the object to rotate/tilt along with the camera, so it is just fixed.
I think I might have to set the object coordinate system to correlate with the camera's coordinate system, but I can't figure out how. Maybe I'm wrong and there's another way to do that.
My game implementation
I have 4 vectors for the camera and 4 vectors for each object: origin, x, y and z (to represent the objects coordinate system).
To move the camera, I substract z axis from origin.
Same for other directions.
In order to tilt the camera, for example to the right, I just calculate rotation around Z axis and apply to X,Y axes.
Note: Movement in the world works good, in all directions and angles.
Here's the (the relevant) code I use to position objects in the world. Before drawing them I first put them in their origin (recall: I save an origin and x,y,z axes to all my objects), then do some scale to fit my desired size:
// translate to position gl.glTranslatef((float)origin.x, (float)origin.y, (float)origin.z); // scale to size gl.glScalef((float)size.x, (float)size.y, (float)size.z);