Jump to content
  • Advertisement
Sign in to follow this  
Matthewj234

Rotating a FPS view model

This topic is 2321 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys, so this has been annoying me for a while now.

I am trying to rotate a model about a point, (the camera), and have it render in the same place. This is proving difficult, as the model always either shoots away, or just doesn't render in the right place.

The model is a set of arms, as a First Person View. Any ideas on how to do this? I have found multiple sites saying how, I tried them, and they just didn't work.

Thanks in advance!

EDIT:

My render code:


public void renderModel(Camera cam) {
setPos(0, 0, 0);
glPushMatrix();
glLoadIdentity();
glRotatef(cam.pitch, 1f, 0f, 0.0f);
glRotatef(-cam.yaw, 0.0f, 1f, 0.0f);
glRotatef(cam.roll, 0.0f, 0f, 1f);
setPos(cam.x + 1, cam.y - 2, cam.z + 1);
glBegin(GL_TRIANGLES);
glColor3f(colour[0], colour[1], colour[2]);
for (Face face : faces) {
Vector3f n1 = normals.get((int) face.normal.x - 1);
glNormal3f(n1.x, n1.y, n1.z);
Vector3f v1 = vertices.get((int) face.vertex.x - 1);
glVertex3f(v1.x + xPos, v1.y + yPos, v1.z + zPos);
Vector3f n2 = normals.get((int) face.normal.y - 1);
glNormal3f(n2.x, n2.y, n2.z);
Vector3f v2 = vertices.get((int) face.vertex.y - 1);
glVertex3f(v2.x + xPos, v2.y + yPos, v2.z + zPos);
Vector3f n3 = normals.get((int) face.normal.z - 1);
glNormal3f(n3.x, n3.y, n3.z);
Vector3f v3 = vertices.get((int) face.vertex.z - 1);
glVertex3f(v3.x + xPos, v3.y + yPos, v3.z + zPos);
}
glEnd();
glPopMatrix();
}
Edited by Matthewj234

Share this post


Link to post
Share on other sites
Advertisement
For something like an FPS where the gun/hands are always relative to the camera. Then you don't need a view matrix. Just call glLoadIdentity() and treat it that way. It doesn't ever matter where or what your camera is looking at.

Share this post


Link to post
Share on other sites

For something like an FPS where the gun/hands are always relative to the camera. Then you don't need a view matrix. Just call glLoadIdentity() and treat it that way. It doesn't ever matter where or what your camera is looking at.


I had never thought of it that way. Thinking about it now, it makes perfect sense! Thank you very much, and it all works now :)

Regards,

Matt

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!