|
|
|
@ -16,12 +16,16 @@ namespace MWRender
|
|
|
|
|
: mCamera(camera),
|
|
|
|
|
mPlayerNode(node),
|
|
|
|
|
mCameraNode(mPlayerNode->createChildSceneNode()),
|
|
|
|
|
mVanityNode(mPlayerNode->createChildSceneNode()),
|
|
|
|
|
mFirstPersonView(true),
|
|
|
|
|
mVanityMode(false),
|
|
|
|
|
mPreviewMode(false)
|
|
|
|
|
mPreviewMode(false),
|
|
|
|
|
mHeight(40.f)
|
|
|
|
|
{
|
|
|
|
|
Ogre::SceneNode *pitchNode = mCameraNode->createChildSceneNode();
|
|
|
|
|
pitchNode->attachObject(mCamera);
|
|
|
|
|
mCameraNode->attachObject(mCamera);
|
|
|
|
|
mCameraNode->setPosition(0.f, 0.f, mHeight);
|
|
|
|
|
|
|
|
|
|
mPreviewCam.yaw = 0.f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Player::rotate(const Ogre::Vector3 &rot, bool adjust)
|
|
|
|
@ -32,7 +36,7 @@ namespace MWRender
|
|
|
|
|
mTimeIdle = 0.f;
|
|
|
|
|
|
|
|
|
|
if (mVanityMode) {
|
|
|
|
|
toggleVanityMode();
|
|
|
|
|
toggleVanityMode(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return !mVanityMode && !mPreviewMode;
|
|
|
|
@ -44,26 +48,21 @@ namespace MWRender
|
|
|
|
|
Ogre::SceneNode *yawNode = pitchNode->getParentSceneNode();
|
|
|
|
|
|
|
|
|
|
if (adjust) {
|
|
|
|
|
float f =
|
|
|
|
|
limitPitchAngle(89.5f, Ogre::Radian(rot.x).valueDegrees());
|
|
|
|
|
|
|
|
|
|
if (f != 0.0) {
|
|
|
|
|
pitchNode->pitch(Ogre::Degree(f));
|
|
|
|
|
}
|
|
|
|
|
yawNode->yaw(Ogre::Radian(-rot.z));
|
|
|
|
|
setYaw(getYaw() + rot.z);
|
|
|
|
|
setPitch(getPitch() + rot.x);
|
|
|
|
|
} else {
|
|
|
|
|
Ogre::Radian radx(rot.x);
|
|
|
|
|
if (radx.valueDegrees() > 89.5f) {
|
|
|
|
|
radx = Ogre::Degree(89.5f);
|
|
|
|
|
} else if (radx.valueDegrees() < -89.5f) {
|
|
|
|
|
radx = Ogre::Degree(-89.5f);
|
|
|
|
|
}
|
|
|
|
|
Ogre::Quaternion xr(radx, Ogre::Vector3::UNIT_X);
|
|
|
|
|
Ogre::Quaternion yr(Ogre::Radian(-rot.z), Ogre::Vector3::UNIT_Y);
|
|
|
|
|
|
|
|
|
|
pitchNode->setOrientation(xr);
|
|
|
|
|
yawNode->setOrientation(yr);
|
|
|
|
|
setYaw(rot.z);
|
|
|
|
|
setPitch(rot.x);
|
|
|
|
|
}
|
|
|
|
|
Ogre::Quaternion xr(
|
|
|
|
|
Ogre::Radian(getPitch() + Ogre::Math::HALF_PI),
|
|
|
|
|
Ogre::Vector3::UNIT_X
|
|
|
|
|
);
|
|
|
|
|
Ogre::Quaternion zr(Ogre::Radian(getYaw()), Ogre::Vector3::UNIT_Z);
|
|
|
|
|
|
|
|
|
|
pitchNode->setOrientation(xr);
|
|
|
|
|
yawNode->setOrientation(zr);
|
|
|
|
|
|
|
|
|
|
updateListener();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -77,27 +76,6 @@ namespace MWRender
|
|
|
|
|
ptr.getRefData().setBaseNode(mPlayerNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float Player::limitPitchAngle(float limitAbs, float shift)
|
|
|
|
|
{
|
|
|
|
|
Ogre::Quaternion orient =
|
|
|
|
|
mCamera->getParentSceneNode()->getOrientation();
|
|
|
|
|
|
|
|
|
|
float pitchAngle =
|
|
|
|
|
(2 * Ogre::Degree(Ogre::Math::ASin(orient.x)).valueDegrees());
|
|
|
|
|
|
|
|
|
|
if (pitchAngle + shift < limitAbs && pitchAngle + shift > -limitAbs) {
|
|
|
|
|
return shift;
|
|
|
|
|
}
|
|
|
|
|
if (pitchAngle > 0) {
|
|
|
|
|
float f = limitAbs - pitchAngle - shift;
|
|
|
|
|
return (f > 0.f) ? f : 0.f;
|
|
|
|
|
} else if (pitchAngle < 0) {
|
|
|
|
|
float f = -limitAbs - pitchAngle - shift;
|
|
|
|
|
return (f < 0.f) ? f : 0.f;
|
|
|
|
|
}
|
|
|
|
|
return 0.f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Player::updateListener()
|
|
|
|
|
{
|
|
|
|
|
Ogre::Vector3 pos = mCamera->getRealPosition();
|
|
|
|
@ -116,7 +94,7 @@ namespace MWRender
|
|
|
|
|
++mUpdates;
|
|
|
|
|
mTimeIdle += duration;
|
|
|
|
|
if (mTimeIdle > 30.f) {
|
|
|
|
|
toggleVanityMode();
|
|
|
|
|
toggleVanityMode(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (mFirstPersonView && !mVanityMode) {
|
|
|
|
@ -139,54 +117,83 @@ namespace MWRender
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Player::toggleVanityMode()
|
|
|
|
|
void Player::toggleVanityMode(bool enable, bool force)
|
|
|
|
|
{
|
|
|
|
|
mVanityMode = !mVanityMode;
|
|
|
|
|
if (mVanityMode == enable) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
mVanityMode = enable;
|
|
|
|
|
|
|
|
|
|
float offset = 300.f;
|
|
|
|
|
Ogre::Vector3 rot(0.f, 0.f, 0.f);
|
|
|
|
|
if (mVanityMode) {
|
|
|
|
|
mYaw = getYawAngle();
|
|
|
|
|
mPitch = getPitchAngle();
|
|
|
|
|
mOffset = mCamera->getPosition().z;
|
|
|
|
|
|
|
|
|
|
rot.x = Ogre::Degree(-30.f).valueRadians();
|
|
|
|
|
mMainCam.offset = mCamera->getPosition().z;
|
|
|
|
|
|
|
|
|
|
mPlayerNode->removeChild(mCameraNode);
|
|
|
|
|
mVanityNode->addChild(mCameraNode);
|
|
|
|
|
} else {
|
|
|
|
|
rot.x = Ogre::Degree(mPitch).valueRadians();
|
|
|
|
|
rot.z = Ogre::Degree(mYaw).valueRadians();
|
|
|
|
|
offset = mOffset;
|
|
|
|
|
rot.x = getPitch();
|
|
|
|
|
offset = mMainCam.offset;
|
|
|
|
|
|
|
|
|
|
mVanityNode->removeChild(mCameraNode);
|
|
|
|
|
mPlayerNode->addChild(mCameraNode);
|
|
|
|
|
}
|
|
|
|
|
rot.z = getYaw();
|
|
|
|
|
mCamera->setPosition(0.f, 0.f, offset);
|
|
|
|
|
rotateCamera(rot, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Player::togglePreviewMode()
|
|
|
|
|
void Player::togglePreviewMode(bool enable)
|
|
|
|
|
{
|
|
|
|
|
/// \todo move camera
|
|
|
|
|
mPreviewMode = !mPreviewMode;
|
|
|
|
|
if (mPreviewMode == enable) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
mPreviewMode = enable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float Player::getPitchAngle()
|
|
|
|
|
float Player::getYaw()
|
|
|
|
|
{
|
|
|
|
|
Ogre::Quaternion orient
|
|
|
|
|
= mCamera->getParentSceneNode()->getOrientation();
|
|
|
|
|
|
|
|
|
|
float angle =
|
|
|
|
|
(2 * Ogre::Degree(Ogre::Math::ASin(orient.x)).valueDegrees());
|
|
|
|
|
if (mVanityMode || mPreviewMode) {
|
|
|
|
|
return mPreviewCam.yaw;
|
|
|
|
|
}
|
|
|
|
|
return mMainCam.yaw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return angle;
|
|
|
|
|
void Player::setYaw(float angle)
|
|
|
|
|
{
|
|
|
|
|
if (angle > Ogre::Math::PI) {
|
|
|
|
|
angle -= Ogre::Math::TWO_PI;
|
|
|
|
|
} else if (angle < -Ogre::Math::PI) {
|
|
|
|
|
angle += Ogre::Math::TWO_PI;
|
|
|
|
|
}
|
|
|
|
|
if (mVanityMode || mPreviewMode) {
|
|
|
|
|
mPreviewCam.yaw = angle;
|
|
|
|
|
} else {
|
|
|
|
|
mMainCam.yaw = angle;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float Player::getYawAngle()
|
|
|
|
|
float Player::getPitch()
|
|
|
|
|
{
|
|
|
|
|
Ogre::Quaternion orient
|
|
|
|
|
= mCameraNode->getOrientation();
|
|
|
|
|
if (mVanityMode || mPreviewMode) {
|
|
|
|
|
return mPreviewCam.pitch;
|
|
|
|
|
}
|
|
|
|
|
return mMainCam.pitch;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float angle =
|
|
|
|
|
(2 * Ogre::Degree(Ogre::Math::ASin(orient.y)).valueDegrees());
|
|
|
|
|
if (orient.w < 0) {
|
|
|
|
|
angle = -angle;
|
|
|
|
|
void Player::setPitch(float angle)
|
|
|
|
|
{
|
|
|
|
|
if (angle > Ogre::Math::HALF_PI) {
|
|
|
|
|
angle = Ogre::Math::HALF_PI - 0.01;
|
|
|
|
|
} else if (angle < -Ogre::Math::HALF_PI) {
|
|
|
|
|
angle = -Ogre::Math::HALF_PI + 0.01;
|
|
|
|
|
}
|
|
|
|
|
if (mVanityMode || mPreviewMode) {
|
|
|
|
|
mPreviewCam.pitch = angle;
|
|
|
|
|
} else {
|
|
|
|
|
mMainCam.pitch = angle;
|
|
|
|
|
}
|
|
|
|
|
return -angle;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|