Sign in to follow this  
h3ro

Problem with rotation

Recommended Posts

Hallo, I am trying to add rotation to my 2d "engine", but I have some problem The sprite I am trying to draw gets very distorted when i try to rotate it. If i try to draw it at 90 degrees, I only get a single line of pixels drawn with a 90 degree slope. 0, 360 and 180 degrees work perfect. The sprite is located at 0,0 when i rotate it. Here is my code:
void rotatPixelList(std::vector<pixel> &list, int rotation)
{
	double PI =  3.14159265;

	double r = rotation * PI / 180;

	for(int i = 0; i < list.size(); i++)
	{
		list[i].xPos = list[i].xPos * cos(-r) - list[i].yPos * sin(-r);
		list[i].yPos = list[i].yPos * cos(-r) + list[i].xPos * sin(-r);
	}
}

Regards, Ole Kristian

Share this post


Link to post
Share on other sites
Thanks for pointing that out. The rotation works fine now.

But there is one more problem. My writeToScreen() function uses integers for position (as it writes to the actual pixel position) and because of that I get some weired results. Some places I get no colour as the position is rounded off to the wrong position. So I end up with some pixels with nothing in them, and some with two or more.

Hope my managed to make some sense.

Regards,
Ole Kristian

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this