🎉 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!

2D ROTATION PROBLEM

Started by
1 comment, last by Super_Man 24 years, 6 months ago
What is the code supposed to do, and what are you getting? It's hard to tell with what you've posted. It looks like it will draw four lines, but three of them are going to be off-screen.
Advertisement
Hello everybody

I want to rotate point P1(100,100) about point P2(0,0) by 90 degree.

My src is like this:

int x = 100;
int y = 100;
float angle = 90*(3.14/180);

do {

x1 = x*cos(angle)-y*sin(angle);
y1 = x*sin(angle)+y*cos(angle);

line(x1,y1,0,0,redcolor);

x = x1;
y = y1;

}while(...);

Why doesn't this work??????? Can sombody out their help me please? Source example might be helpful.

NO FANCY STUFF, Please! I just want straight forward code/info (no matrix and all that).

PS: Does this has to do something about projection? Do I convert x,y before or after?

try this...

float angle;
const float anglei = 3.14159 / 180.0;

int x, y, nx, ny;

x = 100;
y = 0;

for(angle = 0.0; angle < 6.28; angle += anglei)
{
nx = x * cos(angle) - y * sin(angle);
ny = x * sin(angle) + y * cos(angle);
line(nx + 160, ny + 100, 0, 0, redcolor);
}

Now...here were your problems...one small issue may have been the cumulative error of rotating a new vector by 90 degrees every time, instead of rotating the same vector by a different angle. Another problem is you weren't translating the lines to somewhere on screen, so 3 of the 4 lines you were drawing would be off screen. Oh well, I hope this helps...It should draw 360 lines, all the way around point (160, 100), one for each degree from 0 to 359.

This topic is closed to new replies.

Advertisement