GetFacedHandle in Physics. RenderingManager constructor code added

actorid
Jason Hooks 13 years ago
parent 3315de8b4a
commit fcf404d27b

@ -1,12 +1,64 @@
#include "renderingmanager.hpp"
#include <assert.h>
#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 <components/esm/loadstat.hpp>
#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 ()

@ -4,17 +4,53 @@
#include "sky.hpp"
#include "../mwworld/ptr.hpp"
#include <utility>
#include <openengine/ogre/renderer.hpp>
#include <openengine/bullet/physic.hpp>
#include <vector>
#include <string>
#include "../mwworld/ptr.hpp"
#include <boost/filesystem.hpp>
namespace MWRender
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?

@ -10,6 +10,7 @@
#include "OgreTextureManager.h"
using namespace Ogre;
namespace MWWorld
{
@ -23,6 +24,22 @@ namespace MWWorld
{
}
std::pair<std::string, float> 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<std::string, Ogre::Vector3> > PhysicsSystem::doPhysics (float duration,
const std::vector<std::pair<std::string, Ogre::Vector3> >& actors)

@ -32,6 +32,7 @@ namespace MWWorld
void scaleObject (const std::string& handle, float scale);
bool toggleCollisionMode();
std::pair<std::string, float> getFacedHandle (MWWorld::World& world);
private:
OEngine::Render::OgreRenderer &mRender;

@ -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()

Loading…
Cancel
Save