| |
SIDWAVE Account closed
Registered: Apr 2002 Posts: 2238 |
Making smooth curve movements
K, so i want to make some kinda smooth curves to move sprites along.
I know I could use specially tailored sinus data, but then i still have to code something to do the movement exactly as i want it.
So i consider to make a small movement recorder, where i move a sprite with a joystick, and record the path.
So, now comes the hard part: if i record some (as perfect as can be) movement (a path), then how could i flatten out the recorded data afterwards, so my imprefect drawn move, becomes super smooth ?
This is some math i know nothing about, anyone ? |
|
| |
chatGPZ
Registered: Dec 2001 Posts: 11386 |
interpolation using splines comes into mind.
a simple thing you can try is running a lowpass filter over your recorded data, that might already make it good enough. |
| |
Mr. SID
Registered: Jan 2003 Posts: 424 |
You can find lots of information about splines on the Internet. Try Wikipedia.
There are many different kinds of splines, depending on how you want your curve to look.
In all of these, you basically use control points to define the shape, and optionally vectors at the points to define the tangent of the curve at the control points, you might know that from vector graphics apps such as Illustrator or Corel Draw.
Some algorithms will make sure that the curve touches each control point, and others will only approximate the control point, but never really reach them.
I would start with a simple 4 point bezier curve:
http://en.wikipedia.org/wiki/Bezier_curve
If you get that, then you can do more advanced stuff... |
| |
Pantaloon
Registered: Aug 2003 Posts: 124 |
some kickassembler macros for doing interpolation.
.function linear(a,b,t)
{
.return [a*[1.0-t]] + [b*t]
}
.function cosine(a,b,t)
{
.var ft = t * PI
.var f = [1.0 - cos(ft)] * 0.5
.return [a*[1.0-f]] + [b*f]
}
.function catrom(a,b,da,db,t)
{
.var t2 = t * t
.var t3 = t * t2
.return a * [2.0 * t3 - 3.0 * t2 + 1.0] +
b * [3.0 * t2 - 2.0 * t3] +
da * [t3 - 2.0 * t2 + t] +
db * [t3 - t2]
}
.function cubic(a,b,t)
{
.var t2 = t * t
.var t3 = t * t2
.return a * [2.0 * t3 - 3.0 * t2 + 1.0] + b * [3.0 * t2 - 2.0 * t3]
}
|
| |
Devia
Registered: Oct 2004 Posts: 401 |
Splines in C=Hacking Issue #20
I guess you could also draw your path in any 3D prg or even MS Paint using splines, and export/convert the data to usable sprite coords.
Or you could go get something like this and just plot in your known coords in Excel and have it generate a complete coordinate table for you.
...which makes me wonder why Excel doesn't have functions for this already, as it clearly uses similar algorithms for displaying various types of graphs. |
| |
Frantic
Registered: Mar 2003 Posts: 1648 |
Yet another way is to work with acceleration variables. So... You have a table (one for x-movement and one for y-movement) that specifies. "Add XX to movement speed x-wise for YY frames". If XX is negative, it will be a deacceleration and if it results in "negative" speed, then it becomes a movement in the other direaction. Even though you would have to tweak some values to get it exactly the way you want to, it will at least be quite easy to do so, since everything is specified by simple tables.
Since the movement will not just be "on/off", but a matter of gradual acceleration and deacceleration, the movements will be curved and smooth.
Just a thought... |
| |
Devia
Registered: Oct 2004 Posts: 401 |
yes but... it's quite early so maybe i'm a bit daft.. how do you calculate anything that would give you tables for this purpose? (or am I missing the point?)
|
| |
Hein
Registered: Apr 2004 Posts: 954 |
Quote: Yet another way is to work with acceleration variables. So... You have a table (one for x-movement and one for y-movement) that specifies. "Add XX to movement speed x-wise for YY frames". If XX is negative, it will be a deacceleration and if it results in "negative" speed, then it becomes a movement in the other direaction. Even though you would have to tweak some values to get it exactly the way you want to, it will at least be quite easy to do so, since everything is specified by simple tables.
Since the movement will not just be "on/off", but a matter of gradual acceleration and deacceleration, the movements will be curved and smooth.
Just a thought...
I find that a good approach for realtime curves:
See here |
| |
Slammer
Registered: Feb 2004 Posts: 416 |
Working with accelerations can give you movements of a second degree polynomial. If you spice it up a bit and use acceleration on the acceleration you can have third degree polynomials which makes it possible to do Bezier/Hermite spline movements in realtime without doing one single multiplication and without having to use large memory areas for tables.
|
| |
Devia
Registered: Oct 2004 Posts: 401 |
yes, but again: how would you calculate those tables? |
| |
Slammer
Registered: Feb 2004 Posts: 416 |
Siggraph have some material on splines, but if you are not familiar with the subject I guess this stuff can be hard to read (try searching for better pages).
http://www.siggraph.org/education/materials/HyperGraph/modeling..
|
... 18 posts hidden. Click here to view all posts.... |
Previous - 1 | 2 | 3 - Next |