Changeset 1698
- Timestamp:
- Aug 5, 2012, 7:06:28 PM (10 years ago)
- Location:
- trunk/test
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/BtPhysTest.cpp
r1647 r1698 97 97 } 98 98 99 { 100 quat NewRotation = quat(1.f); 101 vec3 NewPosition = pos_offset + vec3(5.0f, -20.0f, -15.0f); 102 103 PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 0); 104 105 m_platform_list << NewPhyobj; 106 Ticker::Ref(NewPhyobj); 107 108 NewPosition = pos_offset + vec3(-20.0f, -25.0f, 5.0f); 109 110 NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 0); 111 112 m_platform_list << NewPhyobj; 113 Ticker::Ref(NewPhyobj); 114 } 115 99 116 if (1) 100 117 { … … 325 342 } 326 343 327 if ( 1)344 if (0) 328 345 { 329 346 for (int i = 0; i < m_ground_list.Count(); i++) … … 338 355 * GroundMat; 339 356 PhysObj->SetTransform(GroundMat.v3.xyz, quat(GroundMat)); 357 } 358 } 359 360 { 361 for (int i = 0; i < m_platform_list.Count(); i++) 362 { 363 PhysicsObject* PhysObj = m_platform_list[i]; 364 365 mat4 GroundMat = PhysObj->GetTransform(); 366 if (i == 0) 367 { 368 GroundMat = GroundMat * mat4(quat::fromeuler_xyz(vec3(20.f, .0f, .0f) * seconds)); 369 PhysObj->SetTransform(GroundMat.v3.xyz, quat(GroundMat)); 370 } 371 else 372 { 373 GroundMat = GroundMat * mat4::translate(vec3(.0f, .0f, 10.0f) * seconds); 374 if (GroundMat.v3.z > 40.0f) 375 GroundMat = GroundMat * mat4::translate(vec3(.0f, .0f, -80.0f)); 376 PhysObj->SetTransform(GroundMat.v3.xyz, quat(GroundMat)); 377 } 340 378 } 341 379 } … … 448 486 Ticker::Unref(CurPop); 449 487 } 488 while (m_platform_list.Count()) 489 { 490 PhysicsObject* CurPop = m_platform_list.Last(); 491 m_platform_list.Pop(); 492 CurPop->GetPhysic()->RemoveFromSimulation(m_simulation); 493 Ticker::Unref(CurPop); 494 } 450 495 while (m_physobj_list.Count()) 451 496 { -
trunk/test/BtPhysTest.h
r1633 r1698 29 29 Array<PhysicsObject*> m_physobj_list; 30 30 Array<PhysicsObject*> m_ground_list; 31 Array<PhysicsObject*> m_platform_list; 31 32 32 33 #if 0 -
trunk/test/PhysicObject.h
r1696 r1698 35 35 } 36 36 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); 48 } 49 37 50 PhysicsObject(Simulation* new_sim, float base_mass, const vec3 &base_location, int RandValue = -1) 38 51 : m_ready(false), m_should_render(true) -
trunk/test/Physics/EasyPhysics.cpp
r1633 r1698 33 33 m_collision_object(NULL), 34 34 m_rigid_body(NULL), 35 m_ghost_object(NULL), 35 36 m_collision_shape(NULL), 36 37 m_motion_state(NULL), … … 107 108 void EasyPhysic::SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation) 108 109 { 109 if (m_ motion_state)110 m_ motion_state->setWorldTransform(btTransform(LOL2BT_QUAT(base_rotation), LOL2BT_VEC3(base_location * LOL2BT_UNIT)));110 if (m_ghost_object) 111 m_ghost_object->setWorldTransform(btTransform(LOL2BT_QUAT(base_rotation), LOL2BT_VEC3(base_location * LOL2BT_UNIT))); 111 112 else 112 m_motion_state = new btDefaultMotionState(btTransform(LOL2BT_QUAT(base_rotation), LOL2BT_VEC3(base_location * LOL2BT_UNIT))); 113 { 114 if (m_motion_state) 115 m_motion_state->setWorldTransform(btTransform(LOL2BT_QUAT(base_rotation), LOL2BT_VEC3(base_location * LOL2BT_UNIT))); 116 else 117 m_motion_state = new btDefaultMotionState(btTransform(LOL2BT_QUAT(base_rotation), LOL2BT_VEC3(base_location * LOL2BT_UNIT))); 118 } 113 119 } 114 120 … … 138 144 delete m_collision_object; 139 145 140 SetLocalInertia(m_mass);141 146 if (!m_motion_state) 142 147 SetTransform(vec3(.0f)); … … 153 158 } 154 159 160 //Init to Ghost object, for Overlap/Sweep Test/Touching logic 161 void EasyPhysic::InitBodyToGhost() 162 { 163 if (m_collision_object) 164 delete m_collision_object; 165 166 m_ghost_object = new btGhostObject(); 167 m_ghost_object->setCollisionShape(m_collision_shape); 168 m_collision_object = m_ghost_object; 169 170 SetTransform(vec3(.0f)); 171 172 m_ghost_object->setCollisionFlags(m_ghost_object->getCollisionFlags()); 173 //btCollisionObject::CF_CHARACTER_OBJECT 174 } 175 176 //Add Physic object to the simulation 155 177 void EasyPhysic::AddToSimulation(class Simulation* current_simulation) 156 178 { … … 158 180 if (dynamics_world) 159 181 { 160 if (m_rigid_body) 182 if (m_ghost_object) 183 { 184 dynamics_world->addCollisionObject(m_ghost_object, m_collision_group, m_collision_mask); 185 current_simulation->AddToGhost(this); 186 } 187 else if (m_rigid_body) 161 188 { 162 189 dynamics_world->addRigidBody(m_rigid_body, m_collision_group, m_collision_mask); -
trunk/test/Physics/EasyPhysics.h
r1633 r1698 22 22 #include <bullet/btBulletDynamicsCommon.h> 23 23 #include <bullet/btBulletCollisionCommon.h> 24 #include <bullet/BulletCollision/CollisionDispatch/btGhostObject.h> 24 25 #endif 25 26 … … 51 52 void SetMass(float mass); 52 53 void InitBodyToRigid(bool ZeroMassIsKinematic=false); 54 void InitBodyToGhost(); 53 55 void AddToSimulation(class Simulation* current_simulation); 54 56 void RemoveFromSimulation(class Simulation* current_simulation); … … 60 62 61 63 btCollisionObject* m_collision_object; 64 65 btGhostObject* m_ghost_object; 62 66 63 67 btRigidBody* m_rigid_body; … … 82 86 void SetMass(float mass) { } 83 87 void InitBodyToRigid() { } 88 void InitBodyToGhost() { } 84 89 void AddToSimulation(class Simulation* current_simulation) { } 85 90 void RemoveFromSimulation(class Simulation* current_simulation) { } -
trunk/test/Physics/LolPhysics.h
r1641 r1698 160 160 void AddToDynamic(EasyPhysic* NewEPDynamic) { m_dynamic_list << NewEPDynamic; } 161 161 void AddToStatic(EasyPhysic* NewEPStatic) { m_static_list << NewEPStatic; } 162 void AddToGhost(EasyPhysic* NewEPGhost) { m_ghost_list << NewEPGhost; } 162 163 void AddToConstraint(EasyConstraint* NewEC) { m_constraint_list << NewEC; } 163 164 … … 165 166 Array<EasyPhysic*> m_dynamic_list; 166 167 Array<EasyPhysic*> m_static_list; 168 Array<EasyPhysic*> m_ghost_list; 167 169 Array<EasyConstraint*> m_constraint_list; 168 170
Note: See TracChangeset
for help on using the changeset viewer.