Changeset 1722
- Timestamp:
- Aug 12, 2012, 5:23:25 PM (8 years ago)
- Location:
- trunk/test
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/BtPhysTest.cpp
r1698 r1722 50 50 int gNumObjects = 64; 51 51 52 #define USE_WALL 1 53 #define USE_PLATFORM 1 54 #define USE_ROPE 0 55 #define USE_BODIES 0 56 #define USE_ROTATION 0 57 #define USE_CHARACTER 1 58 52 59 BtPhysTest::BtPhysTest(bool editor) 53 60 { … … 73 80 float offset = 29.5f; 74 81 vec3 pos_offset = vec3(.0f, 30.f, .0f); 75 for (int i=0; i < 6; i++) 76 { 77 vec3 NewPosition = vec3(.0f); 78 quat NewRotation = quat(1.f); 79 80 PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation); 81 82 int idx = i/2; 83 NewPosition = pos_offset; 84 NewPosition[idx] += offset; 85 offset *= -1.f; 86 87 if (idx != 1) 88 { 89 vec3 axis = vec3(.0f); 90 axis[2 - idx] = 1; 91 NewRotation = quat::rotate(90.f, axis); 92 } 93 94 NewPhyobj->SetTransform(NewPosition, NewRotation); 95 Ticker::Ref(NewPhyobj); 96 m_ground_list << NewPhyobj; 97 } 98 99 { 100 quat NewRotation = quat(1.f); 82 if (USE_WALL) 83 { 84 for (int i=0; i < 6; i++) 85 { 86 vec3 NewPosition = vec3(.0f); 87 quat NewRotation = quat(1.f); 88 89 PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation); 90 91 int idx = i/2; 92 NewPosition = pos_offset; 93 NewPosition[idx] += offset; 94 offset *= -1.f; 95 96 if (idx != 1) 97 { 98 vec3 axis = vec3(.0f); 99 axis[2 - idx] = 1; 100 NewRotation = quat::rotate(90.f, axis); 101 } 102 103 NewPhyobj->SetTransform(NewPosition, NewRotation); 104 Ticker::Ref(NewPhyobj); 105 m_ground_list << NewPhyobj; 106 } 107 } 108 109 if (USE_PLATFORM) 110 { 111 quat NewRotation = quat::fromeuler_xyz(5.f, 0.f, 0.f); 101 112 vec3 NewPosition = pos_offset + vec3(5.0f, -20.0f, -15.0f); 102 113 103 PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 0);114 PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1); 104 115 105 116 m_platform_list << NewPhyobj; … … 108 119 NewPosition = pos_offset + vec3(-20.0f, -25.0f, 5.0f); 109 120 110 NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 0);121 NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1); 111 122 112 123 m_platform_list << NewPhyobj; … … 114 125 } 115 126 116 if (1) 127 if (USE_CHARACTER) 128 { 129 quat NewRotation = quat::fromeuler_xyz(0.f, 0.f, 0.f); 130 vec3 NewPosition = pos_offset + vec3(.0f, 40.0f, .0f); 131 132 PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 2); 133 134 m_character_list << NewPhyobj; 135 Ticker::Ref(NewPhyobj); 136 } 137 138 if (USE_BODIES) 117 139 { 118 140 for (int x=0; x < 6; x++) … … 132 154 } 133 155 134 if ( 1)156 if (USE_ROPE) 135 157 { 136 158 Array<PhysicsObject*> RopeElements; … … 315 337 vec3 PhysObjBarycenter = vec3(.0f); 316 338 float factor = .0f; 317 318 for (int i = 0; i < m_ground_list.Count(); i++) 319 { 320 PhysicsObject* PhysObj = m_ground_list[i]; 321 mat4 GroundMat = PhysObj->GetTransform(); 322 323 GroundBarycenter += GroundMat.v3.xyz; 324 factor += 1.f; 325 } 326 327 GroundBarycenter /= factor; 328 329 for (int i = 0; i < m_ground_list.Count(); i++) 330 { 331 PhysicsObject* PhysObj = m_ground_list[i]; 332 333 mat4 GroundMat = PhysObj->GetTransform(); 334 vec3 CenterToGround = GroundMat.v3.xyz - GroundBarycenter; 335 vec3 CenterToCam = m_camera->m_position - GroundBarycenter; 336 337 if (dot(normalize(CenterToCam - CenterToGround), 338 normalize(CenterToGround)) > 0.f) 339 PhysObj->SetRender(false); 340 else 341 PhysObj->SetRender(true); 342 } 343 344 if (0) 339 340 if (USE_WALL) 341 { 342 for (int i = 0; i < m_ground_list.Count(); i++) 343 { 344 PhysicsObject* PhysObj = m_ground_list[i]; 345 mat4 GroundMat = PhysObj->GetTransform(); 346 347 GroundBarycenter += GroundMat.v3.xyz; 348 factor += 1.f; 349 } 350 351 GroundBarycenter /= factor; 352 353 for (int i = 0; i < m_ground_list.Count(); i++) 354 { 355 PhysicsObject* PhysObj = m_ground_list[i]; 356 357 mat4 GroundMat = PhysObj->GetTransform(); 358 vec3 CenterToGround = GroundMat.v3.xyz - GroundBarycenter; 359 vec3 CenterToCam = m_camera->m_position - GroundBarycenter; 360 361 if (dot(normalize(CenterToCam - CenterToGround), 362 normalize(CenterToGround)) > 0.f) 363 PhysObj->SetRender(false); 364 else 365 PhysObj->SetRender(true); 366 } 367 } 368 369 if (USE_ROTATION) 345 370 { 346 371 for (int i = 0; i < m_ground_list.Count(); i++) … … 358 383 } 359 384 385 if (USE_PLATFORM) 360 386 { 361 387 for (int i = 0; i < m_platform_list.Count(); i++) … … 379 405 } 380 406 381 PhysObjBarycenter = vec3(.0f); 382 for (int i = 0; i < m_physobj_list.Count(); i++) 383 { 384 PhysicsObject* PhysObj = m_physobj_list[i]; 385 mat4 GroundMat = PhysObj->GetTransform(); 386 387 PhysObjBarycenter += GroundMat.v3.xyz; 388 factor += 1.f; 389 } 390 391 PhysObjBarycenter /= factor; 392 393 m_camera->SetTarget(PhysObjBarycenter); 394 m_camera->SetPosition(GroundBarycenter + normalize(GroundBarycenter - PhysObjBarycenter) * 60.0f); 407 if (USE_CHARACTER) 408 { 409 for (int i = 0; i < m_character_list.Count(); i++) 410 { 411 PhysicsObject* PhysObj = m_character_list[i]; 412 mat4 GroundMat = PhysObj->GetTransform(); 413 414 PhysObjBarycenter += GroundMat.v3.xyz; 415 factor += 1.f; 416 } 417 418 PhysObjBarycenter /= factor; 419 420 m_camera->SetTarget(PhysObjBarycenter); 421 m_camera->SetPosition(PhysObjBarycenter + vec3(-80.0f, 80.0f, .0f)); 422 } 423 else 424 { 425 PhysObjBarycenter = vec3(.0f); 426 for (int i = 0; i < m_physobj_list.Count(); i++) 427 { 428 PhysicsObject* PhysObj = m_physobj_list[i]; 429 mat4 GroundMat = PhysObj->GetTransform(); 430 431 PhysObjBarycenter += GroundMat.v3.xyz; 432 factor += 1.f; 433 } 434 435 PhysObjBarycenter /= factor; 436 437 m_camera->SetTarget(PhysObjBarycenter); 438 m_camera->SetPosition(GroundBarycenter + normalize(GroundBarycenter - PhysObjBarycenter) * 60.0f); 439 } 395 440 396 441 #if 0 … … 426 471 } 427 472 428 Video::SetClearColor(vec4(0.0f, 0.0f, 0.12f, 1.0f));473 //Video::SetClearColor(vec4(0.0f, 0.0f, 0.12f, 1.0f)); 429 474 430 475 #if 0 … … 486 531 Ticker::Unref(CurPop); 487 532 } 533 while (m_character_list.Count()) 534 { 535 PhysicsObject* CurPop = m_character_list.Last(); 536 m_character_list.Pop(); 537 CurPop->GetCharacter()->RemoveFromSimulation(m_simulation); 538 Ticker::Unref(CurPop); 539 } 488 540 while (m_platform_list.Count()) 489 541 { -
trunk/test/BtPhysTest.h
r1698 r1722 30 30 Array<PhysicsObject*> m_ground_list; 31 31 Array<PhysicsObject*> m_platform_list; 32 Array<PhysicsObject*> m_character_list; 32 33 33 34 #if 0 -
trunk/test/PhysicObject.h
r1698 r1722 23 23 public: 24 24 PhysicsObject(Simulation* new_sim, const vec3 &base_location, const quat &base_rotation) 25 : m_ready(false), m_should_render(true) 25 : m_ready(false), m_should_render(true), m_is_character(false) 26 26 { 27 27 m_mesh.Compile("[sc#ddd afcb60 1 60 -.1]"); … … 36 36 37 37 PhysicsObject(Simulation* new_sim, const vec3 &base_location, const quat &base_rotation, int dummy) 38 : m_ready(false), m_should_render(true) 39 { 40 m_mesh.Compile("[sc#ddd afcb20 1 20 -.1]"); 41 vec3 BoxSize = vec3(20.f, 1.f, 20.f); 42 m_physics.SetCollisionChannel(0, 0xFF); 43 m_physics.SetShapeToBox(BoxSize); 44 m_physics.SetMass(.0f); 45 m_physics.SetTransform(base_location, base_rotation); 46 m_physics.InitBodyToRigid(true); 47 m_physics.AddToSimulation(new_sim); 38 : m_ready(false), m_should_render(true), m_is_character(false) 39 { 40 if (dummy == 1) //for Rope purpose 41 { 42 m_mesh.Compile("[sc#ddd afcb20 1 20 -.1]"); 43 //m_mesh.Compile("[sc#f00 afcb10 10 10 -.1]"); 44 45 vec3 BoxSize = vec3(20.f, 1.f, 20.f); 46 m_physics.SetCollisionChannel(0, 0xFF); 47 m_physics.SetShapeToBox(BoxSize); 48 m_physics.SetMass(.0f); 49 m_physics.SetTransform(base_location, base_rotation); 50 m_physics.InitBodyToRigid(true); 51 m_physics.AddToSimulation(new_sim); 52 } 53 else if (dummy == 2) //for character purpose 54 { 55 m_is_character = true; 56 m_mesh.Compile("[sc#f00 afcb10 10 10 -.1]"); 57 //m_mesh.Compile("[sc#fff scb#fff ac1 2 2 2 0 0]"); 58 vec3 BoxSize = vec3(2.f, 2.f, 2.f); 59 m_character.SetCollisionChannel(0, 0xFF); 60 m_character.SetShapeToCapsule(BoxSize.x, BoxSize.y); 61 m_character.SetMass(.0f); 62 m_character.SetTransform(base_location, base_rotation); 63 m_character.InitBodyToGhost(); 64 m_character.AddToSimulation(new_sim); 65 } 48 66 } 49 67 50 68 PhysicsObject(Simulation* new_sim, float base_mass, const vec3 &base_location, int RandValue = -1) 51 : m_ready(false), m_should_render(true) 69 : m_ready(false), m_should_render(true), m_is_character(false) 52 70 { 53 71 Array<char const *> MeshRand; … … 62 80 int SphereLimit = MeshRand.Count(); 63 81 64 MeshRand << "[sc#add asph1 52 2 2]";65 MeshRand << "[sc#dad asph1 52 2 2]";66 MeshRand << "[sc#dda asph1 52 2 2]";67 MeshRand << "[sc#daa asph1 52 2 2]";68 MeshRand << "[sc#ada asph1 52 2 2]";69 MeshRand << "[sc#aad asph1 52 2 2]";82 MeshRand << "[sc#add asph1 2 2 2]"; 83 MeshRand << "[sc#dad asph1 2 2 2]"; 84 MeshRand << "[sc#dda asph1 2 2 2]"; 85 MeshRand << "[sc#daa asph1 2 2 2]"; 86 MeshRand << "[sc#ada asph1 2 2 2]"; 87 MeshRand << "[sc#aad asph1 2 2 2]"; 70 88 71 89 int ConeLimit = MeshRand.Count(); 72 90 73 MeshRand << "[sc#add scb#add ad 48 2 0 rx180 ty-1 ac482 2 0 0 0]";74 MeshRand << "[sc#dad scb#dad ad 48 2 0 rx180 ty-1 ac482 2 0 0 0]";75 MeshRand << "[sc#dda scb#dda ad 48 2 0 rx180 ty-1 ac482 2 0 0 0]";76 MeshRand << "[sc#daa scb#daa ad 48 2 0 rx180 ty-1 ac482 2 0 0 0]";77 MeshRand << "[sc#ada scb#ada ad 48 2 0 rx180 ty-1 ac482 2 0 0 0]";78 MeshRand << "[sc#aad scb#aad ad 48 2 0 rx180 ty-1 ac482 2 0 0 0]";91 MeshRand << "[sc#add scb#add ad1 2 0 rx180 ty-1 ac1 2 2 0 0 0]"; 92 MeshRand << "[sc#dad scb#dad ad1 2 0 rx180 ty-1 ac1 2 2 0 0 0]"; 93 MeshRand << "[sc#dda scb#dda ad1 2 0 rx180 ty-1 ac1 2 2 0 0 0]"; 94 MeshRand << "[sc#daa scb#daa ad1 2 0 rx180 ty-1 ac1 2 2 0 0 0]"; 95 MeshRand << "[sc#ada scb#ada ad1 2 0 rx180 ty-1 ac1 2 2 0 0 0]"; 96 MeshRand << "[sc#aad scb#aad ad1 2 0 rx180 ty-1 ac1 2 2 0 0 0]"; 79 97 80 98 int CylLimit = MeshRand.Count(); 81 99 82 MeshRand << "[sc#add scb#add ad 96 2 0 rx180 ty-1 my ac962 2 2 0 0]";83 MeshRand << "[sc#dad scb#dad ad 96 2 0 rx180 ty-1 my ac962 2 2 0 0]";84 MeshRand << "[sc#dda scb#dda ad 96 2 0 rx180 ty-1 my ac962 2 2 0 0]";85 MeshRand << "[sc#daa scb#daa ad 96 2 0 rx180 ty-1 my ac962 2 2 0 0]";86 MeshRand << "[sc#ada scb#ada ad 96 2 0 rx180 ty-1 my ac962 2 2 0 0]";87 MeshRand << "[sc#aad scb#aad ad 96 2 0 rx180 ty-1 my ac962 2 2 0 0]";100 MeshRand << "[sc#add scb#add ad1 2 0 rx180 ty-1 my ac1 2 2 2 0 0]"; 101 MeshRand << "[sc#dad scb#dad ad1 2 0 rx180 ty-1 my ac1 2 2 2 0 0]"; 102 MeshRand << "[sc#dda scb#dda ad1 2 0 rx180 ty-1 my ac1 2 2 2 0 0]"; 103 MeshRand << "[sc#daa scb#daa ad1 2 0 rx180 ty-1 my ac1 2 2 2 0 0]"; 104 MeshRand << "[sc#ada scb#ada ad1 2 0 rx180 ty-1 my ac1 2 2 2 0 0]"; 105 MeshRand << "[sc#aad scb#aad ad1 2 0 rx180 ty-1 my ac1 2 2 2 0 0]"; 88 106 89 107 int CapsLimit = MeshRand.Count(); 90 108 91 MeshRand << "[sc#add scb#add acap 21 2 1]";92 MeshRand << "[sc#dad scb#dad acap 21 2 1]";93 MeshRand << "[sc#dda scb#dda acap 21 2 1]";94 MeshRand << "[sc#daa scb#daa acap 21 2 1]";95 MeshRand << "[sc#ada scb#ada acap 21 2 1]";96 MeshRand << "[sc#aad scb#aad acap 21 2 1]";109 MeshRand << "[sc#add scb#add acap1 2 1]"; 110 MeshRand << "[sc#dad scb#dad acap1 2 1]"; 111 MeshRand << "[sc#dda scb#dda acap1 2 1]"; 112 MeshRand << "[sc#daa scb#daa acap1 2 1]"; 113 MeshRand << "[sc#ada scb#ada acap1 2 1]"; 114 MeshRand << "[sc#aad scb#aad acap1 2 1]"; 97 115 98 116 switch (RandValue) … … 168 186 void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation=lol::quat(lol::mat4(1.0f))) 169 187 { 170 m_physics.SetTransform(base_location, base_rotation); 188 if (m_is_character) 189 m_character.SetTransform(base_location, base_rotation); 190 else 191 m_physics.SetTransform(base_location, base_rotation); 171 192 } 172 193 173 194 lol::mat4 GetTransform() 174 195 { 175 return m_physics.GetTransform(); 196 if (m_is_character) 197 return m_character.GetTransform(); 198 else 199 return m_physics.GetTransform(); 176 200 } 177 201 … … 183 207 EasyMesh *GetMesh() { return &m_mesh; } 184 208 EasyPhysic *GetPhysic() { return &m_physics; } 209 EasyPhysic *GetCharacter() { return &m_character; } 185 210 186 211 ~PhysicsObject() … … 207 232 208 233 if (m_should_render) 209 m_mesh.Render(m_physics.GetTransform()); 234 { 235 if (m_is_character) 236 m_mesh.Render(m_character.GetTransform()); 237 else 238 m_mesh.Render(m_physics.GetTransform()); 239 } 210 240 } 211 241 212 242 private: 213 243 //Base datas 214 EasyMesh m_mesh; 215 EasyPhysic m_physics; 244 EasyMesh m_mesh; 245 EasyPhysic m_physics; 246 EasyCharacterController m_character; 216 247 217 248 bool m_ready; 218 249 bool m_should_render; 250 bool m_is_character; 219 251 }; 220 252 -
trunk/test/Physics/EasyPhysics.cpp
r1708 r1722 76 76 { 77 77 vec3 new_box_size = box_size * LOL2BT_UNIT * LOL2BT_SIZE; 78 SetShapeTo(new btBoxShape(LOL2BT_VEC3(new_box_size))); 78 m_convex_shape = new btBoxShape(LOL2BT_VEC3(new_box_size)); 79 SetShapeTo(m_convex_shape); 79 80 } 80 81 81 82 void EasyPhysic::SetShapeToSphere(float radius) 82 83 { 83 SetShapeTo(new btSphereShape(radius * LOL2BT_UNIT * LOL2BT_SIZE)); 84 m_convex_shape = new btSphereShape(radius * LOL2BT_UNIT * LOL2BT_SIZE); 85 SetShapeTo(m_convex_shape); 84 86 } 85 87 86 88 void EasyPhysic::SetShapeToCone(float radius, float height) 87 89 { 88 SetShapeTo(new btConeShape( radius * LOL2BT_UNIT, 89 height * LOL2BT_UNIT)); 90 m_convex_shape = new btConeShape( radius * LOL2BT_UNIT, 91 height * LOL2BT_UNIT); 92 SetShapeTo(m_convex_shape); 90 93 } 91 94 … … 94 97 vec3 new_cyl_size = cyl_size * LOL2BT_UNIT; 95 98 new_cyl_size.y *= LOL2BT_SIZE; 96 SetShapeTo(new btCylinderShape(LOL2BT_VEC3(new_cyl_size))); 99 m_convex_shape = new btCylinderShape(LOL2BT_VEC3(new_cyl_size)); 100 SetShapeTo(m_convex_shape); 97 101 } 98 102 99 103 void EasyPhysic::SetShapeToCapsule(float radius, float height) 100 104 { 101 SetShapeTo(new btCapsuleShape( radius * LOL2BT_UNIT * LOL2BT_SIZE, 102 height * LOL2BT_UNIT * LOL2BT_SIZE)); 105 m_convex_shape = new btCapsuleShape(radius * LOL2BT_UNIT * LOL2BT_SIZE, 106 height * LOL2BT_UNIT * LOL2BT_SIZE); 107 SetShapeTo(m_convex_shape); 103 108 } 104 109 … … 108 113 void EasyPhysic::SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation) 109 114 { 115 m_local_to_world = lol::mat4::translate(base_location) * mat4(base_rotation); 116 110 117 if (m_ghost_object) 111 118 m_ghost_object->setWorldTransform(btTransform(LOL2BT_QUAT(base_rotation), LOL2BT_VEC3(base_location * LOL2BT_UNIT))); … … 151 158 m_collision_object = m_rigid_body; 152 159 153 if (m_mass == .0f && SetToKinematic) 154 { 155 m_rigid_body->setActivationState(DISABLE_DEACTIVATION); 156 m_rigid_body->setCollisionFlags(m_rigid_body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT); 157 } 160 if (m_mass == .0f) 161 { 162 if (SetToKinematic) 163 { 164 m_rigid_body->setActivationState(DISABLE_DEACTIVATION); 165 m_rigid_body->setCollisionFlags(m_rigid_body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT); 166 } 167 } 168 else 169 SetMass(m_mass); 170 } 171 172 //Return correct Ghost Object 173 btGhostObject* EasyPhysic::GetGhostObject() 174 { 175 return new btGhostObject(); 158 176 } 159 177 … … 164 182 delete m_collision_object; 165 183 166 m_ghost_object = new btGhostObject();184 m_ghost_object = GetGhostObject(); 167 185 m_ghost_object->setCollisionShape(m_collision_shape); 168 186 m_collision_object = m_ghost_object; 169 187 170 SetTransform( vec3(.0f));188 SetTransform(m_local_to_world.v3.xyz, lol::quat(m_local_to_world)); 171 189 172 190 m_ghost_object->setCollisionFlags(m_ghost_object->getCollisionFlags()); 173 //btCollisionObject::CF_CHARACTER_OBJECT174 191 } 175 192 … … 206 223 if (m_rigid_body) 207 224 dynamics_world->removeRigidBody(m_rigid_body); 208 else 225 else if (m_collision_object) 209 226 dynamics_world->removeCollisionObject(m_collision_object); 210 227 } … … 242 259 //-- 243 260 244 void EasyCharacterController::SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation) 245 { 246 247 } 248 void EasyCharacterController::SetMass(float mass) 249 { 250 251 } 261 //Deactivated for Character controller 252 262 void EasyCharacterController::InitBodyToRigid(bool ZeroMassIsKinematic) 253 263 { 254 255 } 264 } 265 266 //Return correct Ghost Object 267 btGhostObject* EasyCharacterController::GetGhostObject() 268 { 269 return new btPairCachingGhostObject(); 270 } 271 272 //Init to Pair caching ghost object, since Character uses that one. 256 273 void EasyCharacterController::InitBodyToGhost() 257 274 { 258 //btCollisionObject::CF_CHARACTER_OBJECT 259 } 275 EasyPhysic::InitBodyToGhost(); 276 277 m_pair_caching_object = (btPairCachingGhostObject*)m_ghost_object; 278 m_ghost_object->setCollisionFlags(btCollisionObject::CF_CHARACTER_OBJECT | m_ghost_object->getCollisionFlags()); 279 } 280 281 //Add Physic object to the simulation 260 282 void EasyCharacterController::AddToSimulation(class Simulation* current_simulation) 261 283 { 262 263 } 284 EasyPhysic::AddToSimulation(current_simulation); 285 286 btDiscreteDynamicsWorld* dynamics_world = current_simulation->GetWorld(); 287 if (dynamics_world) 288 { 289 if (m_character) 290 delete m_character; 291 292 m_character = new btKinematicCharacterController(m_pair_caching_object, m_convex_shape, m_step_height, m_up_axis); 293 dynamics_world->addAction(m_character); 294 } 295 } 296 297 //Remove Physic object to the simulation 264 298 void EasyCharacterController::RemoveFromSimulation(class Simulation* current_simulation) 265 299 { 266 267 } 268 mat4 EasyCharacterController::GetTransform() 269 { 270 return mat4(1.f); 300 EasyPhysic::RemoveFromSimulation(current_simulation); 301 302 btDiscreteDynamicsWorld* dynamics_world = current_simulation->GetWorld(); 303 if (dynamics_world) 304 { 305 if (m_character) 306 dynamics_world->removeAction(m_character); 307 } 271 308 } 272 309 -
trunk/test/Physics/EasyPhysics.h
r1702 r1722 23 23 #include <bullet/btBulletCollisionCommon.h> 24 24 #include <bullet/BulletCollision/CollisionDispatch/btGhostObject.h> 25 #include <BulletDynamics/Character/btKinematicCharacterController.h> 25 26 #endif 26 27 … … 61 62 virtual void SetShapeTo(btCollisionShape* collision_shape); 62 63 64 virtual btGhostObject* GetGhostObject(); 65 63 66 btCollisionObject* m_collision_object; 64 67 … … 69 72 70 73 btCollisionShape* m_collision_shape; 74 btConvexShape* m_convex_shape; 71 75 btMotionState* m_motion_state; 72 76 … … 91 95 virtual mat4 GetTransform() { return mat4(1.0f); } 92 96 97 virtual void InitBodyToGhost() { } 98 93 99 #endif // PHYSIC IMPLEMENTATION 94 100 … … 122 128 123 129 public: 124 EasyCharacterController(); 125 ~EasyCharacterController(); 126 127 virtual void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation=lol::quat(lol::mat4(1.0f))); 128 virtual void SetMass(float mass); 130 EasyCharacterController() : 131 EasyPhysic(), 132 m_character(NULL) 133 { 134 m_up_axis = 1; 135 } 136 ~EasyCharacterController() 137 { 138 delete m_character; 139 } 140 129 141 virtual void InitBodyToRigid(bool ZeroMassIsKinematic=false); 130 142 virtual void InitBodyToGhost(); 131 143 virtual void AddToSimulation(class Simulation* current_simulation); 132 144 virtual void RemoveFromSimulation(class Simulation* current_simulation); 133 virtual mat4 GetTransform();134 145 135 146 protected: 136 147 148 virtual btGhostObject* GetGhostObject(); 149 137 150 btPairCachingGhostObject* m_pair_caching_object; 151 btKinematicCharacterController* m_character; 152 153 float m_step_height; 154 int m_up_axis; 138 155 139 156 #else // NO PHYSIC IMPLEMENTATION
Note: See TracChangeset
for help on using the changeset viewer.