True Axis Physics SDK 1.2.0.1 Beta Documentation
www.trueaxis.com

DynamicObject.h

Go to the documentation of this file.
00001 //---------------------------------------------------------------------------------
00002 // File Name: DynamicObject.h
00003 // Description:
00006 //
00007 // Copyright (C) 2004 - 2006 True Axis Pty Ltd, Australia. 
00008 // All Rights Reserved.
00009 //
00010 // History:
00011 //      Created File.
00012 //---------------------------------------------------------------------------------
00013 
00014 #ifndef TA_DYNAMICOBJECT_H
00015 #define TA_DYNAMICOBJECT_H
00016 
00017 #ifndef TA_MFRAME_H
00018 #include "../Common/MFrame.h"
00019 #endif // TA_MFRAME_H
00020 
00021 #ifndef TA_AABB_H
00022 #include "../Common/AABB.h"
00023 #endif // TA_AABB_H
00024 
00025 #ifndef TA_ARRAY_H
00026 #include "../Common/Array.h"
00027 #endif // TA_ARRAY_H
00028 
00029 #ifndef TA_LIST_H
00030 #include "../Common/List.h"
00031 #endif // TA_LIST_H
00032 
00033 #ifndef TA_POOL_H
00034 #include "../Common/Pool.h"
00035 #endif // TA_POOL_H
00036 
00037 #ifndef TA_FLAGS_H
00038 #include "../Common/Flags.h"
00039 #endif // TA_FLAGS_H
00040 
00041 #ifndef TA_PHYSICSOBJECT_H
00042 #include "PhysicsObject.h"
00043 #endif // TA_PHYSICSOBJECT_H
00044 
00045 #ifndef TA_SPACEDIVISIONOBJECT_H
00046 #include "SpaceDivisionObject.h"
00047 #endif // TA_SPACEDIVISIONOBJECT_H
00048 
00049 #ifndef TA_PHYSICSJOINT_H
00050 #include "PhysicsJoint.h"
00051 #endif // TA_PHYSICSJOINT_H
00052 
00053 #ifndef TA_COLLISIONOBJECT_H
00054 #include "CollisionObject.h"
00055 #endif // TA_COLLISIONOBJECT_H
00056 
00057 #ifndef TA_COLLISION_H
00058 #include "Collision.h"
00059 #endif // TA_COLLISION_H
00060 
00061 #ifndef TA_DYNAMICOBJECTCOLLISIONITERATOR_H
00062 #include "DynamicObjectCollisionIterator.h"
00063 #endif // TA_DYNAMICOBJECTCOLLISIONITERATOR_H
00064 
00065 TA_OBFUSCATION_SKIP_PASS_2
00066 
00067 namespace TA
00068 {
00069 
00070 class CollisionObjectCombo;
00071 class CollisionObjectComplex;
00072 class DynamicObjectGroup;
00073 struct EulerAngles;
00074 struct Globals;
00075 
00076 
00077 const float JOINT_LIMIT_DISABLED = k_fMaxFloat;
00078 
00079 /*class TAPHYSICS_CLASS MovingObject
00080 {
00081     float m_fMass;
00082     float m_fFriction;
00083     float m_fRestitution;
00084     float m_fRestTimeMultiplier;
00085     float m_fGravityMult;
00086     float m_fSolverScale;
00087     u32 m_nFlags;
00088     int m_nBuildMatrixNumber;
00089     int m_nID;
00090     void* m_pGroupHandle;
00091     int m_nUserGroupId;
00092     u32 m_nUserGroupItemId; // Only one bit is set at a time.
00093     u32 m_nNotAllowedToCollideWith;         // the number of each bit refers to a m_nUserGroupItemId value
00094     CollisionObjectCombo* m_pCollisionObject;
00095     DynamicObjectGroup* m_pDynamicObjectGroup;
00096     void* m_pUserData;
00097     DynamicObjectPairListItem* m_pPairList;
00098     int m_nNumPairs;
00099     int m_nPairID;
00100     Array<LineIntersection, false> m_lineIntersectionArray;
00101     List<PhysicsJoint> m_jointList; 
00102     List<PhysicsJoint*> m_connectedFromJointList;   
00103 
00104     Mat33 m_m33Inertia; // Inertia tensor
00105 
00106 
00107     Vec3 m_v3CenterOffset;
00108     MFrame m_frame; 
00109     MFrame m_nextFrame;
00110     MFrame m_smoothedFrame;
00111     MFrame m_previousFrame;
00112     MFrame m_gfxFrame;
00113     Vec3 m_v3LinearVelocity;
00114     Vec3 m_v3AngularVelocity;
00115     Vec3 m_v3PreviousLinearVelocity;
00116     Vec3 m_v3PreviousAngularVelocity;
00117     Vec3 m_v3AccumulatedForce;
00118     Vec3 m_v3AccumulatedTorque;
00119     Vec3 m_v3AccumulatedMovement;
00120     Vec3 m_v3AccumulatedRotation;
00121 };*/
00122 
00123 #ifdef TA_PHYSICS_INTERNAL
00124     
00125 /*#define TA_DEFINE_OPTIMIZED_FUNCTIONS(PRE, NAMESPACE) \
00126 namespace NAMESPACE \
00127 {\
00128     PRE void TAC_CALL DoCollision(float fSeparatingSpeed, Collision& collision); \
00129     PRE void TAC_CALL DoCollisionPropagated(float fSeparatingSpeed, float fScale, float fFrictionScale, Collision& collision); \
00130     PRE bool TAC_CALL DoFriction(float fImpulse, Collision& collision); \
00131     PRE void TAC_CALL DoFrictionPropagated(float fSeparatingSpeed, float fScale, Collision& collision); \
00132 }*
00133 
00134 TA_DEFINE_OPTIMIZED_FUNCTIONS(extern, Optimized)
00135 TA_DEFINE_OPTIMIZED_FUNCTIONS(extern, OptimizedSSE2)*/
00136 
00137 #define TA_DEFINE_OPTIMIZED_FUNCTIONS(PRE, NAMESPACE) \
00138 namespace NAMESPACE \
00139 { \
00140     PRE void TAC_CALL DoCollision(float fSeparatingSpeed, Collision& collision); \
00141     PRE void TAC_CALL DoCollisionPropagated(float fSeparatingSpeed, float fScale, float fFrictionScale, Collision& collision); \
00142     PRE bool TAC_CALL DoFriction(float fImpulse, Collision& collision); \
00143     PRE void TAC_CALL DoFrictionPropagated(float fSeparatingSpeed, float fScale, Collision& collision); \
00144     PRE float TAC_CALL CalculateSeparatingSpeed(float fDt, Collision& collision); \
00145 }
00146 
00147 TA_DEFINE_OPTIMIZED_FUNCTIONS(extern, Optimized)
00148 TA_DEFINE_OPTIMIZED_FUNCTIONS(extern, OptimizedSSE2)
00149 
00150 #endif 
00151 
00152 class TAPHYSICS_CLASS DynamicObject : public PhysicsObject, public SpaceDivisionObject
00153 {
00154 public: 
00155     TA_OBFUSCATION_RESERVED_ON
00156     struct LineIntersection
00157     {
00158         float GetIntersectionDepth() const;
00159         DynamicObject* GetDynamicObject() const;
00160         CollisionObject* GetCollisionObject() const;
00161         int GetAttribute() const;
00162         const Vec3& GetPosition() const;
00163         const Vec3& GetNormal() const;
00164         TA_OBFUSCATION_RESERVED_OFF
00165 
00166     private:
00167         friend class DynamicObject;
00168         friend class DynamicObjectCar;
00169         float fIntersectingDepth;
00170         DynamicObject* pDynamicObject;
00171         CollisionObject* pCollisionObject;
00172         int nAttribute;
00173         Vec3 v3Position;
00174         Vec3 v3Normal;
00175     };
00176     TA_OBFUSCATION_RESERVED_ON
00177 
00178 
00179     typedef List<PhysicsJoint>::Iterator JointIterator;
00180     typedef DynamicObjectCollisionIterator CollisionIterator;
00181 
00182     const static float JOINT_LIMIT_DISABLED;
00183 
00184     //pl.BeginExportClass(DynamicObject)
00185 
00186     enum ReinitFlags
00187     {
00188         REINIT_FLAG_UPDATE_MASS = 0x1,
00189         REINIT_FLAG_UPDATE_INERTIA_TENSOR = 0x2,
00190         REINIT_FLAG_UPDATE_CENTER_OFFSET = 0x4,
00191     };
00192 
00194 
00195     void InitialiseFromFile(const Char* szFileName);
00196     void InitialiseAsABox(const AABB& aabb);
00197     void InitialiseAsAnOrientedBox(const AABB& aabb, const MFrame& mFrame);
00198     void InitialiseAsACapsule(const Vec3& v3Start, const Vec3& v3End, float fRadius);
00199     void InitialiseAsASphere(const Vec3& v3Center, float fRadius);
00200     void InitialiseAsACylinder(const Vec3& v3Start, const Vec3& v3End, float fRadius);
00201     void Initialise(CollisionObjectCombo* pCollisionObjectCombo);
00202     void Initialise(CollisionObjectComplex* pCollisionObjectComplex);
00203 #ifdef TA_PHYSICS_INTERNAL
00204     void InitialiseAsWorldObject();
00205 #endif // TA_PHYSICS_INTERNAL
00206     void Finalise();
00208 
00210 
00211     const MFrame& GetFrame() const;
00212     void SetFrame(const MFrame& frame);
00213     const MFrame& GetNextFrame() const;
00214     const MFrame& GetPreviousFrame() const;
00215     const MFrame& GetGraphicsFrame() const;
00216     const Vec3& GetPosition() const;
00217     void SetPosition(const Vec3& v3Position);
00218     const Vec3& GetCenterOfMass() const;
00219     const Vec3& GetNextCenterOfMass() const;
00220     const Vec3& GetCenterOffset() const;
00221     void SetCenterOffset(const Vec3& v3CenterOffset);
00222     // Added for super sampling in the Update function.
00223     // Todo: think of a safer way of doing this.
00224     void SetFrameDirect(const MFrame& frame);
00226 
00228 
00229     float GetMass() const;
00230     float GetInverseMass() const;
00231     void SetMass(float fMass);
00232     const Mat33& GetInertia() const;
00233     void SetInertiaFromBox(const AABB& aabb);
00234     void SetInertiaFromBox(float fX, float fY, float fZ);
00235     const Mat33& GetInverseInertia() const;
00236     const Mat33& GetWorldSpaceInertia() const;
00237     const Mat33& GetWorldSpaceInverseInertia() const;
00239 
00241 
00242     void SetFriction(float fFriction);
00243     float GetFriction() const;
00244     void SetRestitution(float fRestitution);
00245     float GetRestitution() const;
00246     void SetGravityMult(float fGravityMult);
00247     float GetGravityMult() const;
00248     void SetRotationDisabled(bool bValue);
00249     bool RotationDisabled() const;
00250     void SetMovementDisabled(bool bValue);
00251     bool MovementDisabled() const;
00252     void SetExtraStability(bool bValue);
00253     bool ExtraStability() const;
00254     void SetRigidFrictionDisabled(bool bValue);
00255     bool RigidFrictionDisabled() const;
00256     void SetCollisionDisabled(bool bValue);
00257     bool CollisionDisabled() const;
00258     void SetUpdateDisabled(bool bValue);
00259     bool UpdateDisabled() const;
00260     void SetGhost(bool bValue);
00261     bool Ghost() const;
00262     void SetInfiniteMass(bool bValue);
00263     bool InfiniteMass() const;
00264     void SetFindVelocityFromNextFrame(bool bValue);
00265     bool GetFindVelocityFromNextFrame() const;
00266     bool IsWorldObject() const;
00267     void SetRestTimeMultiplier(float fRestTimeMultiplier);
00268     float GetRestTimeMultiplier() const;
00269     void SetID(int nID); // WARNING, non unique ID's will cause problems.
00270     int GetID() const;
00271     Physics* GetPhysics();
00273 
00275 
00276     bool IsInMovingList() const;
00277     void SetToMoving();
00278     void SetToResting();
00280 
00281     TA_OBFUSCATION_RESERVED_OFF
00282     
00284 
00285 #ifdef TA_PHYSICS_INTERNAL
00286     float GetTimeRestConditionsMet() const { return m_fTimeRestConditionsMet; }
00287     void IncTimeRestConditionsMet(float fDt) { m_fTimeRestConditionsMet += fDt * m_fRestTimeMultiplier; SetAlmostAtRest(false); }
00288     void ResetTimeRestConditionsMet() { m_fTimeRestConditionsMet = 0.0f; SetAlmostAtRest(false); }
00289     void SetAlmostAtRest(bool bValue) { SetFlag(m_nFlags, ALMOST_AT_REST, bValue); }
00290     bool IsAlmostAtRest() const { return GetFlag(m_nFlags, ALMOST_AT_REST); }
00291     void SetWorldObject(bool bValue) { SetFlag(m_nFlags, WORLD_OBJECT, bValue); }
00292 
00293     // Internal use only
00294     int GetNumRestingPoints() const { return m_nNumRestingPoints; }
00295     void IncNumRestingPoints() { m_nNumRestingPoints++; }
00296     void ResetNumRestingPoints() { m_nNumRestingPoints = 0; }   
00297 
00298     // Internal use only
00299     void SetInMovingList(void* pMovingListData) { m_pMovingListData = pMovingListData; SetFlag(m_nFlags, IN_MOVING_LIST, m_pMovingListData != 0); SetFlag(m_nFlags, ALMOST_AT_REST, m_pMovingListData == 0); }
00300     void* GetInMovingListData() { return m_pMovingListData; }
00301 
00302     void SetReadyToComeToRest(bool bValue) { SetFlag(m_nFlags, READY_TO_COME_TO_REST, bValue); }
00303     bool IsReadyToComeToRest() const { return GetFlag(m_nFlags, READY_TO_COME_TO_REST); }
00304 
00305     // Internal use only
00306     void SetTemporarySolidForSolver(bool bValue) { SetFlag(m_nFlags, TEMPORARY_SOLID_FOR_SOLVER, bValue); }
00307     bool IsTemporarySolidForSolver() const { return GetFlag(m_nFlags, TEMPORARY_SOLID_FOR_SOLVER); }
00308     void SetMarked1(bool bValue) { SetFlag(m_nFlags, MARKED1, bValue); }
00309     bool IsMarked1() const { return GetFlag(m_nFlags, MARKED1); }
00310     void SetMarked2(bool bValue) { SetFlag(m_nFlags, MARKED2, bValue); }
00311     bool IsMarked2() const { return GetFlag(m_nFlags, MARKED2); }
00312     u32& FlagsRef() { return m_nFlags; }
00313     u32 GetFlags() const { return m_nFlags; }
00314     
00315     Globals* GetGlobals() { return m_pGlobals; }
00316     void SetGlobals(Globals* pGlobals) { m_pGlobals = pGlobals; }
00317 
00318 #define TA_DEFINE_COLLISION_FUNCTIONS(PRE, NAMESPACE) \
00319     PRE void TAC_CALL NAMESPACE::DoCollision(float fSeparatingSpeed, Collision& collision); \
00320     PRE void TAC_CALL NAMESPACE::DoCollisionPropagated(float fSeparatingSpeed, float fScale, float fFrictionScale, Collision& collision); \
00321     PRE bool TAC_CALL NAMESPACE::DoFriction(float fImpulse, Collision& collision); \
00322     PRE void TAC_CALL NAMESPACE::DoFrictionPropagated(float fSeparatingSpeed, float fScale, Collision& collision);
00323     
00324     TA_DEFINE_COLLISION_FUNCTIONS(friend, Optimized)
00325     TA_DEFINE_COLLISION_FUNCTIONS(friend, OptimizedSSE2)
00326 
00327 /*  friend void TAC_CALL DoCollision(float fSeparatingSpeed, Collision& collision);
00328     friend void TAC_CALL DoCollision_SSE2(float fSeparatingSpeed, Collision& collision);
00329     friend void TAC_CALL DoCollisionPropagated(float fSeparatingSpeed, float fScale, float fFrictionScale, Collision& collision);
00330     friend void TAC_CALL DoCollisionPropagated_SSE2(float fSeparatingSpeed, float fScale, float fFrictionScale, Collision& collision);
00331     friend bool TAC_CALL DoFriction(float fImpulse, Collision& collision);
00332     friend bool TAC_CALL DoFriction_SSE2(float fImpulse, Collision& collision);
00333     friend void TAC_CALL DoFrictionPropagated(float fSeparatingSpeed, float fScale, Collision& collision);  
00334     friend void TAC_CALL DoFrictionPropagated_SSE2(float fSeparatingSpeed, float fScale, Collision& collision);*/
00335 
00336 #endif // TA_PHYSICS_INTERNAL
00338     
00339     TA_OBFUSCATION_RESERVED_ON
00341 
00342     const Vec3& GetLinearVelocity() const;
00343     void SetLinearVelocity(const Vec3& v3LinearVelocity);
00344     const Vec3& GetAngularVelocity() const;
00345     void SetAngularVelocity(const Vec3& v3AngularVelocity);
00346     void SetVelocitiesToMoveToFrame(const MFrame& mFrame, float fDt);
00347     Vec3 GetVelocityAtWorldPosition(const Vec3& v3Position) const;
00348     void ApplyImpulse(const Vec3& v3WorldImpulse, const Vec3& v3WorldPosition);
00349     void ApplyLinearImpulse(const Vec3& v3WorldLinearImpulse);
00350     void ApplyAngularImpulse(const Vec3& v3WorldAngularImpulse);
00352 
00354 
00355     void AssertForceAndTorqueCleared() const;
00356     void AccumulateGravity();   
00357     void AccumulateForceAndTorque(const Vec3& v3WorldForce, const Vec3& v3WorldPosition);
00358     void AccumulateLinearForce(const Vec3& v3WorldForce);
00359     void ApplyForceAndTorqueToVelocities(float fDt);
00360     void ClearForceAndTorque();
00362 
00364 
00365     void Clear();
00366     void UpdateWorldSpaceInertialTensor();
00367     virtual void Update(float fDt);
00368     virtual void UpdateGraphics(float fDt, float fInterpolant);
00369     void Extrapolate(
00370         const MFrame& frameA,
00371         const MFrame& frameB,
00372         const Vec3& v3VelocityA,
00373         const Vec3& v3VelocityB,
00374         float fDt,
00375         float fExtrapolation);
00376     virtual void ApplyVelocityToNextFrame(float fDt);
00377     void ApplyNextFrame();
00379 
00381 
00382     void Render();
00383     //&}
00384 
00385     // Used by collision group manager to group contacting objects
00387 
00388     TA_OBFUSCATION_RESERVED_OFF
00389 #ifdef TA_PHYSICS_INTERNAL
00390     void SetGroupHandle(void* pGroupHandle) { m_pGroupHandle = pGroupHandle; }
00391     void* GetGroupHandle() { return m_pGroupHandle; }
00392 #endif // TA_PHYSICS_INTERNAL
00393     TA_OBFUSCATION_RESERVED_ON
00395 
00397 
00398     void CalculateWorldAABB();
00399     const AABB& GetWorldAABB();
00400 #ifndef TA_WRAPPER  
00401     CollisionObject& GetCollisionObject();
00402 #endif // TA_WRAPPER
00403     CollisionObjectCombo* GetCollisionObjectCombo();
00404     CollisionObjectComplex* GetCollisionObjectComplex();
00405     void SetCollisionObject(
00406         CollisionObjectCombo* pCollisionObjectCombo, 
00407         int nFlags = (REINIT_FLAG_UPDATE_MASS | REINIT_FLAG_UPDATE_INERTIA_TENSOR | REINIT_FLAG_UPDATE_CENTER_OFFSET));
00408     void SetCollisionObjectChanged(
00409         int nFlags = (REINIT_FLAG_UPDATE_MASS | REINIT_FLAG_UPDATE_INERTIA_TENSOR | REINIT_FLAG_UPDATE_CENTER_OFFSET));
00410     void ReinitCollisionAsABox(
00411         const AABB& aabb, 
00412         int nFlags = (REINIT_FLAG_UPDATE_MASS | REINIT_FLAG_UPDATE_INERTIA_TENSOR | REINIT_FLAG_UPDATE_CENTER_OFFSET));
00413     void ReinitCollisionAsAnOrientedBox(
00414         const AABB& aabb, 
00415         const MFrame& mFrame, 
00416         int nFlags = (REINIT_FLAG_UPDATE_MASS | REINIT_FLAG_UPDATE_INERTIA_TENSOR | REINIT_FLAG_UPDATE_CENTER_OFFSET));
00417     void ReinitCollisionAsACapsule(
00418         const Vec3& v3Start, 
00419         const Vec3& v3End, 
00420         float fRadius, 
00421         int nFlags = (REINIT_FLAG_UPDATE_MASS | REINIT_FLAG_UPDATE_INERTIA_TENSOR | REINIT_FLAG_UPDATE_CENTER_OFFSET));
00422     void ReinitCollisionAsASphere(
00423         const Vec3& v3Center, 
00424         float fRadius, 
00425         int nFlags = (REINIT_FLAG_UPDATE_MASS | REINIT_FLAG_UPDATE_INERTIA_TENSOR | REINIT_FLAG_UPDATE_CENTER_OFFSET));
00426     void ReinitCollisionAsACylinder(
00427         const Vec3& v3Start, 
00428         const Vec3& v3End, 
00429         float fRadius, 
00430         int nFlags = (REINIT_FLAG_UPDATE_MASS | REINIT_FLAG_UPDATE_INERTIA_TENSOR | REINIT_FLAG_UPDATE_CENTER_OFFSET));
00431     
00432 #ifndef TA_WRAPPER
00433     CollisionIterator GetCollisionIterator();
00434 #ifndef TA_REMOVE_DEPRECATED
00435     void SetCollisionListEnabled(bool bValue);
00436     bool CollisionListEnabled() const;
00437 #endif
00438 #endif // TA_WRAPPER
00439     bool TestLineForCollision(
00440         const Vec3& v3Start,
00441         const Vec3& v3Normal,
00442         float fLength,
00443         Collision& collision) const;
00445 
00447 
00448     TA_OBFUSCATION_RESERVED_OFF
00449 #ifdef TA_PHYSICS_INTERNAL
00450     void AddLineCollision(
00451         int nLineID,
00452         DynamicObject* pDynamicObject,
00453         CollisionObject* pCollisionObject,
00454         u32 nAttribute,
00455         float fIntersectingDepth,
00456         const Vec3& v3Position,
00457         const Vec3& v3Normal);
00458 #endif // TA_PHYSICS_INTERNAL
00459     TA_OBFUSCATION_RESERVED_ON
00461 
00463 
00464     int GetNumLineCollisions();
00465     const LineIntersection& GetLineCollision(int nIndex) const;
00467 
00469 
00470     PhysicsJoint& AddJoint(
00471         DynamicObject* pOtherObject);
00472     // Note: Is is necessary to call this before calling release if you 
00473     // wish to destroy the objects
00474     void RemoveAllJoints();     
00475     void RemoveJoint(PhysicsJoint& joint);
00476     void RemoveJointsToObject(DynamicObject* pDynamicObject);
00478 
00480 
00481 #ifndef TA_REMOVE_DEPRECATED
00482     PhysicsJoint& AddJoint(
00483         DynamicObject* pOtherObject, 
00484         const Vec3& v3LocalPos, 
00485         const Vec3& v3LocalPosOnOtherObject,
00486         const Mat33& m33DefaultRotationOfOtherObject,
00487         const EulerAngles& minAngles,
00488         const EulerAngles& maxAngles);
00489     PhysicsJoint& AddJointTypeHinge(
00490         DynamicObject* pOtherObject, 
00491         const Vec3& v3LocalPos,
00492         const Vec3& v3LocalPosOnOtherObject,
00493         const Vec3& v3LocalHingeAxis, 
00494         const Vec3& v3LocalHingeNormal, 
00495         float fMinAngle,
00496         float fMaxAngle);
00497     PhysicsJoint& AddJointTypeSocket(
00498         DynamicObject* pOtherObject, 
00499         const Vec3& v3LocalPos, 
00500         const Vec3& v3LocalPosOnOtherObject,
00501         const Vec3& v3LimitCenterNormal,
00502         const Vec3& v3LimitCenterNormalOnOtherObject,
00503         float fMaxAngle);
00504     PhysicsJoint& AddJointTypeLimitedSocket(
00505         DynamicObject* pOtherObject, 
00506         const Vec3& v3LocalPos, 
00507         const Vec3& v3LocalPosOnOtherObject,
00508         const Mat33& m33DefaultRotationOfOtherObject,
00509         float fMaxAngleY,
00510         float fMaxAngleXZ);
00511     PhysicsJoint& AddJointTypeSquareSocket(
00512         DynamicObject* pOtherObject, 
00513         const Vec3& v3LocalPos, 
00514         const Vec3& v3LocalPosOnOtherObject,
00515         const Mat33& m33DefaultRotationOfOtherObject,
00516         float fMinX,
00517         float fMaxX,
00518         float fMinY,
00519         float fMaxY,
00520         float fMinZ,
00521         float fMaxZ);
00522     PhysicsJoint& AddJointTypeSlider(
00523         DynamicObject* pOtherObject, 
00524         const Vec3& v3LocalPos,
00525         const Vec3& v3StartPosOnOtherObject,
00526         const Vec3& v3EndPosPosOnOtherObject);
00527     PhysicsJoint& AddRotationConstraint(
00528         DynamicObject* pOtherObject, 
00529         const Mat33& m33DefaultRotationOfOtherObject,
00530         const EulerAngles& minAngles,
00531         const EulerAngles& maxAngles);
00532     PhysicsJoint& AddVectorConstraint(
00533         DynamicObject* pOtherObject,
00534         const Vec3& v3LimitCenterNormal,
00535         const Vec3& v3LimitCenterNormalOnOtherObject,
00536         float fMaxAngle);
00537 #endif // TA_REMOVE_DEPRECATED
00538 #ifndef TA_WRAPPER
00539     /*PhysicsJoint& AddJointFixed(
00540         DynamicObject* pOtherObject, 
00541         const Vec3& v3LocalPos, 
00542         const Vec3& v3LocalPosOnOtherObject,
00543         const Mat33& m33DefaultRotationOfOtherObject);*/
00544 #ifdef TA_DYNAMIC_OBJECT_GROUP_ENABLED
00545     DynamicObjectGroup* GetDynamicObjectGroup() { return m_pDynamicObjectGroup; }
00546 #endif // TA_DYNAMIC_OBJECT_GROUP_ENABLED
00547 #endif // TA_WRAPPER    
00548 
00549     
00550 #ifndef TA_WRAPPER
00551     JointIterator GetJointIterator();
00552 #endif // TA_WRAPPER
00553 
00554 
00556 
00557     TA_OBFUSCATION_RESERVED_OFF
00558 #ifdef TA_PHYSICS_INTERNAL
00559     List<PhysicsJoint*>::Iterator GetConnectedJointIterator() { return m_connectedFromJointList.GetIterator(); }
00560     void ClearCollisions();
00561     DynamicObjectPair* GetPair(DynamicObject* pOther, bool bCreateIfNotFound);
00562     DynamicObjectPair* CreatePair(DynamicObject* pOther);
00563     DynamicObjectPairListItem* GetPairList() { return m_pPairList; }
00564     int GetCurrentPairID() { return m_nPairID; }
00565     void SetCurrentPairID(int nPairID) { m_nPairID = nPairID; }
00566     void SetPairIdForAllPairs(int nPairID);
00567     void SetPairIdForAllJointsWithCollisionDisabled(int nPairID);
00568     void ForAllPairs(void (TAC_CALL *pfnForPair)(DynamicObjectPair& pair, void* pData), void* pData);
00569     void RemoveAllPairs();
00570     void OnFreePair(DynamicObjectPair& pair);
00571     void SetBuildMatrixNumber(int nBuildMatrixNumber) { m_nBuildMatrixNumber = nBuildMatrixNumber; }
00572     int GetBuildMatrixNumber() const { return m_nBuildMatrixNumber; }
00573     void UpdatePreviousVelocities();
00574     void ResetToPreviousVelocities();
00575     void SetAccumulatedImpulse(float fValue) { m_fAccumulatedImpulse = fValue; }
00576     void AccumulateImpulse(float fValue) { m_fAccumulatedImpulse += fValue; }
00577     float GetAccumulatedImpulse() const { return m_fAccumulatedImpulse; }
00578     const Vec3& GetPreviousLinearVelocity() const { return m_v3PreviousLinearVelocity; }
00579     const Vec3& GetPreviousAngularVelocity() const { return m_v3PreviousAngularVelocity; }  
00580     const void SetNextFrame(const MFrame& frame) { m_nextFrame = frame; m_v3NextWorldCenterOfMass = m_v3CenterOffset * frame; }
00581     void UpdateAccumulatedMovement(float fDt);
00582     const Vec3& GetAccumulatedMovement() const { return m_v3AccumulatedMovement; }
00583     const Vec3& GetAccumulatedRotation() const { return m_v3AccumulatedRotation; }
00584     void AddAllJointConnectedObjectToMovingList();
00585     float GetSolverScale() const { return m_fSolverScale; } 
00586     bool CanAddToCollisionGroup() const { return (m_nFlags & (INFINITE_MASS | MOVEMENT_DISABLED | IN_MOVING_LIST)) == IN_MOVING_LIST; }
00587     //bool CanAddToCollisionGroup() const { return (m_nFlags & (INFINITE_MASS | MOVEMENT_DISABLED)) == 0; }
00588 #endif // TA_PHYSICS_INTERNAL
00589     TA_OBFUSCATION_RESERVED_ON
00591     
00593 
00594     bool IsAllowedToCollideWith(const DynamicObject& otherObject) const;
00595     void SetUserGroup(int nUserGroupId);
00596     int GetUserGroup() const;
00597     void SetUserGroupItemId(int nUserGroupItemId);
00598     int GetUserGroupItemId() const;
00599     void DisallowCollisionWithUserGroupItemId(int nUserGroupItemId);
00600     void AllowCollisionWithUserGroupItemId(int nUserGroupItemId);
00601 #ifndef TA_REMOVE_DEPRECATED
00602     void SetCollisionUserData(void* pData);
00603     void* GetCollisionUserData() const;
00604 #endif // TA_REMOVE_DEPRECATED
00605     void SetUserData(void* pData);
00606     void* GetUserData() const;
00608 
00609 
00610     static int TAC_CALL CreateUserGroup();
00612 
00613     static DynamicObject* TAC_CALL CreateNew();
00614     //pl.Release()
00615     
00616     //pl.EndExportClass(DynamicObject)
00617         
00618 
00619 protected:  
00620     DynamicObject();
00621     virtual ~DynamicObject();
00622     void InitialiseCommon();
00623     void ClearLineIntersections();
00624     TA_OBFUSCATION_RESERVED_OFF
00625 
00626 private:
00627     //friend DynamicObjectGroup;
00628 #ifdef TA_PHYSICS_INTERNAL
00629 public:
00630 #endif // TA_PHYSICS_INTERNAL
00631     enum Flags
00632     {
00633         IN_MOVING_LIST =                    0x1,
00634         READY_TO_COME_TO_REST =             0x2,
00635         NO_RIGID_FRICTION =                 0x4,
00636         ROTATION_DISABLED =                 0x8,
00637         EXTRA_STABILITY =                   0x10,
00638         DISABLE_COLLISION =                 0x20,
00639         GHOST =                             0x40,
00640         DISABLE_UPDATE =                    0x80,
00641         MOVEMENT_DISABLED =                 0x100,
00642         TEMPORARY_SOLID_FOR_SOLVER =        0x400,
00643         COLLISION_LIST_ENABLED =            0x800,
00644         INFINITE_MASS =                     0x1000,
00645         ALMOST_AT_REST =                    0x2000,
00646         MARKED1 =                           0x4000,
00647         MARKED2 =                           0x8000,
00648         FIND_VELOCITY_FROM_NEXT_FRAME =     0x10000,
00649         WORLD_OBJECT =                      0x20000,
00650     };  
00651 #ifdef TA_PHYSICS_INTERNAL
00652 private:
00653 #endif //TA_PHYSICS_INTERNAL
00654     float m_fMass;
00655     float m_fInverseMass;
00656     float m_fFriction;
00657     float m_fRestitution;
00658     float m_fTimeRestConditionsMet;
00659     float m_fRestTimeMultiplier;
00660     float m_fGravityMult;
00661     float m_fAccumulatedImpulse;
00662     float m_fSolverScale;
00663     int m_nNumRestingPoints;
00664     u32 m_nFlags;
00665     int m_nBuildMatrixNumber;
00666     int m_nID;
00667     void* m_pMovingListData;
00668     void* m_pGroupHandle;
00669     int m_nUserGroupId;
00670     u32 m_nUserGroupItemId; // Only one bit is set at a time.
00671     u32 m_nNotAllowedToCollideWith;         // the number of each bit refers to a m_nUserGroupItemId value
00672     CollisionObject* m_pCollisionObject;
00673     DynamicObjectGroup* m_pDynamicObjectGroup;
00674     void* m_pUserData;
00675     DynamicObjectPairListItem* m_pPairList;
00676     int m_nNumPairs;
00677     int m_nPairID;
00678     Globals* m_pGlobals;
00679     Array<LineIntersection, false> m_lineIntersectionArray;
00680     List<PhysicsJoint> m_jointList; 
00681     List<PhysicsJoint*> m_connectedFromJointList;   
00682     Mat33 m_m33Inertia; // Inertia tensor
00683     Mat33 m_m33InverseInertia;
00684     Mat33 m_m33InertiaWorld; // Inertia tensor in world space
00685     Mat33 m_m33InverseInertiaWorld;
00686     Vec3 m_v3CenterOffset;
00687     Vec3 m_v3WorldCenterOfMass;
00688     Vec3 m_v3NextWorldCenterOfMass;
00689     MFrame m_frame;
00690     MFrame m_nextFrame;
00691     MFrame m_smoothedFrame;
00692     MFrame m_previousFrame;
00693     MFrame m_gfxFrame;
00694     Vec3 m_v3LinearVelocity;
00695     Vec3 m_v3AngularVelocity;
00696     Vec3 m_v3PreviousLinearVelocity;
00697     Vec3 m_v3PreviousAngularVelocity;
00698     Vec3 m_v3AccumulatedForce;
00699     Vec3 m_v3AccumulatedTorque;
00700     Vec3 m_v3AccumulatedMovement;
00701     Vec3 m_v3AccumulatedRotation;
00702     AABB m_worldAABB;
00703     
00704     bool CanApplyImpulse() const { return (m_nFlags & (INFINITE_MASS | MOVEMENT_DISABLED | IN_MOVING_LIST)) == IN_MOVING_LIST; }
00705 
00706     // collision grid object virtual functions
00707     virtual const Vec3& GetCollisionGridWorldPos() const { return m_worldAABB.v3Center; }//GetPosition().x; }
00708     virtual const AABB& GetCollisionGridWorldAABB() const { return m_worldAABB; }
00709     virtual const AABB& GetCollisionGridGetLocalAABB() const { return m_pCollisionObject->GetAABB(); }
00710 
00711 };
00712 
00713 }
00714 
00715 #include "DynamicObject.inl"
00716 
00717 #endif // TA_DYNAMICOBJECT_H


© Copyright 2004-2006 TRUE AXIS PTY LTD Australia. All rights reserved.