2010-06-05 18:37:01 +00:00
|
|
|
#include "mwscene.hpp"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
2010-06-06 11:36:45 +00:00
|
|
|
#include "OgreRoot.h"
|
|
|
|
#include "OgreRenderWindow.h"
|
|
|
|
#include "OgreSceneManager.h"
|
|
|
|
#include "OgreViewport.h"
|
|
|
|
#include "OgreCamera.h"
|
|
|
|
#include "OgreTextureManager.h"
|
|
|
|
|
2010-08-25 07:19:15 +00:00
|
|
|
#include "../mwworld/world.hpp" // these includes can be removed once the static-hack is gone
|
|
|
|
#include "../mwworld/ptr.hpp"
|
|
|
|
#include <components/esm/loadstat.hpp>
|
|
|
|
|
2011-01-08 14:11:37 +00:00
|
|
|
#include "player.hpp"
|
|
|
|
|
2010-06-08 11:53:34 +00:00
|
|
|
using namespace MWRender;
|
2010-06-05 18:37:01 +00:00
|
|
|
using namespace Ogre;
|
|
|
|
|
2011-10-22 04:15:15 +00:00
|
|
|
Debugging::Debugging(OEngine::Physic::PhysicEngine* engine){
|
|
|
|
eng = engine;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Debugging::toggleRenderMode (int mode){
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case MWWorld::World::Render_CollisionDebug:
|
|
|
|
|
|
|
|
// TODO use a proper function instead of accessing the member variable
|
|
|
|
// directly.
|
|
|
|
eng->setDebugRenderingMode (!eng->isDebugCreated);
|
|
|
|
return eng->isDebugCreated;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-02-19 18:18:03 +00:00
|
|
|
MWScene::MWScene(OEngine::Render::OgreRenderer &_rend , OEngine::Physic::PhysicEngine* physEng)
|
2011-04-01 21:35:56 +00:00
|
|
|
: rend(_rend)
|
2010-06-05 18:37:01 +00:00
|
|
|
{
|
2011-04-01 21:35:56 +00:00
|
|
|
eng = physEng;
|
|
|
|
rend.createScene("PlayerCam", 55, 5);
|
2010-06-05 18:37:01 +00:00
|
|
|
|
2011-04-01 21:35:56 +00:00
|
|
|
// Set default mipmap level (NB some APIs ignore this)
|
|
|
|
TextureManager::getSingleton().setDefaultNumMipmaps(5);
|
2010-06-05 18:37:01 +00:00
|
|
|
|
2011-04-01 21:35:56 +00:00
|
|
|
// Load resources
|
|
|
|
ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
|
2010-06-05 18:37:01 +00:00
|
|
|
|
2011-04-01 21:35:56 +00:00
|
|
|
// 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));
|
2010-08-03 18:17:31 +00:00
|
|
|
|
2011-04-01 21:35:56 +00:00
|
|
|
//used to obtain ingame information of ogre objects (which are faced or selected)
|
|
|
|
mRaySceneQuery = rend.getScene()->createRayQuery(Ray());
|
2011-01-08 14:11:37 +00:00
|
|
|
|
2011-08-27 08:30:38 +00:00
|
|
|
Ogre::SceneNode *playerNode = mwRoot->createChildSceneNode ("player");
|
2011-04-01 21:35:56 +00:00
|
|
|
playerNode->pitch(Degree(90));
|
|
|
|
Ogre::SceneNode *cameraYawNode = playerNode->createChildSceneNode();
|
|
|
|
Ogre::SceneNode *cameraPitchNode = cameraYawNode->createChildSceneNode();
|
|
|
|
cameraPitchNode->attachObject(getCamera());
|
2011-02-10 11:56:19 +00:00
|
|
|
|
2011-02-22 13:11:53 +00:00
|
|
|
|
2011-04-01 21:35:56 +00:00
|
|
|
mPlayer = new MWRender::Player (getCamera(), playerNode->getName());
|
2011-01-08 14:11:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MWScene::~MWScene()
|
|
|
|
{
|
|
|
|
delete mPlayer;
|
2010-06-05 18:37:01 +00:00
|
|
|
}
|
2010-08-03 18:17:31 +00:00
|
|
|
|
2010-08-25 07:19:15 +00:00
|
|
|
std::pair<std::string, float> MWScene::getFacedHandle (MWWorld::World& world)
|
2010-08-03 18:17:31 +00:00
|
|
|
{
|
2010-08-03 18:40:45 +00:00
|
|
|
std::string handle = "";
|
2010-08-03 18:17:31 +00:00
|
|
|
|
|
|
|
//get a ray pointing to the center of the viewport
|
|
|
|
Ray centerRay = getCamera()->getCameraToViewportRay(
|
|
|
|
getViewport()->getWidth()/2,
|
|
|
|
getViewport()->getHeight()/2);
|
2011-03-17 09:54:38 +00:00
|
|
|
//let's avoid the capsule shape of the player.
|
|
|
|
centerRay.setOrigin(centerRay.getOrigin() + 20*centerRay.getDirection());
|
2011-03-19 18:54:18 +00:00
|
|
|
btVector3 from(centerRay.getOrigin().x,-centerRay.getOrigin().z,centerRay.getOrigin().y);
|
2011-03-22 20:30:46 +00:00
|
|
|
btVector3 to(centerRay.getPoint(500).x,-centerRay.getPoint(500).z,centerRay.getPoint(500).y);
|
2010-08-03 18:40:45 +00:00
|
|
|
|
2011-02-22 19:52:05 +00:00
|
|
|
return eng->rayTest(from,to);
|
2010-08-03 18:17:31 +00:00
|
|
|
}
|
2011-01-23 14:28:42 +00:00
|
|
|
|
2011-04-26 19:38:21 +00:00
|
|
|
bool MWScene::toggleRenderMode (int mode)
|
2011-03-16 08:09:45 +00:00
|
|
|
{
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case MWWorld::World::Render_CollisionDebug:
|
|
|
|
|
|
|
|
// TODO use a proper function instead of accessing the member variable
|
|
|
|
// directly.
|
|
|
|
eng->setDebugRenderingMode (!eng->isDebugCreated);
|
2011-04-26 19:38:21 +00:00
|
|
|
return eng->isDebugCreated;
|
2011-03-16 08:09:45 +00:00
|
|
|
}
|
2011-04-26 19:38:21 +00:00
|
|
|
|
|
|
|
return false;
|
2011-03-16 08:09:45 +00:00
|
|
|
}
|