From fcf404d27b435d20bcf0867454e00011ead87375 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Thu, 20 Oct 2011 18:15:30 -0400 Subject: [PATCH] GetFacedHandle in Physics. RenderingManager constructor code added --- apps/openmw/mwrender/renderingmanager.cpp | 56 ++++++++++++++++++++++- apps/openmw/mwrender/renderingmanager.hpp | 42 +++++++++++++++-- apps/openmw/mwworld/physicssystem.cpp | 17 +++++++ apps/openmw/mwworld/physicssystem.hpp | 1 + apps/openmw/mwworld/world.cpp | 3 +- 5 files changed, 113 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index f083d206d..095323dea 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -1,12 +1,64 @@ #include "renderingmanager.hpp" +#include + +#include "OgreRoot.h" +#include "OgreRenderWindow.h" +#include "OgreSceneManager.h" +#include "OgreViewport.h" +#include "OgreCamera.h" +#include "OgreTextureManager.h" + +#include "../mwworld/world.hpp" // these includes can be removed once the static-hack is gone +#include "../mwworld/ptr.hpp" +#include + +#include "player.hpp" + +using namespace MWRender; +using namespace Ogre; + namespace MWRender { -RenderingManager::RenderingManager (Ogre::RenderWindow* window, Ogre::Camera* cam, const boost::filesystem2::path& resDir) +RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const boost::filesystem2::path& resDir) :rend(_rend) { - mSkyManager = MWRender::SkyManager::create(window, cam, resDir); + camera = rend.getCamera(); + mSkyManager = MWRender::SkyManager::create(rend.getWindow(), camera, resDir); + + + rend.createScene("PlayerCam", 55, 5); + + // Set default mipmap level (NB some APIs ignore this) + TextureManager::getSingleton().setDefaultNumMipmaps(5); + + // Load resources + ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); + + // Turn the entire scene (represented by the 'root' node) -90 + // degrees around the x axis. This makes Z go upwards, and Y go into + // the screen (when x is to the right.) This is the orientation that + // Morrowind uses, and it automagically makes everything work as it + // should. + + SceneNode *rt = rend.getScene()->getRootSceneNode(); + mwRoot = rt->createChildSceneNode(); + mwRoot->pitch(Degree(-90)); + + //used to obtain ingame information of ogre objects (which are faced or selected) + mRaySceneQuery = rend.getScene()->createRayQuery(Ray()); + + Ogre::SceneNode *playerNode = mwRoot->createChildSceneNode ("player"); + playerNode->pitch(Degree(90)); + Ogre::SceneNode *cameraYawNode = playerNode->createChildSceneNode(); + Ogre::SceneNode *cameraPitchNode = cameraYawNode->createChildSceneNode(); + cameraPitchNode->attachObject(camera); + + + mPlayer = new MWRender::Player (camera, playerNode->getName()); + + } RenderingManager::~RenderingManager () diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index ac14ee389..ec03e970a 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -4,17 +4,53 @@ #include "sky.hpp" -#include "../mwworld/ptr.hpp" +#include #include #include + +#include +#include + +#include "../mwworld/ptr.hpp" + #include +namespace Ogre +{ + class Camera; + class Viewport; + class SceneManager; + class SceneNode; + class RaySceneQuery; + class Quaternion; + class Vector3; +} + +namespace MWWorld +{ + class World; +} + namespace MWRender { - + class Player; class RenderingManager { + + OEngine::Render::OgreRenderer &rend; + Ogre::Camera* camera; + + /// Root node for all objects added to the scene. This is rotated so + /// that the OGRE coordinate system matches that used internally in + /// Morrowind. + Ogre::SceneNode *mwRoot; + Ogre::RaySceneQuery *mRaySceneQuery; + + OEngine::Physic::PhysicEngine* eng; + + MWRender::Player *mPlayer; + public: - RenderingManager(Ogre::RenderWindow* window, Ogre::Camera* cam, const boost::filesystem2::path& resDir); + RenderingManager(OEngine::Render::OgreRenderer& _rend, const boost::filesystem2::path& resDir); ~RenderingManager(); void removeCell (MWWorld::Ptr::CellStore *store); // TODO do we want this? diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index fa617a9c7..b06fa1a48 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -10,6 +10,7 @@ #include "OgreTextureManager.h" +using namespace Ogre; namespace MWWorld { @@ -23,6 +24,22 @@ namespace MWWorld { } + std::pair PhysicsSystem::getFacedHandle (MWWorld::World& world) + { + std::string handle = ""; + + //get a ray pointing to the center of the viewport + Ray centerRay = mRender.getCamera()->getCameraToViewportRay( + mRender.getViewport()->getWidth()/2, + mRender.getViewport()->getHeight()/2); + //let's avoid the capsule shape of the player. + centerRay.setOrigin(centerRay.getOrigin() + 20*centerRay.getDirection()); + btVector3 from(centerRay.getOrigin().x,-centerRay.getOrigin().z,centerRay.getOrigin().y); + btVector3 to(centerRay.getPoint(500).x,-centerRay.getPoint(500).z,centerRay.getPoint(500).y); + + return mEngine->rayTest(from,to); + } + std::vector< std::pair > PhysicsSystem::doPhysics (float duration, const std::vector >& actors) diff --git a/apps/openmw/mwworld/physicssystem.hpp b/apps/openmw/mwworld/physicssystem.hpp index 7f7bfdcbb..17640c074 100644 --- a/apps/openmw/mwworld/physicssystem.hpp +++ b/apps/openmw/mwworld/physicssystem.hpp @@ -32,6 +32,7 @@ namespace MWWorld void scaleObject (const std::string& handle, float scale); bool toggleCollisionMode(); + std::pair getFacedHandle (MWWorld::World& world); private: OEngine::Render::OgreRenderer &mRender; diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index cee73a433..4174e6457 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -207,7 +207,8 @@ namespace MWWorld mPhysEngine = physEng; mWorldScene = new Scene(environment, this, mScene, mPhysics); - mRenderingManager = new MWRender::RenderingManager(renderer.getWindow(), mScene.getCamera(), resDir); + mRenderingManager = new MWRender::RenderingManager(renderer, + resDir); } World::~World()