verlet constraints

Blitz3D Forums/Blitz3D Programming/verlet constraints

oops. sorry. c\e# is the "springiness" from 0-1. at 1 it is infinitly strong, and at 0 it is nothing. One thing that is advisable, and doesn't add to much speed lag is to include masses in your verlets. It's rather simple. Add together the masses of the two verlets effected by the constraint, and when calculating verlet #1's movement, replace the .5 with #2's mass/ total mass. Do the same for #2's movement. Replace the .5 with #1's mass/ total mass. If the two masses are equal, then this will be .5, the original value.

here's the code now.

dx#=EntityX#(c\Cp1\pivot)-EntityX#(c\Cp2\pivot)
dy#=EntityY#(c\Cp1\pivot)-EntityY#(c\Cp2\pivot)
dz#=EntityZ#(c\cp1\pivot)-EntityZ#(c\cp2\pivot)
cd#=Sqr(dx#*dx#+dy#*dy#+dz#*dz#)
diff#=(cd#-c\td#)/cd#
tmass#=c\Cp1\mass#+c\Cp2\mass#
tmp#=C\Cp2\mass#/tmass#
PositionEntity c\Cp1\pivot,EntityX#(c\Cp1\pivot)-(dx#*diff#*c\e#*tmp#),EntityY#(c\Cp1\pivot)-(dy#*diff#*c\e#*tmp#),EntityZ#(c\cp1\pivot)-(dz#*diff#*tmp#*.5)
tmp#=C\Cp1\mass#/tmass#
PositionEntity c\Cp2\pivot,EntityX#(c\Cp2\pivot)+(dx#*diff#*c\e#*tmp#),EntityY#(c\Cp2\pivot)+(dy#*diff#*c\e#*tmp#),EntityZ#(c\cp2\pivot)+(dz#*diff#*tmp#*.5)


Note that I haven't tested this one, but you should be able to get the jist of it.