Advertisement Jump to content
Sign in to follow this  

vertex rotation help please

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

Hi guys,


Having some issues with vertex rotation. Each vertex is just a 2d vector with an x,y component. Currently the shape is a simple rectangle, which is meant to rotate aroun its center

void update(float dt,float angle){
		x = ((x - x_origin) * cos(angle)) - ((y_origin - y) * sin(angle)) + x_origin
		y = ((y_origin - y) * cos(angle)) - ((x - x_origin) * sin(angle)) + y_origin






When I run it, it just hangs up, and displays nothing. Any help would be greatly appreciated.



Share this post

Link to post
Share on other sites

You add the center position to undo the shift of the enter to the world origin, done as the last operation. So I assume that the first operation is to subtract the center of interest from the vertex position. If so, then the sign of every second term with the cosines is wrong. Try out:





EDIT: Oops, my original suggestion suggestion also suffered from the problem mentioned by Álvaro below, so I've edited it to use other target variables.

Edited by haegarr

Share this post

Link to post
Share on other sites

Notice that by the time you get to your second line of code, the value of v1.x has already changed. This is a mistake that most of us have made at some point or another. Using my current programming style, the point before and after the rotation would be different variables, and then this problem doesn't happen.


When I run it, it just hangs up, and displays nothing.



It sounds like you need to learn how to debug your code and arrive at more useful descriptions of the problem. Like "when presented with this particular input, the code generates this output, but I expected this other output".

Share this post

Link to post
Share on other sites

Hi guys,


Thanks for the help, after I got home from work yesterday I managed to get the program to work. The main issue was my drawLine(Vec v1, Vec v2) function, which was hanging up the program.


Thanks again for your help Alvaro and Heagarr!



Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!