| |
Oswald
Registered: Apr 2002 Posts: 5094 |
CL13 spring water- how ?
anyone would care to share how the spring math works in there?
I've tried yesterday to make a simple spring, but it very rarely got close to resting, 8 out of 10 tweaks it "blows" up due to something google said is a problem with the euler equation. :)
so yes I'm trying to be lazy here and asking for the solution right away. Arok is less than 2 weeks away and I need to finish this fast :)
I've found verlet method, but dont understand it in the depth thats enough to turn it into 8 bit code.
for reference:
http://gamedevelopment.tutsplus.com/tutorials/make-a-splash-wit..
thanks, |
|
... 5 posts hidden. Click here to view all posts.... |
| |
Copyfault
Registered: Dec 2001 Posts: 478 |
sorry, I f**ked up my last posting, at least the "code part".
Another try ;))
u lda #$40
- cmp $d012
bne -
ldy springhh ;spring height HI byte
ldx springsh ;speed value hi byte for damp calculation
lda acc_lo,y ;0 height is assumed resting
sec ;damp table is 16 bit, x/2^7 signed used to change velocity
sbc damp_lo,x ;formula says "acc = k*x - d*speed"
adc springsl
sta springsl ;spring speed LO
lda acc_hi,y
adc springsh
sbc damp_hi,x
sta springsh ;spring speed HI
lda springhl
clc
adc springsl
sta springhl ;spring height + spring speed 16 bit
lda springhh
adc springsh
sta springhh
sta $d000 ;to see how it moves
jmp u
Maybe your damp-table is a combination of both acc_lo/hi and damp_lo/hi, but how can you get the dependencies right with only one table?
Guess Axis knows best, he's gone through it already.
Let's see where this leads to, I'm alread looking forward to this year's Arok party;) |
| |
JackAsser
Registered: Jun 2002 Posts: 2014 |
Bah, just animate it using delta compressed motion on each column. :) |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
copyfault,
formula says:
float x = Height - TargetHeight;
float acceleration = -k * x;
Position += Velocity;
Velocity += acceleration;
I took targetheight to be 0, so acceleration = damptable(height)
Position += Velocity; this is the last part in my code
Velocity += acceleration; this is the adc damp,x part
aha gotcha ! I mixed things up, I wasnt doing any dampening at all, that was just the normal spring part.
thanks! :) |
| |
Axis/Oxyron Account closed
Registered: Apr 2007 Posts: 91 |
In C my code looks like:
velocity=velocities[x];
for (int dx=-4 ; dx<=4 ; dx++)
{
delta=height[x+dx]-waterplane;
velocity-=delta*weight[dx];
}
velocities[x]=velocity;
height[x]+=velocity*damping;
In my case weight is a gaussian distance table. If you only consider a single value its just a constant that can be used for tweaking. Perhaps it can even be optimized away, because my weight table sums up to 256.
Damping is a constant factor for tweaking motions.
So a simplified version considering only 1 column would look like this:
delta=height[x]-waterplane;
velocities[x]-=delta*weight; ;perhaps weight is 1 and can be removed
height[x]+=velocities[x]*damping;
|
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
thanks that will nail it, basically I should've feed the speed into a table that always reduces it a "bit". |
| |
chatGPZ
Registered: Dec 2001 Posts: 11386 |
Quote:just animate it
that actually seems the correct answer to the original question :=) |
| |
Rudi Account closed
Registered: May 2010 Posts: 125 |
Better do it in C or your language of choice before coding it in assembler. So you have an reference point. If c64 asm-code doesnt work you know its not the algorithm that is wrong. If you dont allready do that.
It takes a few tries to get something up and working. I made a cloth simulation ~10 years ago (in C on PC) and it worked very nicely after many tries. I learned from Hugo Elias also, he still have some of those great articles and pseudocode on subjects like these here:
http://freespace.virgin.net/hugo.elias/models/m_string.htm
and
http://freespace.virgin.net/hugo.elias/models/m_cloth.htm |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
well, adding up a few 16 bit values and a table lookup looked simple enough to go straight for it, the problem rather was I did not fully understand the math, also the article gives a source code without damping and then later talks about damping.
now I've wrote the code by looking at that incomplete source snippet.
animating it is out of the q, in fact its simpler to make this realtime imho. why animate stuff thats a few dozens of 16 bit adds and table lookups.
remember kids, realtime rules :) |
| |
Digger
Registered: Mar 2005 Posts: 437 |
Oswald, here you can edit the code online and strip it out until you get the idea :) http://paperjs.org/examples/future-splash/ |
| |
Martin Piper
Registered: Nov 2007 Posts: 722 |
Verlet maths can be quite sensitive to numerical accuracy because small numerical errors can get magnified quite quickly without suitable damping.
For example https://github.com/martinpiper/C64Public/blob/master/Verlet/Tes.. |
Previous - 1 | 2 - Next |