Topic: Vector Math/Moving Animations Pages that link to <a href="https://ozoneasylum.com/backlink?for=11426" title="Pages that link to Topic: Vector Math/Moving Animations" rel="nofollow" >Topic: Vector Math/Moving Animations\

 
Author Thread
Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

IP logged posted posted 06-16-2003 21:19 Edit Quote

Hello,
I'm currently trying to create a kind of simulation...
anyhow, I want to be able to say to an object: move to X. Then the object's supposed to speed up a bit (up to a maximum speed), start to slow down at the right location and the right amount, until it hit's X (where it's supposed to stand still).
Now, this will be in three-d, but for now, I'm doing it in one dimension, just to get started.

But I can't seem to get the brake condition right, it starts to brake one 'tick' early (and I should say that there's a limit to deltaDeltaV (ie. the acceleration) as well), then finds that it's stopped motioning to early, starting up again.. etc. looks a bit jumpy.

Has any of you done something along these lines?
I'd sure appreciate some help.
(uh, and don't assume that the object is stationary when receiving the order... it might have already had a target location, that now no longer is valid, or maybe had to evade some other object...)

so long,

Tyberius Prime

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

IP logged posted posted 06-17-2003 08:50 Edit Quote

what, no one ever done anything like that?

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

IP logged posted posted 06-18-2003 23:17 Edit Quote

ok, I got a pretty well working one now,
only, if I reassign a new target in mid flight,
it sometimes happens that it keeps on deaccelerating right of the screen, and never comes back.
Somehow I can't find a way to fix it.
here's my code so for

code:
procedure TBasicObject.adjustDeltaVToTarget();
var targetPosConnection: TGLCoordinates;
var distanceToTarget: single;
var ticksToTarget,ticksToBrake: single;
var newVector: TVector4f;
var angle: single;
var oldDeltaVLength: Single;
begin

if self.fpos.Equals(self.fTarget.AsVector) then
begin
self.deltaV.X := 0;
self.deltaV.y := 0;
self.deltaV.z := 0;
end
else
begin
targetPosConnection := TGLCoordinates.Create(nil);
targetPosConnection.X := self.fTarget.X - self.fpos.X;
targetPosConnection.y := self.fTarget.y - self.fpos.y;
targetPosConnection.z := self.fTarget.z - self.fpos.z;
distanceToTarget := targetPosConnection.VectorLength;

if Self.deltaV.VectorLength = 0 then
ticksToTarget := Infinity
else
begin
ticksToTarget := (distanceToTarget / self.deltaV.VectorLength)
end;

ticksToBrake := (self.deltaV.VectorLength / self.maxDeltaVDelta);

if (ticksToBrake >= ticksToTarget) then //this is the one that seems to go wrong when the glowbee keeps on 'deaccelerating' till all eternity...
begin
if distanceToTarget < self.maxDeltaVDelta then
begin
self.deltaV.Initialize(targetPosConnection.AsVector)
end
else
begin
angle := VectorAngleCosine(targetPosConnection.AsAffineVector,deltaV.AsAffineVector);
oldDeltaVLength := self.deltaV.VectorLength;
self.deltaV.AddScaledVector(-1 * Self.maxDeltaVDelta / targetPosConnection.VectorLength,targetPosConnection.AsVector);
if self.deltaV.VectorLength > self.maxDeltaV then
self.deltaV.AddScaledVector(-1,targetPosConnection.AsVector)
end;
end;
end
else
begin
targetPosConnection.Scale(Self.maxDeltaVDelta / targetPosConnection.VectorLength);
self.deltaV.AddScaledVector(1,targetPosConnection.AsVector);
if self.deltaV.VectorLength > self.maxDeltaV then
self.deltaV.AddScaledVector(-1,targetPosConnection.AsVector);
end;
targetPosConnection.Free;
end;
end;



Thank you for your replies,

Tyberius Prime

Bmud
Bipolar (III) Inmate

From: Raleigh, NC
Insane since: Mar 2001

IP logged posted posted 06-19-2003 09:08 Edit Quote

I've been trying to do this for a long long time myself. I'll look through your code more when I've the time for it.

For now I've used this thought process:

V = the current velocity
function go { multiplies a force >1 by the current velocity }
function stop { multiplies a force <1 by the current velocity }

So then it's a matter of thinking about
+ What distance does it take for the entire thing to accelerate?
+ Is that distance the same for desceleration?
+ If the object is going a distance that is not long enough to fit both distances how should the functions overlap or better yet find a way to switch off in the middle?
+ If the target location suddenly changes to an opposite direction will my code be able to accomodate by decelerating and accelerating?

This is just without getting into the trig or anything like that. So you tell me? Are we on the same pageor no?

Shine and shine. :: [Cell=992] :: [See my team's 30 second animation!! ]

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

IP logged posted posted 06-19-2003 13:45 Edit Quote

more or less.
Only that I'm looking each tick wether I'm supposed to be accelerating or deaccelerating.
(And I'm de/accelerating by building a vector from *here* to *target* and scaling that down to 'maxAccelerationPerTick', (-*1 for deacceleration)) and adding it to the current velocity.
looks quite nice, like flying curves and stuff.
Only problem is, at times it decides that it's got to keep on deaccelerating... until it misses the point and keeps on deaccelerating even more. never comes back either.

Dracusis
Maniac (V) Inmate

From: Brisbane, Australia
Insane since: Apr 2001

IP logged posted posted 07-08-2003 01:30 Edit Quote

Damn, I usualy check this forum often but I've been so busy lately...

Anyways, have a read through these pages:
http://www.jmckell.com/

SOme really nice stuff about animaion and maths there. Even a bit on 3D.

The site and thes examples are done for director, but he explains the math first before showing any lingo code... and lingo script is very straight forward, I'm sure you can make good use of it.

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

IP logged posted posted 07-08-2003 19:18 Edit Quote

ok, bookmarked.
Once the finals are over, I'll look into it.



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu