Re: [stella] acceleration and inertia

Subject: Re: [stella] acceleration and inertia
From: Manuel Rotschkar <cybergoth@xxxxxxxx>
Date: Wed, 07 Jan 2004 08:59:29 +0100
Hi there!

> When I start thinking about modeling all these 
> attributes I can't help but start to roll my eyes over 
> the sheer amount of processing it will take to get to 
> the point where I apply a change to the x and y of 
> each car.

> Any tips?

Don't start with the full blown thing. Start with the 
very basic things, that is:

X-Postion
Y-Position

X-Speed
Y-Speed

For your needs, The Position values are two bytes:

X-Pixel and X-Float
Y-Pixel and Y-Float

And the Speed is basically the sum of all other effects 
like traction and acceleration.

Now. Assume we're driving straight right and all we 
consider is "full" speed:

X-Speed = 100
Y-Speed = 0

So we can ignore th Y-Axxis for the moment.

Look at this code snippet

    LDA xPosfloat,X	; Load current float value
    CLC
    ADC xPosadd,X    ; Add current speed
    STA xPosfloat,X  ; Save current float value

    LDA xPosabs,X	; Load absolute x pixel position
    ADC #$00		; If float value exceeded 255
    STA xPosabs,X    ; Increment it by one
    STA xPosabs,X    ; Store away pixel position

What the code does is this:

Frame 1:
XPos   = 0
Xfloat = 100

Frame 2:
XPos   = 0
Xfloat = 200

Frame 3:
XPos   = 1
Xfloat = 45

Frame 4:
XPos   = 1
Xfloat = 45

Frame 5:
XPos   = 1
Xfloat = 145

Frame 6:
XPos   = 1
Xfloat = 245

Frame 7:
XPos   = 2
Xfloat = 90

...

You see, it's moving a pixel ~ every 2.5 frames.

Now this has everything moving 0-1 pixel per frame.

To achieve higher Speeds, just add the addvalue 2 or 3 
or more times per frame.

To get the basic movement of your car going like this 
for the start, you'd need tables for every possible 
angle like in:

up     x=0  *speed,    y=1  *speed
down   x=0  *speed,    y=-1 *speed
left   x=-1 *speed,    y=0  *speed
right  x=1  *speed,    y=0  *speed

So you'd divide 360 by any "power of 2" of your choice 
and calculate the sine and cosine values for each of 
these angles. Above is the simplest case for 360/4, 
you'l probably need 360/16 or 360/32.

Hm...

Ok, that was just a quick start to get you an idea.

Greetings,
	Manuel

----------------------------------------------------------------------------------------------
Archives (includes files) at http://www.biglist.com/lists/stella/archives/
Unsub & more at http://www.biglist.com/lists/stella/


Current Thread