Placing Weapon In Ego Perspective

Started by
0 comments, last by d h k 18 years, 8 months ago
Hello everybody, I am working on a simple ego-shooter at the moment. Everything is fine except, that the weapon model needs to turn correctly around the player, in order to stay placed correctly whenever the player turns. At the moment it just turns around itself and not the player. I know NeHe mentions this point somewhere in his tutorials but I couldn't find anything there. This is my relevant code: ( I based my code upon NeHe's Tutorial 10 )

        // move to player
	GLfloat x, z;
	x = xpos - (float)sin ( heading * piover180 ) * 0.05f;
	z = zpos - (float)cos ( heading * piover180 ) * 0.05f;
	glTranslatef ( x + 0.15f, 0.15f, z - 0.5f );

	// also rotate
	glRotatef ( yrot, 0.0f, 1.0f, 0.0f );
	glRotatef ( -lookupdown, 1.0f, 0.0f, 0.0f );


The translating part works fine now, but still the weapon rotates around its own centre point and not the players. Is there an (easy) way to fix this (I just started with OpenGL two days ago ;) )... Thanks.
Advertisement
Nevermind, I just thought about a possible solution, that should work. Sorry for my 'to early' post.

This topic is closed to new replies.

Advertisement