Jump to content

  • Log In with Google      Sign In   
  • Create Account

Rotating a FPS view model


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Matthewj234   Members   -  Reputation: 797

Like
0Likes
Like

Posted 04 June 2012 - 09:40 AM

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, 04 June 2012 - 09:59 AM.


Sponsor:

#2 dpadam450   Members   -  Reputation: 947

Like
1Likes
Like

Posted 05 June 2012 - 11:42 PM

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.

#3 Matthewj234   Members   -  Reputation: 797

Like
0Likes
Like

Posted 07 June 2012 - 05:29 PM

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS