Skip to main content
GameDev.net gamedev.net
🔒 Locked

Curve Approximation VS Parametric Eqs

Started by Ctank02 Dec 19, 2010 at 1:11 PM 5 replies 2.3k views
Original Post
Ctank02
Ctank02
I've searched around the site and found quite a few posts about this but nothing ever really seems to come to a definite closure.

I have been tinkering with a Galaga clone in XNA/C#. I've got all the basics working, but I want the enemies to move in patterns like we saw in Galaga and other games.

I've seen people mention things like Bezier Curves and B Splines. Unfortunately, at least with Bezier--not very familiar with B splines, it uses all of the control points to interpolate the smoothed curve. In other words, making a curve like the one seen here: http://mathforum.org/mathimages/index.php/Parametric_Equations (Butterfly curve), would be impossible. From what little I gathered about B splines, it seemed like they had some of the same properties (I know by definition, Bezier curves can be made entirely out of B Splines).

Unfortunately, get parametric equations like the one below to map to the window space is rather annoying:
float x = (float)(3 * Math.Sin(elapsedTime * 5));float y = (float)(3 * Math.Cos(elapsedTime * 3));


Any ideas or suggestions? Has anyone successfully created a clone with the patterns? What approach did you take?
Zahlman
Zahlman
Quote:
Original post by Ctank02
I have been tinkering with a Galaga clone in XNA/C#. I've got all the basics working, but I want the enemies to move in patterns like we saw in Galaga and other games.

Unfortunately, get parametric equations like the one below to map to the window space is rather annoying:
*** Source Snippet Removed ***


... Have you actually played Galaga? Enemies go off-screen all the time. :) Seriously though, for movements that are supposed to include things that look "circular", I would use parametric equations, and stick with splines for things that are supposed to look more "parabolic". (Words in quotes because I am being very hand-wavy about the aesthetics.) You should be able to figure out the bounds of parametric functions that use 'sin' and 'cos' pretty easily; try substituting {-1, 0, 1} for the sin and cos terms and see what yields the minimum and maximum x/y values.

You might also consider implementing "homing" rather than a particular pre-determined path: each physics update, set the object's acceleration to be towards the target. (You may also need to implement some kind of friction/drag for these enemies so they do not get ridiculously fast.)
Ctank02
Ctank02
The issue I am having with items like sin and cos is that they only go from -1 to 1 from 0 to 2*pi. The issue is scaling the function to the screen but still controlling the speed of the enemy (You don't want them to gain 'uber' speeds at local min and maxes of the function).


Obviously, I could mark out every single point I want the enemy to hit, but that doesn't seem like the approach that the original creators probably took (not to mention it seems tedious and not very portable).



daydalus
daydalus
If you are using XNA, you can always use the Curve class. You can use this to "normalize" the curve to your x and y coordinates

Iterate through the Sin or Cos function to specify your CurveKeys.

Or you could oscillate your velocity to positive and negative values, then put a clamp on it so you don't go faster than a set speed.

I can post some code if you still need ideas -
-Building DIY games since 2010. Daydalus.net
alvaro
alvaro
I would stick to cubic splines for everything. Any smooth motion can be approximated well by cubic splines, and editing the paths is actually pretty easy (you can even make a graphical editor).

Start by implementing Catmull-Rom splines and you'll see that you can have very natural=looking movements without much effort.
relsoft
relsoft
Quote:
Original post by alvaro
I would stick to cubic splines for everything. Any smooth motion can be approximated well by cubic splines, and editing the paths is actually pretty easy (you can even make a graphical editor).

Start by implementing Catmull-Rom splines and you'll see that you can have very natural=looking movements without much effort.


I second this.

Unlike Beziers Catmull-Roms go through it's control points. You could just even randomize your control points, give values to the last 2 and the first 2 as your destination and start coords and your galaga insects would move naturally.


Hi.
Ctank02
Ctank02
Thanks for the replies guy. I think I can use the XNA curve editor (found on their site) and some spiffy tricks to do what I want, but I plan on looking into the Catmull-Rom splines mentioned.

I will post what worked out best for me once I get the level architecture finished.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.