Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // C++
- // Função responsável por criar o joint
- void HEntity::createFixedJoint(HEntity* target)
- {
- physx::PxPhysics* physics = HEngine::getInstance()->getPhysicsContext()->getPhysics();
- physx::PxRigidActor* _target = target->getPhysicsBody();
- physx::PxVec3 pos_a = m_pPhysicsBody->getGlobalPose().p;
- physx::PxVec3 pos_b = _target->getGlobalPose().p;
- physx::PxVec3 offset = (pos_a - pos_b).abs() / 2;
- physx::PxFixedJoint* joint = physx::PxFixedJointCreate(*physics, m_pPhysicsBody, physx::PxTransform(-offset), _target, physx::PxTransform(offset));
- joint->setConstraintFlag(physx::PxConstraintFlag::eVISUALIZATION, true);
- joint->setConstraintFlag(physx::PxConstraintFlag::eCOLLISION_ENABLED, false);
- m_lpJoints.push_back(joint);
- }
- -- Lua
- -- Função responsável por criar os cubos em serie
- function createJointCubes()
- local parent = scene:getObjectByName("Object.2") -- Cubo já presente na cena
- local last_obj = nil;
- for i = 1, 12 do
- local obj = HGameObject:new()
- obj:setName("Object_Phy." .. i)
- obj:setMesh(HEngine.importWavefront(imports[2]))
- if last_obj == nil then
- obj:setWorldPosition(parent:getWorldPosition()+HVec3(2, 0, 0))
- else
- obj:setWorldPosition(last_obj:getWorldPosition()+HVec3(2, 0, 0))
- end
- obj:createPhysicsBody()
- if last_obj == nil then
- obj:createFixedJoint(parent)
- else
- obj:createFixedJoint(last_obj)
- end
- scene:addObject(obj)
- last_obj = obj
- end
- end
- // C++
- // Acada frame ("Parentando")
- m_FilhoWorldTransform = m_pPai->getWorldTransform() * m_FilhoWorldTransform;
- // ...
- // Adicionando shape "filho" ao rigidbody "Pai"
- m_pPai->getRigidBody()->attachShape(m_Filho->getShape());
- // ...
- // Atualizando massa e inércia
- physx::PxU32 mass_count = 2; // Numero de shapes/massas
- physx::PxReal* masses = new physx::PxReal[2];
- masses[0] = pai_mass;
- masses[1] = filho_mass;
- physx::PxRigidBodyExt::setMassAndUpdateInertia(*parent->getRigidDynamic(), masses, mass_count);
- delete masses;
Add Comment
Please, Sign In to add comment