Changeset 2908 for code/branches/questsystem5/src/bullet/BulletDynamics/ConstraintSolver/btSolverBody.h
- Timestamp:
- Apr 8, 2009, 12:58:47 AM (16 years ago)
- Location:
- code/branches/questsystem5
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/questsystem5
- Property svn:mergeinfo changed
-
code/branches/questsystem5/src/bullet/BulletDynamics/ConstraintSolver/btSolverBody.h
r2907 r2908 24 24 #include "LinearMath/btTransformUtil.h" 25 25 26 ///Until we get other contributions, only use SIMD on Windows, when using Visual Studio 2008 or later, and not double precision27 #ifdef BT_USE_SSE28 #define USE_SIMD 129 #endif //30 31 32 #ifdef USE_SIMD33 34 struct btSimdScalar35 {36 SIMD_FORCE_INLINE btSimdScalar()37 {38 39 }40 41 SIMD_FORCE_INLINE btSimdScalar(float fl)42 :m_vec128 (_mm_set1_ps(fl))43 {44 }45 46 SIMD_FORCE_INLINE btSimdScalar(__m128 v128)47 :m_vec128(v128)48 {49 }50 union51 {52 __m128 m_vec128;53 float m_floats[4];54 int m_ints[4];55 btScalar m_unusedPadding;56 };57 SIMD_FORCE_INLINE __m128 get128()58 {59 return m_vec128;60 }61 62 SIMD_FORCE_INLINE const __m128 get128() const63 {64 return m_vec128;65 }66 67 SIMD_FORCE_INLINE void set128(__m128 v128)68 {69 m_vec128 = v128;70 }71 72 SIMD_FORCE_INLINE operator __m128()73 {74 return m_vec128;75 }76 SIMD_FORCE_INLINE operator const __m128() const77 {78 return m_vec128;79 }80 81 SIMD_FORCE_INLINE operator float() const82 {83 return m_floats[0];84 }85 86 };87 88 ///@brief Return the elementwise product of two btSimdScalar89 SIMD_FORCE_INLINE btSimdScalar90 operator*(const btSimdScalar& v1, const btSimdScalar& v2)91 {92 return btSimdScalar(_mm_mul_ps(v1.get128(),v2.get128()));93 }94 95 ///@brief Return the elementwise product of two btSimdScalar96 SIMD_FORCE_INLINE btSimdScalar97 operator+(const btSimdScalar& v1, const btSimdScalar& v2)98 {99 return btSimdScalar(_mm_add_ps(v1.get128(),v2.get128()));100 }101 102 103 #else104 #define btSimdScalar btScalar105 #endif106 26 107 27 ///The btSolverBody is an internal datastructure for the constraint solver. Only necessary data is packed to increase cache coherence/performance. … … 109 29 { 110 30 BT_DECLARE_ALIGNED_ALLOCATOR(); 111 btVector3 m_deltaLinearVelocity; 112 btVector3 m_deltaAngularVelocity; 113 btScalar m_angularFactor; 114 btScalar m_invMass; 115 btScalar m_friction; 31 32 btMatrix3x3 m_worldInvInertiaTensor; 33 34 btVector3 m_angularVelocity; 35 btVector3 m_linearVelocity; 36 btVector3 m_centerOfMassPosition; 37 btVector3 m_pushVelocity; 38 btVector3 m_turnVelocity; 39 40 float m_angularFactor; 41 float m_invMass; 42 float m_friction; 116 43 btRigidBody* m_originalBody; 117 btVector3 m_pushVelocity;118 //btVector3 m_turnVelocity;119 120 44 121 SIMD_FORCE_INLINE void getVelocityInLocalPointObsolete(const btVector3& rel_pos, btVector3& velocity ) const 45 46 SIMD_FORCE_INLINE void getVelocityInLocalPoint(const btVector3& rel_pos, btVector3& velocity ) const 122 47 { 123 if (m_originalBody) 124 velocity = m_originalBody->getLinearVelocity()+m_deltaLinearVelocity + (m_originalBody->getAngularVelocity()+m_deltaAngularVelocity).cross(rel_pos); 125 else 126 velocity.setValue(0,0,0); 48 velocity = m_linearVelocity + m_angularVelocity.cross(rel_pos); 127 49 } 128 50 129 SIMD_FORCE_INLINE void getAngularVelocity(btVector3& angVel) const 51 //Optimization for the iterative solver: avoid calculating constant terms involving inertia, normal, relative position 52 SIMD_FORCE_INLINE void internalApplyImpulse(const btVector3& linearComponent, const btVector3& angularComponent,btScalar impulseMagnitude) 130 53 { 131 if (m_originalBody) 132 angVel = m_originalBody->getAngularVelocity()+m_deltaAngularVelocity; 133 else 134 angVel.setValue(0,0,0); 54 if (m_invMass) 55 { 56 m_linearVelocity += linearComponent*impulseMagnitude; 57 m_angularVelocity += angularComponent*(impulseMagnitude*m_angularFactor); 58 } 135 59 } 136 137 138 //Optimization for the iterative solver: avoid calculating constant terms involving inertia, normal, relative position 139 SIMD_FORCE_INLINE void applyImpulse(const btVector3& linearComponent, const btVector3& angularComponent,const btScalar impulseMagnitude) 60 61 SIMD_FORCE_INLINE void internalApplyPushImpulse(const btVector3& linearComponent, const btVector3& angularComponent,btScalar impulseMagnitude) 140 62 { 141 //if (m_invMass)63 if (m_invMass) 142 64 { 143 m_ deltaLinearVelocity += linearComponent*impulseMagnitude;144 m_ deltaAngularVelocity += angularComponent*(impulseMagnitude*m_angularFactor);65 m_pushVelocity += linearComponent*impulseMagnitude; 66 m_turnVelocity += angularComponent*(impulseMagnitude*m_angularFactor); 145 67 } 146 68 } 147 69 148 149 /*150 70 151 71 void writebackVelocity() … … 153 73 if (m_invMass) 154 74 { 155 m_originalBody->setLinearVelocity(m_ originalBody->getLinearVelocity()+ m_deltaLinearVelocity);156 m_originalBody->setAngularVelocity(m_ originalBody->getAngularVelocity()+m_deltaAngularVelocity);75 m_originalBody->setLinearVelocity(m_linearVelocity); 76 m_originalBody->setAngularVelocity(m_angularVelocity); 157 77 158 78 //m_originalBody->setCompanionId(-1); 159 79 } 160 80 } 161 */81 162 82 163 void writebackVelocity(btScalar timeStep =0)83 void writebackVelocity(btScalar timeStep) 164 84 { 165 85 if (m_invMass) 166 86 { 167 m_originalBody->setLinearVelocity(m_originalBody->getLinearVelocity()+m_deltaLinearVelocity); 168 m_originalBody->setAngularVelocity(m_originalBody->getAngularVelocity()+m_deltaAngularVelocity); 87 m_originalBody->setLinearVelocity(m_linearVelocity); 88 m_originalBody->setAngularVelocity(m_angularVelocity); 89 90 //correct the position/orientation based on push/turn recovery 91 btTransform newTransform; 92 btTransformUtil::integrateTransform(m_originalBody->getWorldTransform(),m_pushVelocity,m_turnVelocity,timeStep,newTransform); 93 m_originalBody->setWorldTransform(newTransform); 94 169 95 //m_originalBody->setCompanionId(-1); 170 96 } 171 97 } 98 99 void readVelocity() 100 { 101 if (m_invMass) 102 { 103 m_linearVelocity = m_originalBody->getLinearVelocity(); 104 m_angularVelocity = m_originalBody->getAngularVelocity(); 105 } 106 } 107 172 108 173 109
Note: See TracChangeset
for help on using the changeset viewer.