🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

rotate a sprite using trigonometry

Started by
1 comment, last by Tom Sloper 2 years, 1 month ago

I am attempting to rotate a sprite using sin and cos. it almost works, however when I use the rotating keys it rotates in an oblique fashion. It is hard to explain what the sprite actually does. Here is my code.

void drawShip()
{
	glEnable(GL_TEXTURE_2D);

	glBindTexture(GL_TEXTURE_2D, texture[0]);
	glBegin(GL_POLYGON);
	float cosA = cos(shipAngle);
	float sinA = sin(shipAngle);
	float offsets[4][2] = { { -10.0f,-5.0f},{10.0f,-5.0f},{10.0f,5.0f},{-10.0f,5.0f} };
	glTexCoord3f(0.0f, 0.0f, 0.0f);
	glVertex3f(offsets[0][0]*cosA-offsets[0][1]*sinA, offsets[0][0] * sinA - offsets[0][1] * cosA, 0.0f);

	glTexCoord3f(1.0f, 0.0f, 0.0f);
	glVertex3f(offsets[1][0] * cosA - offsets[1][1] * sinA, offsets[1][0] * sinA - offsets[1][1] * cosA, 0.0f);

	glTexCoord3f(1.0f, 1.0f, 0.0f);
	glVertex3f(offsets[2][0] * cosA - offsets[2][1] * sinA, offsets[2][0] * sinA - offsets[2][1] * cosA, 0.0f);

	glTexCoord3f(0.0f, 1.0f, 0.0f);
	glVertex3f(offsets[3][0] * cosA - offsets[3][1] * sinA, offsets[3][0] * sinA - offsets[3][1] * cosA, 0.0f);
	glEnd();

	glDisable(GL_TEXTURE_2D);
}
Advertisement

Phil, if you want to share code, you can write a blog. Thread closed.

-- Tom Sloper -- sloperama.com

This topic is closed to new replies.

Advertisement