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

rotating everywhere?

Started by BFMVfavorite Apr 7, 2007 at 2:30 AM 1 replies 550+ views
Original Post
BFMVfavorite
BFMVfavorite
hi all,

for(b = 0;b < numberEnemies;b++)
{
	glTranslatef(enemies.position.x,enemies.position.y,0);
	glRotatef(FindAngle(m_character.position,enemies.position) + 90,0,0,1);
	glBegin(GL_QUADS);
	glColor3f(1,1,1);
	glTexCoord2f(0.5,0.59);glVertex2f(-2,1);
	glTexCoord2f(1,0.59);glVertex2f(2,1);
	glTexCoord2f(1,1);glVertex2f(2,-1);
	glTexCoord2f(0.5,1);glVertex2f(-2,-1);
	glEnd();
}
all i'm doing is rotating each enemy to face the character, and yet only the 1st one follows it the way it should. i have everyone drawn in the middle, and i translate and rotate, so it should rotate around its center. however, after the first object, everything rotates around the whole entire screen, and i have no clue as to why...what could be causing this? btw, FindAngle() code:

float FindAngle(CVector point1,CVector point2)
{
	CVector lookAt1 = CVector(point1.x - point2.x,point1.y - point2.y,point1.z - point2.z);
	lookAt1.Normalize();
	float radians3 = atan2(lookAt1.y,lookAt1.x);	
	return (180.0f * (radians3 + 90.0f) / PI);
}
Thanks for the help, --nathan
Zakwayda
Zakwayda
Try:
for(b = 0;b < numberEnemies;b++){    <font color="red">glMatrixMode(GL_MODELVIEW); // Just in case...    glPushMatrix();</font>    glTranslatef(enemies.position.x,enemies.position.y,0);    glRotatef(FindAngle(m_character.position,enemies.position) + 90,0,0,1);    glBegin(GL_QUADS);    glColor3f(1,1,1);    glTexCoord2f(0.5,0.59);glVertex2f(-2,1);    glTexCoord2f(1,0.59);glVertex2f(2,1);    glTexCoord2f(1,1);glVertex2f(2,-1);    glTexCoord2f(0.5,1);glVertex2f(-2,-1);    glEnd();    <font color="red">glPopMatrix();</font>}
As it is now, the transform for each object is being concatenated with the combined transforms of all the previous objects, which is not what you want.
BFMVfavorite
BFMVfavorite
thank you very much jyk, it seems i should go to bed earlier so my mind is a little more fresh :P instead of putting the push and pop inside the loop i put it outisde of it...overthinking myself
but putting the push and pop inside the loop worked the problem out, so thanks

--nathan

Topic Locked

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

Sign in to reply to this topic.