1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-25 06:35:30 +00:00

Port MWRender::Camera

This commit is contained in:
scrawl 2015-05-21 23:54:39 +02:00
parent 0fb97bd2e7
commit 9b8e2e9db3
11 changed files with 329 additions and 173 deletions

View File

@ -22,8 +22,7 @@ source_group(game FILES ${GAME} ${GAME_HEADER})
add_openmw_dir (mwrender add_openmw_dir (mwrender
actors objects renderingmanager animation sky npcanimation vismask actors objects renderingmanager animation sky npcanimation vismask
creatureanimation effectmanager util renderinginterface pathgrid rendermode creatureanimation effectmanager util renderinginterface pathgrid rendermode
bulletdebugdraw globalmap characterpreview bulletdebugdraw globalmap characterpreview camera
# camera
# localmap occlusionquery water shadows # localmap occlusionquery water shadows
# ripplesimulation refraction # ripplesimulation refraction
# terrainstorage weaponanimation # terrainstorage weaponanimation

View File

@ -5,7 +5,6 @@
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
#include <osgGA/TrackballManipulator>
#include <osgViewer/ViewerEventHandlers> #include <osgViewer/ViewerEventHandlers>
#include <osgDB/ReadFile> #include <osgDB/ReadFile>
@ -592,8 +591,6 @@ void OMW::Engine::go()
} }
// Start the main rendering loop // Start the main rendering loop
mViewer->setCameraManipulator(new osgGA::TrackballManipulator);
osg::Timer frameTimer; osg::Timer frameTimer;
while (!mViewer->done() && !MWBase::Environment::get().getStateManager()->hasQuitRequest()) while (!mViewer->done() && !MWBase::Environment::get().getStateManager()->hasQuitRequest())
{ {

View File

@ -249,6 +249,11 @@ namespace MWRender
mInsert->removeChild(mObjectRoot); mInsert->removeChild(mObjectRoot);
} }
MWWorld::Ptr Animation::getPtr()
{
return mPtr;
}
void Animation::setActive(bool active) void Animation::setActive(bool active)
{ {
if (SceneUtil::Skeleton* skel = dynamic_cast<SceneUtil::Skeleton*>(mObjectRoot.get())) if (SceneUtil::Skeleton* skel = dynamic_cast<SceneUtil::Skeleton*>(mObjectRoot.get()))

View File

@ -254,6 +254,8 @@ public:
Animation(const MWWorld::Ptr &ptr, osg::ref_ptr<osg::Group> parentNode, Resource::ResourceSystem* resourceSystem); Animation(const MWWorld::Ptr &ptr, osg::ref_ptr<osg::Group> parentNode, Resource::ResourceSystem* resourceSystem);
virtual ~Animation(); virtual ~Animation();
MWWorld::Ptr getPtr();
/// Set active flag on the object skeleton, if one exists. /// Set active flag on the object skeleton, if one exists.
/// @see SceneUtil::Skeleton::setActive /// @see SceneUtil::Skeleton::setActive
void setActive(bool active); void setActive(bool active);

View File

@ -1,9 +1,6 @@
#include "camera.hpp" #include "camera.hpp"
#include <OgreSceneNode.h> #include <osg/PositionAttitudeTransform>
#include <OgreCamera.h>
#include <OgreSceneManager.h>
#include <OgreTagPoint.h>
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/windowmanager.hpp" #include "../mwbase/windowmanager.hpp"
@ -13,12 +10,38 @@
#include "npcanimation.hpp" #include "npcanimation.hpp"
namespace
{
class UpdateCameraCallback : public osg::NodeCallback
{
public:
UpdateCameraCallback(MWRender::Camera* cam)
: 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;
};
}
namespace MWRender namespace MWRender
{ {
Camera::Camera (Ogre::Camera *camera)
Camera::Camera (osg::Camera* camera)
: mCamera(camera), : mCamera(camera),
mCameraNode(NULL),
mCameraPosNode(NULL),
mAnimation(NULL), mAnimation(NULL),
mFirstPersonView(true), mFirstPersonView(true),
mPreviewMode(false), mPreviewMode(false),
@ -27,10 +50,11 @@ namespace MWRender
mFurthest(800.f), mFurthest(800.f),
mIsNearest(false), mIsNearest(false),
mHeight(124.f), mHeight(124.f),
mCameraDistance(192.f), mMaxCameraDistance(192.f),
mDistanceAdjusted(false), mDistanceAdjusted(false),
mVanityToggleQueued(false), mVanityToggleQueued(false),
mViewModeToggleQueued(false) mViewModeToggleQueued(false),
mCameraDistance(0.f)
{ {
mVanity.enabled = false; mVanity.enabled = false;
mVanity.allowed = true; mVanity.allowed = true;
@ -41,10 +65,46 @@ namespace MWRender
mMainCam.pitch = 0.f; mMainCam.pitch = 0.f;
mMainCam.yaw = 0.f; mMainCam.yaw = 0.f;
mMainCam.offset = 400.f; mMainCam.offset = 400.f;
mUpdateCallback = new UpdateCameraCallback(this);
mCamera->addUpdateCallback(mUpdateCallback);
} }
Camera::~Camera() Camera::~Camera()
{ {
mCamera->removeUpdateCallback(mUpdateCallback);
}
MWWorld::Ptr Camera::getTrackingPtr() const
{
return mTrackingPtr;
}
void Camera::updateCamera(osg::Camera *cam)
{
if (mTrackingPtr.isEmpty())
return;
const osg::Node* trackNode = mTrackingNode;
if (!trackNode)
return;
osg::MatrixList mats = trackNode->getWorldMatrices();
if (!mats.size())
return;
const osg::Matrix& worldMat = mats[0];
osg::Vec3 position = worldMat.getTrans();
if (!isFirstPerson())
position.z() += mHeight;
osg::Quat orient = osg::Quat(getPitch(), osg::Vec3(1,0,0)) * osg::Quat(getYaw(), osg::Vec3(0,0,1));
osg::Vec3 offset = orient * osg::Vec3(0, -mCameraDistance, 0);
position += offset;
osg::Vec3 forward = orient * osg::Vec3(0,1,0);
osg::Vec3 up = orient * osg::Vec3(0,0,1);
cam->setViewMatrixAsLookAt(position, position + forward, up);
} }
void Camera::reset() void Camera::reset()
@ -55,68 +115,20 @@ namespace MWRender
toggleViewMode(); toggleViewMode();
} }
void Camera::rotateCamera(const Ogre::Vector3 &rot, bool adjust) void Camera::rotateCamera(float pitch, float yaw, bool adjust)
{ {
if (adjust) { if (adjust)
setYaw(getYaw() + rot.z); {
setPitch(getPitch() + rot.x); pitch += getPitch();
} else { yaw += getYaw();
setYaw(rot.z);
setPitch(rot.x);
} }
setYaw(yaw);
Ogre::Quaternion xr(Ogre::Radian(getPitch() + Ogre::Math::HALF_PI), Ogre::Vector3::UNIT_X); setPitch(pitch);
Ogre::Quaternion orient = xr;
if (mVanity.enabled || mPreviewMode) {
Ogre::Quaternion zr(Ogre::Radian(getYaw()), Ogre::Vector3::UNIT_Z);
orient = zr * xr;
}
if (isFirstPerson())
mCamera->getParentNode()->setOrientation(orient);
else
mCameraNode->setOrientation(orient);
} }
const std::string &Camera::getHandle() const void Camera::attachTo(const MWWorld::Ptr &ptr)
{
return mTrackingPtr.getRefData().getHandle();
}
Ogre::SceneNode* Camera::attachTo(const MWWorld::Ptr &ptr)
{ {
mTrackingPtr = ptr; mTrackingPtr = ptr;
Ogre::SceneNode *node = mTrackingPtr.getRefData().getBaseNode()->createChildSceneNode(Ogre::Vector3(0.0f, 0.0f, mHeight));
node->setInheritScale(false);
Ogre::SceneNode *posNode = node->createChildSceneNode();
posNode->setInheritScale(false);
if(mCameraNode)
{
node->setOrientation(mCameraNode->getOrientation());
posNode->setPosition(mCameraPosNode->getPosition());
mCameraNode->getCreator()->destroySceneNode(mCameraNode);
mCameraNode->getCreator()->destroySceneNode(mCameraPosNode);
}
mCameraNode = node;
mCameraPosNode = posNode;
if (!isFirstPerson())
{
mCamera->detachFromParent();
mCameraPosNode->attachObject(mCamera);
}
return mCameraPosNode;
}
void Camera::setPosition(const Ogre::Vector3& position)
{
mCameraPosNode->setPosition(position);
}
void Camera::setPosition(float x, float y, float z)
{
setPosition(Ogre::Vector3(x,y,z));
} }
void Camera::update(float duration, bool paused) void Camera::update(float duration, bool paused)
@ -147,9 +159,7 @@ namespace MWRender
if(mVanity.enabled) if(mVanity.enabled)
{ {
Ogre::Vector3 rot(0.f, 0.f, 0.f); rotateCamera(0.f, osg::DegreesToRadians(3.f * duration), true);
rot.z = Ogre::Degree(3.f * duration).valueRadians();
rotateCamera(rot, true);
} }
} }
@ -169,9 +179,9 @@ namespace MWRender
processViewChange(); processViewChange();
if (mFirstPersonView) { if (mFirstPersonView) {
setPosition(0.f, 0.f, 0.f); mCameraDistance = 0.f;
} else { } else {
setPosition(0.f, 0.f, mCameraDistance); mCameraDistance = mMaxCameraDistance;
} }
} }
@ -202,18 +212,15 @@ namespace MWRender
processViewChange(); processViewChange();
float offset = mPreviewCam.offset; float offset = mPreviewCam.offset;
Ogre::Vector3 rot(0.f, 0.f, 0.f);
if (mVanity.enabled) { if (mVanity.enabled) {
rot.x = Ogre::Degree(-30.f).valueRadians(); setPitch(osg::DegreesToRadians(-30.f));
mMainCam.offset = mCameraPosNode->getPosition().z; mMainCam.offset = mCameraDistance;
} else { } else {
rot.x = getPitch();
offset = mMainCam.offset; offset = mMainCam.offset;
} }
rot.z = getYaw();
setPosition(0.f, 0.f, offset); mCameraDistance = offset;
rotateCamera(rot, false);
return true; return true;
} }
@ -229,7 +236,7 @@ namespace MWRender
mPreviewMode = enable; mPreviewMode = enable;
processViewChange(); processViewChange();
float offset = mCameraPosNode->getPosition().z; float offset = mCameraDistance;
if (mPreviewMode) { if (mPreviewMode) {
mMainCam.offset = offset; mMainCam.offset = offset;
offset = mPreviewCam.offset; offset = mPreviewCam.offset;
@ -238,13 +245,12 @@ namespace MWRender
offset = mMainCam.offset; offset = mMainCam.offset;
} }
setPosition(0.f, 0.f, offset); mCameraDistance = offset;
} }
void Camera::setSneakOffset(float offset) void Camera::setSneakOffset(float offset)
{ {
if(mAnimation) // TODO: implement
mAnimation->addFirstPersonOffset(Ogre::Vector3(0.f, 0.f, -offset));
} }
float Camera::getYaw() float Camera::getYaw()
@ -256,10 +262,10 @@ namespace MWRender
void Camera::setYaw(float angle) void Camera::setYaw(float angle)
{ {
if (angle > Ogre::Math::PI) { if (angle > osg::PI) {
angle -= Ogre::Math::TWO_PI; angle -= osg::PI*2;
} else if (angle < -Ogre::Math::PI) { } else if (angle < -osg::PI) {
angle += Ogre::Math::TWO_PI; angle += osg::PI*2;
} }
if (mVanity.enabled || mPreviewMode) { if (mVanity.enabled || mPreviewMode) {
mPreviewCam.yaw = angle; mPreviewCam.yaw = angle;
@ -279,7 +285,7 @@ namespace MWRender
void Camera::setPitch(float angle) void Camera::setPitch(float angle)
{ {
const float epsilon = 0.000001f; const float epsilon = 0.000001f;
float limit = Ogre::Math::HALF_PI - epsilon; float limit = osg::PI_2 - epsilon;
if(mPreviewMode) if(mPreviewMode)
limit /= 2; limit /= 2;
@ -297,7 +303,7 @@ namespace MWRender
float Camera::getCameraDistance() const float Camera::getCameraDistance() const
{ {
return mCameraPosNode->getPosition().z; return mCameraDistance;
} }
void Camera::setCameraDistance(float dist, bool adjust, bool override) void Camera::setCameraDistance(float dist, bool adjust, bool override)
@ -307,25 +313,24 @@ namespace MWRender
mIsNearest = false; mIsNearest = false;
Ogre::Vector3 v(0.f, 0.f, dist); if (adjust)
if (adjust) { dist += mCameraDistance;
v += mCameraPosNode->getPosition();
} if (dist >= mFurthest) {
if (v.z >= mFurthest) { dist = mFurthest;
v.z = mFurthest; } else if (!override && dist < 10.f) {
} else if (!override && v.z < 10.f) { dist = -10.f;
v.z = 10.f; } else if (override && dist <= mNearest) {
} else if (override && v.z <= mNearest) { dist = -mNearest;
v.z = mNearest;
mIsNearest = true; mIsNearest = true;
} }
setPosition(v); mCameraDistance = dist;
if (override) { if (override) {
if (mVanity.enabled || mPreviewMode) { if (mVanity.enabled || mPreviewMode) {
mPreviewCam.offset = v.z; mPreviewCam.offset = mCameraDistance;
} else if (!mFirstPersonView) { } else if (!mFirstPersonView) {
mCameraDistance = v.z; mMaxCameraDistance = mCameraDistance;
} }
} else { } else {
mDistanceAdjusted = true; mDistanceAdjusted = true;
@ -336,9 +341,9 @@ namespace MWRender
{ {
if (mDistanceAdjusted) { if (mDistanceAdjusted) {
if (mVanity.enabled || mPreviewMode) { if (mVanity.enabled || mPreviewMode) {
setPosition(0, 0, mPreviewCam.offset); mCameraDistance = mPreviewCam.offset;
} else if (!mFirstPersonView) { } else if (!mFirstPersonView) {
setPosition(0, 0, mCameraDistance); mCameraDistance = mMaxCameraDistance;
} }
} }
mDistanceAdjusted = false; mDistanceAdjusted = false;
@ -351,7 +356,6 @@ namespace MWRender
if(mAnimation && mAnimation != anim) if(mAnimation && mAnimation != anim)
{ {
mAnimation->setViewMode(NpcAnimation::VM_Normal); mAnimation->setViewMode(NpcAnimation::VM_Normal);
mAnimation->detachObjectFromBone(mCamera);
} }
mAnimation = anim; mAnimation = anim;
@ -360,29 +364,25 @@ namespace MWRender
void Camera::processViewChange() void Camera::processViewChange()
{ {
mAnimation->detachObjectFromBone(mCamera);
mCamera->detachFromParent();
if(isFirstPerson()) if(isFirstPerson())
{ {
mAnimation->setViewMode(NpcAnimation::VM_FirstPerson); mAnimation->setViewMode(NpcAnimation::VM_FirstPerson);
Ogre::TagPoint *tag = mAnimation->attachObjectToBone("Head", mCamera); mTrackingNode = mAnimation->getNode("Head");
tag->setInheritOrientation(false);
} }
else else
{ {
mAnimation->setViewMode(NpcAnimation::VM_Normal); mAnimation->setViewMode(NpcAnimation::VM_Normal);
mCameraPosNode->attachObject(mCamera); mTrackingNode = mTrackingPtr.getRefData().getBaseNode();
} }
rotateCamera(Ogre::Vector3(getPitch(), 0.f, getYaw()), false); rotateCamera(getPitch(), getYaw(), false);
} }
void Camera::getPosition(Ogre::Vector3 &focal, Ogre::Vector3 &camera) void Camera::getPosition(osg::Vec3 &focal, osg::Vec3 &camera)
{ {
mCamera->getParentSceneNode()->needUpdate(true); //mCamera->getParentSceneNode()->needUpdate(true);
camera = mCamera->getRealPosition(); //camera = mCamera->getRealPosition();
focal = mCameraNode->_getDerivedPosition(); //focal = mCameraNode->_getDerivedPosition();
} }
void Camera::togglePlayerLooking(bool enable) void Camera::togglePlayerLooking(bool enable)

View File

@ -3,13 +3,16 @@
#include <string> #include <string>
#include <osg/ref_ptr>
#include <osg/Vec3>
#include "../mwworld/ptr.hpp" #include "../mwworld/ptr.hpp"
namespace Ogre namespace osg
{ {
class Vector3;
class Camera; class Camera;
class SceneNode; class NodeCallback;
class Node;
} }
namespace MWRender namespace MWRender
@ -24,10 +27,9 @@ namespace MWRender
}; };
MWWorld::Ptr mTrackingPtr; MWWorld::Ptr mTrackingPtr;
osg::ref_ptr<const osg::Node> mTrackingNode;
Ogre::Camera *mCamera; osg::ref_ptr<osg::Camera> mCamera;
Ogre::SceneNode *mCameraNode;
Ogre::SceneNode *mCameraPosNode;
NpcAnimation *mAnimation; NpcAnimation *mAnimation;
@ -42,7 +44,7 @@ namespace MWRender
bool enabled, allowed; bool enabled, allowed;
} mVanity; } mVanity;
float mHeight, mCameraDistance; float mHeight, mMaxCameraDistance;
CamData mMainCam, mPreviewCam; CamData mMainCam, mPreviewCam;
bool mDistanceAdjusted; bool mDistanceAdjusted;
@ -50,19 +52,25 @@ namespace MWRender
bool mVanityToggleQueued; bool mVanityToggleQueued;
bool mViewModeToggleQueued; bool mViewModeToggleQueued;
void setPosition(const Ogre::Vector3& position); float mCameraDistance;
void setPosition(float x, float y, float z);
osg::ref_ptr<osg::NodeCallback> mUpdateCallback;
public: public:
Camera(Ogre::Camera *camera); Camera(osg::Camera* camera);
~Camera(); ~Camera();
MWWorld::Ptr getTrackingPtr() const;
/// Update the view matrix of \a cam
void updateCamera(osg::Camera* cam);
/// Reset to defaults /// Reset to defaults
void reset(); void reset();
/// Set where the camera is looking at. Uses Morrowind (euler) angles /// Set where the camera is looking at. Uses Morrowind (euler) angles
/// \param rot Rotation angles in radians /// \param rot Rotation angles in radians
void rotateCamera(const Ogre::Vector3 &rot, bool adjust); void rotateCamera(float pitch, float yaw, bool adjust);
float getYaw(); float getYaw();
void setYaw(float angle); void setYaw(float angle);
@ -70,10 +78,8 @@ namespace MWRender
float getPitch(); float getPitch();
void setPitch(float angle); void setPitch(float angle);
const std::string &getHandle() const;
/// Attach camera to object /// Attach camera to object
Ogre::SceneNode* attachTo(const MWWorld::Ptr &); void attachTo(const MWWorld::Ptr &);
/// @param Force view mode switch, even if currently not allowed by the animation. /// @param Force view mode switch, even if currently not allowed by the animation.
void toggleViewMode(bool force=false); void toggleViewMode(bool force=false);
@ -85,9 +91,6 @@ namespace MWRender
void togglePreviewMode(bool enable); void togglePreviewMode(bool enable);
/// \brief Lowers the camera for sneak. /// \brief Lowers the camera for sneak.
/// As animation is tied to the camera, this needs
/// to be set each frame after the animation is
/// applied.
void setSneakOffset(float offset); void setSneakOffset(float offset);
bool isFirstPerson() const bool isFirstPerson() const
@ -111,7 +114,7 @@ namespace MWRender
void setAnimation(NpcAnimation *anim); void setAnimation(NpcAnimation *anim);
/// Stores focal and camera world positions in passed arguments /// Stores focal and camera world positions in passed arguments
void getPosition(Ogre::Vector3 &focal, Ogre::Vector3 &camera); void getPosition(osg::Vec3 &focal, osg::Vec3 &camera);
void togglePlayerLooking(bool enable); void togglePlayerLooking(bool enable);

View File

@ -31,6 +31,7 @@
#include "npcanimation.hpp" #include "npcanimation.hpp"
#include "vismask.hpp" #include "vismask.hpp"
#include "pathgrid.hpp" #include "pathgrid.hpp"
#include "camera.hpp"
namespace MWRender namespace MWRender
{ {
@ -104,6 +105,8 @@ namespace MWRender
mEffectManager.reset(new EffectManager(mRootNode, mResourceSystem)); mEffectManager.reset(new EffectManager(mRootNode, mResourceSystem));
mCamera.reset(new Camera(mViewer->getCamera()));
mViewer->setLightingMode(osgViewer::View::NO_LIGHT); mViewer->setLightingMode(osgViewer::View::NO_LIGHT);
osg::ref_ptr<osg::LightSource> source = new osg::LightSource; osg::ref_ptr<osg::LightSource> source = new osg::LightSource;
@ -253,11 +256,21 @@ namespace MWRender
mSky->update(dt); mSky->update(dt);
} }
void RenderingManager::updatePlayerPtr(const MWWorld::Ptr &ptr)
{
if(mPlayerAnimation.get())
mPlayerAnimation->updatePtr(ptr);
mCamera->attachTo(ptr);
}
void RenderingManager::rotateObject(const MWWorld::Ptr &ptr, const osg::Quat& rot) void RenderingManager::rotateObject(const MWWorld::Ptr &ptr, const osg::Quat& rot)
{ {
//if(ptr.getRefData().getHandle() == mCamera->getHandle() && if(ptr == mCamera->getTrackingPtr() &&
// !mCamera->isVanityOrPreviewModeEnabled()) !mCamera->isVanityOrPreviewModeEnabled())
// mCamera->rotateCamera(-rot, false); {
mCamera->rotateCamera(-ptr.getRefData().getPosition().rot[0], -ptr.getRefData().getPosition().rot[2], false);
}
ptr.getRefData().getBaseNode()->setAttitude(rot); ptr.getRefData().getBaseNode()->setAttitude(rot);
} }
@ -321,11 +334,30 @@ namespace MWRender
{ {
mPlayerAnimation.reset(new NpcAnimation(player, player.getRefData().getBaseNode(), mResourceSystem, 0)); mPlayerAnimation.reset(new NpcAnimation(player, player.getRefData().getBaseNode(), mResourceSystem, 0));
//mCamera->setAnimation(mPlayerAnimation); mCamera->setAnimation(mPlayerAnimation.get());
mCamera->attachTo(player);
//mWater->removeEmitter(ptr); //mWater->removeEmitter(ptr);
//mWater->addEmitter(ptr); //mWater->addEmitter(ptr);
} }
void RenderingManager::rebuildPtr(const MWWorld::Ptr &ptr)
{
NpcAnimation *anim = NULL;
if(ptr == mPlayerAnimation->getPtr())
anim = mPlayerAnimation.get();
else
anim = dynamic_cast<NpcAnimation*>(mObjects->getAnimation(ptr));
if(anim)
{
anim->rebuild();
if(mCamera->getTrackingPtr() == ptr)
{
mCamera->attachTo(ptr);
mCamera->setAnimation(anim);
}
}
}
void RenderingManager::updateProjectionMatrix() void RenderingManager::updateProjectionMatrix()
{ {
double fovy, aspect, zNear, zFar; double fovy, aspect, zNear, zFar;
@ -370,4 +402,75 @@ namespace MWRender
} }
} }
bool RenderingManager::vanityRotateCamera(const float *rot)
{
if(!mCamera->isVanityOrPreviewModeEnabled())
return false;
mCamera->rotateCamera(rot[0], rot[2], true);
return true;
}
void RenderingManager::setCameraDistance(float dist, bool adjust, bool override)
{
if(!mCamera->isVanityOrPreviewModeEnabled() && !mCamera->isFirstPerson())
{
if(mCamera->isNearest() && dist > 0.f)
mCamera->toggleViewMode();
else
mCamera->setCameraDistance(-dist / 120.f * 10, adjust, override);
}
else if(mCamera->isFirstPerson() && dist < 0.f)
{
mCamera->toggleViewMode();
mCamera->setCameraDistance(0.f, false, override);
}
}
void RenderingManager::resetCamera()
{
mCamera->reset();
}
float RenderingManager::getCameraDistance() const
{
return mCamera->getCameraDistance();
}
Camera* RenderingManager::getCamera()
{
return mCamera.get();
}
void RenderingManager::togglePOV()
{
mCamera->toggleViewMode();
}
void RenderingManager::togglePreviewMode(bool enable)
{
mCamera->togglePreviewMode(enable);
}
bool RenderingManager::toggleVanityMode(bool enable)
{
return mCamera->toggleVanityMode(enable);
}
void RenderingManager::allowVanityMode(bool allow)
{
mCamera->allowVanityMode(allow);
}
void RenderingManager::togglePlayerLooking(bool enable)
{
mCamera->togglePlayerLooking(enable);
}
void RenderingManager::changeVanityModeScale(float factor)
{
if(mCamera->isVanityOrPreviewModeEnabled())
mCamera->setCameraDistance(-factor/120.f*10, true, true);
}
} }

View File

@ -41,6 +41,7 @@ namespace MWRender
class SkyManager; class SkyManager;
class NpcAnimation; class NpcAnimation;
class Pathgrid; class Pathgrid;
class Camera;
class RenderingManager : public MWRender::RenderingInterface class RenderingManager : public MWRender::RenderingInterface
{ {
@ -66,7 +67,6 @@ namespace MWRender
void updatePtr(const MWWorld::Ptr& old, const MWWorld::Ptr& updated); void updatePtr(const MWWorld::Ptr& old, const MWWorld::Ptr& updated);
// TODO rename to setRotation/setPosition/setScale, along with the World equivalents
void rotateObject(const MWWorld::Ptr& ptr, const osg::Quat& rot); void rotateObject(const MWWorld::Ptr& ptr, const osg::Quat& rot);
void moveObject(const MWWorld::Ptr& ptr, const osg::Vec3f& pos); void moveObject(const MWWorld::Ptr& ptr, const osg::Vec3f& pos);
void scaleObject(const MWWorld::Ptr& ptr, const osg::Vec3f& scale); void scaleObject(const MWWorld::Ptr& ptr, const osg::Vec3f& scale);
@ -92,11 +92,28 @@ namespace MWRender
Animation* getAnimation(const MWWorld::Ptr& ptr); Animation* getAnimation(const MWWorld::Ptr& ptr);
Animation* getPlayerAnimation(); Animation* getPlayerAnimation();
void updatePlayerPtr(const MWWorld::Ptr &ptr);
void setupPlayer(const MWWorld::Ptr& player); void setupPlayer(const MWWorld::Ptr& player);
void renderPlayer(const MWWorld::Ptr& player); void renderPlayer(const MWWorld::Ptr& player);
void rebuildPtr(const MWWorld::Ptr& ptr);
void processChangedSettings(const Settings::CategorySettingVector& settings); void processChangedSettings(const Settings::CategorySettingVector& settings);
// camera stuff
bool vanityRotateCamera(const float *rot);
void setCameraDistance(float dist, bool adjust, bool override);
void resetCamera();
float getCameraDistance() const;
Camera* getCamera();
void togglePOV();
void togglePreviewMode(bool enable);
bool toggleVanityMode(bool enable);
void allowVanityMode(bool allow);
void togglePlayerLooking(bool enable);
void changeVanityModeScale(float factor);
private: private:
void updateProjectionMatrix(); void updateProjectionMatrix();
void updateTextureFiltering(); void updateTextureFiltering();
@ -114,6 +131,7 @@ namespace MWRender
std::auto_ptr<EffectManager> mEffectManager; std::auto_ptr<EffectManager> mEffectManager;
std::auto_ptr<NpcAnimation> mPlayerAnimation; std::auto_ptr<NpcAnimation> mPlayerAnimation;
osg::ref_ptr<osg::PositionAttitudeTransform> mPlayerNode; osg::ref_ptr<osg::PositionAttitudeTransform> mPlayerNode;
std::auto_ptr<Camera> mCamera;
osg::ref_ptr<StateUpdater> mStateUpdater; osg::ref_ptr<StateUpdater> mStateUpdater;

View File

@ -406,7 +406,7 @@ namespace MWWorld
world->getPlayer().setCell(cell); world->getPlayer().setCell(cell);
MWWorld::Ptr player = world->getPlayerPtr(); MWWorld::Ptr player = world->getPlayerPtr();
//mRendering.updatePlayerPtr(player); mRendering.updatePlayerPtr(player);
if (adjustPlayerPos) { if (adjustPlayerPos) {
world->moveObject(player, pos.pos[0], pos.pos[1], pos.pos[2]); world->moveObject(player, pos.pos[0], pos.pos[1], pos.pos[2]);

View File

@ -37,6 +37,7 @@
//#include "../mwrender/animation.hpp" //#include "../mwrender/animation.hpp"
#include "../mwrender/renderingmanager.hpp" #include "../mwrender/renderingmanager.hpp"
#include "../mwrender/camera.hpp"
#include "../mwscript/interpretercontext.hpp" #include "../mwscript/interpretercontext.hpp"
#include "../mwscript/globalscripts.hpp" #include "../mwscript/globalscripts.hpp"
@ -211,7 +212,7 @@ namespace MWWorld
setupPlayer(); setupPlayer();
renderPlayer(); renderPlayer();
//mRendering->resetCamera(); mRendering->resetCamera();
MWBase::Environment::get().getWindowManager()->updatePlayer(); MWBase::Environment::get().getWindowManager()->updatePlayer();
@ -531,7 +532,6 @@ namespace MWWorld
void World::useDeathCamera() void World::useDeathCamera()
{ {
#if 0
if(mRendering->getCamera()->isVanityOrPreviewModeEnabled() ) if(mRendering->getCamera()->isVanityOrPreviewModeEnabled() )
{ {
mRendering->getCamera()->togglePreviewMode(false); mRendering->getCamera()->togglePreviewMode(false);
@ -539,7 +539,6 @@ namespace MWWorld
} }
if(mRendering->getCamera()->isFirstPerson()) if(mRendering->getCamera()->isFirstPerson())
mRendering->getCamera()->toggleViewMode(true); mRendering->getCamera()->toggleViewMode(true);
#endif
} }
MWWorld::Player& World::getPlayer() MWWorld::Player& World::getPlayer()
@ -1479,7 +1478,7 @@ namespace MWWorld
bool World::toggleCollisionMode() bool World::toggleCollisionMode()
{ {
return 0;//mPhysics->toggleCollisionMode(); return mPhysics->toggleCollisionMode();
} }
bool World::toggleRenderMode (MWRender::RenderMode mode) bool World::toggleRenderMode (MWRender::RenderMode mode)
@ -1607,7 +1606,16 @@ namespace MWWorld
} }
*/ */
//mWorldScene->playerMoved(mRendering->getEyePos()); // Sink the camera while sneaking
bool sneaking = getPlayerPtr().getClass().getCreatureStats(getPlayerPtr()).getStance(MWMechanics::CreatureStats::Stance_Sneak);
bool inair = !isOnGround(getPlayerPtr());
bool swimming = isSwimming(getPlayerPtr());
static const float i1stPersonSneakDelta = getStore().get<ESM::GameSetting>().find("i1stPersonSneakDelta")->getFloat();
if(!paused && sneaking && !(swimming || inair))
mRendering->getCamera()->setSneakOffset(i1stPersonSneakDelta);
else
mRendering->getCamera()->setSneakOffset(0.f);
} }
void World::updateSoundListener() void World::updateSoundListener()
@ -2091,14 +2099,49 @@ namespace MWWorld
*/ */
} }
void World::togglePOV()
{
mRendering->togglePOV();
}
bool World::isFirstPerson() const
{
return mRendering->getCamera()->isFirstPerson();
}
void World::togglePreviewMode(bool enable)
{
mRendering->togglePreviewMode(enable);
}
bool World::toggleVanityMode(bool enable)
{
return mRendering->toggleVanityMode(enable);
}
void World::allowVanityMode(bool allow)
{
mRendering->allowVanityMode(allow);
}
void World::togglePlayerLooking(bool enable)
{
mRendering->togglePlayerLooking(enable);
}
void World::changeVanityModeScale(float factor)
{
mRendering->changeVanityModeScale(factor);
}
bool World::vanityRotateCamera(float * rot) bool World::vanityRotateCamera(float * rot)
{ {
return 0;//mRendering->vanityRotateCamera(rot); return mRendering->vanityRotateCamera(rot);
} }
void World::setCameraDistance(float dist, bool adjust, bool override_) void World::setCameraDistance(float dist, bool adjust, bool override_)
{ {
//mRendering->setCameraDistance(dist, adjust, override_); mRendering->setCameraDistance(dist, adjust, override_);
} }
void World::setupPlayer() void World::setupPlayer()
@ -2509,7 +2552,7 @@ namespace MWWorld
void World::reattachPlayerCamera() void World::reattachPlayerCamera()
{ {
//mRendering->rebuildPtr(getPlayerPtr()); mRendering->rebuildPtr(getPlayerPtr());
} }
void World::setWerewolf(const MWWorld::Ptr& actor, bool werewolf) void World::setWerewolf(const MWWorld::Ptr& actor, bool werewolf)
@ -2542,7 +2585,7 @@ namespace MWWorld
// NpcAnimation::updateParts will already rebuild the animation when it detects change of Npc type. // NpcAnimation::updateParts will already rebuild the animation when it detects change of Npc type.
// the following is just for reattaching the camera properly. // the following is just for reattaching the camera properly.
//mRendering->rebuildPtr(actor); mRendering->rebuildPtr(actor);
if(actor == getPlayerPtr()) if(actor == getPlayerPtr())
{ {

View File

@ -467,33 +467,19 @@ namespace MWWorld
virtual bool isWading(const MWWorld::Ptr &object) const; virtual bool isWading(const MWWorld::Ptr &object) const;
virtual bool isOnGround(const MWWorld::Ptr &ptr) const; virtual bool isOnGround(const MWWorld::Ptr &ptr) const;
virtual void togglePOV() { virtual void togglePOV();
//mRendering->togglePOV();
}
virtual bool isFirstPerson() const { virtual bool isFirstPerson() const;
return 0;//mRendering->getCamera()->isFirstPerson();
}
virtual void togglePreviewMode(bool enable) { virtual void togglePreviewMode(bool enable);
//mRendering->togglePreviewMode(enable);
}
virtual bool toggleVanityMode(bool enable) { virtual bool toggleVanityMode(bool enable);
return 0;//mRendering->toggleVanityMode(enable);
}
virtual void allowVanityMode(bool allow) { virtual void allowVanityMode(bool allow);
//mRendering->allowVanityMode(allow);
}
virtual void togglePlayerLooking(bool enable) { virtual void togglePlayerLooking(bool enable);
//mRendering->togglePlayerLooking(enable);
}
virtual void changeVanityModeScale(float factor) { virtual void changeVanityModeScale(float factor);
//mRendering->changeVanityModeScale(factor);
}
virtual bool vanityRotateCamera(float * rot); virtual bool vanityRotateCamera(float * rot);
virtual void setCameraDistance(float dist, bool adjust = false, bool override = true); virtual void setCameraDistance(float dist, bool adjust = false, bool override = true);