DiK2Pos ArMoveProperty::GetIntersectionLineRound(const DiK2Pos& linePos1, const DiK2Pos& linePos2, const DiK2Pos& roundCenter, float fRadius) { DI_ASSERT(linePos1.Distance(roundCenter) >= fRadius); DI_ASSERT(linePos2.Distance(roundCenter) <= fRadius); DiVec3 vLinePos1(linePos1.x, 0.0f, linePos1.z); DiVec3 vLinePos2(linePos2.x, 0.0f, linePos2.z); DiVec3 vRoundCenter(roundCenter.x, 0.0f, roundCenter.z); vLinePos1 -= vRoundCenter; vLinePos2 -= vRoundCenter; DiVec3 vRotation1 = vLinePos1 - vLinePos2; vRotation1.normalise(); DiVec3 vRotation2(1.0f, 0.0f, 0.0f); vRotation2.normalise(); DiQuat quaternion = vRotation1.getRotationTo(vRotation2); vLinePos1 = quaternion*vLinePos1; vLinePos2 = quaternion*vLinePos2; float x = fRadius*fRadius - vLinePos1.z*vLinePos1.z; x = (float)sqrt(x); if (vLinePos1.x < vLinePos2.x) x = -x; DiVec3 vFinalPos(x, 0.0f, vLinePos1.z); DiQuat quaternion2 = vRotation2.getRotationTo(vRotation1); vFinalPos = quaternion2*vFinalPos; vFinalPos += vRoundCenter; DiK2Pos intersection(vFinalPos.x, vFinalPos.z); return intersection; }
LTBOOL RotatingDoor::GetMoveTestPosRot(LTVector & vTestPos, LTRotation & rTestRot) { LTVector vFinalPos(0.0f, 0.0f, 0.0f); LTFLOAT fSpeed = 0.0f; LTVector vOldAngles(m_fPitch, m_fYaw, m_fRoll); switch (m_dwDoorState) { case DOORSTATE_CLOSING: { // Calculate new pitch, yaw, and roll... CalcAngle(m_fPitch, m_fPitch, m_vOpenAngles.x, m_vOpenDir.x, m_fSpeed); CalcAngle(m_fYaw, m_fYaw, m_vOpenAngles.y, m_vOpenDir.y, m_fSpeed); CalcAngle(m_fRoll, m_fRoll, m_vOpenAngles.z, m_vOpenDir.z, m_fSpeed); } break; case DOORSTATE_OPENING: { // Calculate new pitch, yaw, and roll... CalcAngle(m_fPitch, m_fPitch, m_vClosedAngles.x, -m_vOpenDir.x, m_fClosingSpeed); CalcAngle(m_fYaw, m_fYaw, m_vClosedAngles.y, -m_vOpenDir.y, m_fClosingSpeed); CalcAngle(m_fRoll, m_fRoll, m_vClosedAngles.z, -m_vOpenDir.z, m_fClosingSpeed); } break; default: return LTFALSE; break; } // Rotate the object... CalcPosAndRot(vTestPos, rTestRot); // Restore real angles... m_fPitch = vOldAngles.x; m_fYaw = vOldAngles.y; m_fRoll = vOldAngles.z; return LTTRUE; }