Make any actor orbit a given coordinate or around another actor (whether canvas, normal, wire frame region or fill region).
BASIC INFORMATION
void orbitActor (Actor *theActor, double orbStep, int orient, double cenX, double cenY, double radius)
theActor - The Actor that does the orbitting. Use ampersand with your actor name to use in function [ e.g. orbitActor ( &yourActorName,... ) ]
orbStep - The incremental step for your orbit in degrees (e.g. 0.5 will advance by half a degree each time you call the function).
orient - The orientation for your orbit. 1 = Orbit clockwise, -1 = Orbit anti-clockwise.
cenX, cenY - The central point about which your actor will orbit. This can be any x,y coordinate or x,y position of another actor.
radius - The distance in pixels from the central point set by cenX & cenY.
CODE USAGE
1. Create an actor variable with a real value, call it: orbAngle.
(script > Global Code > Variables > ADD. Click Name > type: orbAngle. Click Integer > select Real, Click Global > select Actor variable, Click ADD).
2. Add the global code below as orbitActor (or whatever you want).
- Code: Select all
void orbitActor (Actor *theActor, double orbStep, int orient, double cenX, double cenY, double radius)
{
double dx=0.0; double dy=0.0;
orbAngle+=orbStep; orient*=-1;
dx=radius*orient*sin(degtorad(orbAngle)); dy=radius*cos(degtorad(orbAngle));
theActor->x=dx+cenX;
theActor->y=dy+cenY;
if(orbAngle>359){ orbAngle=0; }
if(orbAngle<0){ orbAngle=359; }
}
3. Create your actors and call the orbitActor() function.
EXAMPLE
Got 2 actors, TEST1 & TEST2.
When space key pressed make TEST2 orbit TEST1. Make TEST1 orbit point x=50, y=50.
Advance orbit by 1 degree steps clockwise. TEST2 at 50 & TEST1 at 100 pixel distance.
SPACE KEY down event of TEST1:
- Code: Select all
orbitActor(&TEST1, 1, 1, 50, 50, 100);
SPACE KEY down event of TEST2:
- Code: Select all
orbitActor(&TEST2, 1, 1, TEST1.x, TEST1.y, 50);
* You can make any type of actor orbit any point or any actor, whether they are fill/wire regions, canvas or normal.
* Remember to put the "&" in front of the actor you use in the orbitActor function.