Jump to content
  • Advertisement

Archived

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

powdahound

Rotating a number of textured objects at once.

This topic is 5829 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 ***
	glLoadIdentity();		// reset
	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]);

			glBegin(GL_QUADS);
				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 this post


Link to post
Share on other sites
Advertisement
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]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!