Roket_PhysicsJointUniversal::Roket_PhysicsJointUniversal( NewtonWorld* worldd, irr::core::vector3df point, irr::core::vector3df pin0, irr::core::vector3df pin1, Roket_PhysicsBody* child, Roket_PhysicsBody* parent, RPhysicsJoint* rjoint) { world = worldd; float pointD[3]; pointD[0] = point.X; pointD[1] = point.Y; pointD[2] = point.Z; float pointP0[3]; pointP0[0] = pin0.X; pointP0[1] = pin0.Y; pointP0[2] = pin0.Z; float pointP1[3]; pointP1[0] = pin1.X; pointP1[1] = pin1.Y; pointP1[2] = pin1.Z; if (parent == NULL) joint = NewtonConstraintCreateUniversal(world, &pointD[0], &pointP0[0], &pointP1[0], child->body, NULL); else joint = NewtonConstraintCreateUniversal(world, &pointD[0], &pointP0[0], &pointP1[0], child->body, parent->body); NewtonJointSetUserData(joint, &rjoint); NewtonJointSetDestructor(joint, &JointDestructor); }
/** * @brief * Constructor */ JointUniversal::JointUniversal(PLPhysics::World &cWorld, PLPhysics::Body *pParentBody, PLPhysics::Body *pChildBody, const Vector3 &vPivotPoint, const Vector3 &vPinDir1, const Vector3 &vPinDir2) : PLPhysics::JointUniversal(cWorld, static_cast<World&>(cWorld).CreateJointImpl(), pParentBody, pChildBody, vPivotPoint, vPinDir1, vPinDir2) { // Deactivate the physics simulation if required const bool bSimulationActive = cWorld.IsSimulationActive(); if (bSimulationActive) cWorld.SetSimulationActive(false); // Get the Newton physics world Newton::NewtonWorld *pNewtonWorld = static_cast<World&>(cWorld).GetNewtonWorld(); // Flush assigned bodies (MUST be done before creating the joint!) if (pParentBody) static_cast<BodyImpl&>(pParentBody->GetBodyImpl()).Flush(); if (pChildBody) static_cast<BodyImpl&>(pChildBody ->GetBodyImpl()).Flush(); // Get the Newton physics parent and child bodies const Newton::NewtonBody *pNewtonParentBody = pParentBody ? static_cast<BodyImpl&>(pParentBody->GetBodyImpl()).GetNewtonBody() : nullptr; const Newton::NewtonBody *pNewtonChildBody = pChildBody ? static_cast<BodyImpl&>(pChildBody ->GetBodyImpl()).GetNewtonBody() : nullptr; // [TODO] ?? /* if (pNewtonParentBody) NewtonBodySetUserData(pNewtonParentBody, nullptr); if (pNewtonChildBody) NewtonBodySetUserData(pNewtonChildBody, nullptr); */ // Get body initial transform matrix if (pParentBody) { // Get transform matrix Quaternion qQ; pParentBody->GetRotation(qQ); Vector3 vPos; pParentBody->GetPosition(vPos); Matrix3x4 mTrans; mTrans.FromQuatTrans(qQ, vPos); // And transform the initial joint anchor into the body object space mTrans.Invert(); m_vLocalAnchor = mTrans*vPivotPoint; } // Create the Newton physics joint Newton::NewtonJoint *pNewtonJoint = NewtonConstraintCreateUniversal(pNewtonWorld, m_vPivotPoint, m_vPinDir1, m_vPinDir2, pNewtonChildBody, pNewtonParentBody); // Set Newton universal callback function NewtonUniversalSetUserCallback(pNewtonJoint, JointUserCallback); // Initialize the Newton physics joint static_cast<JointImpl&>(GetJointImpl()).InitializeNewtonJoint(*this, *pNewtonJoint); // Reactivate the physics simulation if required if (bSimulationActive) cWorld.SetSimulationActive(bSimulationActive); }