attach mesh to a camera

Started by
6 comments, last by Ademan555 18 years, 10 months ago
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
Advertisement
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
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."
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


I didnt say to translate it. Just do glLoadIdentity() then render it

EDIT: sorry if that sounded crabby, ive got a headache lol

hope that helps
-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."
geez that was easy can't believe i didn't think of that, anyway thanks heaps buddy it's perfect now
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
call gluPerspective(...) as you did when you set up your Window but you can now skip the glViewport(...) thing.

Make sure to set it back again :)
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
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."

This topic is closed to new replies.

Advertisement