• 9
• 9
• 11
• 12
• 9

# Rotating a FPS view model

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

## 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.

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 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.

##### 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