View Full Version : Verlet integration
Benek 06-30-2010, 05:30 AM Whilst searching some stuff, I came across Verlet Integration and wondered if it was possible to do something with it in Cinema. I've spent some time thinking about how to get a basic formula working but I haven't managed to figure it out. Would anybody know whether this is possible using Xpresso and/or Coffee? I'm trying to animate movement based on an object's current and previous positions...
New position = (2 x Current position - previous position) + acceleration x t²
x¹ = 2x - x* + a·Δt²
x* = x
x¹= new position
x = current position
x* = previous position
a = acceleration
Δt = time step
Here's the link...
http://www.gamasutra.com/resource_guide/20030121/jacobson_01.shtml
|
|
Scott Ayers
07-01-2010, 12:43 AM
There are ways to store the value of an object's position in both xpresso and coffee. And then use the distance node or vlen() function to subtract them. And then do something with that value later on.
But the way you want to carry this all out is kind of important to know in order to give you a more specific answer.
Perhaps if you explained how you want to do the animation rather than the mathematical formula. Someone might reply?
-ScottA
Darter
07-01-2010, 03:51 AM
Here's a quick translation of the formula into COFFEE code for a single position. Arrays could be used for multiple values. The acceleration variable has been initialized with an arbitrary value but for meaningful application you'll need something like the force accumulation function in the Gamasutra example.
var framePrev;
var posPrev;
main(doc,op)
{
// allow pos to be reset at current frame
var frame = doc->GetTime()->GetFrame(doc->GetFps());
if(!framePrev) framePrev = 0;
var pos = op->GetPosition();
if(frame == framePrev) posPrev = pos;
// calculate new position
var accel = vector(0, 1, 0);
var timeStep = 0.5;
var temp = pos;
if(!posPrev) posPrev = pos;
pos += pos - posPrev + accel * timeStep * timeStep;
doc->StartUndo();
doc->AddUndo(UNDO_CHANGE, op);
op->SetPosition(pos);
doc->EndUndo();
framePrev = frame;
posPrev = temp;
}
Benek
07-01-2010, 06:55 AM
Thanks Darter, I'll look into this a let you know how I get on.
Scott, at the moment I have no specific ideas on how I plan to use this... I was just experimenting, this came up and I couldn't resolve it... and sometimes I just can't let things go until I find an answer.
For now, I'm just trying to perform the function on any object, like a cube or vertex. I've set up a quick Xpresso file which seems to function. The thing that confuses me is taking an object's current position and feeding it a new position in the same expression – my Xpresso lags by 1 frame/step, but I don't think I can help that... It's also quite unstable
CGTalk Moderation
07-01-2010, 06:55 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.