Archived

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

DeadlyPencil

need some help with rotating objects in circles

Recommended Posts

right now in my program i have a tank bottom that i wish to rotate... i used a formula to find out all the y coordinates that matched the x coordinates around the circle and redrew my tank bottom(a sqaure) based on that... it would fine rotating but as i move around the circle my sqaure gets skinner and stuff here is a pic of it in its starting position... here is a pic of it at is skinnest piont... (it will get bigger than smaller and stuff) those red line are there just to make sure its rotating proporly and stuff... can any of you guys explain to me why it gets skinny, mabe how to solve it or how you would go about spining an sqaure inside a circle. thanx [edited by - deadlypencil on May 5, 2002 1:05:17 PM]

Share this post


Link to post
Share on other sites
if you want to rotate 2D polygons use those formulas:

new_x =
(old_x - ox)*(cos(angle*DEGTORAD)) - (old_y - oy)*(sin(angle*DEGTORAD)) + ox;

new_y =
(old_y - oy)*(cos(angle*DEGTORAD)) + (old_x - ox)*(sin(angle*DEGTORAD)) + oy;

note that ox and oy are respectivly the X axis and the Y axis cooridinates of the point you want to rotate your object around.

tell me if you want a mathematical proof for those .

[edited by - xeno on May 5, 2002 1:31:07 PM]

Share this post


Link to post
Share on other sites
umm ok ill try and get that to work... what do i have to include to use sin/cos???

[edit]soooo... if i want to rotate it aroudn like point 50,50... my ox and oy would be teh 50,50 then?[/edit]

[edited by - stickman on May 5, 2002 1:59:17 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by stickman
umm ok ill try and get that to work... what do i have to include to use sin/cos???



Math.h

quote:

[edit]soooo... if i want to rotate it aroudn like point 50,50... my ox and oy would be teh 50,50 then?[/edit]

[edited by - stickman on May 5, 2002 1:59:17 PM]



Yep .

Share this post


Link to post
Share on other sites
it doesn''t seem to be working....
the point is originally at about 135 degrees

and the xy is 50,50

when i change the angle to 150 degrees the x coord becomes 85 with your formula... the x should be going down not up...

can anyone help?


<div CLASS=source>
 



if (KEYDOWN(VK_LEFT))
{
angle=angle+10;
old_x = p1.tl_sq_x;
old_y = p1.tl_sq_y;
p1.tl_sq_x =(old_x - p1.clo_gun_x)*(cos(angle*DEGTORAD)) - (old_y - p1.clo_gun_y)*(sin(angle*DEGTORAD)) + p1.clo_gun_x;
p1.tl_sq_y =(old_y - p1.clo_gun_y)*(cos(angle*DEGTORAD)) + (old_x - p1.clo_gun_x)*(sin(angle*DEGTORAD)) + p1.clo_gun_y;
}


</div>

Share this post


Link to post
Share on other sites