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

Rotation of a point

Started by
3 comments, last by korybricker 24 years, 7 months ago
well i spent months asking the same question i was trying to rotate polygons. i have the answer, but i spent ages looking for it, and so can you.
Advertisement
Nice to see you have embraced the experience/knowledge sharing puprose of this message board. Nice to see that we aren't missing much though seeing as it took you "months" to figure out this problem and I got it after a night of sleep and looking at the code with a fresh set of eyes.

Anyway for anyone in the future that may come across this message and having the same problem, it was because I had defined PI as

const PI = 3.1415926535897932384626433832795;

when I should have done

const float PI = 3.1415926535897932384626433832795;

All I can say is:

kieren, your response to this question was not productive at all. Why do you deserve to laugh in front of someone else who is trying to solve a problem that you have already solved? Although rotation should NOT have taken you "months" to figure out, at least your result might have helped him out.

Meanwhile, although you don't believe in sharing solutions, I see you ask questions on this board that are IN documentation. This at least is not.

Basically, you are a hypocrite, and if you want others to answer your questions in the future, you might as well return the favor every so often.

- Splat

I'm trying to rotate an image around a point and I don't understand whyit isn't woring right or what is happening. The problem is that instead of taking 360 iterations to complete a circle, it only takes 30.

I create a look-up table in the following manner:

for(int x =0; x <360; x++)
{
look_cos[x] = cos(x*(PI/180));
look_sin[x] = sin(x*(PI/180));
}

Later I "plot" some points (actually I am blitting an image but just using the left, top coordinate as the point that is being rotated) in the following manner (not optimized at all because I'm trying to keep it simple until it works):
For this example I just use 3 "steps" and am attempting to have them be just 1 degree appart but they aren't. They are WAY more than just 1 degree off (actually look something closer to 90 degrees apart). Any ideas why?

FYI - 166,165 that I use are the width and height of the image being "rotated"

XPos = 300 * look_cos[0] + (g_DisplayWidth / 2 - (166 / 2));
YPos = 300 * look_sin[0] + (g_DisplayHeight / 2 - (165 / 2));

SetRect(&OutputRect,XPos, YPos, XPos + 166, YPos + 165);
g_pDDSBack->Blt(&OutputRect, g_pDDSSprite, NULL, DDBLT_WAIT | DDBLT_KEYSRC, &ddbltfx);

XPos = 300 * look_cos[1] + (g_DisplayWidth / 2 - (166 / 2));
YPos = 300 * look_sin[1] + (g_DisplayHeight / 2 - (165 / 2));

SetRect(&OutputRect,XPos, YPos, XPos + 166, YPos + 165);
g_pDDSBack->Blt(&OutputRect, g_pDDSSprite, NULL, DDBLT_WAIT | DDBLT_KEYSRC, &ddbltfx);

XPos = 300 * look_cos[2] + (g_DisplayWidth / 2 - (166 / 2));
YPos = 300 * look_sin[2] + (g_DisplayHeight / 2 - (165 / 2));

SetRect(&OutputRect,XPos, YPos, XPos + 166, YPos + 165);
g_pDDSBack->Blt(&OutputRect, g_pDDSSprite, NULL, DDBLT_WAIT | DDBLT_KEYSRC, &ddbltfx);

BTW, you might want to use

#define PI 3.14159...

instead. That way you don't have to worry about casting to match type (I think cos and sin officially take a double). Since you're making a lookup table, it probably doesn't matter that much, but if you end up using PI in other parts of the code it'll work alot more nicely.

My bonehead sin/cos rotating problem was plugging degrees into sin / cos instead of radians. I haven't had any formal math in a while and openGL uses degrees, so I blotted radians and gradients from my memory. I came very close to destroying a perfectly nice 17" monitor with my fist.

-the logistical one-http://members.bellatlantic.net/~olsongt

This topic is closed to new replies.

Advertisement