2011-01-08 14:11:37 +00:00
|
|
|
#include "player.hpp"
|
|
|
|
|
2012-07-03 13:32:38 +00:00
|
|
|
#include <OgreSceneNode.h>
|
2012-08-08 20:15:52 +00:00
|
|
|
#include <OgreCamera.h>
|
|
|
|
|
2012-08-09 13:01:03 +00:00
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
|
2012-08-08 20:15:52 +00:00
|
|
|
#include "../mwworld/ptr.hpp"
|
|
|
|
#include "../mwworld/refdata.hpp"
|
2012-07-03 13:32:38 +00:00
|
|
|
|
2012-08-09 13:01:03 +00:00
|
|
|
#include "../mwsound/soundmanager.hpp"
|
|
|
|
|
2011-01-08 14:11:37 +00:00
|
|
|
namespace MWRender
|
|
|
|
{
|
2011-11-17 02:15:49 +00:00
|
|
|
Player::Player (Ogre::Camera *camera, Ogre::SceneNode* node)
|
2012-08-08 20:15:52 +00:00
|
|
|
: mCamera (camera),
|
|
|
|
mNode (node),
|
|
|
|
mFirstPersonView(true),
|
|
|
|
mVanityModeEnabled(false)
|
2011-01-08 14:11:37 +00:00
|
|
|
{}
|
2012-05-30 13:52:39 +00:00
|
|
|
|
2012-08-08 20:15:52 +00:00
|
|
|
bool Player::setRotation(const Ogre::Vector3 &rot)
|
2012-05-30 13:52:39 +00:00
|
|
|
{
|
2012-08-08 20:15:52 +00:00
|
|
|
Ogre::SceneNode *sceneNode = mNode;
|
|
|
|
Ogre::Node* yawNode = sceneNode->getChildIterator().getNext();
|
|
|
|
Ogre::Node* pitchNode = yawNode->getChildIterator().getNext();
|
|
|
|
|
|
|
|
// we are only interested in X and Y rotation
|
2012-05-30 13:52:39 +00:00
|
|
|
|
2012-08-08 20:15:52 +00:00
|
|
|
// Rotate around X axis
|
2012-08-09 06:24:18 +00:00
|
|
|
Ogre::Quaternion xr(Ogre::Degree(rot.x), Ogre::Vector3::UNIT_X);
|
2012-05-30 13:52:39 +00:00
|
|
|
|
2012-08-08 20:15:52 +00:00
|
|
|
// Rotate around Y axis
|
2012-08-09 06:24:18 +00:00
|
|
|
Ogre::Quaternion yr(Ogre::Degree(-rot.z), Ogre::Vector3::UNIT_Y);
|
2012-05-30 13:52:39 +00:00
|
|
|
|
2012-08-08 20:15:52 +00:00
|
|
|
pitchNode->setOrientation(xr);
|
|
|
|
yawNode->setOrientation(yr);
|
2012-05-30 13:52:39 +00:00
|
|
|
|
2012-08-09 06:24:18 +00:00
|
|
|
controlFlip();
|
2012-08-09 13:01:03 +00:00
|
|
|
updateListener();
|
2012-08-09 06:24:18 +00:00
|
|
|
|
2012-08-08 20:15:52 +00:00
|
|
|
return !mVanityModeEnabled;
|
2012-05-30 13:52:39 +00:00
|
|
|
}
|
2012-07-03 13:32:38 +00:00
|
|
|
|
|
|
|
std::string Player::getHandle() const
|
|
|
|
{
|
|
|
|
return mNode->getName();
|
|
|
|
}
|
2012-08-08 20:15:52 +00:00
|
|
|
|
|
|
|
void Player::attachTo(const MWWorld::Ptr &ptr)
|
|
|
|
{
|
|
|
|
ptr.getRefData().setBaseNode(mNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Player::adjustRotation(const Ogre::Vector3 &rot)
|
|
|
|
{
|
|
|
|
Ogre::SceneNode *pitchNode = mCamera->getParentSceneNode();
|
|
|
|
Ogre::SceneNode *yawNode = pitchNode->getParentSceneNode();
|
|
|
|
|
|
|
|
pitchNode->pitch(Ogre::Degree(rot.x));
|
2012-08-09 06:24:18 +00:00
|
|
|
yawNode->yaw(Ogre::Degree(-rot.z));
|
|
|
|
|
|
|
|
controlFlip();
|
2012-08-09 13:01:03 +00:00
|
|
|
updateListener();
|
2012-08-08 20:15:52 +00:00
|
|
|
|
|
|
|
return !mVanityModeEnabled;
|
|
|
|
}
|
2012-08-09 06:24:18 +00:00
|
|
|
|
|
|
|
void Player::controlFlip()
|
|
|
|
{
|
|
|
|
Ogre::SceneNode *pitchNode = mCamera->getParentSceneNode();
|
|
|
|
Ogre::Quaternion orient = pitchNode->getOrientation();
|
|
|
|
|
|
|
|
float pitchAngle =
|
|
|
|
(2 * Ogre::Degree(Ogre::Math::ACos(orient.w)).valueDegrees());
|
|
|
|
|
|
|
|
// Limit the pitch between -90 degress and +90 degrees, Quake3-style.
|
|
|
|
if (pitchAngle > 90.0f)
|
|
|
|
{
|
|
|
|
Ogre::Real sqrt = Ogre::Math::Sqrt(0.5f);
|
|
|
|
if (orient.x > 0) {
|
|
|
|
// Set orientation to 90 degrees on X-axis.
|
|
|
|
pitchNode->setOrientation(Ogre::Quaternion(sqrt, sqrt, 0, 0));
|
|
|
|
} else if (orient.x < 0) {
|
|
|
|
// Sets orientation to -90 degrees on X-axis.
|
|
|
|
pitchNode->setOrientation(Ogre::Quaternion(sqrt, -sqrt, 0, 0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-09 13:01:03 +00:00
|
|
|
|
|
|
|
void Player::updateListener()
|
|
|
|
{
|
|
|
|
Ogre::Vector3 pos = mCamera->getRealPosition();
|
|
|
|
Ogre::Vector3 dir = mCamera->getRealDirection();
|
|
|
|
|
|
|
|
Ogre::Real xch;
|
|
|
|
xch = pos.y, pos.y = -pos.z, pos.z = xch;
|
|
|
|
xch = dir.y, dir.y = -dir.z, dir.z = xch;
|
|
|
|
|
|
|
|
MWBase::Environment::get().getSoundManager()->setListenerPosDir(pos, dir);
|
|
|
|
}
|
2011-01-08 14:11:37 +00:00
|
|
|
}
|