2 Copyright (C) 2009 Sony Computer Entertainment Inc.
\r
5 This software is provided 'as-is', without any express or implied warranty.
\r
6 In no event will the authors be held liable for any damages arising from the use of this software.
\r
7 Permission is granted to anyone to use this software for any purpose,
\r
8 including commercial applications, and to alter it and redistribute it freely,
\r
9 subject to the following restrictions:
\r
11 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
\r
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
\r
13 3. This notice may not be removed or altered from any source distribution.
\r
17 #ifndef BT_TRBSTATEVEC_H__
\r
18 #define BT_TRBSTATEVEC_H__
\r
21 #ifdef PFX_USE_FREE_VECTORMATH
\r
22 #include "vecmath/vmInclude.h"
\r
24 #include "vectormath/vmInclude.h"
\r
25 #endif //PFX_USE_FREE_VECTORMATH
\r
28 #include "PlatformDefinitions.h"
\r
31 static inline vmVector3 read_Vector3(const float* p)
\r
38 static inline vmQuat read_Quat(const float* p)
\r
45 static inline void store_Vector3(const vmVector3 &src, float* p)
\r
51 static inline void store_Quat(const vmQuat &src, float* p)
\r
59 PfxMotionTypeFixed = 0,
\r
60 PfxMotionTypeActive,
\r
61 PfxMotionTypeKeyframe,
\r
62 PfxMotionTypeOneWay,
\r
63 PfxMotionTypeTrigger,
\r
67 #define PFX_MOTION_MASK_DYNAMIC 0x0a // Active,OneWay
\r
68 #define PFX_MOTION_MASK_STATIC 0x95 // Fixed,Keyframe,Trigger,Sleeping
\r
69 #define PFX_MOTION_MASK_SLEEP 0x0e // Can sleep
\r
70 #define PFX_MOTION_MASK_TYPE 0x7f
\r
76 #ifdef __CELLOS_LV2__
\r
77 ATTRIBUTE_ALIGNED128(class) TrbState
\r
79 ATTRIBUTE_ALIGNED16(class) TrbState
\r
86 setMotionType(PfxMotionTypeActive);
\r
87 contactFilterSelf=contactFilterTarget=0xffffffff;
\r
94 useContactCallback = 0;
\r
95 useSleepCallback = 0;
\r
96 linearDamping = 1.0f;
\r
97 angularDamping = 0.99f;
\r
100 TrbState(const uint8_t m, const vmVector3& x, const vmQuat& q, const vmVector3& v, const vmVector3& omega );
\r
102 uint16_t mSleepCount;
\r
103 uint8_t mMotionType;
\r
104 uint8_t deleted : 1;
\r
105 uint8_t mSleeping : 1;
\r
106 uint8_t useSleep : 1;
\r
107 uint8_t useCcd : 1;
\r
108 uint8_t useContactCallback : 1;
\r
109 uint8_t useSleepCallback : 1;
\r
111 uint16_t trbBodyIdx;
\r
112 uint32_t contactFilterSelf;
\r
113 uint32_t contactFilterTarget;
\r
115 float center[3]; // AABB center(World)
\r
116 float half[3]; // AABB half(World)
\r
118 float linearDamping;
\r
119 float angularDamping;
\r
121 float deltaLinearVelocity[3];
\r
122 float deltaAngularVelocity[3];
\r
124 float fX[3]; // position
\r
125 float fQ[4]; // orientation
\r
126 float fV[3]; // velocity
\r
127 float fOmega[3]; // angular velocity
\r
129 inline void setZero(); // Zeroes out the elements
\r
130 inline void setIdentity(); // Sets the rotation to identity and zeroes out the other elements
\r
132 bool isDeleted() const {return deleted==1;}
\r
134 uint16_t getRigidBodyId() const {return trbBodyIdx;}
\r
135 void setRigidBodyId(uint16_t i) {trbBodyIdx = i;}
\r
138 uint32_t getContactFilterSelf() const {return contactFilterSelf;}
\r
139 void setContactFilterSelf(uint32_t filter) {contactFilterSelf = filter;}
\r
141 uint32_t getContactFilterTarget() const {return contactFilterTarget;}
\r
142 void setContactFilterTarget(uint32_t filter) {contactFilterTarget = filter;}
\r
144 float getLinearDamping() const {return linearDamping;}
\r
145 float getAngularDamping() const {return angularDamping;}
\r
147 void setLinearDamping(float damping) {linearDamping=damping;}
\r
148 void setAngularDamping(float damping) {angularDamping=damping;}
\r
151 uint8_t getMotionType() const {return mMotionType;}
\r
152 void setMotionType(uint8_t t) {mMotionType = t;mSleeping=0;mSleepCount=0;}
\r
154 uint8_t getMotionMask() const {return (1<<mMotionType)|(mSleeping<<7);}
\r
156 bool isAsleep() const {return mSleeping==1;}
\r
157 bool isAwake() const {return mSleeping==0;}
\r
159 void wakeup() {mSleeping=0;mSleepCount=0;}
\r
160 void sleep() {if(useSleep) {mSleeping=1;mSleepCount=0;}}
\r
162 uint8_t getUseSleep() const {return useSleep;}
\r
163 void setUseSleep(uint8_t b) {useSleep=b;}
\r
165 uint8_t getUseCcd() const {return useCcd;}
\r
166 void setUseCcd(uint8_t b) {useCcd=b;}
\r
168 uint8_t getUseContactCallback() const {return useContactCallback;}
\r
169 void setUseContactCallback(uint8_t b) {useContactCallback=b;}
\r
171 uint8_t getUseSleepCallback() const {return useSleepCallback;}
\r
172 void setUseSleepCallback(uint8_t b) {useSleepCallback=b;}
\r
174 void incrementSleepCount() {mSleepCount++;}
\r
175 void resetSleepCount() {mSleepCount=0;}
\r
176 uint16_t getSleepCount() const {return mSleepCount;}
\r
178 vmVector3 getPosition() const {return read_Vector3(fX);}
\r
179 vmQuat getOrientation() const {return read_Quat(fQ);}
\r
180 vmVector3 getLinearVelocity() const {return read_Vector3(fV);}
\r
181 vmVector3 getAngularVelocity() const {return read_Vector3(fOmega);}
\r
182 vmVector3 getDeltaLinearVelocity() const {return read_Vector3(deltaLinearVelocity);}
\r
183 vmVector3 getDeltaAngularVelocity() const {return read_Vector3(deltaAngularVelocity);}
\r
185 void setPosition(const vmVector3 &pos) {store_Vector3(pos, fX);}
\r
186 void setLinearVelocity(const vmVector3 &vel) {store_Vector3(vel, fV);}
\r
187 void setAngularVelocity(const vmVector3 &vel) {store_Vector3(vel, fOmega);}
\r
188 void setDeltaLinearVelocity(const vmVector3 &vel) {store_Vector3(vel, deltaLinearVelocity);}
\r
189 void setDeltaAngularVelocity(const vmVector3 &vel) {store_Vector3(vel, deltaAngularVelocity);}
\r
190 void setOrientation(const vmQuat &rot) {store_Quat(rot, fQ);}
\r
192 inline void setAuxils(const vmVector3 ¢erLocal,const vmVector3 &halfLocal);
\r
193 inline void setAuxilsCcd(const vmVector3 ¢erLocal,const vmVector3 &halfLocal,float timeStep);
\r
194 inline void reset();
\r
198 TrbState::TrbState(const uint8_t m, const vmVector3& x, const vmQuat& q, const vmVector3& v, const vmVector3& omega)
\r
211 fOmega[0] = omega[0];
\r
212 fOmega[1] = omega[1];
\r
213 fOmega[2] = omega[2];
\r
214 contactFilterSelf=contactFilterTarget=0xffff;
\r
220 useContactCallback = 0;
\r
221 useSleepCallback = 0;
\r
223 linearDamping = 1.0f;
\r
224 angularDamping = 0.99f;
\r
228 TrbState::setIdentity()
\r
246 TrbState::setZero()
\r
264 TrbState::setAuxils(const vmVector3 ¢erLocal,const vmVector3 &halfLocal)
\r
266 vmVector3 centerW = getPosition() + rotate(getOrientation(),centerLocal);
\r
267 vmVector3 halfW = absPerElem(vmMatrix3(getOrientation())) * halfLocal;
\r
268 center[0] = centerW[0];
\r
269 center[1] = centerW[1];
\r
270 center[2] = centerW[2];
\r
271 half[0] = halfW[0];
\r
272 half[1] = halfW[1];
\r
273 half[2] = halfW[2];
\r
277 TrbState::setAuxilsCcd(const vmVector3 ¢erLocal,const vmVector3 &halfLocal,float timeStep)
\r
279 vmVector3 centerW = getPosition() + rotate(getOrientation(),centerLocal);
\r
280 vmVector3 halfW = absPerElem(vmMatrix3(getOrientation())) * halfLocal;
\r
282 vmVector3 diffvec = getLinearVelocity()*timeStep;
\r
284 vmVector3 newCenter = centerW + diffvec;
\r
285 vmVector3 aabbMin = minPerElem(newCenter - halfW,centerW - halfW);
\r
286 vmVector3 aabbMax = maxPerElem(newCenter + halfW,centerW + halfW);
\r
288 centerW = 0.5f * (aabbMin + aabbMax);
\r
289 halfW =0.5f * (aabbMax - aabbMin);
\r
291 center[0] = centerW[0];
\r
292 center[1] = centerW[1];
\r
293 center[2] = centerW[2];
\r
295 half[0] = halfW[0];
\r
296 half[1] = halfW[1];
\r
297 half[2] = halfW[2];
\r
301 void TrbState::reset()
\r
305 mMotionType = PfxMotionTypeActive;
\r
310 mUseContactCallback = 0;
\r
311 mUseSleepCallback = 0;
\r
313 mContactFilterSelf = 0xffffffff;
\r
314 mContactFilterTarget = 0xffffffff;
\r
315 mLinearDamping = 1.0f;
\r
316 mAngularDamping = 0.99f;
\r
317 mPosition = vmVector3(0.0f);
\r
318 mOrientation = vmQuat::identity();
\r
319 mLinearVelocity = vmVector3(0.0f);
\r
320 mAngularVelocity = vmVector3(0.0f);
\r
323 setMotionType(PfxMotionTypeActive);
\r
324 contactFilterSelf=contactFilterTarget=0xffffffff;
\r
331 useContactCallback = 0;
\r
332 useSleepCallback = 0;
\r
333 linearDamping = 1.0f;
\r
334 angularDamping = 0.99f;
\r
337 #endif //BT_TRBSTATEVEC_H__
\r