Ok I finished the basics of the physics engine and it works well Thanks for the advice sledge and to everyone that answered my questions which I know were not very good.
click the mouse to make it bounce around. :)
Graphics 640,480
Global Gravity# = .1
Global VerletList:TList = New TList
Global ConstraintList:TList = New TList
V1:Tverlet = TVerlet.CreateVerlet(100,100,1)
V2:Tverlet = TVerlet.CreateVerlet(150,50,1)
V3:Tverlet = Tverlet.CreateVerlet(100,50,1)
V4:TVerlet = TVerlet.CreateVerlet(150,100,1)
Tconstraint.ConstrainVerlets(V1:Tverlet,V2:TVerlet)
Tconstraint.ConstrainVerlets(V1:TVerlet,V3:TVerlet)
Tconstraint.ConstrainVerlets(V2:TVerlet,V3:TVerlet)
Tconstraint.ConstrainVerlets(V1:Tverlet,V4:TVerlet)
Tconstraint.ConstrainVerlets(V2:Tverlet,V4:TVerlet)
Tconstraint.ConstrainVerlets(V3:Tverlet,V4:TVerlet)
While Not AppTerminate()
Cls
If MouseDown(1) Then
V1.y# = V1.y# - 1
EndIf
UpdatePhysics()
Flip
Wend
End
Type Tverlet
Field x#,y#
Field dx#,dy#
Field ox#,oy#
Field ID
Field VID
Field active
Field mass#
Field collided
Method Update()
If active = True Then
If collided = True Then
fric# = .8
Else
fric# = 1
EndIf
collided = False
dx# = (x#-ox#)*fric
dy# = (y#-oy#)*fric
ox# = x#
oy# = y#
x# = x# + dx#
y# = y# + dy# + Gravity#
If y# > 480 Then
collided = True
y# = 480
oy# = 480+(dy#/3)
EndIf
EndIf
End Method
Method Draw()
'SetScale 1,1
'SetColor 255,255,255
'SetRotation 0
DrawOval x# - 10 , y# - 10 , 20 , 20
End Method
Method AddLast( list:TList )
link=list.AddLast( Self )
End Method
Function CreateVerlet:TVerlet(x#,y#,ID,active = True)
V:Tverlet = New Tverlet
V.x# = x#
V.y# = y#
V.ID = ID
V.ox# = x#
V.oy# = y#
V.Active = active
V.AddLast VerletList
Return V
End Function
End Type
Type TConstraint
Field V1:TVerlet
Field V2:TVerlet
Field length#
Method Update()
tx# = V1.x#-V2.x#
ty# = V1.y#-V2.y#
dist# = Sqr(tx#*tx#+ty#*ty#)
tx# = tx# / 2
ty# = ty# / 2
If dist# <> 0 Then
diff# = (dist# - Length#) / dist#
EndIf
V1.x# = V1.x# - diff# * tx#
V1.y# = V1.y# - diff# * ty#
V2.x# = V2.x# + diff# * tx#
V2.y# = V2.y# + diff# * ty#
SetColor 255,255,255
DrawLine V1.x#,v1.y#,v2.x#,v2.y#
End Method
Method AddLast( list:TList )
link=list.AddLast( Self )
End Method
Function ConstrainVerlets( V1:TVerlet , V2:TVerlet )
C:TConstraint = New TConstraint
C.V1:TVerlet = V1:TVerlet
C.V2:TVerlet = V2:TVerlet
C.Length# = Sqr((C.V1.x#-C.V2.x#)^2 + (C.V1.y#-C.V2.y#)^2)
C.AddLast ConstraintList
End Function
End Type
Function UpdatePhysics()
For V:TVerlet = EachIn VerletList:TList
V.Update
Next
For C:TConstraint = EachIn ConstraintList:TList
C.Update
Next
'For V:TVerlet = EachIn VerletList:TList
' V.draw
'Next
End Function