Changeset 1768 for trunk/test/Physics/Include
- Timestamp:
- Aug 17, 2012, 7:41:36 PM (11 years ago)
- Location:
- trunk/test/Physics/Include
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/Physics/Include/EasyCharacterController.h
r1764 r1768 30 30 { 31 31 32 class EasyCharacterController : public EasyPhysic 32 class EasyCharacterController : public EasyPhysic, 33 public Entity 33 34 { 34 35 … … 38 39 EasyCharacterController(WorldEntity* NewOwnerEntity) : 39 40 EasyPhysic(NewOwnerEntity), 40 m_character(NULL) 41 m_pair_caching_object(NULL), 42 m_character(NULL), 43 m_step_height(.0f), 44 m_base_is_updating(false), 45 m_base_cached_movement(vec3(0.f)), 46 m_frame_cached_movement(vec3(0.f)) 41 47 { 48 m_gamegroup = GAMEGROUP_EZP_CHAR_CTRLR; 42 49 m_up_axis = 1; 43 50 } … … 53 60 virtual void SetMovementForFrame(vec3 const &MoveQuantity); 54 61 62 virtual void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation); 63 protected: 64 virtual void BaseTransformChanged(const lol::mat4& PreviousMatrix, const lol::mat4& NewMatrix); 65 public: 66 virtual void TickGame(float seconds); 67 55 68 protected: 56 69 57 virtual btGhostObject* GetGhostObject ();70 virtual btGhostObject* GetGhostObjectInstance(); 58 71 59 72 btPairCachingGhostObject* m_pair_caching_object; … … 62 75 float m_step_height; 63 76 int m_up_axis; 77 bool m_base_is_updating; 78 vec3 m_base_cached_movement; 79 vec3 m_frame_cached_movement; 64 80 65 81 #else // NO PHYSIC IMPLEMENTATION -
trunk/test/Physics/Include/EasyPhysics.h
r1764 r1768 35 35 36 36 friend class EasyConstraint; 37 friend class Simulation; 37 38 38 39 #ifdef HAVE_PHYS_USE_BULLET … … 49 50 50 51 virtual bool CanChangeCollisionChannel() { return (m_rigid_body == NULL); } 52 virtual mat4 GetTransform(); 51 53 virtual void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation=lol::quat(lol::mat4(1.0f))); 52 pr ivate:54 protected: 53 55 virtual void BaseTransformChanged(const lol::mat4& PreviousMatrix, const lol::mat4& NewMatrix); 54 56 public: … … 58 60 virtual void AddToSimulation(class Simulation* current_simulation); 59 61 virtual void RemoveFromSimulation(class Simulation* current_simulation); 60 virtual mat4 GetTransform();61 62 62 63 protected: … … 64 65 virtual void SetShapeTo(btCollisionShape* collision_shape); 65 66 66 virtual btGhostObject* GetGhostObject ();67 virtual btGhostObject* GetGhostObjectInstance(); 67 68 68 69 btCollisionObject* m_collision_object; … … 89 90 90 91 virtual bool CanChangeCollisionChannel() { return true; } 92 virtual mat4 GetTransform() { return mat4(1.0f); } 91 93 virtual void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation=lol::quat(lol::mat4(1.0f))) { } 92 94 private: … … 98 100 virtual void AddToSimulation(class Simulation* current_simulation) { } 99 101 virtual void RemoveFromSimulation(class Simulation* current_simulation) { } 100 virtual mat4 GetTransform() { return mat4(1.0f); }101 102 102 103 virtual void InitBodyToGhost() { } … … 123 124 virtual void AttachTo(EasyPhysic* NewBase, bool NewBaseLockLocation = true, bool NewBaseLockRotation = true) 124 125 { 125 if (NewBase == this || NewBase->m_base_physic == this)126 if (NewBase == this || (NewBase && NewBase->m_base_physic == this)) 126 127 return; 127 128 … … 138 139 m_base_lock_rotation = NewBaseLockRotation; 139 140 } 140 else 141 else if (m_base_physic) 141 142 { 142 for (int i = 0; i < NewBase->m_based_physic_list.Count(); ++i)143 if ( NewBase->m_based_physic_list[i] == this)144 NewBase->m_based_physic_list.Remove(i--);143 for (int i = 0; i < m_base_physic->m_based_physic_list.Count(); ++i) 144 if (m_base_physic->m_based_physic_list[i] == this) 145 m_base_physic->m_based_physic_list.Remove(i--); 145 146 m_base_physic = NULL; 146 147 } -
trunk/test/Physics/Include/LolBtPhysicsIntegration.h
r1747 r1768 20 20 namespace lol 21 21 { 22 //Override Gamegroups names for Physic-useage 23 //"_ENT_" means that this is a group for Entities that use EasyPhysic primitives. 24 //"_EZP_" means that this is a group for EasyPhysic primitives. 25 #define GAMEGROUP_ENT_PLATFORM GAMEGROUP_BEFORE 26 #define GAMEGROUP_ENT_MAIN GAMEGROUP_DEFAULT 27 #define GAMEGROUP_EZP_CHAR_CTRLR GAMEGROUP_AFTER 28 #define GAMEGROUP_SIMULATION GAMEGROUP_AFTER_POST 22 29 23 30 #ifdef HAVE_PHYS_USE_BULLET … … 32 39 #define BT2LOL_VEC3(ELEMENT) (*(lol::vec3*)(&(ELEMENT))) 33 40 41 //Same as above with Unit taken into account 42 #define LOL2BTU_VEC3(ELEMENT) btVector3((ELEMENT).x * LOL2BT_UNIT, (ELEMENT).y * LOL2BT_UNIT, (ELEMENT).z * LOL2BT_UNIT) 43 #define BT2LOLU_VEC3(ELEMENT) (*(lol::vec3*)(&(ELEMENT))) * BT2LOL_UNIT 44 34 45 #define LOL2BT_QUAT(ELEMENT) btQuaternion((ELEMENT).x, (ELEMENT).y, (ELEMENT).z, (ELEMENT).w) 35 46 #define BT2LOL_QUAT(ELEMENT) lol::quat((ELEMENT).getW(), BT2LOL_VEC3((ELEMENT).getAxis()) -
trunk/test/Physics/Include/LolPhysics.h
r1758 r1768 10 10 11 11 #ifdef HAVE_PHYS_USE_BULLET 12 #include <cstring> 12 13 #include <bullet/btBulletDynamicsCommon.h> 13 14 #include <bullet/btBulletCollisionCommon.h> 15 #include <BulletDynamics/Character/btKinematicCharacterController.h> 14 16 #include "LolBtPhysicsIntegration.h" 15 17 #include "EasyPhysics.h" … … 22 24 namespace phys 23 25 { 26 27 enum eRaycastType 28 { 29 ERT_Closest, 30 ERT_AllHit, 31 ERT_AnyHit, //Will stop at the first hit. Hit data are supposed to be irrelevant 32 33 ERT_MAX 34 }; 35 36 struct RayCastResult 37 { 38 RayCastResult(int CollisionFilterGroup=1, int CollisionFilterMask=(0xFF)) 39 { 40 memset(this, 0, sizeof(RayCastResult)); 41 42 m_collision_filter_group = CollisionFilterGroup; 43 m_collision_filter_mask = CollisionFilterMask; 44 } 45 void Reset() 46 { 47 m_collider_list.Empty(); 48 m_hit_normal_list.Empty(); 49 m_hit_point_list.Empty(); 50 m_hit_fraction_list.Empty(); 51 } 52 53 Array<EasyPhysic*> m_collider_list; 54 Array<vec3> m_hit_normal_list; 55 Array<vec3> m_hit_point_list; 56 Array<float> m_hit_fraction_list; 57 58 short int m_collision_filter_group; 59 short int m_collision_filter_mask; 60 unsigned int m_flags; //??? 61 }; 24 62 25 63 class Simulation : public Entity … … 34 72 m_timestep(1.f/60.f) 35 73 { 74 m_gamegroup = GAMEGROUP_SIMULATION; 36 75 } 37 76 ~Simulation() … … 80 119 } 81 120 121 //Reap-Off of the btKinematicClosestNotMeRayResultCallback 122 class LolClosestNotMeRayResultCallback : public btCollisionWorld::ClosestRayResultCallback 123 { 124 public: 125 LolClosestNotMeRayResultCallback(btCollisionObject* Me, const btVector3& rayFromWorld, const btVector3& rayToWorld) : 126 btCollisionWorld::ClosestRayResultCallback(rayFromWorld, rayToWorld) 127 { 128 m_me = Me; 129 } 130 131 virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult& rayResult,bool normalInWorldSpace) 132 { 133 if (rayResult.m_collisionObject == m_me) 134 return 1.0; 135 136 return ClosestRayResultCallback::addSingleResult(rayResult, normalInWorldSpace); 137 } 138 protected: 139 btCollisionObject* m_me; 140 }; 141 142 //Will stop at the first hit. Hit data are supposed to be irrelevant 143 class AnyHitRayResultCallback : public btCollisionWorld::ClosestRayResultCallback 144 { 145 public: 146 AnyHitRayResultCallback(const btVector3& rayFromWorld, const btVector3& rayToWorld) : 147 btCollisionWorld::ClosestRayResultCallback(rayFromWorld, rayToWorld) 148 { 149 } 150 151 virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult& rayResult,bool normalInWorldSpace) 152 { 153 return .0f; 154 } 155 }; 156 157 //Returns true when hitting something. If SourceCaster is set, it will be ignored by Raycast. 158 bool RayHits(RayCastResult& HitResult, eRaycastType RaycastType, const vec3& RayFrom, const vec3& RayTo, EasyPhysic* SourceCaster=NULL) 159 { 160 bool bResult = false; 161 162 btCollisionWorld::RayResultCallback* BtRayResult = NULL; 163 btCollisionWorld::ClosestRayResultCallback* BtRayResult_Closest; 164 btCollisionWorld::AllHitsRayResultCallback* BtRayResult_AllHits; 165 166 switch (RaycastType) 167 { 168 case ERT_Closest: 169 { 170 if (SourceCaster) 171 BtRayResult_Closest = new LolClosestNotMeRayResultCallback(SourceCaster->m_collision_object, LOL2BTU_VEC3(RayFrom), LOL2BTU_VEC3(RayTo)); 172 else 173 BtRayResult_Closest = new btCollisionWorld::ClosestRayResultCallback(LOL2BTU_VEC3(RayFrom), LOL2BTU_VEC3(RayTo)); 174 BtRayResult = BtRayResult_Closest; 175 break; 176 } 177 case ERT_AllHit: 178 { 179 BtRayResult_AllHits = new btCollisionWorld::AllHitsRayResultCallback(LOL2BTU_VEC3(RayFrom), LOL2BTU_VEC3(RayTo)); 180 BtRayResult = BtRayResult_AllHits; 181 break; 182 } 183 case ERT_AnyHit: 184 { 185 BtRayResult_Closest = new AnyHitRayResultCallback(LOL2BTU_VEC3(RayFrom), LOL2BTU_VEC3(RayTo)); 186 BtRayResult = BtRayResult_Closest; 187 break; 188 } 189 } 190 191 m_dynamics_world->rayTest(LOL2BTU_VEC3(RayFrom), LOL2BTU_VEC3(RayTo), *BtRayResult); 192 if (BtRayResult->hasHit()) 193 { 194 bResult = true; 195 196 switch (RaycastType) 197 { 198 case ERT_Closest: 199 { 200 HitResult.m_collider_list << (EasyPhysic*)BtRayResult_Closest->m_collisionObject->getUserPointer(); 201 HitResult.m_hit_normal_list << BT2LOLU_VEC3(BtRayResult_Closest->m_hitNormalWorld); 202 HitResult.m_hit_point_list << BT2LOLU_VEC3(BtRayResult_Closest->m_hitPointWorld); 203 HitResult.m_hit_fraction_list << BtRayResult_Closest->m_closestHitFraction; 204 break; 205 } 206 case ERT_AllHit: 207 { 208 for (int i = 0; i < BtRayResult_AllHits->m_collisionObjects.size(); i++) 209 { 210 HitResult.m_collider_list << (EasyPhysic*)BtRayResult_AllHits->m_collisionObjects[i]->getUserPointer(); 211 HitResult.m_hit_normal_list << BT2LOLU_VEC3(BtRayResult_AllHits->m_hitNormalWorld[i]); 212 HitResult.m_hit_point_list << BT2LOLU_VEC3(BtRayResult_AllHits->m_hitPointWorld[i]); 213 HitResult.m_hit_fraction_list << BtRayResult_AllHits->m_hitFractions[i]; 214 } 215 break; 216 } 217 } 218 } 219 220 delete BtRayResult; 221 222 return bResult; 223 } 224 225 82 226 void Exit() 83 227 { … … 129 273 void Init() { } 130 274 void TickGame(float seconds) { } 275 bool RayHits(RayCastResult& HitResult, eRaycastType RaycastType, const vec3& RayFrom, const vec3& RayTo, EasyPhysic* SourceCaster=NULL) { return false; } 131 276 void Exit() { } 132 277 private:
Note: See TracChangeset
for help on using the changeset viewer.