/** * @brief * Gets the current camera viewport corners */ bool SNCamera::GetViewportCorners(Vector3 &vUpperRight, Vector3 &vLowerRight, Vector3 &vLowerLeft, Vector3 &vUpperLeft, bool bContainerSpace, float fDistance) { // Get the viewport const Renderer &cRenderer = GetSceneContext()->GetRendererContext().GetRenderer(); const uint32 nViewportWidth = static_cast<uint32>(cRenderer.GetViewport().GetWidth()); const uint32 nViewportHeight = static_cast<uint32>(cRenderer.GetViewport().GetHeight()); // Get near x/y/z const float fAspectRadio = static_cast<float>(nViewportWidth)/(static_cast<float>(nViewportHeight)*m_fAspect); const float e = static_cast<float>(1/Math::Tan(Math::DegToRad*m_fFOV*0.5f)); // Get viewport corners vUpperRight.SetXYZ( fDistance/e, fAspectRadio*fDistance/e, -fDistance); vLowerRight.SetXYZ( fDistance/e, -fAspectRadio*fDistance/e, -fDistance); vLowerLeft.SetXYZ(-fDistance/e, -fAspectRadio*fDistance/e, -fDistance); vUpperLeft.SetXYZ(-fDistance/e, fAspectRadio*fDistance/e, -fDistance); // Transform the corners into container space? if (bContainerSpace) { Matrix3x4 mWorld = GetViewMatrix(); mWorld.Invert(); vUpperRight = mWorld*vUpperRight; vLowerRight = mWorld*vLowerRight; vLowerLeft = mWorld*vLowerLeft; vUpperLeft = mWorld*vUpperLeft; } // Done return true; }
/** * @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); }