From 6961830efb5f4141d9ed97256672330d0a82109a Mon Sep 17 00:00:00 2001 From: greye Date: Fri, 17 Aug 2012 10:10:37 +0400 Subject: [PATCH] using real player eye direction when moving --- apps/openmw/mwrender/player.cpp | 12 ++++++++++++ apps/openmw/mwrender/player.hpp | 3 +++ apps/openmw/mwrender/renderingmanager.cpp | 7 +++++++ apps/openmw/mwrender/renderingmanager.hpp | 2 ++ apps/openmw/mwworld/physicssystem.cpp | 24 ++++++++++++++--------- apps/openmw/mwworld/physicssystem.hpp | 8 +++++++- apps/openmw/mwworld/worldimp.cpp | 5 +++++ 7 files changed, 51 insertions(+), 10 deletions(-) diff --git a/apps/openmw/mwrender/player.cpp b/apps/openmw/mwrender/player.cpp index 8ad7e04b0..c9db96ead 100644 --- a/apps/openmw/mwrender/player.cpp +++ b/apps/openmw/mwrender/player.cpp @@ -11,6 +11,7 @@ #include "../mwworld/refdata.hpp" #include "npcanimation.hpp" +#include namespace MWRender { @@ -333,4 +334,15 @@ namespace MWRender return mFirstPersonView && !mVanity.enabled && !mPreviewMode; } + + Ogre::Vector3 Player::getPosition() + { + return mPlayerNode->getPosition(); + } + + void Player::getSightAngles(float &pitch, float &yaw) + { + pitch = mMainCam.pitch; + yaw = mMainCam.yaw; + } } diff --git a/apps/openmw/mwrender/player.hpp b/apps/openmw/mwrender/player.hpp index c3585db9d..cc0fcac77 100644 --- a/apps/openmw/mwrender/player.hpp +++ b/apps/openmw/mwrender/player.hpp @@ -103,6 +103,9 @@ namespace MWRender /// Stores player and camera world positions in passed arguments /// \return true if camera at the eye-place bool getPosition(Ogre::Vector3 &player, Ogre::Vector3 &camera); + Ogre::Vector3 getPosition(); + + void getSightAngles(float &pitch, float &yaw); }; } diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index f1d2029bb..2d29e8f55 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -856,4 +856,11 @@ void RenderingManager::renderPlayer(const MWWorld::Ptr &ptr) mPlayer->setAnimation(anim); } +void RenderingManager::getPlayerData(Ogre::Vector3 &eyepos, float &pitch, float &yaw) +{ + eyepos = mPlayer->getPosition(); + eyepos.z += mPlayer->getHeight(); + mPlayer->getSightAngles(pitch, yaw); +} + } // namespace diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index aa07bbc22..170083556 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -72,6 +72,8 @@ class RenderingManager: private RenderingInterface, public Ogre::WindowEventList mPlayer->allowVanityMode(allow); } + void getPlayerData(Ogre::Vector3 &eyepos, float &pitch, float &yaw); + void attachCameraTo(const MWWorld::Ptr &ptr); void renderPlayer(const MWWorld::Ptr &ptr); diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index 1bbfe33fd..24e2cdbb1 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -16,6 +16,8 @@ #include "ptr.hpp" #include "class.hpp" +#include + using namespace Ogre; namespace MWWorld { @@ -42,10 +44,8 @@ namespace MWWorld return mEngine; } - std::pair PhysicsSystem::getFacedHandle (MWWorld::World& world) - { - std::string handle = ""; - + std::pair PhysicsSystem::getFacedHandle (MWWorld::World& world) + { //get a ray pointing to the center of the viewport Ray centerRay = mRender.getCamera()->getCameraToViewportRay( mRender.getViewport()->getWidth()/2, @@ -190,12 +190,11 @@ namespace MWWorld float pitch = 0.f; if (iter->first == "player") { - /// \fixme should not rely on player camera, real pitch needed - Ogre::SceneNode *node = mRender.getCamera()->getParentSceneNode(); - pitch = node->getOrientation().getPitch().valueDegrees(); + playerphysics->ps.viewangles.x = + Ogre::Radian(mPlayerData.pitch).valueDegrees(); - playerphysics->ps.viewangles.x = pitch - 90; - playerphysics->ps.viewangles.y = -yaw + 90; + playerphysics->ps.viewangles.y = + Ogre::Radian(mPlayerData.yaw).valueDegrees() + 90; pm_ref.rightmove = -iter->second.x; pm_ref.forwardmove = -iter->second.y; @@ -392,4 +391,11 @@ namespace MWWorld return true; } + + void PhysicsSystem::updatePlayerData(Ogre::Vector3 &eyepos, float pitch, float yaw) + { + mPlayerData.eyepos = eyepos; + mPlayerData.pitch = pitch; + mPlayerData.yaw = yaw; + } } diff --git a/apps/openmw/mwworld/physicssystem.hpp b/apps/openmw/mwworld/physicssystem.hpp index e42fa536b..c6b8199fa 100644 --- a/apps/openmw/mwworld/physicssystem.hpp +++ b/apps/openmw/mwworld/physicssystem.hpp @@ -70,7 +70,14 @@ namespace MWWorld bool getObjectAABB(const MWWorld::Ptr &ptr, Ogre::Vector3 &min, Ogre::Vector3 &max); + void updatePlayerData(Ogre::Vector3 &eyepos, float pitch, float yaw); + private: + struct { + Ogre::Vector3 eyepos; + float pitch, yaw; + } mPlayerData; + OEngine::Render::OgreRenderer &mRender; OEngine::Physic::PhysicEngine* mEngine; bool mFreeFly; @@ -80,7 +87,6 @@ namespace MWWorld PhysicsSystem (const PhysicsSystem&); PhysicsSystem& operator= (const PhysicsSystem&); }; - } #endif diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 7a8f73034..655397c1f 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -806,6 +806,11 @@ namespace MWWorld /// \todo split this function up into subfunctions mWorldScene->update (duration); + + float pitch, yaw; + Ogre::Vector3 eyepos; + mRendering->getPlayerData(eyepos, pitch, yaw); + mPhysics->updatePlayerData(eyepos, pitch, yaw); mWeatherManager->update (duration);