Advertisement

rotate using sin and cos

Started by November 03, 2019 10:13 PM
13 comments, last by Bozemoto 5 years, 1 month ago

you can close this thread.

1 minute ago, phil67rpg said:

you can close this thread.

Read rule 7 of this forum, which you've posted in for years and years.

Hello to all my stalkers.

Advertisement

sorry lactose

Just in case someone trips over this post in the future, some useful math when thinking about this kind of stuff.
sin and cos give you a x or y offset on the unit circle, so if you use both then you have a 2D vector.


vec2 dir = { cos(ang), sin(ang) };

Now if you want a vector that is orthogonal to this one you swap the X and Y round and put a negative on one of them. Which one will decide it it's rotated 90 degrees to the left or right.


vec2 orth = { dir.y, -dir.x };

Once you have this you can use these you can use them to make a rectangle like so


vec2 pos[4] = { {0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f} }
vec2 rotated_pos[4] = {};
for(int i=0; i<4; ++i)
{
	rotated_pos[i] = (pos[i].x * orth) + (pos[i].y * dir);
}

Think this is what you're doing but wanted to try and provide some clarity to the topic.

Video Game Programmer.
5 years in industry.

This topic is closed to new replies.

Advertisement