I hacked mines to work with time intervals no physics formula but it works.
I dont know how well you understand OOP but you you can probably use it with minor modifications. Movement is at time spaced intervals but it doesn't restart at modulus 1. you would have to modify it for that(apply your own delta timing too):
'****************************************************************
' this spline uses x, y, dir and speed from Tmovement
' calculates the current position and angle. x,y is the new Position
'****************************************************************
Type Tbezier Extends Tmovement
Field ax:Float
Field ay:Float
Field bx:Float
Field by:Float
Field cx:Float
Field cy:Float
Field dx:Float
Field dy:Float
Field t1:Float
Field t2:Float
Field x2:Float
Field y2:Float
Field d:Float
Field t:Float
Field rate:Float
Field old_x:Float
Field old_y:Float
Field old_dir:Float
Field fixed:Int
Method New()
name = "BEZIER"
End Method
' (ax,ay) line 1 point 1, (bx,by) line 1 point 2,(cx,cy) line 2 point 1, (dx,dy) line 2 point 2, fixed(true/false) fixed speed/position speed
Function Create:Tbezier(ax:Float, ay:Float, bx:Float, by:Float, cx:Float, cy:Float, dx:Float, dy:Float,_speed:Float = .5,fixed:Int = True)
Local b:Tbezier = New Tbezier
b.ax = ax
b.ay = ay
b.bx = bx
b.by = by
b.cx = cx
b.cy = cy
b.dx = dx
b.dy = dy
b.t1 = 0
b.t2 = 0
b.speed = 0
b.x = ax
b.y = ay
b.x2 = ax
b.y2 = ay
b.rate = _speed
b.fixed = fixed
Return b
End Function
Method init:Tbezier(ax:Float, ay:Float, bx:Float, by:Float, cx:Float, cy:Float, dx:Float, dy:Float,_speed:Float = .5,fixed:Int = True)
Self.ax = ax
Self.ay = ay
Self.bx = bx
Self.by = by
Self.cx = cx
Self.cy = cy
Self.dx = dx
Self.dy = dy
Self.t1 = 0
Self.t2 = 0
Self.speed = 0
Self.x = ax
Self.y = ay
Self.x2 = ax
Self.y2 = ay
Self.rate = _speed
Self.fixed = fixed
End Method
'**************************************************************************
' displays the complete spline includes points
'**************************************************************************
Method DrawSpline()
Local t:Float,b:Float
SetColor 255,0,0
SetRotation 0
DrawLine ax,ay,bx,by
DrawLine cx,cy,dx,dy
Local ox:Float=ax
Local oy:Float=ay
SetColor 100,100,100
For t=0 To 1 Step .01
b=1-t
Local px:Float=ax*b^3 + 3*bx*b^2*t + 3*cx*b*t^2 + dx*t^3
Local py:Float=ay*b^3 + 3*by*b^2*t + 3*cy*b*t^2 + dy*t^3
DrawRect px-1,py-1,3,3
DrawLine ox,oy,px,py
ox=px
oy=py
Next
End Method
Method OnStandBy()
End Method
'compute classic spline movement.
'returns true after cycle has been completed
'returns false while in cycle.
Method update:Int()
Local vx:Float
Local vy:Float
Local ox:Float = x
Local oy:Float = y
Local ox2:Float = x2
Local oy2:Float = y2
t1:+speed*FRL.delta
If t1>1 Then Return False
Local a:Float = t1
Local b:Float = 1-t1
old_x = x
old_y = y
old_dir# = dir#
x=ax*b^3 + 3*bx*b^2*a + 3*cx*b*a^2 + dx * a^3
y=ay*b^3 + 3*by*b^2*a + 3*cy*b*a^2 + dy * a^3
dir = ATan2(y - old_y,x - old_x)
If fixed = False
d = Sqr(x*x+y*y)
speed#= rate/d/4
Else
vx=-3*ax*b*b + 3*bx*b*(b-2*a) + 3*cx*a*(2*b-a) + dx*3*a*a
vy=-3*ay*b*b + 3*by*b*(b-2*a) + 3*cy*a*(2*b-a) + dy*3*a*a
d=Sqr(vx*vx+vy*vy)
' adjust the one 1.5 to a more consistent value to the normal movement.
speed#= rate/d/1.5
EndIf
Return True
End Method
End Type
|