2013-04-29 05:50:40 -07:00
|
|
|
#include "camera.hpp"
|
2011-01-08 15:11:37 +01:00
|
|
|
|
2015-06-14 23:13:26 +02:00
|
|
|
#include <osg/Camera>
|
2012-08-09 00:15:52 +04:00
|
|
|
|
2015-11-20 21:57:04 +01:00
|
|
|
#include <components/sceneutil/positionattitudetransform.hpp>
|
|
|
|
|
2012-08-09 17:01:03 +04:00
|
|
|
#include "../mwbase/environment.hpp"
|
2012-08-17 16:55:21 +02:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
2012-08-09 17:01:03 +04:00
|
|
|
|
2012-08-09 00:15:52 +04:00
|
|
|
#include "../mwworld/ptr.hpp"
|
|
|
|
#include "../mwworld/refdata.hpp"
|
2012-07-03 15:32:38 +02:00
|
|
|
|
2012-08-14 20:33:29 +04:00
|
|
|
#include "npcanimation.hpp"
|
|
|
|
|
2015-05-21 23:54:39 +02:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2015-09-24 15:21:42 +02:00
|
|
|
class UpdateRenderCameraCallback : public osg::NodeCallback
|
2015-05-21 23:54:39 +02:00
|
|
|
{
|
|
|
|
public:
|
2015-09-24 15:21:42 +02:00
|
|
|
UpdateRenderCameraCallback(MWRender::Camera* cam)
|
2015-05-21 23:54:39 +02:00
|
|
|
: mCamera(cam)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
|
|
|
|
{
|
|
|
|
osg::Camera* cam = static_cast<osg::Camera*>(node);
|
|
|
|
|
|
|
|
// traverse first to update animations, in case the camera is attached to an animated node
|
|
|
|
traverse(node, nv);
|
|
|
|
|
|
|
|
mCamera->updateCamera(cam);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
MWRender::Camera* mCamera;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-01-08 15:11:37 +01:00
|
|
|
namespace MWRender
|
|
|
|
{
|
2015-05-21 23:54:39 +02:00
|
|
|
|
|
|
|
Camera::Camera (osg::Camera* camera)
|
2015-11-09 17:30:11 +01:00
|
|
|
: mHeightScale(1.f),
|
|
|
|
mCamera(camera),
|
2018-10-09 10:21:12 +04:00
|
|
|
mAnimation(nullptr),
|
2012-08-09 00:15:52 +04:00
|
|
|
mFirstPersonView(true),
|
2012-08-14 02:36:18 +04:00
|
|
|
mPreviewMode(false),
|
2012-08-17 13:23:02 +04:00
|
|
|
mFreeLook(true),
|
2013-07-29 16:43:16 +02:00
|
|
|
mNearest(30.f),
|
2013-07-29 16:45:35 +02:00
|
|
|
mFurthest(800.f),
|
|
|
|
mIsNearest(false),
|
2014-10-01 17:45:20 +02:00
|
|
|
mHeight(124.f),
|
2015-05-21 23:54:39 +02:00
|
|
|
mMaxCameraDistance(192.f),
|
2013-12-27 00:36:06 +01:00
|
|
|
mVanityToggleQueued(false),
|
2016-06-10 01:39:37 +02:00
|
|
|
mVanityToggleQueuedValue(false),
|
2015-05-21 23:54:39 +02:00
|
|
|
mViewModeToggleQueued(false),
|
|
|
|
mCameraDistance(0.f)
|
2012-05-30 15:52:39 +02:00
|
|
|
{
|
2012-08-14 14:37:48 +04:00
|
|
|
mVanity.enabled = false;
|
|
|
|
mVanity.allowed = true;
|
|
|
|
|
2013-12-30 21:47:06 +01:00
|
|
|
mPreviewCam.pitch = 0.f;
|
2012-08-14 02:36:18 +04:00
|
|
|
mPreviewCam.yaw = 0.f;
|
2012-08-16 13:15:38 +04:00
|
|
|
mPreviewCam.offset = 400.f;
|
2013-12-30 21:47:06 +01:00
|
|
|
mMainCam.pitch = 0.f;
|
2013-07-31 18:46:32 +02:00
|
|
|
mMainCam.yaw = 0.f;
|
|
|
|
mMainCam.offset = 400.f;
|
2015-05-21 23:54:39 +02:00
|
|
|
|
2016-06-10 01:05:43 +02:00
|
|
|
mCameraDistance = mMaxCameraDistance;
|
|
|
|
|
2015-09-24 15:21:42 +02:00
|
|
|
mUpdateCallback = new UpdateRenderCameraCallback(this);
|
2015-05-21 23:54:39 +02:00
|
|
|
mCamera->addUpdateCallback(mUpdateCallback);
|
2012-08-12 15:50:37 +04:00
|
|
|
}
|
2012-09-13 19:03:31 +02:00
|
|
|
|
2013-04-29 05:50:40 -07:00
|
|
|
Camera::~Camera()
|
2012-09-13 19:03:31 +02:00
|
|
|
{
|
2015-05-21 23:54:39 +02:00
|
|
|
mCamera->removeUpdateCallback(mUpdateCallback);
|
2012-09-13 19:03:31 +02:00
|
|
|
}
|
2012-07-03 15:32:38 +02:00
|
|
|
|
2015-05-21 23:54:39 +02:00
|
|
|
MWWorld::Ptr Camera::getTrackingPtr() const
|
2013-05-17 22:53:43 +02:00
|
|
|
{
|
2015-05-21 23:54:39 +02:00
|
|
|
return mTrackingPtr;
|
2013-05-17 22:53:43 +02:00
|
|
|
}
|
|
|
|
|
2015-06-01 15:34:46 +02:00
|
|
|
osg::Vec3d Camera::getFocalPoint()
|
2012-07-03 15:32:38 +02:00
|
|
|
{
|
2015-05-21 23:54:39 +02:00
|
|
|
const osg::Node* trackNode = mTrackingNode;
|
|
|
|
if (!trackNode)
|
2015-06-01 15:34:46 +02:00
|
|
|
return osg::Vec3d();
|
2016-02-22 18:58:19 +01:00
|
|
|
osg::NodePathList nodepaths = trackNode->getParentalNodePaths();
|
|
|
|
if (nodepaths.empty())
|
2015-06-01 15:34:46 +02:00
|
|
|
return osg::Vec3d();
|
2016-02-22 18:58:19 +01:00
|
|
|
osg::Matrix worldMat = osg::computeLocalToWorld(nodepaths[0]);
|
2013-04-27 01:24:36 -07:00
|
|
|
|
2015-05-31 23:09:37 +02:00
|
|
|
osg::Vec3d position = worldMat.getTrans();
|
2015-05-21 23:54:39 +02:00
|
|
|
if (!isFirstPerson())
|
2015-11-09 17:30:11 +01:00
|
|
|
position.z() += mHeight * mHeightScale;
|
2015-06-01 15:34:46 +02:00
|
|
|
return position;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Camera::updateCamera(osg::Camera *cam)
|
|
|
|
{
|
|
|
|
if (mTrackingPtr.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
osg::Vec3d position = getFocalPoint();
|
2014-10-01 18:55:35 +02:00
|
|
|
|
2015-05-31 23:09:37 +02:00
|
|
|
osg::Quat orient = osg::Quat(getPitch(), osg::Vec3d(1,0,0)) * osg::Quat(getYaw(), osg::Vec3d(0,0,1));
|
2015-05-21 23:54:39 +02:00
|
|
|
|
2016-06-10 01:05:43 +02:00
|
|
|
osg::Vec3d offset = orient * osg::Vec3d(0, isFirstPerson() ? 0 : -mCameraDistance, 0);
|
2015-05-21 23:54:39 +02:00
|
|
|
position += offset;
|
|
|
|
|
2015-05-31 23:09:37 +02:00
|
|
|
osg::Vec3d forward = orient * osg::Vec3d(0,1,0);
|
|
|
|
osg::Vec3d up = orient * osg::Vec3d(0,0,1);
|
2015-05-21 23:54:39 +02:00
|
|
|
|
|
|
|
cam->setViewMatrixAsLookAt(position, position + forward, up);
|
2012-08-09 00:15:52 +04:00
|
|
|
}
|
2012-08-09 10:24:18 +04:00
|
|
|
|
2015-05-21 23:54:39 +02:00
|
|
|
void Camera::reset()
|
2012-08-09 10:24:18 +04:00
|
|
|
{
|
2015-05-21 23:54:39 +02:00
|
|
|
togglePreviewMode(false);
|
|
|
|
toggleVanityMode(false);
|
|
|
|
if (!mFirstPersonView)
|
|
|
|
toggleViewMode();
|
2012-08-12 15:50:37 +04:00
|
|
|
}
|
|
|
|
|
2015-05-21 23:54:39 +02:00
|
|
|
void Camera::rotateCamera(float pitch, float yaw, bool adjust)
|
2012-08-12 15:50:37 +04:00
|
|
|
{
|
2015-05-21 23:54:39 +02:00
|
|
|
if (adjust)
|
2013-04-28 23:44:44 -07:00
|
|
|
{
|
2015-05-21 23:54:39 +02:00
|
|
|
pitch += getPitch();
|
|
|
|
yaw += getYaw();
|
2013-04-28 23:44:44 -07:00
|
|
|
}
|
2015-05-21 23:54:39 +02:00
|
|
|
setYaw(yaw);
|
|
|
|
setPitch(pitch);
|
2014-10-01 18:55:35 +02:00
|
|
|
}
|
|
|
|
|
2015-05-21 23:54:39 +02:00
|
|
|
void Camera::attachTo(const MWWorld::Ptr &ptr)
|
2014-10-01 18:55:35 +02:00
|
|
|
{
|
2015-05-21 23:54:39 +02:00
|
|
|
mTrackingPtr = ptr;
|
2012-08-12 15:50:37 +04:00
|
|
|
}
|
|
|
|
|
2013-07-30 23:24:18 +02:00
|
|
|
void Camera::update(float duration, bool paused)
|
2012-08-12 15:50:37 +04:00
|
|
|
{
|
2014-08-28 00:41:52 +02:00
|
|
|
if (mAnimation->upperBodyReady())
|
2013-12-27 00:36:06 +01:00
|
|
|
{
|
|
|
|
// Now process the view changes we queued earlier
|
|
|
|
if (mVanityToggleQueued)
|
|
|
|
{
|
2016-06-10 01:39:37 +02:00
|
|
|
toggleVanityMode(mVanityToggleQueuedValue);
|
2013-12-27 00:36:06 +01:00
|
|
|
mVanityToggleQueued = false;
|
|
|
|
}
|
|
|
|
if (mViewModeToggleQueued)
|
|
|
|
{
|
|
|
|
|
|
|
|
togglePreviewMode(false);
|
|
|
|
toggleViewMode();
|
|
|
|
mViewModeToggleQueued = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-30 23:24:18 +02:00
|
|
|
if (paused)
|
|
|
|
return;
|
2012-10-01 11:24:44 +04:00
|
|
|
|
2012-08-27 19:18:55 +02:00
|
|
|
// only show the crosshair in game mode and in first person mode.
|
2013-04-28 23:44:44 -07:00
|
|
|
MWBase::WindowManager *wm = MWBase::Environment::get().getWindowManager();
|
|
|
|
wm->showCrosshair(!wm->isGuiMode() && (mFirstPersonView && !mVanity.enabled && !mPreviewMode));
|
2012-08-27 19:18:55 +02:00
|
|
|
|
2013-04-28 23:44:44 -07:00
|
|
|
if(mVanity.enabled)
|
|
|
|
{
|
2015-05-21 23:54:39 +02:00
|
|
|
rotateCamera(0.f, osg::DegreesToRadians(3.f * duration), true);
|
2012-08-12 15:50:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-05 17:21:02 +02:00
|
|
|
void Camera::toggleViewMode(bool force)
|
2012-08-12 15:50:37 +04:00
|
|
|
{
|
2013-12-27 00:36:06 +01:00
|
|
|
// Changing the view will stop all playing animations, so if we are playing
|
|
|
|
// anything important, queue the view change for later
|
2014-08-28 00:41:52 +02:00
|
|
|
if (!mAnimation->upperBodyReady() && !force)
|
2013-12-27 00:36:06 +01:00
|
|
|
{
|
|
|
|
mViewModeToggleQueued = true;
|
|
|
|
return;
|
|
|
|
}
|
2014-07-03 19:37:12 +02:00
|
|
|
else
|
|
|
|
mViewModeToggleQueued = false;
|
2013-12-27 00:36:06 +01:00
|
|
|
|
2012-08-12 15:50:37 +04:00
|
|
|
mFirstPersonView = !mFirstPersonView;
|
2013-07-13 16:12:38 -07:00
|
|
|
processViewChange();
|
2012-08-12 15:50:37 +04:00
|
|
|
}
|
2012-08-14 14:37:48 +04:00
|
|
|
|
2013-04-29 05:50:40 -07:00
|
|
|
void Camera::allowVanityMode(bool allow)
|
2012-08-14 14:37:48 +04:00
|
|
|
{
|
2013-04-27 01:24:36 -07:00
|
|
|
if (!allow && mVanity.enabled)
|
2012-08-14 14:37:48 +04:00
|
|
|
toggleVanityMode(false);
|
|
|
|
mVanity.allowed = allow;
|
|
|
|
}
|
2012-08-12 15:50:37 +04:00
|
|
|
|
2013-04-29 05:50:40 -07:00
|
|
|
bool Camera::toggleVanityMode(bool enable)
|
2012-08-12 15:50:37 +04:00
|
|
|
{
|
2013-12-27 00:36:06 +01:00
|
|
|
// Changing the view will stop all playing animations, so if we are playing
|
|
|
|
// anything important, queue the view change for later
|
2016-06-10 01:44:32 +02:00
|
|
|
if (mFirstPersonView && !mAnimation->upperBodyReady())
|
2013-12-27 00:36:06 +01:00
|
|
|
{
|
|
|
|
mVanityToggleQueued = true;
|
2016-06-10 01:39:37 +02:00
|
|
|
mVanityToggleQueuedValue = enable;
|
2013-12-27 00:36:06 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-04-27 01:24:36 -07:00
|
|
|
if(!mVanity.allowed && enable)
|
2012-08-14 14:37:48 +04:00
|
|
|
return false;
|
2013-04-27 01:24:36 -07:00
|
|
|
|
|
|
|
if(mVanity.enabled == enable)
|
2012-08-14 14:37:48 +04:00
|
|
|
return true;
|
|
|
|
mVanity.enabled = enable;
|
2012-08-12 18:35:35 +04:00
|
|
|
|
2013-07-13 16:12:38 -07:00
|
|
|
processViewChange();
|
2013-04-09 15:10:14 -07:00
|
|
|
|
2012-08-16 13:15:38 +04:00
|
|
|
float offset = mPreviewCam.offset;
|
2015-05-21 23:54:39 +02:00
|
|
|
|
2012-08-14 14:37:48 +04:00
|
|
|
if (mVanity.enabled) {
|
2015-05-21 23:54:39 +02:00
|
|
|
setPitch(osg::DegreesToRadians(-30.f));
|
|
|
|
mMainCam.offset = mCameraDistance;
|
2012-08-12 18:35:35 +04:00
|
|
|
} else {
|
2012-08-14 02:36:18 +04:00
|
|
|
offset = mMainCam.offset;
|
2012-08-14 22:39:42 +04:00
|
|
|
}
|
2013-04-27 01:24:36 -07:00
|
|
|
|
2015-05-21 23:54:39 +02:00
|
|
|
mCameraDistance = offset;
|
2012-08-14 14:37:48 +04:00
|
|
|
|
|
|
|
return true;
|
2012-08-12 15:50:37 +04:00
|
|
|
}
|
|
|
|
|
2013-04-29 05:50:40 -07:00
|
|
|
void Camera::togglePreviewMode(bool enable)
|
2012-08-12 15:50:37 +04:00
|
|
|
{
|
2014-08-28 00:41:52 +02:00
|
|
|
if (mFirstPersonView && !mAnimation->upperBodyReady())
|
2013-12-27 00:36:06 +01:00
|
|
|
return;
|
|
|
|
|
2013-04-27 01:24:36 -07:00
|
|
|
if(mPreviewMode == enable)
|
2012-08-14 02:36:18 +04:00
|
|
|
return;
|
2013-04-27 01:24:36 -07:00
|
|
|
|
2012-08-14 02:36:18 +04:00
|
|
|
mPreviewMode = enable;
|
2013-07-13 16:12:38 -07:00
|
|
|
processViewChange();
|
2013-04-27 01:24:36 -07:00
|
|
|
|
2015-05-21 23:54:39 +02:00
|
|
|
float offset = mCameraDistance;
|
2012-08-14 14:37:48 +04:00
|
|
|
if (mPreviewMode) {
|
|
|
|
mMainCam.offset = offset;
|
|
|
|
offset = mPreviewCam.offset;
|
|
|
|
} else {
|
|
|
|
mPreviewCam.offset = offset;
|
|
|
|
offset = mMainCam.offset;
|
2012-08-14 22:39:42 +04:00
|
|
|
}
|
2013-04-27 01:24:36 -07:00
|
|
|
|
2015-05-21 23:54:39 +02:00
|
|
|
mCameraDistance = offset;
|
2012-08-12 15:50:37 +04:00
|
|
|
}
|
2012-08-12 18:35:35 +04:00
|
|
|
|
2014-01-10 22:39:01 +01:00
|
|
|
void Camera::setSneakOffset(float offset)
|
2013-10-02 05:16:52 -04:00
|
|
|
{
|
2015-05-31 02:26:31 +02:00
|
|
|
mAnimation->setFirstPersonOffset(osg::Vec3f(0,0,-offset));
|
2013-10-02 05:16:52 -04:00
|
|
|
}
|
|
|
|
|
2013-04-29 05:50:40 -07:00
|
|
|
float Camera::getYaw()
|
2012-08-12 18:35:35 +04:00
|
|
|
{
|
2013-04-27 01:24:36 -07:00
|
|
|
if(mVanity.enabled || mPreviewMode)
|
2012-08-14 02:36:18 +04:00
|
|
|
return mPreviewCam.yaw;
|
|
|
|
return mMainCam.yaw;
|
|
|
|
}
|
2012-08-12 18:35:35 +04:00
|
|
|
|
2013-04-29 05:50:40 -07:00
|
|
|
void Camera::setYaw(float angle)
|
2012-08-14 02:36:18 +04:00
|
|
|
{
|
2015-05-21 23:54:39 +02:00
|
|
|
if (angle > osg::PI) {
|
|
|
|
angle -= osg::PI*2;
|
|
|
|
} else if (angle < -osg::PI) {
|
|
|
|
angle += osg::PI*2;
|
2012-08-14 02:36:18 +04:00
|
|
|
}
|
2012-08-14 14:37:48 +04:00
|
|
|
if (mVanity.enabled || mPreviewMode) {
|
2012-08-14 02:36:18 +04:00
|
|
|
mPreviewCam.yaw = angle;
|
|
|
|
} else {
|
|
|
|
mMainCam.yaw = angle;
|
|
|
|
}
|
2012-08-12 18:35:35 +04:00
|
|
|
}
|
|
|
|
|
2013-04-29 05:50:40 -07:00
|
|
|
float Camera::getPitch()
|
2012-08-12 18:35:35 +04:00
|
|
|
{
|
2012-08-14 14:37:48 +04:00
|
|
|
if (mVanity.enabled || mPreviewMode) {
|
2012-08-14 02:36:18 +04:00
|
|
|
return mPreviewCam.pitch;
|
|
|
|
}
|
|
|
|
return mMainCam.pitch;
|
|
|
|
}
|
2012-08-12 18:35:35 +04:00
|
|
|
|
2013-04-29 05:50:40 -07:00
|
|
|
void Camera::setPitch(float angle)
|
2012-08-14 14:37:48 +04:00
|
|
|
{
|
2013-04-27 01:24:36 -07:00
|
|
|
const float epsilon = 0.000001f;
|
2015-05-21 23:54:39 +02:00
|
|
|
float limit = osg::PI_2 - epsilon;
|
2013-04-27 01:24:36 -07:00
|
|
|
if(mPreviewMode)
|
|
|
|
limit /= 2;
|
|
|
|
|
|
|
|
if(angle > limit)
|
2013-04-07 15:52:43 +02:00
|
|
|
angle = limit;
|
2013-04-27 01:24:36 -07:00
|
|
|
else if(angle < -limit)
|
2013-04-07 15:52:43 +02:00
|
|
|
angle = -limit;
|
2013-04-27 01:24:36 -07:00
|
|
|
|
2012-08-14 14:37:48 +04:00
|
|
|
if (mVanity.enabled || mPreviewMode) {
|
2012-08-14 02:36:18 +04:00
|
|
|
mPreviewCam.pitch = angle;
|
|
|
|
} else {
|
|
|
|
mMainCam.pitch = angle;
|
2012-08-12 18:35:35 +04:00
|
|
|
}
|
|
|
|
}
|
2012-08-14 14:37:48 +04:00
|
|
|
|
2014-01-01 23:59:17 +01:00
|
|
|
float Camera::getCameraDistance() const
|
|
|
|
{
|
2016-06-10 01:05:43 +02:00
|
|
|
if (isFirstPerson())
|
|
|
|
return 0.f;
|
2015-05-21 23:54:39 +02:00
|
|
|
return mCameraDistance;
|
2014-01-01 23:59:17 +01:00
|
|
|
}
|
|
|
|
|
2013-04-29 05:50:40 -07:00
|
|
|
void Camera::setCameraDistance(float dist, bool adjust, bool override)
|
2012-08-14 14:37:48 +04:00
|
|
|
{
|
2013-04-27 01:24:36 -07:00
|
|
|
if(mFirstPersonView && !mPreviewMode && !mVanity.enabled)
|
2012-08-16 13:15:38 +04:00
|
|
|
return;
|
2013-04-27 01:24:36 -07:00
|
|
|
|
2013-07-29 16:43:16 +02:00
|
|
|
mIsNearest = false;
|
|
|
|
|
2015-05-21 23:54:39 +02:00
|
|
|
if (adjust)
|
|
|
|
dist += mCameraDistance;
|
|
|
|
|
|
|
|
if (dist >= mFurthest) {
|
|
|
|
dist = mFurthest;
|
|
|
|
} else if (!override && dist < 10.f) {
|
2015-05-28 03:47:53 +02:00
|
|
|
dist = 10.f;
|
2015-05-21 23:54:39 +02:00
|
|
|
} else if (override && dist <= mNearest) {
|
2015-05-28 03:47:53 +02:00
|
|
|
dist = mNearest;
|
2013-07-29 16:43:16 +02:00
|
|
|
mIsNearest = true;
|
2012-08-16 13:15:38 +04:00
|
|
|
}
|
2015-05-21 23:54:39 +02:00
|
|
|
mCameraDistance = dist;
|
2012-08-14 14:37:48 +04:00
|
|
|
|
2012-08-16 13:15:38 +04:00
|
|
|
if (override) {
|
|
|
|
if (mVanity.enabled || mPreviewMode) {
|
2015-05-21 23:54:39 +02:00
|
|
|
mPreviewCam.offset = mCameraDistance;
|
2012-08-16 13:15:38 +04:00
|
|
|
} else if (!mFirstPersonView) {
|
2015-05-21 23:54:39 +02:00
|
|
|
mMaxCameraDistance = mCameraDistance;
|
2012-08-14 14:37:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-14 20:33:29 +04:00
|
|
|
|
2013-04-29 05:50:40 -07:00
|
|
|
void Camera::setCameraDistance()
|
2012-08-16 13:15:38 +04:00
|
|
|
{
|
2016-07-17 19:44:55 +02:00
|
|
|
if (mVanity.enabled || mPreviewMode) {
|
|
|
|
mCameraDistance = mPreviewCam.offset;
|
|
|
|
} else if (!mFirstPersonView) {
|
|
|
|
mCameraDistance = mMaxCameraDistance;
|
2012-08-16 13:15:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-29 05:50:40 -07:00
|
|
|
void Camera::setAnimation(NpcAnimation *anim)
|
2012-08-15 15:17:35 +04:00
|
|
|
{
|
|
|
|
mAnimation = anim;
|
2013-07-13 16:12:38 -07:00
|
|
|
|
|
|
|
processViewChange();
|
2012-08-15 15:17:35 +04:00
|
|
|
}
|
|
|
|
|
2013-07-13 16:12:38 -07:00
|
|
|
void Camera::processViewChange()
|
2012-08-14 20:33:29 +04:00
|
|
|
{
|
2013-07-13 16:12:38 -07:00
|
|
|
if(isFirstPerson())
|
|
|
|
{
|
|
|
|
mAnimation->setViewMode(NpcAnimation::VM_FirstPerson);
|
2015-05-31 01:07:43 +02:00
|
|
|
mTrackingNode = mAnimation->getNode("Camera");
|
2015-06-01 04:41:03 +02:00
|
|
|
if (!mTrackingNode)
|
|
|
|
mTrackingNode = mAnimation->getNode("Head");
|
2015-11-09 17:30:11 +01:00
|
|
|
mHeightScale = 1.f;
|
2013-07-13 16:12:38 -07:00
|
|
|
}
|
2014-10-01 18:55:35 +02:00
|
|
|
else
|
2013-07-13 16:12:38 -07:00
|
|
|
{
|
|
|
|
mAnimation->setViewMode(NpcAnimation::VM_Normal);
|
2015-11-20 21:57:04 +01:00
|
|
|
SceneUtil::PositionAttitudeTransform* transform = mTrackingPtr.getRefData().getBaseNode();
|
2015-11-09 17:30:11 +01:00
|
|
|
mTrackingNode = transform;
|
|
|
|
if (transform)
|
2015-11-11 17:23:47 +01:00
|
|
|
mHeightScale = transform->getScale().z();
|
2015-11-09 17:30:11 +01:00
|
|
|
else
|
|
|
|
mHeightScale = 1.f;
|
2013-07-13 16:12:38 -07:00
|
|
|
}
|
2015-05-21 23:54:39 +02:00
|
|
|
rotateCamera(getPitch(), getYaw(), false);
|
2012-08-14 20:33:29 +04:00
|
|
|
}
|
|
|
|
|
2015-06-01 15:34:46 +02:00
|
|
|
void Camera::getPosition(osg::Vec3f &focal, osg::Vec3f &camera)
|
2012-08-16 13:15:38 +04:00
|
|
|
{
|
2015-06-01 15:34:46 +02:00
|
|
|
focal = getFocalPoint();
|
2012-08-16 13:15:38 +04:00
|
|
|
|
2015-06-01 15:34:46 +02:00
|
|
|
osg::Quat orient = osg::Quat(getPitch(), osg::Vec3d(1,0,0)) * osg::Quat(getYaw(), osg::Vec3d(0,0,1));
|
|
|
|
|
2016-06-10 01:05:43 +02:00
|
|
|
osg::Vec3d offset = orient * osg::Vec3d(0, isFirstPerson() ? 0 : -mCameraDistance, 0);
|
2015-06-01 15:34:46 +02:00
|
|
|
camera = focal + offset;
|
2012-08-17 10:10:37 +04:00
|
|
|
}
|
2012-08-17 12:08:31 +04:00
|
|
|
|
2013-04-29 05:50:40 -07:00
|
|
|
void Camera::togglePlayerLooking(bool enable)
|
2012-08-17 13:23:02 +04:00
|
|
|
{
|
|
|
|
mFreeLook = enable;
|
|
|
|
}
|
2012-08-17 22:08:16 +04:00
|
|
|
|
2013-04-29 05:50:40 -07:00
|
|
|
bool Camera::isVanityOrPreviewModeEnabled()
|
2013-03-08 00:12:56 +01:00
|
|
|
{
|
|
|
|
return mPreviewMode || mVanity.enabled;
|
|
|
|
}
|
2013-07-29 16:43:16 +02:00
|
|
|
|
|
|
|
bool Camera::isNearest()
|
|
|
|
{
|
|
|
|
return mIsNearest;
|
|
|
|
}
|
2011-01-08 15:11:37 +01:00
|
|
|
}
|