| 1 | #ifndef _ROLL_H_ | 
| 2 | #define _ROLL_H_ | 
| 3 | #include "Rattle.hpp" | 
| 4 | #include "Vector3d.hpp" | 
| 5 | //////////////////////////////////////////////////////////////////////////////// | 
| 6 | //Declaration of DCRollAFunctor | 
| 7 | //////////////////////////////////////////////////////////////////////////////// | 
| 8 | class DCRollAFunctor : public DCRattleAFunctor{ | 
| 9 | public: | 
| 10 | DCRollAFunctor(SimInfo* info) : DCRattleAFunctor(info) {} | 
| 11 | virtual int operator()(ConstraintAtom* consAtom1, ConstraintAtom* consAtom2); | 
| 12 | //virtual int operator()(ConstraintAtom* consAtom,ConstraintRigidBody* consRB); | 
| 13 | virtual int operator()(ConstraintRigidBody* consRB1, ConstraintRigidBody* consRB2); | 
| 14 | private: | 
| 15 |  | 
| 16 | void calcZeta(ConstraintAtom* consAtom, const Vector3d& bondDir, Vector3d&zeta); | 
| 17 | void integrate(ConstraintAtom* consAtom, const Vector3d& force); | 
| 18 |  | 
| 19 | void calcZeta(ConstraintRigidBody* consRB, const Vector3d& bondDir, Vector3d& zeta); | 
| 20 | void integrate(ConstraintRigidBody* consRB, const Vector3d& force); | 
| 21 | void rotationPropagation(StuntDouble* sd, double ji[3]); | 
| 22 | void rotate(int axes1, int axes2, double angle, double ji[3], double A[3][3]); | 
| 23 | }; | 
| 24 |  | 
| 25 | //////////////////////////////////////////////////////////////////////////////// | 
| 26 | //Declaration of JCRollAFunctor | 
| 27 | //////////////////////////////////////////////////////////////////////////////// | 
| 28 | class JCRollAFunctor : public JCRattleAFunctor{ | 
| 29 | public: | 
| 30 | JCRollAFunctor(SimInfo* info) : JCRattleAFunctor(info) {} | 
| 31 | //virtual int operator()(ConstraintAtom* consAtom1, ConstraintAtom* consAtom2); | 
| 32 | //virtual int operator()(ConstraintAtom* consAtom,ConstraintRigidBody* consRB); | 
| 33 | //virtual int operator()(ConstraintRigidBody* consRB1, ConstraintRigidBody* consRB2); | 
| 34 | }; | 
| 35 |  | 
| 36 | //////////////////////////////////////////////////////////////////////////////// | 
| 37 | //Declaration of RollA | 
| 38 | //////////////////////////////////////////////////////////////////////////////// | 
| 39 | class RollA : public ConstraintAlgorithm{ | 
| 40 | public: | 
| 41 | RollA(SimInfo* rhs) : ConstraintAlgorithm(rhs){ | 
| 42 | registerCallback(typeid(DistanceConstraintPair), new DCRollAFunctor(rhs)); | 
| 43 | registerCallback(typeid(JointConstraintPair), new JCRollAFunctor(rhs)); | 
| 44 | } | 
| 45 | }; | 
| 46 |  | 
| 47 | //////////////////////////////////////////////////////////////////////////////// | 
| 48 | //Declaration of DCRollBFunctor | 
| 49 | //////////////////////////////////////////////////////////////////////////////// | 
| 50 | class DCRollBFunctor : public DCRattleBFunctor{ | 
| 51 | public: | 
| 52 | DCRollBFunctor(SimInfo* info) : DCRattleBFunctor(info) {} | 
| 53 | //virtual int operator()(ConstraintAtom* consAtom1, ConstraintAtom* consAtom2); | 
| 54 | //virtual int operator()(ConstraintAtom* consAtom,ConstraintRigidBody* consRB); | 
| 55 | virtual int operator()(ConstraintRigidBody* consRB1, ConstraintRigidBody* consRB2); | 
| 56 | private: | 
| 57 | void getZeta(ConstraintRigidBody* consRB, const Vector3d& bondDir, Vector3d& zeta); | 
| 58 | void integrate(ConstraintRigidBody* consRB, const Vector3d& force); | 
| 59 | }; | 
| 60 |  | 
| 61 | //////////////////////////////////////////////////////////////////////////////// | 
| 62 | //Declaration of JCRollBFunctor | 
| 63 | //////////////////////////////////////////////////////////////////////////////// | 
| 64 | class JCRollBFunctor : public JCRattleBFunctor{ | 
| 65 | public: | 
| 66 | JCRollBFunctor(SimInfo* info) : JCRattleBFunctor(info) {} | 
| 67 | //virtual int operator()(ConstraintAtom* consAtom1, ConstraintAtom* consAtom2); | 
| 68 | //virtual int operator()(ConstraintAtom* consAtom,ConstraintRigidBody* consRB); | 
| 69 | //virtual int operator()(ConstraintRigidBody* consRB1, ConstraintRigidBody* consRB2); | 
| 70 | }; | 
| 71 |  | 
| 72 | //////////////////////////////////////////////////////////////////////////////// | 
| 73 | //Declaration of RollB | 
| 74 | //////////////////////////////////////////////////////////////////////////////// | 
| 75 | class RollB : public ConstraintAlgorithm{ | 
| 76 | public: | 
| 77 | RollB(SimInfo* rhs) : ConstraintAlgorithm(rhs){ | 
| 78 | registerCallback(typeid(DistanceConstraintPair), new DCRollBFunctor(rhs)); | 
| 79 | registerCallback(typeid(JointConstraintPair), new JCRollBFunctor(rhs)); | 
| 80 | } | 
| 81 | }; | 
| 82 |  | 
| 83 | //////////////////////////////////////////////////////////////////////////////// | 
| 84 | //Declaration of RollFramework | 
| 85 | //////////////////////////////////////////////////////////////////////////////// | 
| 86 | //class RattleAlgorithm will encapsulate preConstraint, RattleA and RattleB | 
| 87 | //actually, we could use factory pattern to seperate the creation process | 
| 88 | class RollFramework : public VelVerletConsFramework{ | 
| 89 | public: | 
| 90 | RollFramework(SimInfo* rhs) : VelVerletConsFramework(rhs){ | 
| 91 | raAlgo = new RollA(rhs); | 
| 92 | rbAlgo = new RollB(rhs); | 
| 93 | } | 
| 94 |  | 
| 95 | ~RollFramework(){ | 
| 96 | delete raAlgo; | 
| 97 | delete rbAlgo; | 
| 98 | } | 
| 99 |  | 
| 100 | virtual int doConstrainA(){ | 
| 101 | raAlgo->doConstrain(); | 
| 102 | return raAlgo->haveError()? -1 : 1; | 
| 103 |  | 
| 104 | } | 
| 105 |  | 
| 106 | virtual int doConstrainB(){ | 
| 107 | rbAlgo->doConstrain(); | 
| 108 | return rbAlgo->haveError()? -1 : 1; | 
| 109 |  | 
| 110 | } | 
| 111 | private: | 
| 112 | RollA* raAlgo; | 
| 113 | RollB* rbAlgo; | 
| 114 | }; | 
| 115 | #endif //end ifndef _ROLL_H_ |