Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.



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

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.

Share this post

Link to post
Share on other sites
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);


x = x1;
y = y1;


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?

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites

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