Guest User

Untitled

a guest
Oct 18th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. // C++
  2. // Função responsável por criar o joint
  3. void HEntity::createFixedJoint(HEntity* target)
  4. {
  5. physx::PxPhysics* physics = HEngine::getInstance()->getPhysicsContext()->getPhysics();
  6. physx::PxRigidActor* _target = target->getPhysicsBody();
  7.  
  8. physx::PxVec3 pos_a = m_pPhysicsBody->getGlobalPose().p;
  9. physx::PxVec3 pos_b = _target->getGlobalPose().p;
  10. physx::PxVec3 offset = (pos_a - pos_b).abs() / 2;
  11.  
  12. physx::PxFixedJoint* joint = physx::PxFixedJointCreate(*physics, m_pPhysicsBody, physx::PxTransform(-offset), _target, physx::PxTransform(offset));
  13.  
  14. joint->setConstraintFlag(physx::PxConstraintFlag::eVISUALIZATION, true);
  15. joint->setConstraintFlag(physx::PxConstraintFlag::eCOLLISION_ENABLED, false);
  16.  
  17. m_lpJoints.push_back(joint);
  18. }
  19.  
  20. -- Lua
  21. -- Função responsável por criar os cubos em serie
  22. function createJointCubes()
  23. local parent = scene:getObjectByName("Object.2") -- Cubo já presente na cena
  24. local last_obj = nil;
  25.  
  26. for i = 1, 12 do
  27. local obj = HGameObject:new()
  28. obj:setName("Object_Phy." .. i)
  29. obj:setMesh(HEngine.importWavefront(imports[2]))
  30.  
  31. if last_obj == nil then
  32. obj:setWorldPosition(parent:getWorldPosition()+HVec3(2, 0, 0))
  33. else
  34. obj:setWorldPosition(last_obj:getWorldPosition()+HVec3(2, 0, 0))
  35. end
  36.  
  37. obj:createPhysicsBody()
  38.  
  39. if last_obj == nil then
  40. obj:createFixedJoint(parent)
  41. else
  42. obj:createFixedJoint(last_obj)
  43. end
  44.  
  45. scene:addObject(obj)
  46. last_obj = obj
  47. end
  48. end
  49.  
  50. // C++
  51. // Acada frame ("Parentando")
  52. m_FilhoWorldTransform = m_pPai->getWorldTransform() * m_FilhoWorldTransform;
  53. // ...
  54. // Adicionando shape "filho" ao rigidbody "Pai"
  55. m_pPai->getRigidBody()->attachShape(m_Filho->getShape());
  56. // ...
  57. // Atualizando massa e inércia
  58. physx::PxU32 mass_count = 2; // Numero de shapes/massas
  59. physx::PxReal* masses = new physx::PxReal[2];
  60. masses[0] = pai_mass;
  61. masses[1] = filho_mass;
  62.  
  63. physx::PxRigidBodyExt::setMassAndUpdateInertia(*parent->getRigidDynamic(), masses, mass_count);
  64. delete masses;
Add Comment
Please, Sign In to add comment