Archived

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

EagleWarrior

Rotating a missle around the fighters center

Recommended Posts

i want to add some missles on my FIghter object. I want to rotate the missle around the Fighters center. I will initilize the pos of the missle to where i want it to be on the fighter. All i want is for the missle to rotate around the objects center , translating will be easy. and when i fire the missle i will initilaze its own local axis. thxs

Share this post


Link to post
Share on other sites
I think you do circular motion like this (not tested):


  
//create this variable outside of the main loop

int degrees = 0;

//////////////////////////


//degrees cycles up to 360, then resets to 0

degrees += (degrees == 360) ?-360:0;

//circle information

int center_x = 300;
int center_y = 300;
int radius = 10;

//ypos will have a max of center_y + 10, min of center_y - 10

int ypos = center_y + sin(degrees)*radius

//xpos will have a max of center_x + 10, min of center_x - 10

int xpos = center_x + cos(degrees)*radius

//xpos and ypos give you are your new co-ordinates on the circle to blit to!


Share this post


Link to post
Share on other sites
yeah. It''s more trigonometry - uses the unit circle phenomenon.

Basically, the degree variable counts up from 0 to 360, then at 360 resets to 0. This represents the rotation angle.

Imagine that your rotation angle is a line extending from the centre of the circle, moving along the circumference of the circle. That''s the path you want the missile to take. As the degree changes, the trigonometric functions of cosine and sine change as well.
It would take a couple hours to explain the unit circle, but basically, sin(degrees)*radius returns the y-coordinate for that rotation angle, and will never be further from the circle''s center than the radius length. cos(degrees)*radius returns the x-coordinate for that rotation angle, and also has a maximum distance from the centre of the radius length.

I''m not sure which language you using, but often you''ll need the degree angle in radians. To convert from degrees to radians, multiply the degree number by (pi/180) before you use it in a sin() or cos() function.

Share this post


Link to post
Share on other sites
If you are using C++ and can implement lists and trees you can make the missile a "child" of the fighter and give it a local matrix in "fighter space" - get your update routines to transform first by the parents world matrix then the child local matrix and you won''t have to rotate the bugger at all - it will do it automatically. When the missile is fired simply unlink it from the parent. Unfortunately this is a little more complex to implement than it is for me to suggest as I have here. It took me ages to get close to doing this and most of it was reading about linked lists which are pretty boring but invaluable tools. You may want to think about it for future endeavours.

-

Geocyte Has Committed Suicide.

Share this post


Link to post
Share on other sites