Positioning weapon just in front of Camera Problem...Unsolved and extended

Started by
14 comments, last by spencerholmes 18 years, 2 months ago
You should really consider learning how opengl actually works. The fact that you are rendering a loaded model encapsulated in a separate class the way you are does not limit the placement of it in the world in any way.
Advertisement
I have already tried written my own methods for it and they don't work. Such as:

void SetPosition(float x, float y, float z) //doesn't work

I have also tried an overloaded constructor for the class, something like:

C3dsLoader(float x, float y, float z, float h, float w, float d);

within the main i have then tried:

C3dsLoader objectLoaded[10];

objectLoaded[0] = new C3dsLoader(0, 0, 0, 2, 2, 2);

//in the update i have called:

objectLoaded.Update();

//in the render

objectLoaded.Render();

Maybe i will post you the code and you can see what you think?

S
Quote:
Just because the TUTORIAL you saw used glTranslatef(), it doesn't mean you can't do other things.
Go with the resetting the matrix approach everyone's already suggested, its a good one.


The original tutorial didn't use glTranslatef(), it is just the only way i can get the objects to re-position!

S

Quote:Original post by spencerholmes

The original tutorial didn't use glTranslatef(), it is just the only way i can get the objects to re-position!

S



To do the aforementioned 'matrix reset' method, you Don't want to reposition the object at all(excpet for fixed offset about where you want it centered on screen). Aside from that, you just leave it more or less at the origin, and since your matrix is reset it stays in the middle of the camera view as you move around. Think of it this way: all those gltranslate and glrotates Don't move your camera, they really move the objects in the world. So by clearing that matrix before rendering your gun model, it stays put in front of the camera.
Quote:Original post by spencerholmes
Quote:
Just because the TUTORIAL you saw used glTranslatef(), it doesn't mean you can't do other things.
Go with the resetting the matrix approach everyone's already suggested, its a good one.


The original tutorial didn't use glTranslatef(), it is just the only way i can get the objects to re-position!
Did you try using a separate view transformation for the weapon, as has been suggested? The details depend on how the weapon is oriented in model space, but it might look something like this:
glMatrixMode(GL_MODELVIEW);glPushMatrix();glLoadIdentity();glTranslatef(offset.x, offset.y, offset.z);// Maybe some 90- or 180- degree rotations here to get the weapon oriented correctlyWeaponModel.Render();glPopMatrix();
Here, 'offset' is constant (not related to the position of your character) and just represents where the weapon is relative to the view. For example, it might be a few units out along the -z axis, a few units to the right, and a few units down (how many depends on the scale of the model). If you need help figuring out what rotations need to be applied, just tell us how the 3ds model is oriented in local space.

There might still be issues of z-buffering and the near clip plane to deal with, but the above method should work.
I will try. Thankyou!

S

This topic is closed to new replies.

Advertisement