Changeset 1764
- Timestamp:
- Aug 16, 2012, 7:14:07 PM (11 years ago)
- Location:
- trunk/test
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/BtPhysTest.cpp
r1749 r1764 110 110 if (USE_PLATFORM) 111 111 { 112 quat NewRotation = quat::fromeuler_xyz( 5.f, 0.f, 0.f);112 quat NewRotation = quat::fromeuler_xyz(0.f, 0.f, 0.f); 113 113 vec3 NewPosition = pos_offset + vec3(5.0f, -25.0f, -15.0f); 114 114 … … 121 121 122 122 NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1); 123 PhysicsObject* BasePhyobj = NewPhyobj; 123 124 124 125 m_platform_list << NewPhyobj; 125 126 Ticker::Ref(NewPhyobj); 127 128 NewRotation = quat::fromeuler_xyz(0.f, 0.f, 90.f); 129 NewPosition = pos_offset + vec3(-25.0f, -25.0f, 5.0f); 130 131 NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1); 132 133 NewPhyobj->GetPhysic()->AttachTo(BasePhyobj->GetPhysic(), true, true); 134 m_platform_list << NewPhyobj; 135 Ticker::Ref(NewPhyobj); 136 137 NewPosition += vec3(-0.0f, .0f, .0f); 138 NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1); 139 140 NewPhyobj->GetPhysic()->AttachTo(BasePhyobj->GetPhysic(), true, false); 141 m_platform_list << NewPhyobj; 142 Ticker::Ref(NewPhyobj); 143 144 NewPosition += vec3(-2.0f, .0f, .0f); 145 NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1); 146 147 NewPhyobj->GetPhysic()->AttachTo(BasePhyobj->GetPhysic(), false, false); 148 m_platform_list << NewPhyobj; 149 Ticker::Ref(NewPhyobj); 126 150 } 127 151 … … 129 153 { 130 154 quat NewRotation = quat::fromeuler_xyz(0.f, 0.f, 0.f); 131 vec3 NewPosition = pos_offset + vec3( .0f, 20.0f, .0f);155 vec3 NewPosition = pos_offset + vec3(-15.0f, 20.0f, .0f); 132 156 133 157 PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 2); … … 181 205 } 182 206 } 183 184 #if 0185 //init Physics186 {187 m_bt_ccd_mode = USE_CCD;188 189 //collision configuration contains default setup for memory, collision setup190 m_bt_collision_config = new btDefaultCollisionConfiguration();191 192 //use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)193 m_bt_dispatcher = new btCollisionDispatcher(m_bt_collision_config);194 m_bt_dispatcher->registerCollisionCreateFunc(BOX_SHAPE_PROXYTYPE,195 BOX_SHAPE_PROXYTYPE,196 m_bt_collision_config->getCollisionAlgorithmCreateFunc(CONVEX_SHAPE_PROXYTYPE,197 CONVEX_SHAPE_PROXYTYPE));198 199 m_bt_broadphase = new btDbvtBroadphase();200 201 ///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)202 m_bt_solver = new btSequentialImpulseConstraintSolver;203 204 m_bt_world = new btDiscreteDynamicsWorld(m_bt_dispatcher, m_bt_broadphase, m_bt_solver, m_bt_collision_config);205 //m_bt_world->setDebugDrawer(&sDebugDrawer);206 m_bt_world->getSolverInfo().m_splitImpulse = true;207 m_bt_world->getSolverInfo().m_numIterations = 20;208 209 m_bt_world->getDispatchInfo().m_useContinuous = (m_bt_ccd_mode == USE_CCD);210 m_bt_world->setGravity(btVector3(0,-10,0));211 212 ///create a few basic rigid bodies213 btBoxShape* box = new btBoxShape(btVector3(btScalar(110.),btScalar(1.),btScalar(110.)));214 btCollisionShape* groundShape = box;215 m_bt_collision_shapes << groundShape;216 m_ground_mesh.Compile("[sc#ddd afcb220 2 220 -1]");217 218 //m_bt_collision_shapes << new btCylinderShape(btVector3(.5f,.5f,.5f));219 220 btTransform groundTransform;221 groundTransform.setIdentity();222 223 //We can also use DemoApplication::localCreateRigidBody, but for clarity it is provided here:224 {225 btScalar mass(0.);226 227 //rigidbody is dynamic if and only if mass is non zero, otherwise static228 bool isDynamic = (mass != 0.f);229 230 btVector3 localInertia(0,0,0);231 if (isDynamic)232 groundShape->calculateLocalInertia(mass,localInertia);233 234 //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects235 btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);236 btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia);237 btRigidBody* body = new btRigidBody(rbInfo);238 239 //add the body to the dynamics world240 m_bt_world->addRigidBody(body);241 }242 243 //Adding Shapes244 {245 //create a few dynamic rigidbodies246 // Re-using the same collision is better for memory usage and performance247 btCollisionShape* colShape = new btBoxShape(btVector3(1,1,1));248 m_rigid_mesh[0].Compile("[sc#add afcb2 2 2 -.1]");249 m_rigid_mesh[1].Compile("[sc#dad afcb2 2 2 -.1]");250 m_rigid_mesh[2].Compile("[sc#dda afcb2 2 2 -.1]");251 m_rigid_mesh[3].Compile("[sc#daa afcb2 2 2 -.1]");252 m_rigid_mesh[4].Compile("[sc#ada afcb2 2 2 -.1]");253 m_rigid_mesh[5].Compile("[sc#aad afcb2 2 2 -.1]");254 255 m_bt_collision_shapes << colShape;256 m_bt_dynamic_shapes << colShape;257 258 /// Create Dynamic Objects259 btTransform startTransform;260 startTransform.setIdentity();261 btScalar mass(1.f);262 263 //rigidbody is dynamic if and only if mass is non zero, otherwise static264 bool isDynamic = (mass != 0.f);265 266 btVector3 localInertia(0,0,0);267 if (isDynamic)268 colShape->calculateLocalInertia(mass,localInertia);269 270 int i;271 for (i=0;i<gNumObjects;i++)272 {273 btCollisionShape* shape = colShape;274 btTransform trans;275 trans.setIdentity();276 277 //stack them278 int colsize = 10;279 int row = int(((float)i*CUBE_HALF_EXTENTS*2.0f)/((float)colsize*2.0f*CUBE_HALF_EXTENTS));280 int row2 = row;281 int col = (i)%(colsize)-colsize/2;282 283 if (col>3)284 {285 col=11;286 row2 |=1;287 }288 289 btVector3 pos(((row+col+row2) % 4)*CUBE_HALF_EXTENTS,290 20.0f + row*8*CUBE_HALF_EXTENTS+CUBE_HALF_EXTENTS+EXTRA_HEIGHT,291 col*8*CUBE_HALF_EXTENTS + 2 * (row2%2)*CUBE_HALF_EXTENTS);292 293 trans.setOrigin(pos);294 295 float mass = 1.f;296 297 298 btAssert((!shape || shape->getShapeType() != INVALID_SHAPE_PROXYTYPE));299 300 //rigidbody is dynamic if and only if mass is non zero, otherwise static301 bool isDynamic = (mass != 0.f);302 303 btVector3 localInertia(0,0,0);304 if (isDynamic)305 shape->calculateLocalInertia(mass,localInertia);306 307 //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects308 309 btDefaultMotionState* myMotionState = new btDefaultMotionState(trans);310 311 btRigidBody::btRigidBodyConstructionInfo cInfo(mass,myMotionState,shape,localInertia);312 313 btRigidBody* body = new btRigidBody(cInfo);314 body->setContactProcessingThreshold(BT_LARGE_FLOAT);315 316 m_bt_world->addRigidBody(body);317 318 ///when using m_ccdMode319 if (m_bt_ccd_mode == USE_CCD)320 {321 body->setCcdMotionThreshold(CUBE_HALF_EXTENTS);322 body->setCcdSweptSphereRadius(0.9*CUBE_HALF_EXTENTS);323 }324 }325 }326 }327 #endif328 207 } 329 208 … … 334 213 if (Input::GetButtonState(27 /*SDLK_ESCAPE*/)) 335 214 Ticker::Shutdown(); 215 216 m_loop_value += seconds; 217 if (m_loop_value > M_PI * 2.0f) 218 m_loop_value -= M_PI * 2.0f; 336 219 337 220 vec3 GroundBarycenter = vec3(.0f); … … 396 279 PhysObj->SetTransform(GroundMat.v3.xyz, quat(GroundMat)); 397 280 } 398 else 281 else if (i == 1) 399 282 { 400 GroundMat = GroundMat * mat4::translate(vec3(.0f, .0f, 10.0f) * seconds); 401 if (GroundMat.v3.z > 40.0f) 402 GroundMat = GroundMat * mat4::translate(vec3(.0f, .0f, -80.0f)); 283 GroundMat = mat4::translate(vec3(-15.0f, 5.0f, lol::cos(m_loop_value) * 8.f)) * 284 mat4(quat::fromeuler_xyz(vec3(.0f, lol::cos(m_loop_value) * 20.f, .0f))); 403 285 PhysObj->SetTransform(GroundMat.v3.xyz, quat(GroundMat)); 404 286 } … … 459 341 } 460 342 461 #if 0462 ///step the simulation463 if (m_bt_world)464 {465 //int steps = (int)(seconds / 0.005f);466 //for (int i = 0; i < steps; i++)467 m_bt_world->stepSimulation(seconds /*/ steps*/);468 //optional but useful: debug drawing469 //m_bt_world->debugDrawWorld();470 }471 #endif472 343 } 473 344 … … 478 349 if (!m_ready) 479 350 { 480 #if 0481 m_ground_mesh.MeshConvert();482 m_rigid_mesh[0].MeshConvert();483 m_rigid_mesh[1].MeshConvert();484 m_rigid_mesh[2].MeshConvert();485 m_rigid_mesh[3].MeshConvert();486 m_rigid_mesh[4].MeshConvert();487 m_rigid_mesh[5].MeshConvert();488 #endif489 351 /* FIXME: this object never cleans up */ 490 352 m_ready = true; … … 493 355 //Video::SetClearColor(vec4(0.0f, 0.0f, 0.12f, 1.0f)); 494 356 495 #if 0496 vec3 BarycenterLocation = vec3(.0f);497 float BarycenterFactor = 0.0f;498 for(int i=0;i<gNumObjects;i++)499 {500 mat4 m(1.0f);501 btMatrix3x3 rot; rot.setIdentity();502 btCollisionObject* colObj = m_bt_world->getCollisionObjectArray()[i];503 btRigidBody* body = btRigidBody::upcast(colObj);504 if(body && body->getMotionState())505 {506 btDefaultMotionState* myMotionState = (btDefaultMotionState*)body->getMotionState();507 myMotionState->m_graphicsWorldTrans.getOpenGLMatrix(&m[0][0]);508 rot = myMotionState->m_graphicsWorldTrans.getBasis();509 }510 else511 {512 colObj->getWorldTransform().getOpenGLMatrix(&m[0][0]);513 rot = colObj->getWorldTransform().getBasis();514 }515 if (i > 0)516 {517 BarycenterLocation += m.v3.xyz;518 BarycenterFactor += 1.0f;519 }520 if (i == 0)521 m_ground_mesh.Render(m);522 else523 m_rigid_mesh[i % 6].Render(m);524 }525 if (BarycenterFactor > .0f)526 {527 BarycenterLocation /= BarycenterFactor;528 529 m_camera->SetTarget(BarycenterLocation);530 m_camera->SetPosition(BarycenterLocation + vec3(-20.0f, 8.0f, .0f));531 }532 #endif533 357 } 534 358 … … 574 398 Ticker::Unref(m_simulation); 575 399 576 #if 0577 //Exit Physics578 {579 //cleanup in the reverse order of creation/initialization580 //remove the rigidbodies from the dynamics world and delete them581 for (int i = m_bt_world->getNumCollisionObjects() - 1; i >= 0 ;i--)582 {583 btCollisionObject* obj = m_bt_world->getCollisionObjectArray()[i];584 btRigidBody* body = btRigidBody::upcast(obj);585 if (body && body->getMotionState())586 delete body->getMotionState();587 588 m_bt_world->removeCollisionObject(obj);589 delete obj;590 }591 592 //delete collision shapes593 for (int j = 0; j < m_bt_collision_shapes.Count(); j++)594 {595 btCollisionShape* shape = m_bt_collision_shapes[j];596 delete shape;597 }598 m_bt_collision_shapes.Empty();599 600 delete m_bt_world;601 delete m_bt_solver;602 delete m_bt_broadphase;603 delete m_bt_dispatcher;604 delete m_bt_collision_config;605 }606 #endif607 400 } 608 401 -
trunk/test/BtPhysTest.h
r1722 r1764 32 32 Array<PhysicsObject*> m_character_list; 33 33 34 #if 0 35 EasyMesh m_ground_mesh; 36 EasyMesh m_rigid_mesh[6]; 37 38 //Bullet Physics Datas 39 enum 40 { 41 USE_CCD=1, 42 USE_NO_CCD 43 }; 44 int m_bt_ccd_mode; 45 btDefaultCollisionConfiguration* m_bt_collision_config; 46 btCollisionDispatcher* m_bt_dispatcher; 47 btDbvtBroadphase* m_bt_broadphase; 48 btSequentialImpulseConstraintSolver* m_bt_solver; 49 btDiscreteDynamicsWorld* m_bt_world; 50 Array<btCollisionShape*> m_bt_collision_shapes; 51 Array<btCollisionShape*> m_bt_dynamic_shapes; 52 #endif 34 float m_loop_value; 53 35 }; 54 36 -
trunk/test/PhysicObject.h
r1747 r1764 27 27 : m_ready(false), m_should_render(true), m_is_character(false) 28 28 { 29 m_physics = new EasyPhysic(this); 30 29 31 m_mesh.Compile("[sc#ddd afcb60 1 60 -.1]"); 30 32 vec3 BoxSize = vec3(60.f, 1.f, 60.f); 31 m_physics .SetCollisionChannel(0, 0xFF);32 m_physics .SetShapeToBox(BoxSize);33 m_physics .SetMass(.0f);34 m_physics .SetTransform(base_location, base_rotation);35 m_physics .InitBodyToRigid(true);36 m_physics .AddToSimulation(new_sim);33 m_physics->SetCollisionChannel(0, 0xFF); 34 m_physics->SetShapeToBox(BoxSize); 35 m_physics->SetMass(.0f); 36 m_physics->SetTransform(base_location, base_rotation); 37 m_physics->InitBodyToRigid(true); 38 m_physics->AddToSimulation(new_sim); 37 39 } 38 40 … … 40 42 : m_ready(false), m_should_render(true), m_is_character(false) 41 43 { 42 if (dummy == 1) //for Rope purpose 43 { 44 if (dummy == 1) //for platform purpose 45 { 46 m_physics = new EasyPhysic(this); 47 44 48 m_mesh.Compile("[sc#ddd afcb20 1 20 -.1]"); 45 49 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);50 m_physics->SetCollisionChannel(0, 0xFF); 51 m_physics->SetShapeToBox(BoxSize); 52 m_physics->SetMass(.0f); 53 m_physics->SetTransform(base_location, base_rotation); 54 m_physics->InitBodyToRigid(true); 55 m_physics->AddToSimulation(new_sim); 52 56 } 53 57 else if (dummy == 2) //for character purpose 54 58 { 59 m_character = new EasyCharacterController(this); 55 60 m_is_character = true; 56 61 //m_mesh.Compile("[sc#f00 afcb10 10 10 -.1]"); … … 78 83 ); 79 84 vec3 BoxSize = vec3(.5f, 2.f, .5f); 80 m_character .SetCollisionChannel(0, 0xFF);81 m_character .SetShapeToCapsule(BoxSize.x, BoxSize.y);82 m_character .SetMass(.0f);83 m_character .SetTransform(base_location, base_rotation);84 m_character .InitBodyToGhost();85 m_character .AddToSimulation(new_sim);85 m_character->SetCollisionChannel(0, 0xFF); 86 m_character->SetShapeToCapsule(BoxSize.x, BoxSize.y); 87 m_character->SetMass(.0f); 88 m_character->SetTransform(base_location, base_rotation); 89 m_character->InitBodyToGhost(); 90 m_character->AddToSimulation(new_sim); 86 91 } 87 92 } … … 168 173 } 169 174 175 m_physics = new EasyPhysic(this); 176 170 177 m_mesh.Compile(MeshRand[RandValue]); 171 178 vec3 BoxSize = vec3(2.0f); … … 173 180 if (RandValue < SphereLimit) 174 181 { 175 m_physics .SetShapeToBox(BoxSize);182 m_physics->SetShapeToBox(BoxSize); 176 183 ColGroup += 0; 177 184 } 178 185 else if (RandValue < ConeLimit) 179 186 { 180 m_physics .SetShapeToSphere(BoxSize.x * 2.f);187 m_physics->SetShapeToSphere(BoxSize.x * 2.f); 181 188 ColGroup += 1; 182 189 } 183 190 else if (RandValue < CylLimit) 184 191 { 185 m_physics .SetShapeToCone(BoxSize.x, BoxSize.y);192 m_physics->SetShapeToCone(BoxSize.x, BoxSize.y); 186 193 ColGroup += 2; 187 194 } 188 195 else if (RandValue < CapsLimit) 189 196 { 190 m_physics .SetShapeToCylinder(BoxSize);197 m_physics->SetShapeToCylinder(BoxSize); 191 198 ColGroup += 3; 192 199 } 193 200 else 194 201 { 195 m_physics .SetShapeToCapsule(BoxSize.x, BoxSize.y);202 m_physics->SetShapeToCapsule(BoxSize.x, BoxSize.y); 196 203 ColGroup += 4; 197 204 } 198 205 199 m_physics .SetCollisionChannel(0, 0xFF);200 //m_physics .SetCollisionChannel(ColGroup, (1<<ColGroup)|(1));201 m_physics .SetMass(base_mass);202 m_physics .SetTransform(base_location);203 m_physics .InitBodyToRigid();204 m_physics .AddToSimulation(new_sim);206 m_physics->SetCollisionChannel(0, 0xFF); 207 //m_physics->SetCollisionChannel(ColGroup, (1<<ColGroup)|(1)); 208 m_physics->SetMass(base_mass); 209 m_physics->SetTransform(base_location); 210 m_physics->InitBodyToRigid(); 211 m_physics->AddToSimulation(new_sim); 205 212 } 206 213 … … 208 215 { 209 216 if (m_is_character) 210 m_character .SetTransform(base_location, base_rotation);217 m_character->SetTransform(base_location, base_rotation); 211 218 else 212 m_physics.SetTransform(base_location, base_rotation); 219 m_physics->SetTransform(base_location, base_rotation); 220 } 221 222 void SetLinearVelocity(const lol::vec3& NewVelocity, bool bIsLocal=false) 223 { 224 //if (m_is_character) 225 // m_character->SetLinearVelocity(NewVelocity); 226 //else 227 // m_physics->SetLinearVelocity(NewVelocity); 213 228 } 214 229 … … 216 231 { 217 232 if (m_is_character) 218 return m_character .GetTransform();233 return m_character->GetTransform(); 219 234 else 220 return m_physics .GetTransform();235 return m_physics->GetTransform(); 221 236 } 222 237 … … 227 242 228 243 EasyMesh *GetMesh() { return &m_mesh; } 229 EasyPhysic *GetPhysic() { return &m_physics; }230 EasyPhysic *GetCharacter() { return &m_character; }244 EasyPhysic *GetPhysic() { return m_physics; } 245 EasyPhysic *GetCharacter() { return m_character; } 231 246 232 247 ~PhysicsObject() … … 255 270 { 256 271 if (m_is_character) 257 m_mesh.Render(m_character .GetTransform());272 m_mesh.Render(m_character->GetTransform()); 258 273 else 259 m_mesh.Render(m_physics .GetTransform());274 m_mesh.Render(m_physics->GetTransform()); 260 275 } 261 276 } … … 263 278 private: 264 279 //Base datas 265 EasyMesh m_mesh;266 EasyPhysic m_physics;267 EasyCharacterController m_character;268 269 bool m_ready;270 bool m_should_render;271 bool m_is_character;280 EasyMesh m_mesh; 281 EasyPhysic* m_physics; 282 EasyCharacterController* m_character; 283 284 bool m_ready; 285 bool m_should_render; 286 bool m_is_character; 272 287 }; 273 288 -
trunk/test/Physics/Include/EasyCharacterController.h
r1749 r1764 36 36 37 37 public: 38 EasyCharacterController( ) :39 EasyPhysic( ),38 EasyCharacterController(WorldEntity* NewOwnerEntity) : 39 EasyPhysic(NewOwnerEntity), 40 40 m_character(NULL) 41 41 { -
trunk/test/Physics/Include/EasyPhysics.h
r1749 r1764 39 39 40 40 public: 41 EasyPhysic( );41 EasyPhysic(WorldEntity* NewOwnerEntity); 42 42 ~EasyPhysic(); 43 43 … … 50 50 virtual bool CanChangeCollisionChannel() { return (m_rigid_body == NULL); } 51 51 virtual void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation=lol::quat(lol::mat4(1.0f))); 52 private: 53 virtual void BaseTransformChanged(const lol::mat4& PreviousMatrix, const lol::mat4& NewMatrix); 54 public: 52 55 virtual void SetMass(float mass); 53 56 virtual void InitBodyToRigid(bool ZeroMassIsKinematic=false); … … 77 80 78 81 public: 79 EasyPhysic( ) {}82 EasyPhysic(WorldEntity* NewOwnerEntity) { m_owner_entity = NewOwnerEntity; } 80 83 81 84 virtual void SetShapeToBox(lol::vec3& BoxSize) { } … … 87 90 virtual bool CanChangeCollisionChannel() { return true; } 88 91 virtual void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation=lol::quat(lol::mat4(1.0f))) { } 92 private: 93 virtual void BaseTransformChanged(const lol::mat4& PreviousMatrix, const lol::mat4& NewMatrix) { } 94 public: 89 95 virtual void SetMass(float mass) { } 90 96 virtual void InitBodyToRigid() { } … … 114 120 int GetCollisionMask() { return m_collision_mask; } 115 121 122 //Base/Attachment logic 123 virtual void AttachTo(EasyPhysic* NewBase, bool NewBaseLockLocation = true, bool NewBaseLockRotation = true) 124 { 125 if (NewBase == this || NewBase->m_base_physic == this) 126 return; 127 128 if (NewBase) 129 { 130 bool bAlreadyExists = false; 131 for (int i = 0; i < NewBase->m_based_physic_list.Count(); ++i) 132 if (NewBase->m_based_physic_list[i] == this) 133 bAlreadyExists = true; 134 if (!bAlreadyExists) 135 NewBase->m_based_physic_list << this; 136 m_base_physic = NewBase; 137 m_base_lock_location = NewBaseLockLocation; 138 m_base_lock_rotation = NewBaseLockRotation; 139 } 140 else 141 { 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--); 145 m_base_physic = NULL; 146 } 147 } 148 116 149 protected: 117 150 lol::mat4 m_local_to_world; … … 119 152 int m_collision_group; 120 153 int m_collision_mask; 154 WorldEntity* m_owner_entity; 155 156 //Base/Attachment logic 157 Array<EasyPhysic*> m_based_physic_list; //List of objects based on this : this object moves, its based object move with it. 158 EasyPhysic* m_base_physic; //Base for this object : The base moves, the object moves with it. 159 bool m_base_lock_location; //when this is TRUE, location moves with rotation change. 160 bool m_base_lock_rotation; //when this is TRUE, rotation moves with rotation change. 161 162 //Touch logic 163 Array<EasyPhysic*> m_touching_physic; //Maintained by ghost objects 121 164 }; 122 165 -
trunk/test/Physics/Src/EasyPhysics.cpp
r1756 r1764 30 30 //-- 31 31 32 EasyPhysic::EasyPhysic( ) :32 EasyPhysic::EasyPhysic(WorldEntity* NewOwnerEntity) : 33 33 m_collision_object(NULL), 34 34 m_ghost_object(NULL), … … 40 40 m_mass(.0f), 41 41 m_collision_group(1), 42 m_collision_mask(1) 42 m_collision_mask(1), 43 m_owner_entity(NewOwnerEntity) 43 44 { 44 45 } … … 114 115 void EasyPhysic::SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation) 115 116 { 116 m_local_to_world = lol::mat4::translate(base_location) * mat4(base_rotation); 117 lol::mat4 PreviousMatrix = m_local_to_world; 118 m_local_to_world = lol::mat4::translate(base_location) * lol::mat4(base_rotation); 117 119 118 120 if (m_ghost_object) … … 124 126 else 125 127 m_motion_state = new btDefaultMotionState(btTransform(LOL2BT_QUAT(base_rotation), LOL2BT_VEC3(base_location * LOL2BT_UNIT))); 128 } 129 130 for (int i = 0; i < m_based_physic_list.Count(); i++) 131 if (m_based_physic_list[i]) 132 m_based_physic_list[i]->BaseTransformChanged(PreviousMatrix, m_local_to_world); 133 else 134 m_based_physic_list.Remove(i--); 135 } 136 137 //Internal callback when Base transform has changed. 138 void EasyPhysic::BaseTransformChanged(const lol::mat4& PreviousMatrix, const lol::mat4& NewMatrix) 139 { 140 mat4 PreviousMatrixLoc = ((m_base_lock_location)?(PreviousMatrix):(lol::mat4::translate(PreviousMatrix.v3.xyz))); 141 mat4 PreviousMatrixRot = ((m_base_lock_rotation)?(lol::mat4(lol::quat(PreviousMatrix))):(lol::mat4(1.f))); 142 mat4 NewMatrixLoc = ((m_base_lock_location)?(NewMatrix):(lol::mat4::translate(NewMatrix.v3.xyz))); 143 mat4 NewMatrixRot = ((m_base_lock_rotation)?(lol::mat4(lol::quat(NewMatrix))):(lol::mat4(1.f))); 144 145 if (m_ghost_object || (m_rigid_body->getCollisionFlags() & btCollisionObject::CF_KINEMATIC_OBJECT)) 146 { 147 mat4 ThisMatrixLoc = NewMatrixLoc * inverse(PreviousMatrixLoc) * lol::mat4::translate(m_local_to_world.v3.xyz); 148 mat4 ThisMatrixRot = NewMatrixRot * inverse(PreviousMatrixRot) * lol::mat4(lol::quat(m_local_to_world)); 149 SetTransform(ThisMatrixLoc.v3.xyz, lol::mat4(lol::quat(ThisMatrixRot))); 126 150 } 127 151 }
Note: See TracChangeset
for help on using the changeset viewer.