Skip to main content
GameDev.net gamedev.net
🔒 Locked

Rotating a FPS view model

Started by Matthewj234 Jun 4, 2012 at 3:40 PM 1 replies 1.6k views
Original Post
Matthewj234
Matthewj234
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();
}
- Numprt
dpadam450
dpadam450
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.
NBA2K, Madden, Maneater, Killing Floor, Sims 
Matthewj234
Matthewj234

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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.