Sprite Momentum

Hi

Can anyone point me in the right direction for finding some example Sprite
Momentum code.

I would like to be able to set a sprite in motion, headed towards a defined
location. I would like to be able to specify how long (in time) it should
take to get there. I would also like to be able to specify acceleration and
deceleration rates.

I’m sure I could find what I’m looking for, just not exactly sure what to
look for in the first place!

Many thanks in advance for any guidance I might receive.

Regards,

Steve Lupton**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com


What kind of accuracy is required, and what kind of control system are
you using? (Fixed frame rate, frame rate adaptive, or decoupled?)

The “Spitfire Engine” used in Kobo Deluxe uses basic 2D <position,
velocity, acceleration> points, which might be useful. (That part in
itself is very trivial.) The coordinates are 24:8 fixed point, which
isn’t incredibly accurate, but OTOH, you can fix the internal frame rate
to guarantee deterministic results regardless of computer speed or frame
rate. (Output graphics coords are interpolated to utilize the full
rendering frame rate, so the internal frame rate has no effect on
animation smoothness.)

As to the calculation of acceleration/speed curves, you might find some
interesting equations in control engineering papers related to
AC/DC/stepper motor servo systems. That kind of calculations are done by
most of the servo modules used in [C]NC machines. (You configure max acc.

  • decc., and then just send <speed, position> commands to the controller.)

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Friday 26 October 2001 10:01, Steve Lupton wrote:

Hi

Can anyone point me in the right direction for finding some example
Sprite Momentum code.

I would like to be able to set a sprite in motion, headed towards a
defined location. I would like to be able to specify how long (in time)
it should take to get there. I would also like to be able to specify
acceleration and deceleration rates.

on 10/26/01 3:01 AM, Steve Lupton at SL at cre.co.uk wrote:

Hi

Can anyone point me in the right direction for finding some example Sprite
Momentum code.

I would like to be able to set a sprite in motion, headed towards a defined
location. I would like to be able to specify how long (in time) it should
take to get there. I would also like to be able to specify acceleration and
deceleration rates.

I’m sure I could find what I’m looking for, just not exactly sure what to
look for in the first place!

I’m brand new to game programming and I’m finding myself stumped on a lot of
stuff like this. I’ve looked at all the sites like gamasutra, gamedev, etc,
but I’m not really finding what I’m after. Source code to other games isn’t
as helpful as I’d like (although it has helped). So if anyone can point out
some stuff I’d be very grateful :slight_smile:

Right now I’m just making my game blind folded and I just know I’m doing
most everything very poorly :slight_smile:

Matt_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

uh… difficult, i don’t really understand what do you need,
mathematics ?

for a constant speed, just divide lenght by time to have it !

with a given acceleration ‘a’ in a time ‘t’ you travel a distance ‘x’ =
1/2 a t^2

hope this help…

The most common error is probably sprinkling the whole place with low
level animation and control stuff…

Try using a common class or struct for all sprites, and perhaps other
objects as well, if any. Something like this:

struct gfx_object_t
{
	float	x, y;	/* Position */
	float	vx, vy;	/* Speed (pixels/CS frame) */
	float	ax, ay;	/* Acceleration (pixels/(CS frame)^2) */

	float	aframe;	/* Current sprite image frame */
	float	afirst;	/* First frame in loop */
	float	alast;	/* Last frame in loop */
	float	aspeed	/* Animation speed (ms/frame) */

	/*
	 * Called once per CS frame
	 */
	void	(*frame)(struct gfx_object_t *me);

	/*
	 * Called when collision is detected
	 */
	void	(*hit)(struct gfx_object_t *me,
			struct gfx_object_t *other);

	...
	...
	...
};

Note that using floats is the easy way. If you end up doing lots of
float<->int conversions all the time, fixed point would be significantly
faster. For heavy physics and other calculations, sticking with float
might still be a good idea.

After that, you just build your game around that struct. Build game logic
into these objects (rather than around them), to keep things simple and
object oriented. (Keeping track of dynamically allocated objects “from
the outside” quickly gets very messy, and easilly results in hard to
find pointer bugs.)

Extend the struct as required, but keep in mind that adding generally
useful functionality, rather than game specific features will make your
code simpler and easier to maintain in the long run, even if you have to
spend slightly more time thinking before hacking away.

One very important rule, that applies to all (serious) forms of
programming:

NEVER underestimate the importance of clean, readable code!

Games with messy code are rarely finished, especially not if no one is
paying to get it done. Hunting stupid spaghetti induced bugs for ten
hours after every minor change quickly becomes very boring.

No, you won’t remember what you were thinking the next time you look at
that code. Trust me. :slight_smile:

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Friday 26 October 2001 16:58, Matt Greer wrote:

on 10/26/01 3:01 AM, Steve Lupton at SL at cre.co.uk wrote:

Hi

Can anyone point me in the right direction for finding some example
Sprite Momentum code.

I would like to be able to set a sprite in motion, headed towards a
defined location. I would like to be able to specify how long (in
time) it should take to get there. I would also like to be able to
specify acceleration and deceleration rates.

I’m sure I could find what I’m looking for, just not exactly sure
what to look for in the first place!

I’m brand new to game programming and I’m finding myself stumped on a
lot of stuff like this. I’ve looked at all the sites like gamasutra,
gamedev, etc, but I’m not really finding what I’m after. Source code to
other games isn’t as helpful as I’d like (although it has helped). So
if anyone can point out some stuff I’d be very grateful :slight_smile:

Right now I’m just making my game blind folded and I just know I’m
doing most everything very poorly :slight_smile:

> The most common error is probably sprinkling the whole place with low > level animation and control stuff...

Yeah, but it works. :wink:

-bill!
(typically too lazy to worry about programming… too busy writing games! :wink: )On Fri, Oct 26, 2001 at 05:39:41PM +0200, David Olofson wrote:

Yeah, until it’s so messy you can’t keep track of it… :slight_smile:

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Friday 26 October 2001 18:46, William Kendrick wrote:

On Fri, Oct 26, 2001 at 05:39:41PM +0200, David Olofson wrote:

The most common error is probably sprinkling the whole place with low
level animation and control stuff…

Yeah, but it works. :wink:

Hehe… you know how the guys in “The Matrix” can read that crap flying
all over those green screens? (I think that’s Perl, by the way)

Heheh… that movie was cool.

-bill!On Fri, Oct 26, 2001 at 07:32:59PM +0200, David Olofson wrote:

Yeah, until it’s so messy you can’t keep track of it… :slight_smile:

“William Kendrick” a ?crit dans le message news:
mailman.1004117951.10213.sdl at libsdl.org…> On Fri, Oct 26, 2001 at 07:32:59PM +0200, David Olofson wrote:

Yeah, until it’s so messy you can’t keep track of it… :slight_smile:

Hehe… you know how the guys in “The Matrix” can read that crap flying
all over those green screens? (I think that’s Perl, by the way)

Heheh… that movie was cool.

-bill!

No Exitenz was better.