Changeset 1782
- Timestamp:
- Aug 20, 2012, 11:21:01 PM (11 years ago)
- Location:
- trunk/test/Physics
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/Physics/Include/EasyCharacterController.h
r1768 r1782 11 11 12 12 // 13 // The Easy Physicclass13 // The EasyCharacterController class 14 14 // ------------------ 15 // 16 17 //Should try to to make a btKinematicCharacterController for real. 15 18 // 16 19 … … 34 37 { 35 38 39 friend class Simulation; 40 friend class EasyPhysic; 41 36 42 #ifdef HAVE_PHYS_USE_BULLET 37 43 … … 48 54 m_gamegroup = GAMEGROUP_EZP_CHAR_CTRLR; 49 55 m_up_axis = 1; 56 m_gravity = vec3(.0f, -9.81f, .0f); 50 57 } 51 58 ~EasyCharacterController() … … 78 85 vec3 m_base_cached_movement; 79 86 vec3 m_frame_cached_movement; 87 vec3 m_gravity; 88 vec3 m_velocity; 80 89 81 90 #else // NO PHYSIC IMPLEMENTATION -
trunk/test/Physics/Include/EasyConstraint.h
r1749 r1782 31 31 class EasyConstraint 32 32 { 33 34 friend class Simulation; 35 friend class EasyPhysic; 36 33 37 #ifdef HAVE_PHYS_USE_BULLET 34 38 … … 41 45 m_cone_twist_constraint(NULL), 42 46 m_6dof_constraint(NULL), 47 m_owner_simulation(NULL), 43 48 m_a_physobj(NULL), 44 49 m_b_physobj(NULL), … … 194 199 195 200 private: 201 Simulation* m_owner_simulation; 196 202 EasyPhysic* m_a_physobj; 197 203 EasyPhysic* m_b_physobj; -
trunk/test/Physics/Include/EasyPhysics.h
r1768 r1782 34 34 { 35 35 36 friend class Simulation; 36 37 friend class EasyConstraint; 37 friend class Simulation;38 38 39 39 #ifdef HAVE_PHYS_USE_BULLET … … 154 154 int m_collision_mask; 155 155 WorldEntity* m_owner_entity; 156 Simulation* m_owner_simulation; 156 157 157 158 //Base/Attachment logic -
trunk/test/Physics/Include/LolPhysics.h
r1768 r1782 321 321 322 322 private: 323 323 324 friend class EasyPhysic; 325 friend class EasyCharacterController; 324 326 friend class EasyConstraint; 325 327 328 enum eEasyPhysicType 329 { 330 EEPT_Dynamic, 331 EEPT_Static, 332 EEPT_Ghost, 333 EEPT_CollisionObject, 334 EEPT_CharacterController, 335 336 EEPT_MAX 337 }; 338 339 //m_owner_simulation 326 340 //Adds the given EasyPhysic to the correct list. 327 void AddToDynamic(EasyPhysic* NewEPDynamic) { m_dynamic_list << NewEPDynamic; } 328 void AddToStatic(EasyPhysic* NewEPStatic) { m_static_list << NewEPStatic; } 329 void AddToGhost(EasyPhysic* NewEPGhost) { m_ghost_list << NewEPGhost; } 330 void AddToConstraint(EasyConstraint* NewEC) { m_constraint_list << NewEC; } 341 void ObjectRegistration(bool AddObject, EasyPhysic* NewEP, eEasyPhysicType CurType) 342 { 343 Array<EasyPhysic*>* SearchList = NULL; 344 switch(CurType) 345 { 346 case EEPT_Dynamic: 347 { 348 SearchList = &m_dynamic_list; 349 break; 350 } 351 case EEPT_Static: 352 { 353 SearchList = &m_static_list; 354 break; 355 } 356 case EEPT_Ghost: 357 { 358 SearchList = &m_ghost_list; 359 break; 360 } 361 case EEPT_CollisionObject: 362 { 363 SearchList = &m_collision_object_list; 364 break; 365 } 366 case EEPT_CharacterController: 367 { 368 SearchList = &m_character_controller_list; 369 break; 370 } 371 } 372 373 if (AddObject) 374 { 375 NewEP->m_owner_simulation = this; 376 (*SearchList) << NewEP; 377 } 378 else 379 { 380 NewEP->m_owner_simulation = NULL; 381 for (int i = 0; i < SearchList->Count(); ++i) 382 { 383 if ((*SearchList)[i] == NewEP) 384 { 385 SearchList->Remove(i--); 386 break; 387 } 388 } 389 } 390 } 391 void ObjectRegistration(bool AddObject, EasyConstraint* NewEC) 392 { 393 Array<EasyConstraint*>* SearchList = NULL; 394 SearchList = &m_constraint_list; 395 396 if (AddObject) 397 { 398 NewEC->m_owner_simulation = this; 399 (*SearchList) << NewEC; 400 } 401 else 402 { 403 NewEC->m_owner_simulation = NULL; 404 for (int i = 0; i < SearchList->Count(); ++i) 405 { 406 if ((*SearchList)[i] == NewEC) 407 { 408 SearchList->Remove(i--); 409 break; 410 } 411 } 412 } 413 } 331 414 332 415 //Easy Physics body List … … 334 417 Array<EasyPhysic*> m_static_list; 335 418 Array<EasyPhysic*> m_ghost_list; 419 Array<EasyPhysic*> m_collision_object_list; 420 Array<EasyPhysic*> m_character_controller_list; 336 421 Array<EasyConstraint*> m_constraint_list; 337 422 -
trunk/test/Physics/Src/EasyCharacterController.cpp
r1779 r1782 63 63 64 64 m_character = new btKinematicCharacterController(m_pair_caching_object, m_convex_shape, m_step_height, m_up_axis); 65 66 //Deactivate Character controller basic behaviour. 67 //m_character->setGravity(.0f); 68 //m_character->setFallSpeed(.0f); 69 65 70 dynamics_world->addAction(m_character); 71 current_simulation->ObjectRegistration(true, this, Simulation::EEPT_CharacterController); 66 72 Ticker::Ref(this); 67 73 } … … 79 85 { 80 86 dynamics_world->removeAction(m_character); 87 current_simulation->ObjectRegistration(false, this, Simulation::EEPT_CharacterController); 81 88 Ticker::Unref(this); 82 89 } … … 119 126 Entity::TickGame(seconds); 120 127 121 m_character->setVelocityForTimeInterval(LOL2BT_VEC3(LOL2BT_UNIT * (m_base_cached_movement + m_frame_cached_movement)) / seconds, seconds); 128 int IterationsNb = (int)(seconds / m_owner_simulation->m_timestep); 129 float NewSeconds = IterationsNb * m_owner_simulation->m_timestep; 130 m_character->setVelocityForTimeInterval(LOL2BT_VEC3(LOL2BT_UNIT * (m_base_cached_movement + m_frame_cached_movement)) / NewSeconds, NewSeconds); 122 131 m_base_cached_movement = vec3(.0f); 123 132 } -
trunk/test/Physics/Src/EasyConstraint.cpp
r1760 r1782 26 26 { 27 27 dynamics_world->addConstraint(m_typed_constraint, m_disable_a2b_collision); 28 current_simulation-> AddToConstraint(this);28 current_simulation->ObjectRegistration(true, this); 29 29 } 30 30 } … … 34 34 btDiscreteDynamicsWorld* dynamics_world = current_simulation->GetWorld(); 35 35 if (dynamics_world && m_typed_constraint) 36 { 36 37 dynamics_world->removeConstraint(m_typed_constraint); 38 current_simulation->ObjectRegistration(false, this); 39 } 37 40 } 38 41 -
trunk/test/Physics/Src/EasyPhysics.cpp
r1768 r1782 42 42 m_collision_mask(1), 43 43 m_owner_entity(NewOwnerEntity), 44 m_owner_simulation(NULL), 44 45 m_base_physic(NULL) 45 46 { … … 287 288 { 288 289 dynamics_world->addCollisionObject(m_ghost_object, m_collision_group, m_collision_mask); 289 current_simulation-> AddToGhost(this);290 current_simulation->ObjectRegistration(true, this, Simulation::EEPT_Ghost); 290 291 } 291 292 else if (m_rigid_body) … … 293 294 dynamics_world->addRigidBody(m_rigid_body, m_collision_group, m_collision_mask); 294 295 if (m_mass != .0f) 295 current_simulation-> AddToDynamic(this);296 current_simulation->ObjectRegistration(true, this, Simulation::EEPT_Dynamic); 296 297 else 297 current_simulation-> AddToStatic(this);298 current_simulation->ObjectRegistration(true, this, Simulation::EEPT_Static); 298 299 } 299 300 else 301 { 300 302 dynamics_world->addCollisionObject(m_collision_object, m_collision_group, m_collision_mask); 303 current_simulation->ObjectRegistration(true, this, Simulation::EEPT_CollisionObject); 304 } 301 305 } 302 306 } … … 309 313 { 310 314 if (m_rigid_body) 315 { 311 316 dynamics_world->removeRigidBody(m_rigid_body); 312 else if (m_collision_object) 317 if (m_mass != .0f) 318 current_simulation->ObjectRegistration(false, this, Simulation::EEPT_Dynamic); 319 else 320 current_simulation->ObjectRegistration(false, this, Simulation::EEPT_Static); 321 } 322 else 323 { 313 324 dynamics_world->removeCollisionObject(m_collision_object); 325 if (m_ghost_object) 326 current_simulation->ObjectRegistration(false, this, Simulation::EEPT_Ghost); 327 current_simulation->ObjectRegistration(false, this, Simulation::EEPT_CollisionObject); 328 } 314 329 } 315 330 }
Note: See TracChangeset
for help on using the changeset viewer.