why oh why is everyone using blitz movement and pointing commands to do constraints???? Halos' is so slow due to this. Agood way to do it is mathamatical , but it isn't hard at all.
First of all, you need the positional diffrence between the two verlets. call it the delta. Find the length of the delta ( sqr(dx^2+dy^2+dz^2) ), and call it deltalength. Another variable, difference, is the deltalength subtracted by the restlength, divided by the delta length. Finally, the delta's are multiplied by the various diffs, which results in the amount of movement required to put the constraint in restlength. Since you want to move each particle equally, this is halved, and now you have the amount that each particle should move. The direction of the first particle then needs to be reversed in order to move the particles towards each other(or away in the case that the constraint is compressed).
I'm sure a written discription sounds very complicated indeed, and I'm not very good at explaining. here's the psuedo code I based my discrtiption off of:
Note that this is not blitz code. delta,x1,and x2 are vectors.
Here's my blitz interpretation:
This could be optimised by first recording entityx/y/z in variables and calling them, but I was lazy, and this is from my first verlet engine.
First of all, you need the positional diffrence between the two verlets. call it the delta. Find the length of the delta ( sqr(dx^2+dy^2+dz^2) ), and call it deltalength. Another variable, difference, is the deltalength subtracted by the restlength, divided by the delta length. Finally, the delta's are multiplied by the various diffs, which results in the amount of movement required to put the constraint in restlength. Since you want to move each particle equally, this is halved, and now you have the amount that each particle should move. The direction of the first particle then needs to be reversed in order to move the particles towards each other(or away in the case that the constraint is compressed).
I'm sure a written discription sounds very complicated indeed, and I'm not very good at explaining. here's the psuedo code I based my discrtiption off of:
delta = x2-x1 deltalength = sqrt(delta*delta) diff = (deltalength-restlength)/deltalength x1=x1-delta*0.5*diff x2=x2-delta*0.5*diff
Note that this is not blitz code. delta,x1,and x2 are vectors.
Here's my blitz interpretation:
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# PositionEntity c\Cp1\pivot,EntityX#(c\Cp1\pivot)-(dx#*diff#*c\e#*.5),EntityY#(c\Cp1\pivot)-(dy#*diff#*c\e#*.5),EntityZ#(c\cp1\pivot)-(dz#*diff#*c\e#*.5) PositionEntity c\Cp2\pivot,EntityX#(c\Cp2\pivot)+(dx#*diff#*c\e#*.5),EntityY#(c\Cp2\pivot)+(dy#*diff#*c\e#*.5),EntityZ#(c\cp2\pivot)+(dz#*diff#*c\e#*.5)
This could be optimised by first recording entityx/y/z in variables and calling them, but I was lazy, and this is from my first verlet engine.