Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Making smooth curve movements
2010-10-21 19:50
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 ?
2010-10-21 19:57
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.
2010-10-21 20:27
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...
2010-10-21 20:33
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]
}

2010-10-21 21:32
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.
2010-10-22 03:02
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...
2010-10-22 05:21
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?)

2010-10-22 05:44
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
2010-10-22 07:30
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.


2010-10-22 08:09
Devia

Registered: Oct 2004
Posts: 401
yes, but again: how would you calculate those tables?
2010-10-22 08:57
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
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Mike
psych
The Human Co../Maste..
Peacemaker/CENSOR/Hi..
iAN CooG/HVSC
MWR/Visdom
t0m3000/hf^boom!^ibx
Acidchild/Padua
E$G/HF ⭐ 7
Guests online: 125
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.6)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 Dawnfall V1.1  (9.5)
7 Rainbow Connection  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Censor Design  (9.3)
5 Triad  (9.3)
Top Diskmag Editors
1 Magic  (9.8)
2 hedning  (9.6)
3 Jazzcat  (9.5)
4 Elwix  (9.1)
5 Remix  (9.1)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.044 sec.