PDA

View Full Version : Circles.



Joe123
10-13-2007, 05:25 AM
Circles, circles, circles.
I want an FFC that moves in a circle. So I tried the traditionnal (or at least, one that I've seen around here) Sine and Cosine response:

ffc script circle{
void run(){
int n = 1;
while(true){
this->X = Cos(n);
this->Y = Sin(n);
n++;
Waitframe();
}
}
}

Which didn't work. Just had the ffc jerking around in the top left hand corner.

Then I thought I'd try a different approach. On digging out my notes from maths yesterday: The general equation of a circle is
(x-a)^2+(y-b)^2 == r^2
Where the coordinates of the cerntre of the circle are (a,b), r is the radius and x&y are the variables as per usual.
So I plugged this into zscript (which I'm sure I did do very wrong)
giving me:

ffc script circle{
void run(){
int n = 1;
while(true){
9 == (n-100)^2 + (n-100)^2;
n++;
Waitframe();
}
}
}

Which won't even compile; apparently it can't cast from bool to float on the line with the equation. If I knew what that meant...

Also, if I'm just doing mathematics in a script, can I just use the normal brackets for them (obviously I need brackets here) or do they clash because they have seperate functions also?

DarkDragon
10-13-2007, 12:43 PM
The problem with your sine/cosine script is that your circle is centered at (0,0), which is the top left of the screen.

You can use the Cartesian equation you mentioned, but the formula you have, (x-a)^2+(y-b)^2 = r^2, is an implicit equation; when using programming languages you must change it into an explicit equation, ie, one where you have solved for x and y. One way to do this for the circle is
y = t
x = a + sqrt(r^2 - (t-b) ^ 2 )

You can try using this formula, but you will see that it has two distinct disadvantages over the usual polar equation:
1) You only get half of the circle. The reason is clear: when you solved for x, you had to take a square root, losing half of the solution.
2) The curve is not parametrized by arc length; in other words, the FFC's speed is not uniform. It is easy to check that the polar circle equation does have arc-length parametrization.

Gleeok
10-13-2007, 08:35 PM
There's some useful info about rotating ffc's in this (http://www.armageddongames.net/forums/showthread.php?t=98975) thread also.

Here's one that I was using:


ffc flame1 = Screen->LoadFFC(n);
npc shieldy = Screen->LoadNPC(1);
shieldy->HP = enemyHP;
this->X = shieldy->X;
this->Y = shieldy->Y;

flame1->X = this_ffc->X + (radius * Sin(wobble*speed));
flame1->Y = this_ffc->Y + (radius * Cos(wobble*speed));
wobble++;


It stay's centered on an enemy while rotating.

Joe123
10-14-2007, 06:17 PM
Ahhh, I hadn't given it a radius. That probably didn't work so well then. I'll check this out in a bit.