[Plib-cvs] plib/src/sg sg.cxx,1.34,1.35 sg.h,1.36,1.37
Brought to you by:
sjbaker
From: Steve B. <sj...@us...> - 2002-08-11 14:07:12
|
Update of /cvsroot/plib/plib/src/sg In directory usw-pr-cvs1:/tmp/cvs-serv29374/plib/src/sg Modified Files: sg.cxx sg.h Log Message: Added a simple Spring/Mass/Damper model to SG. Index: sg.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/sg/sg.cxx,v retrieving revision 1.34 retrieving revision 1.35 diff -u -d -r1.34 -r1.35 --- sg.cxx 14 Jun 2002 04:38:23 -0000 1.34 +++ sg.cxx 11 Aug 2002 14:07:09 -0000 1.35 @@ -24,6 +24,8 @@ #include "sg.h" +sgVec3 _sgGravity = { 0.0f, 0.0f, -9.8f } ; + void sgVectorProductVec3 ( sgVec3 dst, const sgVec3 a, const sgVec3 b ) { dst[0] = a[1] * b[2] - a[2] * b[1] ; Index: sg.h =================================================================== RCS file: /cvsroot/plib/plib/src/sg/sg.h,v retrieving revision 1.36 retrieving revision 1.37 diff -u -d -r1.36 -r1.37 --- sg.h 14 Jun 2002 04:38:23 -0000 1.36 +++ sg.h 11 Aug 2002 14:07:09 -0000 1.37 @@ -2642,5 +2642,139 @@ void sgdTriangleSolver_SAAtoASS(SGDfloat lenA,SGDfloat angB,SGDfloat angA, SGDfloat *angC,SGDfloat *lenB,SGDfloat *lenC ) ; +/* + SPRING-MASS-DAMPER (with simple Euler integrator) +*/ + + +extern sgVec3 _sgGravity ; + +void sgSetGravity ( float g ) { sgSetVec3 ( _sgGravity, 0.0f, 0.0f, -g ) ; } [...108 lines suppressed...] + void update () + { + sgVec3 dP ; sgSubVec3 ( dP, p0->getPos(), p1->getPos() ) ; + sgVec3 dV ; sgSubVec3 ( dV, p0->getVel(), p1->getVel() ) ; + + float L = sgLengthVec3 ( dP ) ; if ( L == 0.0f ) L = 0.0000001 ; + float H = ( L - restLength ) * stiffness ; + float D = sgScalarProductVec3 ( dV, dP ) * damping / L ; + + sgVec3 F ; sgScaleVec3 ( dP, - ( H + D ) / L ) ; + + p0 -> addForce ( F ) ; + p1 -> addForce ( F ) ; + } + +} ; + + #endif |