Skip to main content
gamedev.net
🔒 Locked

Simple Rotation Question

Started by halogen64 Mar 9, 2008 at 4:24 PM 0 replies 500+ views
Original Post
halogen64
halogen64
I tried searching and couldn't find anything so I figured I'd ask here. When I try to rotate a sprite 180 degrees it of course rotates off of the screen due to that whole ray from the origin concept, I however want it to rotate in place (like the anchor point was in the center of the sprite). I also may want to rotate it in other degrees. Here is the code I have now:

glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, textureID);
		glColor3f(1, 1, 1);
		glPushMatrix();
		glRotatef(rotate, 0.0, 0.0, 1.0);
		glTranslatef(top.x,top.y,0.0f);
		glAlphaFunc(GL_GREATER, 0.9f);
		glEnable(GL_ALPHA_TEST);
		glBegin(GL_QUADS);
			glTexCoord2f(0.0f, 0.0f); glVertex2f (0, 0);
			glTexCoord2f(1.0f, 0.0f); glVertex2f (abs(top.x - bottom.x), 0);
			glTexCoord2f(1.0f, 1.0f); glVertex2f (abs(top.x - bottom.x), abs(top.y - bottom.y));
			glTexCoord2f(0.0f, 1.0f); glVertex2f (0, abs(top.y - bottom.y));
		glEnd();
		glDisable(GL_ALPHA_TEST);
		glPopMatrix();
		glDisable(GL_TEXTURE_2D);


Also, if anybody knows how to clean that up, could they let me know? Thanks in advance EDIT: Also I tried taking half the width and height and doing this instead

float wH = abs(top.x - bottom.x) / 2;
		float hH = abs(top.y - bottom.y) / 2;
		glBegin(GL_QUADS);
			glTexCoord2f(0.0f, 0.0f); glVertex2f (-wH, -hH);
			glTexCoord2f(1.0f, 0.0f); glVertex2f (wH, -hH);
			glTexCoord2f(1.0f, 1.0f); glVertex2f (wH, hH);
			glTexCoord2f(0.0f, 1.0f); glVertex2f (-wH, hH);
		glEnd();

But that did not work either
halogen64
halogen64
Solved it nevermind.

For anyone who cares, this was my final result

float wH = abs(top.x - bottom.x) / 2;		float hH = abs(top.y - bottom.y) / 2;		glEnable(GL_TEXTURE_2D);		glBindTexture(GL_TEXTURE_2D, textureID);		glColor3f(1, 1, 1);		glPushMatrix();		glTranslatef(top.x + wH,top.y + hH,0.0f);		glRotatef(rotate, 0.0, 0.0, 1.0);		glAlphaFunc(GL_GREATER, 0.9f);		glEnable(GL_ALPHA_TEST);		glBegin(GL_QUADS);			glTexCoord2f(0.0f, 0.0f); glVertex2f (-wH, -hH);			glTexCoord2f(1.0f, 0.0f); glVertex2f (wH, -hH);			glTexCoord2f(1.0f, 1.0f); glVertex2f (wH, hH);			glTexCoord2f(0.0f, 1.0f); glVertex2f (-wH, hH);		glEnd();		glDisable(GL_ALPHA_TEST);		glPopMatrix();		glDisable(GL_TEXTURE_2D);

Topic Locked

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

Sign in to reply to this topic.