Changeset 1632


Ignore:
Timestamp:
Jul 15, 2012, 3:04:24 PM (8 years ago)
Author:
touky
Message:

Small name refactor & correct Kinematic integration.
+ Constraint hollow class.

Location:
trunk/test
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/PhysicObject.h

    r1631 r1632  
    3131                m_physics.SetMass(.0f);
    3232                m_physics.SetTransform(base_location, base_rotation);
    33                 m_physics.InitBodyToRigid();
     33                m_physics.InitBodyToRigid(true);
    3434                m_physics.AddToSimulation(new_sim);
    3535        }
     
    165165        //Base datas
    166166        EasyMesh                m_mesh;
    167         EasyPhysics             m_physics;
     167        EasyPhysic              m_physics;
    168168
    169169        bool                    m_ready;
  • trunk/test/Physics/EasyPhysics.cpp

    r1631 r1632  
    3131#ifdef HAVE_PHYS_USE_BULLET
    3232
    33 EasyPhysics::EasyPhysics() :
     33EasyPhysic::EasyPhysic() :
    3434        m_collision_object(NULL),
    3535        m_rigid_body(NULL),
     
    4343}
    4444
    45 EasyPhysics::~EasyPhysics()
     45EasyPhysic::~EasyPhysic()
    4646{
    4747        m_rigid_body = NULL;
     
    5555//--
    5656
    57 void EasyPhysics::SetShapeTo(btCollisionShape* collision_shape)
     57void EasyPhysic::SetShapeTo(btCollisionShape* collision_shape)
    5858{
    5959        bool bReinitToRigidBody = false;
     
    7373
    7474//Box Shape support
    75 void EasyPhysics::SetShapeToBox(lol::vec3& box_size)
     75void EasyPhysic::SetShapeToBox(lol::vec3& box_size)
    7676{
    7777        vec3 new_box_size = box_size * LOL2BT_UNIT * LOL2BT_SIZE;
     
    7979}
    8080
    81 void EasyPhysics::SetShapeToSphere(float radius)
     81void EasyPhysic::SetShapeToSphere(float radius)
    8282{
    8383        SetShapeTo(new btSphereShape(radius * LOL2BT_UNIT * LOL2BT_SIZE));
    8484}
    8585
    86 void EasyPhysics::SetShapeToCone(float radius, float height)
     86void EasyPhysic::SetShapeToCone(float radius, float height)
    8787{
    8888        SetShapeTo(new btConeShape(     radius * LOL2BT_UNIT,
     
    9090}
    9191
    92 void EasyPhysics::SetShapeToCylinder(lol::vec3& cyl_size)
     92void EasyPhysic::SetShapeToCylinder(lol::vec3& cyl_size)
    9393{
    9494        vec3 new_cyl_size = cyl_size * LOL2BT_UNIT;
     
    9797}
    9898
    99 void EasyPhysics::SetShapeToCapsule(float radius, float height)
     99void EasyPhysic::SetShapeToCapsule(float radius, float height)
    100100{
    101101        SetShapeTo(new btCapsuleShape(  radius * LOL2BT_UNIT * LOL2BT_SIZE,
     
    104104
    105105//-------------------------------------------------------------------------
    106 //Bullet collision channel setup
    107 //--
    108 void EasyPhysics::CustomSetCollisionChannel(int NewGroup, int NewMask)
    109 {
    110         if (m_rigid_body)
    111                 m_rigid_body->setCollisionFlags(m_collision_mask);
    112 }
    113 
    114 //-------------------------------------------------------------------------
    115106//Base Location/Rotation setup
    116107//--
    117 void EasyPhysics::SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation)
     108void EasyPhysic::SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation)
    118109{
    119110        if (m_motion_state)
    120         {
    121                 if (m_mass != .0f)
    122                         m_motion_state->setWorldTransform(btTransform(LOL2BT_QUAT(base_rotation), LOL2BT_VEC3(base_location)));
    123                 else
    124                 {
    125                         m_rigid_body->setWorldTransform(btTransform(LOL2BT_QUAT(base_rotation), LOL2BT_VEC3(base_location)));
    126                         m_motion_state->setWorldTransform(btTransform(LOL2BT_QUAT(base_rotation), LOL2BT_VEC3(base_location)));
    127                 }
    128         }
     111                m_motion_state->setWorldTransform(btTransform(LOL2BT_QUAT(base_rotation), LOL2BT_VEC3(base_location)));
    129112        else
    130113                m_motion_state = new btDefaultMotionState(btTransform(LOL2BT_QUAT(base_rotation), LOL2BT_VEC3(base_location)));
     
    135118//--
    136119//Set Shape functions
    137 void EasyPhysics::SetMass(float mass)
     120void EasyPhysic::SetMass(float mass)
    138121{
    139122        m_mass = mass;
     
    151134
    152135//Init to rigid body
    153 void EasyPhysics::InitBodyToRigid()
     136void EasyPhysic::InitBodyToRigid(bool SetToKinematic)
    154137{
    155138        if (m_collision_object)
     
    159142        if (!m_motion_state)
    160143                SetTransform(vec3(.0f));
     144
    161145        btRigidBody::btRigidBodyConstructionInfo NewInfos(m_mass, m_motion_state, m_collision_shape, m_local_inertia);
    162146        m_rigid_body = new btRigidBody(NewInfos);
    163147        m_collision_object = m_rigid_body;
    164 }
    165 
    166 void EasyPhysics::AddToSimulation(class Simulation* current_simulation)
     148
     149        if (m_mass == .0f && SetToKinematic)
     150        {
     151                m_rigid_body->setActivationState(DISABLE_DEACTIVATION);
     152                m_rigid_body->setCollisionFlags(m_rigid_body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
     153        }
     154}
     155
     156void EasyPhysic::AddToSimulation(class Simulation* current_simulation)
    167157{
    168158        btDiscreteDynamicsWorld* dynamics_world = current_simulation->GetWorld();
     
    183173//--
    184174
    185 mat4 EasyPhysics::GetTransform()
     175mat4 EasyPhysic::GetTransform()
    186176{
    187177        m_local_to_world = lol::mat4(1.0f);
     
    198188
    199189//Set Local Inertia
    200 void EasyPhysics::SetLocalInertia(float mass)
     190void EasyPhysic::SetLocalInertia(float mass)
    201191{
    202192        if (mass != .0f)
     
    205195                m_local_inertia = btVector3(.0f, .0f, .0f);
    206196}
    207 #endif
     197
     198#endif // HAVE_PHYS_USE_BULLET
    208199
    209200} /* namespace phys */
  • trunk/test/Physics/EasyPhysics.h

    r1631 r1632  
    1111
    1212//
    13 // The EasyPhysics class
     13// The EasyPhysic class
    1414// ------------------
    1515//
     
    3030{
    3131
    32 class EasyPhysics
     32class EasyPhysic
    3333{
     34
    3435#ifdef HAVE_PHYS_USE_BULLET
     36
    3537public:
    36         EasyPhysics();
    37         ~EasyPhysics();
     38        EasyPhysic();
     39        ~EasyPhysic();
    3840
    3941        void SetShapeToBox(lol::vec3& box_size);
     
    4345        void SetShapeToCapsule(float radius, float height);
    4446
    45         void CustomSetCollisionChannel(int NewGroup, int NewMask);
     47        bool CanChangeCollisionChannel() { return (m_rigid_body == NULL); }
    4648        void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation=lol::quat(lol::mat4(1.0f)));
    4749        void SetMass(float mass);
    48         void InitBodyToRigid();
     50        void InitBodyToRigid(bool ZeroMassIsKinematic=false);
    4951        void AddToSimulation(class Simulation* current_simulation);
    5052        mat4 GetTransform();
     
    6163        btCollisionShape*                                                       m_collision_shape;
    6264        btMotionState*                                                          m_motion_state;
    63 #else
     65
     66#else  // NO PHYSIC IMPLEMENTATION
     67
    6468public:
    65         EasyPhysics() { }
     69        EasyPhysic() { }
    6670
    6771        void SetShapeToBox(lol::vec3& BoxSize) { }
     
    7175        void SetShapeToCapsule(float radius, float height) { }
    7276
    73         void CustomSetCollisionChannel(int NewGroup, int NewMask) { }
     77        bool CanChangeCollisionChannel() { return true; }
    7478        void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation=lol::quat(lol::mat4(1.0f))) { }
    7579        void SetMass(float mass) { }
     
    7781        void AddToSimulation(class Simulation* current_simulation) { }
    7882        mat4 GetTransform() { return mat4(1.0f); }
    79 #endif
     83
     84#endif // PHYSIC IMPLEMENTATION
    8085
    8186public:
    8287        //Sets the collision Group & Mask.
    8388        //Mask can change at runtime, not group !
    84         void SetCollisionChannel(int NewGroup, int NewMask)
     89        bool SetCollisionChannel(int NewGroup, int NewMask)
    8590        {
    86                 m_collision_group = (1<<NewGroup);
    87                 m_collision_mask = NewMask;
    88                 CustomSetCollisionChannel(NewGroup, NewMask);
     91                if (CanChangeCollisionChannel())
     92                {
     93                        m_collision_group = (1<<NewGroup);
     94                        m_collision_mask = NewMask;
     95                        return true;
     96                }
     97                return false;
    8998        }
    9099        int GetCollisionGroup() { return m_collision_group; }
     
    98107};
    99108
     109class EasyConstraint
     110{
     111        EasyConstraint()
     112        {
     113                //btPoint2PointConstraint(bA, bB, PivotA, PivotB)
     114                //btHingeConstraint(bA, bB, TransfA, TransfB, UseRefA)
     115                //btSliderConstraint(bA, bB, TransfA, TransfB, UseRefA)
     116                //btConeTwistConstraint(bA, bB, TransfA, TransfB)
     117                //btGeneric6DofConstraint(bA, bB, TransfA, TransfB, UseRefA)
     118        }
     119
     120#ifdef HAVE_PHYS_USE_BULLET
     121
     122        btTypedConstraint*                      m_typed_constraint;
     123
     124#else  // NO PHYSIC IMPLEMENTATION
     125
     126#endif // PHYSIC IMPLEMENTATION
     127
     128};
     129
    100130} /* namespace phys */
    101131
  • trunk/test/Physics/LolBtPhysicsIntegration.h

    r1614 r1632  
    2121{
    2222
     23#ifdef HAVE_PHYS_USE_BULLET
     24
    2325#define LOL2BT_UNIT                             1.0f
    2426#define BT2LOL_UNIT                             1.0f
     
    3335#define BT2LOL_QUAT(ELEMENT)    lol::quat((ELEMENT).getW(), BT2LOL_VEC3((ELEMENT).getAxis())
    3436
     37#endif // HAVE_PHYS_USE_BULLET
     38
    3539} /* namespace lol */
    3640
  • trunk/test/Physics/LolPhysics.h

    r1631 r1632  
    2424class Simulation : public Entity
    2525{
    26         friend class EasyPhysics;
    27 
    2826public:
    2927        Simulation() :
     
    110108        // The world.
    111109        btDiscreteDynamicsWorld*                                m_dynamics_world;
    112 #else
     110
     111#else  // NO PHYSIC IMPLEMENTATION
     112
    113113public:
    114114        void Init() { }
     
    119119        void CustomSetGravity(vec3 &NewGravity) { }
    120120        void CustomSetTimestep(float NewTimestep) { }
    121 #endif //HAVE_PHYS_USE_BULLET
     121
     122#endif // PHYSIC IMPLEMENTATION
    122123
    123124public:
     
    151152
    152153private:
    153         //Adds the given EasyPhysics to the correct list.
    154         void AddToDynamic(EasyPhysics* dynamic_EP)      { m_dynamic_list << dynamic_EP; }
    155         void AddToStatic(EasyPhysics* static_EP)        { m_static_list << static_EP; }
     154        friend class EasyPhysic;
     155        friend class EasyConstraint;
     156
     157        //Adds the given EasyPhysic to the correct list.
     158        void AddToDynamic(EasyPhysic* NewEPDynamic)     { m_dynamic_list << NewEPDynamic; }
     159        void AddToStatic(EasyPhysic* NewEPStatic)       { m_static_list << NewEPStatic; }
     160        void AddToConstraint(EasyConstraint* NewEC)     { m_constraint_list     << NewEC; }
    156161
    157162        //Easy Physics body List
    158         Array<EasyPhysics*>                                             m_dynamic_list;
    159         Array<EasyPhysics*>                                             m_static_list;
     163        Array<EasyPhysic*>                                              m_dynamic_list;
     164        Array<EasyPhysic*>                                              m_static_list;
     165        Array<EasyConstraint*>                                  m_constraint_list;
    160166
    161167        //Easy Physics data storage
Note: See TracChangeset for help on using the changeset viewer.