Sign in to follow this  
smithy01

attach mesh to a camera

Recommended Posts

hi I am using a camera very similiar to that from ultimategameprogramming and i am trying to attach a 3ds model to the camera(a weapon) ...i can load the mesh into my scene no troubles,when i render the mesh i try to do this glTranslatef(camera.view.x,camera.view.y,camera.view.z); this places the mesh so far away i can hardly see it. i tried glTranslatef(camera.pos.x,camera.pos.y,camera.pos.z); but obviouslly this way the mesh will not rotate when the camera does. anyone got any pointers for me? Thanks

Share this post


Link to post
Share on other sites
Yeah, just do:

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
//render mesh
glPopMatrix();

(note, this means that your model MUST be oriented in a way such that the weapon extends out along the negative z axis, y is up and x is right

(PS: im really really out of it, it may be positive z, but im pretty sure its negative)
hope that helps
-Dan

Share this post


Link to post
Share on other sites
of course i didn't think of that

so anyway i do this

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glTranslatef(camera.View.x,camera.View.y,camera.View.z);
gun->render();
glPopMatrix();

the gun now moves with the view but it doesn't move when i walk forward, or when i strafe etc


Share this post


Link to post
Share on other sites
actually i last question

is it possible to render the weapon using a different FOV than when i render the rest of the scene? ..the weapon looks better with a FOV of 45 but i don't like that FOV for the scene

Share this post


Link to post
Share on other sites
Eh... glLoadIdentity() is an almost no cost function. Chances are something else you were doing was wrong.

EDIT: i was typing one handed so i didnt care to finish my thought. glLoadIdentity() either sends 16 floats over the bus, or simply sends a message over that says change the current matrix to identity. Both of these would take up relatively no time whatsoever.

cheers
-Dan

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this