33 static const physx::PxTransform PITCH_ARM_POSE(physx::PxQuat(physx::PxHalfPi, physx::PxVec3(0.0f, 0.0f, 1.0f)));
43 CPhysXSingleBodyObjectModel(c_engine, c_entity),
44 m_cMiniQuadrotorEntity(c_entity) {
46 SetARGoSReferencePoint(physx::PxVec3(0.0f, 0.0f, -BODY_HALF_HEIGHT));
49 CVector3ToPxVec3(GetEmbodiedEntity().GetOriginAnchor().Position, cPos);
50 physx::PxQuat cOrient;
51 CQuaternionToPxQuat(GetEmbodiedEntity().GetOriginAnchor().Orientation, cOrient);
57 physx::PxTransform cTranslation1(physx::PxVec3(0.0f, 0.0f, BODY_HALF_HEIGHT));
58 physx::PxTransform cRotation(cOrient);
59 physx::PxTransform cTranslation2(cPos);
60 physx::PxTransform cFinalTrans = cTranslation2 * cRotation * cTranslation1;
62 physx::PxCapsuleGeometry cArmGeometry(BODY_HALF_HEIGHT,
65 m_pcBody = GetPhysXEngine().GetPhysics().createRigidDynamic(cFinalTrans);
67 m_pcBody->setRigidBodyFlag(physx::PxRigidBodyFlag::eENABLE_CCD,
true);
69 physx::PxShape* pcRollArmShape =
70 m_pcBody->createShape(cArmGeometry,
71 GetPhysXEngine().GetDefaultMaterial());
72 pcRollArmShape->userData =
this;
74 physx::PxShape* pcPitchArmShape =
75 m_pcBody->createShape(cArmGeometry,
76 GetPhysXEngine().GetDefaultMaterial(),
78 pcPitchArmShape->userData =
this;
80 m_pcBody->setMass(BODY_MASS);
81 m_pcBody->setMassSpaceInertiaTensor(INERTIA_TENSOR_DIAGONAL);
83 GetPhysXEngine().GetScene().addActor(*m_pcBody);
87 CalculateBoundingBox();
95 const Real* pfRotorVel =
98 Real pfSquareRotorVel[4] = {
99 pfRotorVel[0] * pfRotorVel[0],
100 pfRotorVel[1] * pfRotorVel[1],
101 pfRotorVel[2] * pfRotorVel[2],
102 pfRotorVel[3] * pfRotorVel[3]
107 ((pfSquareRotorVel[0]) +
108 (pfSquareRotorVel[1]) +
109 (pfSquareRotorVel[2]) +
110 (pfSquareRotorVel[3]));
112 physx::PxVec3 cTorqueInputs(
113 UPLIFT_COEFFICIENT * ARM_HALF_LENGTH * (pfSquareRotorVel[0] - pfSquareRotorVel[2]),
114 UPLIFT_COEFFICIENT * ARM_HALF_LENGTH * (pfSquareRotorVel[1] - pfSquareRotorVel[3]),
115 DRAG_COEFFICIENT * (pfSquareRotorVel[0] - pfSquareRotorVel[1] + pfSquareRotorVel[2] - pfSquareRotorVel[3]));
117 physx::PxRigidBodyExt::addLocalForceAtLocalPos(
119 physx::PxVec3(0.0f, 0.0f, fUpliftInput),
120 physx::PxVec3(0.0f));
122 physx::PxVec3 cTorque = (-m_pcBody->getAngularVelocity()).cross(INERTIA_TENSOR * m_pcBody->getAngularVelocity()) + cTorqueInputs;
123 m_pcBody->addTorque(cTorque);