1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 23:53:52 +00:00

Rename MWRender's Player to Camera

This commit is contained in:
Chris Robinson 2013-04-29 05:50:40 -07:00
parent dbba126344
commit d17e1e83d5
11 changed files with 113 additions and 135 deletions

View file

@ -14,7 +14,7 @@ set(GAME_HEADER
source_group(game FILES ${GAME} ${GAME_HEADER})
add_openmw_dir (mwrender
renderingmanager debugging sky player animation npcanimation creatureanimation activatoranimation
renderingmanager debugging sky camera animation npcanimation creatureanimation activatoranimation
actors objects renderinginterface localmap occlusionquery terrain terrainmaterial water shadows
compositors characterpreview externalrendering globalmap videoplayer ripplesimulation refraction
)

View file

@ -1,4 +1,4 @@
#include "player.hpp"
#include "camera.hpp"
#include <OgreSceneNode.h>
#include <OgreCamera.h>
@ -15,7 +15,7 @@
namespace MWRender
{
Player::Player (Ogre::Camera *camera)
Camera::Camera (Ogre::Camera *camera)
: mCamera(camera),
mCameraNode(NULL),
mFirstPersonView(true),
@ -33,11 +33,11 @@ namespace MWRender
mPreviewCam.offset = 400.f;
}
Player::~Player()
Camera::~Camera()
{
}
void Player::rotateCamera(const Ogre::Vector3 &rot, bool adjust)
void Camera::rotateCamera(const Ogre::Vector3 &rot, bool adjust)
{
if (adjust) {
setYaw(getYaw() + rot.z);
@ -56,12 +56,12 @@ namespace MWRender
}
}
const std::string &Player::getHandle() const
const std::string &Camera::getHandle() const
{
return mTrackingPtr.getRefData().getHandle();
}
void Player::attachTo(const MWWorld::Ptr &ptr)
void Camera::attachTo(const MWWorld::Ptr &ptr)
{
mTrackingPtr = ptr;
Ogre::SceneNode *node = mTrackingPtr.getRefData().getBaseNode()->createChildSceneNode(Ogre::Vector3(0.0f, 0.0f, mHeight));
@ -76,7 +76,7 @@ namespace MWRender
mCameraNode->attachObject(mCamera);
}
void Player::updateListener()
void Camera::updateListener()
{
Ogre::Vector3 pos = mCamera->getRealPosition();
Ogre::Vector3 dir = mCamera->getRealDirection();
@ -85,7 +85,7 @@ namespace MWRender
MWBase::Environment::get().getSoundManager()->setListenerPosDir(pos, dir, up);
}
void Player::update(float duration)
void Camera::update(float duration)
{
updateListener();
@ -101,7 +101,7 @@ namespace MWRender
}
}
void Player::toggleViewMode()
void Camera::toggleViewMode()
{
mFirstPersonView = !mFirstPersonView;
mAnimation->setViewMode(isFirstPerson() ? NpcAnimation::VM_FirstPerson :
@ -115,14 +115,14 @@ namespace MWRender
}
}
void Player::allowVanityMode(bool allow)
void Camera::allowVanityMode(bool allow)
{
if (!allow && mVanity.enabled)
toggleVanityMode(false);
mVanity.allowed = allow;
}
bool Player::toggleVanityMode(bool enable)
bool Camera::toggleVanityMode(bool enable)
{
if(!mVanity.allowed && enable)
return false;
@ -155,7 +155,7 @@ namespace MWRender
return true;
}
void Player::togglePreviewMode(bool enable)
void Camera::togglePreviewMode(bool enable)
{
if(mPreviewMode == enable)
return;
@ -181,14 +181,14 @@ namespace MWRender
rotateCamera(Ogre::Vector3(getPitch(), 0.f, getYaw()), false);
}
float Player::getYaw()
float Camera::getYaw()
{
if(mVanity.enabled || mPreviewMode)
return mPreviewCam.yaw;
return mMainCam.yaw;
}
void Player::setYaw(float angle)
void Camera::setYaw(float angle)
{
if (angle > Ogre::Math::PI) {
angle -= Ogre::Math::TWO_PI;
@ -202,7 +202,7 @@ namespace MWRender
}
}
float Player::getPitch()
float Camera::getPitch()
{
if (mVanity.enabled || mPreviewMode) {
return mPreviewCam.pitch;
@ -210,7 +210,7 @@ namespace MWRender
return mMainCam.pitch;
}
void Player::setPitch(float angle)
void Camera::setPitch(float angle)
{
const float epsilon = 0.000001f;
float limit = Ogre::Math::HALF_PI - epsilon;
@ -229,7 +229,7 @@ namespace MWRender
}
}
void Player::setCameraDistance(float dist, bool adjust, bool override)
void Camera::setCameraDistance(float dist, bool adjust, bool override)
{
if(mFirstPersonView && !mPreviewMode && !mVanity.enabled)
return;
@ -258,7 +258,7 @@ namespace MWRender
}
}
void Player::setCameraDistance()
void Camera::setCameraDistance()
{
if (mDistanceAdjusted) {
if (mVanity.enabled || mPreviewMode) {
@ -270,7 +270,7 @@ namespace MWRender
mDistanceAdjusted = false;
}
void Player::setAnimation(NpcAnimation *anim)
void Camera::setAnimation(NpcAnimation *anim)
{
// If we're switching to a new NpcAnimation, ensure the old one is
// using a normal view mode
@ -281,18 +281,18 @@ namespace MWRender
NpcAnimation::VM_Normal);
}
void Player::setHeight(float height)
void Camera::setHeight(float height)
{
mHeight = height;
mCameraNode->setPosition(0.f, 0.f, mHeight);
}
float Player::getHeight()
float Camera::getHeight()
{
return mHeight * mTrackingPtr.getRefData().getBaseNode()->getScale().z;
}
bool Player::getPosition(Ogre::Vector3 &player, Ogre::Vector3 &camera)
bool Camera::getPosition(Ogre::Vector3 &player, Ogre::Vector3 &camera)
{
mCamera->getParentSceneNode ()->needUpdate(true);
camera = mCamera->getRealPosition();
@ -301,23 +301,23 @@ namespace MWRender
return mFirstPersonView && !mVanity.enabled && !mPreviewMode;
}
Ogre::Vector3 Player::getPosition()
Ogre::Vector3 Camera::getPosition()
{
return mTrackingPtr.getRefData().getBaseNode()->getPosition();
}
void Player::getSightAngles(float &pitch, float &yaw)
void Camera::getSightAngles(float &pitch, float &yaw)
{
pitch = mMainCam.pitch;
yaw = mMainCam.yaw;
}
void Player::togglePlayerLooking(bool enable)
void Camera::togglePlayerLooking(bool enable)
{
mFreeLook = enable;
}
void Player::setLowHeight(bool low)
void Camera::setLowHeight(bool low)
{
if (low) {
mCameraNode->setPosition(0.f, 0.f, mHeight * 0.85);
@ -326,7 +326,7 @@ namespace MWRender
}
}
bool Player::isVanityOrPreviewModeEnabled()
bool Camera::isVanityOrPreviewModeEnabled()
{
return mPreviewMode || mVanity.enabled;
}

View file

@ -1,5 +1,5 @@
#ifndef GAME_MWRENDER_PLAYER_H
#define GAME_MWRENDER_PLAYER_H
#ifndef GAME_MWRENDER_CAMERA_H
#define GAME_MWRENDER_CAMERA_H
#include <string>
@ -16,8 +16,8 @@ namespace MWRender
{
class NpcAnimation;
/// \brief Player character rendering and camera control
class Player
/// \brief Camera control
class Camera
{
struct CamData {
float pitch, yaw, offset;
@ -49,10 +49,10 @@ namespace MWRender
void setLowHeight(bool low = true);
public:
Player(Ogre::Camera *camera);
~Player();
Camera(Ogre::Camera *camera);
~Camera();
/// Set where the player is looking at. Uses Morrowind (euler) angles
/// Set where the camera is looking at. Uses Morrowind (euler) angles
/// \param rot Rotation angles in radians
void rotateCamera(const Ogre::Vector3 &rot, bool adjust);
@ -65,8 +65,6 @@ namespace MWRender
const std::string &getHandle() const;
/// Attach camera to object
/// \note there is no protection from attaching the same camera to
/// several different objects
void attachTo(const MWWorld::Ptr &);
void toggleViewMode();

View file

@ -20,7 +20,6 @@
#include "../mwworld/ptr.hpp"
#include "player.hpp"
#include "renderconst.hpp"
using namespace Ogre;

View file

@ -39,8 +39,6 @@ namespace MWWorld
namespace MWRender
{
class Player;
class Debugging
{
OEngine::Physic::PhysicEngine* mEngine;

View file

@ -49,8 +49,9 @@ using namespace Ogre;
namespace MWRender {
RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir,
const boost::filesystem::path& cacheDir, OEngine::Physic::PhysicEngine* engine,MWWorld::Fallback* fallback)
RenderingManager::RenderingManager(OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir,
const boost::filesystem::path& cacheDir, OEngine::Physic::PhysicEngine* engine,
MWWorld::Fallback* fallback)
: mRendering(_rend)
, mFallback(fallback)
, mObjects(mRendering, mFallback)
@ -155,7 +156,7 @@ RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const
mObjects.setRootNode(mRootNode);
mActors.setRootNode(mRootNode);
mPlayer = new MWRender::Player(mRendering.getCamera());
mCamera = new MWRender::Camera(mRendering.getCamera());
mShadows = new Shadows(&mRendering);
@ -184,7 +185,7 @@ RenderingManager::~RenderingManager ()
mRendering.removeWindowEventListener(this);
delete mPlayerAnimation;
delete mPlayer;
delete mCamera;
delete mSkyManager;
delete mDebugging;
delete mShadows;
@ -269,8 +270,8 @@ void RenderingManager::rotateObject(const MWWorld::Ptr &ptr)
{
Ogre::Vector3 rot(ptr.getRefData().getPosition().rot);
if(ptr.getRefData().getHandle() == mPlayer->getHandle())
mPlayer->rotateCamera(rot, false);
if(ptr.getRefData().getHandle() == mCamera->getHandle())
mCamera->rotateCamera(rot, false);
Ogre::Quaternion newo = Ogre::Quaternion(Ogre::Radian(-rot.z), Ogre::Vector3::UNIT_Z);
if(!MWWorld::Class::get(ptr).isActor())
@ -300,7 +301,7 @@ void RenderingManager::update (float duration, bool paused)
{
MWBase::World *world = MWBase::Environment::get().getWorld();
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
MWWorld::Ptr player = world->getPlayer().getPlayer();
int blind = MWWorld::Class::get(player).getCreatureStats(player).getMagicEffects().get(MWMechanics::EffectKey(ESM::MagicEffect::Blind)).mMagnitude;
mRendering.getFader()->setFactor(1.f-(blind / 100.f));
@ -313,16 +314,16 @@ void RenderingManager::update (float duration, bool paused)
Ogre::Vector3 playerPos(_playerPos[0], _playerPos[1], _playerPos[2]);
Ogre::Vector3 orig, dest;
mPlayer->setCameraDistance();
if (!mPlayer->getPosition(orig, dest)) {
orig.z += mPlayer->getHeight() * mRootNode->getScale().z;
mCamera->setCameraDistance();
if(!mCamera->getPosition(orig, dest))
{
orig.z += mCamera->getHeight() * mRootNode->getScale().z;
btVector3 btOrig(orig.x, orig.y, orig.z);
btVector3 btDest(dest.x, dest.y, dest.z);
std::pair<std::string, float> test =
mPhysicsEngine->rayTest(btOrig, btDest);
std::pair<std::string,float> test = mPhysicsEngine->rayTest(btOrig, btDest);
if (!test.first.empty()) {
mPlayer->setCameraDistance(test.second * orig.distance(dest), false, false);
mCamera->setCameraDistance(test.second * orig.distance(dest), false, false);
}
}
@ -336,14 +337,12 @@ void RenderingManager::update (float duration, bool paused)
Ogre::Vector3 cam = mRendering.getCamera()->getRealPosition();
applyFog(world->isUnderwater (world->getPlayer().getPlayer().getCell(), cam));
applyFog(world->isUnderwater(player.getCell(), cam));
if(paused)
{
return;
}
mPlayer->update(duration);
mCamera->update(duration);
mActors.update (duration);
mObjects.update (duration);
@ -354,18 +353,11 @@ void RenderingManager::update (float duration, bool paused)
mSkyManager->setGlare(mOcclusionQuery->getSunVisibility());
Ogre::SceneNode *node = data.getBaseNode();
//Ogre::Quaternion orient =
//node->convertLocalToWorldOrientation(node->_getDerivedOrientation());
Ogre::Quaternion orient =
node->_getDerivedOrientation();
Ogre::Quaternion orient = node->_getDerivedOrientation();
mLocalMap->updatePlayer(playerPos, orient);
mWater->updateUnderwater(
world->isUnderwater(
world->getPlayer().getPlayer().getCell(),
cam)
);
mWater->updateUnderwater(world->isUnderwater(player.getCell(), cam));
mWater->update(duration, playerPos);
}
@ -862,7 +854,7 @@ void RenderingManager::getTriangleBatchCount(unsigned int &triangles, unsigned i
void RenderingManager::setupPlayer(const MWWorld::Ptr &ptr)
{
ptr.getRefData().setBaseNode(mRendering.getScene()->getSceneNode("player"));
mPlayer->attachTo(ptr);
mCamera->attachTo(ptr);
}
void RenderingManager::renderPlayer(const MWWorld::Ptr &ptr)
@ -881,27 +873,27 @@ void RenderingManager::renderPlayer(const MWWorld::Ptr &ptr)
MWWorld::Class::get(ptr).getInventoryStore(ptr),
RV_Actors);
}
mPlayer->setAnimation(mPlayerAnimation);
mCamera->setAnimation(mPlayerAnimation);
mWater->removeEmitter(ptr);
mWater->addEmitter(ptr);
// apply race height
MWBase::Environment::get().getWorld()->scaleObject(ptr, 1.f);
}
void RenderingManager::getPlayerData(Ogre::Vector3 &eyepos, float &pitch, float &yaw)
void RenderingManager::getCameraData(Ogre::Vector3 &eyepos, float &pitch, float &yaw)
{
eyepos = mPlayer->getPosition();
eyepos.z += mPlayer->getHeight();
mPlayer->getSightAngles(pitch, yaw);
eyepos = mCamera->getPosition();
eyepos.z += mCamera->getHeight();
mCamera->getSightAngles(pitch, yaw);
}
bool RenderingManager::vanityRotateCamera(float* rot)
bool RenderingManager::vanityRotateCamera(const float *rot)
{
if(!mPlayer->isVanityOrPreviewModeEnabled())
if(!mCamera->isVanityOrPreviewModeEnabled())
return false;
Ogre::Vector3 vRot(rot);
mPlayer->rotateCamera(vRot, true);
mCamera->rotateCamera(vRot, true);
return true;
}

View file

@ -17,7 +17,7 @@
#include "objects.hpp"
#include "actors.hpp"
#include "player.hpp"
#include "camera.hpp"
#include "occlusionquery.hpp"
namespace Ogre
@ -50,47 +50,42 @@ namespace MWRender
class VideoPlayer;
class Animation;
class RenderingManager: private RenderingInterface, public Ogre::WindowEventListener, public Ogre::RenderTargetListener {
private:
class RenderingManager: private RenderingInterface, public Ogre::WindowEventListener, public Ogre::RenderTargetListener
{
private:
virtual MWRender::Objects& getObjects();
virtual MWRender::Actors& getActors();
public:
public:
RenderingManager(OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir,
const boost::filesystem::path& cacheDir, OEngine::Physic::PhysicEngine* engine,MWWorld::Fallback* fallback);
const boost::filesystem::path& cacheDir, OEngine::Physic::PhysicEngine* engine,
MWWorld::Fallback* fallback);
virtual ~RenderingManager();
void togglePOV() {
mPlayer->toggleViewMode();
void togglePOV()
{ mCamera->toggleViewMode(); }
void togglePreviewMode(bool enable)
{ mCamera->togglePreviewMode(enable); }
bool toggleVanityMode(bool enable)
{ return mCamera->toggleVanityMode(enable); }
void allowVanityMode(bool allow)
{ mCamera->allowVanityMode(allow); }
void togglePlayerLooking(bool enable)
{ mCamera->togglePlayerLooking(enable); }
void changeVanityModeScale(float factor)
{
if(mCamera->isVanityOrPreviewModeEnabled())
mCamera->setCameraDistance(-factor/120.f*10, true, true);
}
void togglePreviewMode(bool enable) {
mPlayer->togglePreviewMode(enable);
}
bool vanityRotateCamera(const float *rot);
bool toggleVanityMode(bool enable) {
return mPlayer->toggleVanityMode(enable);
}
void allowVanityMode(bool allow) {
mPlayer->allowVanityMode(allow);
}
void togglePlayerLooking(bool enable) {
mPlayer->togglePlayerLooking(enable);
}
void changeVanityModeScale(float factor) {
if (mPlayer->isVanityOrPreviewModeEnabled())
mPlayer->setCameraDistance(-factor/120.f*10, true, true);
}
bool vanityRotateCamera(float* rot);
void getPlayerData(Ogre::Vector3 &eyepos, float &pitch, float &yaw);
void getCameraData(Ogre::Vector3 &eyepos, float &pitch, float &yaw);
void setupPlayer(const MWWorld::Ptr &ptr);
void renderPlayer(const MWWorld::Ptr &ptr);
@ -204,12 +199,11 @@ class RenderingManager: private RenderingInterface, public Ogre::WindowEventList
void stopVideo();
void frameStarted(float dt);
protected:
virtual void windowResized(Ogre::RenderWindow* rw);
protected:
virtual void windowResized(Ogre::RenderWindow* rw);
virtual void windowClosed(Ogre::RenderWindow* rw);
private:
private:
sh::Factory* mFactory;
void setAmbientMode();
@ -254,7 +248,7 @@ class RenderingManager: private RenderingInterface, public Ogre::WindowEventList
OEngine::Physic::PhysicEngine* mPhysicsEngine;
MWRender::Player *mPlayer;
MWRender::Camera *mCamera;
MWRender::Debugging *mDebugging;

View file

@ -205,7 +205,7 @@ unsigned int Moon::getPhaseInt() const
return 0;
}
SkyManager::SkyManager (SceneNode* root, Camera* pCamera)
SkyManager::SkyManager(Ogre::SceneNode *root, Ogre::Camera *pCamera)
: mHour(0.0f)
, mDay(0)
, mMonth(0)

View file

@ -260,14 +260,13 @@ namespace MWWorld
std::pair<float, std::string> PhysicsSystem::getFacedHandle (MWWorld::World& world, float queryDistance)
{
btVector3 dir(0, 1, 0);
dir = dir.rotate(btVector3(1, 0, 0), mPlayerData.pitch);
dir = dir.rotate(btVector3(0, 0, 1), mPlayerData.yaw);
dir = dir.rotate(btVector3(1, 0, 0), mCameraData.pitch);
dir = dir.rotate(btVector3(0, 0, 1), mCameraData.yaw);
dir.setX(-dir.x());
btVector3 origin(
mPlayerData.eyepos.x,
mPlayerData.eyepos.y,
mPlayerData.eyepos.z);
btVector3 origin(mCameraData.eyepos.x,
mCameraData.eyepos.y,
mCameraData.eyepos.z);
origin += dir * 5;
btVector3 dest = origin + dir * queryDistance;
@ -280,14 +279,13 @@ namespace MWWorld
std::vector < std::pair <float, std::string> > PhysicsSystem::getFacedHandles (float queryDistance)
{
btVector3 dir(0, 1, 0);
dir = dir.rotate(btVector3(1, 0, 0), mPlayerData.pitch);
dir = dir.rotate(btVector3(0, 0, 1), mPlayerData.yaw);
dir = dir.rotate(btVector3(1, 0, 0), mCameraData.pitch);
dir = dir.rotate(btVector3(0, 0, 1), mCameraData.yaw);
dir.setX(-dir.x());
btVector3 origin(
mPlayerData.eyepos.x,
mPlayerData.eyepos.y,
mPlayerData.eyepos.z);
btVector3 origin(mCameraData.eyepos.x,
mCameraData.eyepos.y,
mCameraData.eyepos.z);
origin += dir * 5;
btVector3 dest = origin + dir * queryDistance;
@ -552,10 +550,10 @@ namespace MWWorld
return true;
}
void PhysicsSystem::updatePlayerData(Ogre::Vector3 &eyepos, float pitch, float yaw)
void PhysicsSystem::updateCameraData(const Ogre::Vector3 &eyepos, float pitch, float yaw)
{
mPlayerData.eyepos = eyepos;
mPlayerData.pitch = pitch;
mPlayerData.yaw = yaw;
mCameraData.eyepos = eyepos;
mCameraData.pitch = pitch;
mCameraData.yaw = yaw;
}
}

View file

@ -77,13 +77,13 @@ namespace MWWorld
bool getObjectAABB(const MWWorld::Ptr &ptr, Ogre::Vector3 &min, Ogre::Vector3 &max);
void updatePlayerData(Ogre::Vector3 &eyepos, float pitch, float yaw);
void updateCameraData(const Ogre::Vector3 &eyepos, float pitch, float yaw);
private:
struct {
Ogre::Vector3 eyepos;
float pitch, yaw;
} mPlayerData;
} mCameraData;
OEngine::Render::OgreRenderer &mRender;
OEngine::Physic::PhysicEngine* mEngine;

View file

@ -16,7 +16,6 @@
#include "../mwmechanics/movement.hpp"
#include "../mwrender/sky.hpp"
#include "../mwrender/player.hpp"
#include "../mwclass/door.hpp"
@ -1146,8 +1145,8 @@ namespace MWWorld
float pitch, yaw;
Ogre::Vector3 eyepos;
mRendering->getPlayerData(eyepos, pitch, yaw);
mPhysics->updatePlayerData(eyepos, pitch, yaw);
mRendering->getCameraData(eyepos, pitch, yaw);
mPhysics->updateCameraData(eyepos, pitch, yaw);
performUpdateSceneQueries ();