Jump to content
  • Advertisement
Sign in to follow this  
h3ro

Problem with rotation

This topic is 3800 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

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.xPos = list.xPos * cos(-r) - list.yPos * sin(-r);
		list.yPos = list.yPos * cos(-r) + list.xPos * sin(-r);
	}
}

Regards, Ole Kristian

Share this post


Link to post
Share on other sites
Advertisement
In the for loop, you're modifying the value of xPos in the first line, and then using the new value in the second line where you should have used the original value. Make a copy of xPos before modifying it and use that instead.

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
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!