#### Archived

This topic is now archived and is closed to further replies.

# Rotating a number of textured objects at once.

## Recommended Posts

powdahound    158
I'm working on a space invaders clone and I decided to use opengl just for fun. In the display I have a number of asteroids (with the x,y coordinates stored in a list) and I can draw them to the screen each step just fine. But when I try to rotate them (z axis, so they spin in place) they won't cooperate. Here's what I have so far, tell me what I'm doing wrong (this is in my function for drawing the scene):
	// *** asteroids ***
glEnable(GL_TEXTURE_2D);	// Enable Texture Mapping
for (ast = ast_list->begin(); ast != ast_list->end(); ast++)
{
glPushMatrix();
glTranslatef(ast->x(), ast->y(), 0);
glRotatef(ast_rot, 0.0f, 0.0f, 1.0f);

if (ast->destroyable())
glBindTexture(GL_TEXTURE_2D, texture[4]);
else
glBindTexture(GL_TEXTURE_2D, texture[5]);

glTexCoord2d(0.0,0.0); glVertex2d(ast->x()-16, ast->y()-16);
glTexCoord2d(1.0,0.0); glVertex2d(ast->x()+16, ast->y()-16);
glTexCoord2d(1.0,1.0); glVertex2d(ast->x()+16, ast->y()+16);
glTexCoord2d(0.0,1.0); glVertex2d(ast->x()-16, ast->y()+16);
glEnd();
glPopMatrix();
}
glDisable(GL_TEXTURE_2D);

ast_rot += 0.1f;

Now the problem is that they seem to rotate on a circle with the origin at 0,0 (the upper left of my screen). I don't want them to move on the screen, just rotate in place... Thanks guys. Gamer-Insight.com [edited by - powdahound on June 8, 2002 12:07:55 PM]

##### Share on other sites
danz    122
do the glTranslatef after the glRotatef, this should work

##### Share on other sites
powdahound    158
I forgot to mention I had already tried that. I get the same result just at a different speed.

danz    122

##### Share on other sites
powdahound    158
No go. same result

##### Share on other sites
danz    122
if the game is 2d, try rendering in ortho mode

##### Share on other sites
Since you add ast->x/ast->y to your vertex coordinates AND make a translation, you're actually doing two translations : one before the rotation and one after it.

Try to change :

glTexCoord2d(0.0,0.0); glVertex2d(ast->x()-16, ast->y()-16);
glTexCoord2d(1.0,0.0); glVertex2d(ast->x()+16, ast->y()-16);
glTexCoord2d(1.0,1.0); glVertex2d(ast->x()+16, ast->y()+16);
glTexCoord2d(0.0,1.0); glVertex2d(ast->x()-16, ast->y()+16);

to :

glTexCoord2d(0.0,0.0); glVertex2d(-16, -16);
glTexCoord2d(1.0,0.0); glVertex2d( 16, -16);
glTexCoord2d(1.0,1.0); glVertex2d( 16, 16);
glTexCoord2d(0.0,1.0); glVertex2d(-16, 16);

[edited by - Prosper/LOADED on June 8, 2002 1:08:53 PM]