attach mesh to a camera
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
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
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
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
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
EDIT: sorry if that sounded crabby, ive got a headache lol
hope that helps
-Dan
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
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 :)
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement