forked from mirror/openmw-tes3mp
Merge remote-tracking branch 'scrawl/osg' into appveyor-osg
commit
c40f59179f
@ -0,0 +1,110 @@
|
||||
#include "idcompletionmanager.hpp"
|
||||
|
||||
#include <boost/make_shared.hpp>
|
||||
|
||||
#include <QCompleter>
|
||||
|
||||
#include "../../view/widget/completerpopup.hpp"
|
||||
|
||||
#include "data.hpp"
|
||||
#include "idtablebase.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
std::map<CSMWorld::ColumnBase::Display, CSMWorld::UniversalId::Type> generateModelTypes()
|
||||
{
|
||||
std::map<CSMWorld::ColumnBase::Display, CSMWorld::UniversalId::Type> types;
|
||||
|
||||
types[CSMWorld::ColumnBase::Display_BodyPart ] = CSMWorld::UniversalId::Type_BodyPart;
|
||||
types[CSMWorld::ColumnBase::Display_Cell ] = CSMWorld::UniversalId::Type_Cell;
|
||||
types[CSMWorld::ColumnBase::Display_Class ] = CSMWorld::UniversalId::Type_Class;
|
||||
types[CSMWorld::ColumnBase::Display_CreatureLevelledList] = CSMWorld::UniversalId::Type_Referenceable;
|
||||
types[CSMWorld::ColumnBase::Display_Creature ] = CSMWorld::UniversalId::Type_Referenceable;
|
||||
types[CSMWorld::ColumnBase::Display_Enchantment ] = CSMWorld::UniversalId::Type_Enchantment;
|
||||
types[CSMWorld::ColumnBase::Display_Faction ] = CSMWorld::UniversalId::Type_Faction;
|
||||
types[CSMWorld::ColumnBase::Display_GlobalVariable ] = CSMWorld::UniversalId::Type_Global;
|
||||
types[CSMWorld::ColumnBase::Display_Icon ] = CSMWorld::UniversalId::Type_Icon;
|
||||
types[CSMWorld::ColumnBase::Display_Mesh ] = CSMWorld::UniversalId::Type_Mesh;
|
||||
types[CSMWorld::ColumnBase::Display_Miscellaneous ] = CSMWorld::UniversalId::Type_Referenceable;
|
||||
types[CSMWorld::ColumnBase::Display_Npc ] = CSMWorld::UniversalId::Type_Referenceable;
|
||||
types[CSMWorld::ColumnBase::Display_Race ] = CSMWorld::UniversalId::Type_Race;
|
||||
types[CSMWorld::ColumnBase::Display_Region ] = CSMWorld::UniversalId::Type_Region;
|
||||
types[CSMWorld::ColumnBase::Display_Referenceable ] = CSMWorld::UniversalId::Type_Referenceable;
|
||||
types[CSMWorld::ColumnBase::Display_Script ] = CSMWorld::UniversalId::Type_Script;
|
||||
types[CSMWorld::ColumnBase::Display_Skill ] = CSMWorld::UniversalId::Type_Skill;
|
||||
types[CSMWorld::ColumnBase::Display_Sound ] = CSMWorld::UniversalId::Type_Sound;
|
||||
types[CSMWorld::ColumnBase::Display_SoundRes ] = CSMWorld::UniversalId::Type_SoundRes;
|
||||
types[CSMWorld::ColumnBase::Display_Spell ] = CSMWorld::UniversalId::Type_Spell;
|
||||
types[CSMWorld::ColumnBase::Display_Static ] = CSMWorld::UniversalId::Type_Referenceable;
|
||||
types[CSMWorld::ColumnBase::Display_Texture ] = CSMWorld::UniversalId::Type_Texture;
|
||||
types[CSMWorld::ColumnBase::Display_Weapon ] = CSMWorld::UniversalId::Type_Referenceable;
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
typedef std::map<CSMWorld::ColumnBase::Display,
|
||||
CSMWorld::UniversalId::Type>::const_iterator ModelTypeConstIterator;
|
||||
}
|
||||
|
||||
const std::map<CSMWorld::ColumnBase::Display, CSMWorld::UniversalId::Type>
|
||||
CSMWorld::IdCompletionManager::sCompleterModelTypes = generateModelTypes();
|
||||
|
||||
std::vector<CSMWorld::ColumnBase::Display> CSMWorld::IdCompletionManager::getDisplayTypes()
|
||||
{
|
||||
std::vector<CSMWorld::ColumnBase::Display> types;
|
||||
ModelTypeConstIterator current = sCompleterModelTypes.begin();
|
||||
ModelTypeConstIterator end = sCompleterModelTypes.end();
|
||||
for (; current != end; ++current)
|
||||
{
|
||||
types.push_back(current->first);
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
CSMWorld::IdCompletionManager::IdCompletionManager(CSMWorld::Data &data)
|
||||
{
|
||||
generateCompleters(data);
|
||||
}
|
||||
|
||||
bool CSMWorld::IdCompletionManager::hasCompleterFor(CSMWorld::ColumnBase::Display display) const
|
||||
{
|
||||
return mCompleters.find(display) != mCompleters.end();
|
||||
}
|
||||
|
||||
boost::shared_ptr<QCompleter> CSMWorld::IdCompletionManager::getCompleter(CSMWorld::ColumnBase::Display display)
|
||||
{
|
||||
if (!hasCompleterFor(display))
|
||||
{
|
||||
throw std::logic_error("This column doesn't have an ID completer");
|
||||
}
|
||||
return mCompleters[display];
|
||||
}
|
||||
|
||||
void CSMWorld::IdCompletionManager::generateCompleters(CSMWorld::Data &data)
|
||||
{
|
||||
ModelTypeConstIterator current = sCompleterModelTypes.begin();
|
||||
ModelTypeConstIterator end = sCompleterModelTypes.end();
|
||||
for (; current != end; ++current)
|
||||
{
|
||||
QAbstractItemModel *model = data.getTableModel(current->second);
|
||||
CSMWorld::IdTableBase *table = dynamic_cast<CSMWorld::IdTableBase *>(model);
|
||||
if (table != NULL)
|
||||
{
|
||||
int idColumn = table->searchColumnIndex(CSMWorld::Columns::ColumnId_Id);
|
||||
if (idColumn != -1)
|
||||
{
|
||||
boost::shared_ptr<QCompleter> completer = boost::make_shared<QCompleter>(table);
|
||||
completer->setCompletionColumn(idColumn);
|
||||
// The completion role must be Qt::DisplayRole to get the ID values from the model
|
||||
completer->setCompletionRole(Qt::DisplayRole);
|
||||
completer->setCaseSensitivity(Qt::CaseInsensitive);
|
||||
|
||||
QAbstractItemView *popup = new CSVWidget::CompleterPopup();
|
||||
completer->setPopup(popup); // The completer takes ownership of the popup
|
||||
completer->setMaxVisibleItems(10);
|
||||
|
||||
mCompleters[current->first] = completer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
#ifndef CSM_WORLD_IDCOMPLETIONMANAGER_HPP
|
||||
#define CSM_WORLD_IDCOMPLETIONMANAGER_HPP
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include "columnbase.hpp"
|
||||
#include "universalid.hpp"
|
||||
|
||||
class QCompleter;
|
||||
|
||||
namespace CSMWorld
|
||||
{
|
||||
class Data;
|
||||
|
||||
/// \brief Creates and stores all ID completers
|
||||
class IdCompletionManager
|
||||
{
|
||||
static const std::map<ColumnBase::Display, UniversalId::Type> sCompleterModelTypes;
|
||||
|
||||
std::map<ColumnBase::Display, boost::shared_ptr<QCompleter> > mCompleters;
|
||||
|
||||
// Don't allow copying
|
||||
IdCompletionManager(const IdCompletionManager &);
|
||||
IdCompletionManager &operator = (const IdCompletionManager &);
|
||||
|
||||
void generateCompleters(Data &data);
|
||||
|
||||
public:
|
||||
static std::vector<ColumnBase::Display> getDisplayTypes();
|
||||
|
||||
IdCompletionManager(Data &data);
|
||||
|
||||
bool hasCompleterFor(ColumnBase::Display display) const;
|
||||
boost::shared_ptr<QCompleter> getCompleter(ColumnBase::Display display);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -1,4 +1,5 @@
|
||||
|
||||
#include "lighting.hpp"
|
||||
|
||||
#include <osg/LightSource>
|
||||
|
||||
CSVRender::Lighting::~Lighting() {}
|
||||
|
@ -1,30 +1,35 @@
|
||||
|
||||
#include "lightingbright.hpp"
|
||||
|
||||
#include <OgreSceneManager.h>
|
||||
#include <osg/LightSource>
|
||||
|
||||
CSVRender::LightingBright::LightingBright() : mSceneManager (0), mLight (0) {}
|
||||
CSVRender::LightingBright::LightingBright() {}
|
||||
|
||||
void CSVRender::LightingBright::activate (Ogre::SceneManager *sceneManager,
|
||||
const Ogre::ColourValue *defaultAmbient)
|
||||
void CSVRender::LightingBright::activate (osg::Group* rootNode)
|
||||
{
|
||||
mSceneManager = sceneManager;
|
||||
mRootNode = rootNode;
|
||||
|
||||
mSceneManager->setAmbientLight (Ogre::ColourValue (1.0, 1.0, 1.0, 1));
|
||||
mLightSource = (new osg::LightSource);
|
||||
|
||||
mLight = mSceneManager->createLight();
|
||||
mLight->setType (Ogre::Light::LT_DIRECTIONAL);
|
||||
mLight->setDirection (Ogre::Vector3 (0, 0, -1));
|
||||
mLight->setDiffuseColour (Ogre::ColourValue (1.0, 1.0, 1.0));
|
||||
osg::ref_ptr<osg::Light> light (new osg::Light);
|
||||
light->setAmbient(osg::Vec4f(0.f, 0.f, 0.f, 1.f));
|
||||
light->setPosition(osg::Vec4f(0.f, 0.f, 1.f, 0.f));
|
||||
light->setDiffuse(osg::Vec4f(1.f, 1.f, 1.f, 1.f));
|
||||
light->setSpecular(osg::Vec4f(0.f, 0.f, 0.f, 0.f));
|
||||
light->setConstantAttenuation(1.f);
|
||||
|
||||
mLightSource->setLight(light);
|
||||
|
||||
mRootNode->addChild(mLightSource);
|
||||
}
|
||||
|
||||
void CSVRender::LightingBright::deactivate()
|
||||
{
|
||||
if (mLight)
|
||||
{
|
||||
mSceneManager->destroyLight (mLight);
|
||||
mLight = 0;
|
||||
}
|
||||
if (mRootNode && mLightSource.get())
|
||||
mRootNode->removeChild(mLightSource);
|
||||
}
|
||||
|
||||
void CSVRender::LightingBright::setDefaultAmbient (const Ogre::ColourValue& colour) {}
|
||||
osg::Vec4f CSVRender::LightingBright::getAmbientColour(osg::Vec4f* /*defaultAmbient*/)
|
||||
{
|
||||
return osg::Vec4f(1.f, 1.f, 1.f, 1.f);
|
||||
}
|
||||
|
@ -1,36 +1,36 @@
|
||||
|
||||
#include "lightingday.hpp"
|
||||
|
||||
#include <OgreSceneManager.h>
|
||||
#include <osg/LightSource>
|
||||
|
||||
CSVRender::LightingDay::LightingDay() : mSceneManager (0), mLight (0) {}
|
||||
CSVRender::LightingDay::LightingDay(){}
|
||||
|
||||
void CSVRender::LightingDay::activate (Ogre::SceneManager *sceneManager,
|
||||
const Ogre::ColourValue *defaultAmbient)
|
||||
void CSVRender::LightingDay::activate (osg::Group* rootNode)
|
||||
{
|
||||
mSceneManager = sceneManager;
|
||||
mRootNode = rootNode;
|
||||
|
||||
if (defaultAmbient)
|
||||
mSceneManager->setAmbientLight (*defaultAmbient);
|
||||
else
|
||||
mSceneManager->setAmbientLight (Ogre::ColourValue (0.7, 0.7, 0.7, 1));
|
||||
mLightSource = new osg::LightSource;
|
||||
|
||||
mLight = mSceneManager->createLight();
|
||||
mLight->setType (Ogre::Light::LT_DIRECTIONAL);
|
||||
mLight->setDirection (Ogre::Vector3 (0, 0, -1));
|
||||
mLight->setDiffuseColour (Ogre::ColourValue (1, 1, 1));
|
||||
osg::ref_ptr<osg::Light> light (new osg::Light);
|
||||
light->setPosition(osg::Vec4f(0.f, 0.f, 1.f, 0.f));
|
||||
light->setAmbient(osg::Vec4f(0.f, 0.f, 0.f, 1.f));
|
||||
light->setDiffuse(osg::Vec4f(1.f, 1.f, 1.f, 1.f));
|
||||
light->setSpecular(osg::Vec4f(0.f, 0.f, 0.f, 0.f));
|
||||
light->setConstantAttenuation(1.f);
|
||||
|
||||
mLightSource->setLight(light);
|
||||
mRootNode->addChild(mLightSource);
|
||||
}
|
||||
|
||||
void CSVRender::LightingDay::deactivate()
|
||||
{
|
||||
if (mLight)
|
||||
{
|
||||
mSceneManager->destroyLight (mLight);
|
||||
mLight = 0;
|
||||
}
|
||||
if (mRootNode && mLightSource.get())
|
||||
mRootNode->removeChild(mLightSource);
|
||||
}
|
||||
|
||||
void CSVRender::LightingDay::setDefaultAmbient (const Ogre::ColourValue& colour)
|
||||
osg::Vec4f CSVRender::LightingDay::getAmbientColour(osg::Vec4f *defaultAmbient)
|
||||
{
|
||||
mSceneManager->setAmbientLight (colour);
|
||||
if (defaultAmbient)
|
||||
return *defaultAmbient;
|
||||
else
|
||||
return osg::Vec4f(0.7f, 0.7f, 0.7f, 1.f);
|
||||
}
|
||||
|
@ -1,36 +1,37 @@
|
||||
|
||||
#include "lightingnight.hpp"
|
||||
|
||||
#include <OgreSceneManager.h>
|
||||
#include <osg/LightSource>
|
||||
|
||||
CSVRender::LightingNight::LightingNight() : mSceneManager (0), mLight (0) {}
|
||||
CSVRender::LightingNight::LightingNight() {}
|
||||
|
||||
void CSVRender::LightingNight::activate (Ogre::SceneManager *sceneManager,
|
||||
const Ogre::ColourValue *defaultAmbient)
|
||||
void CSVRender::LightingNight::activate (osg::Group* rootNode)
|
||||
{
|
||||
mSceneManager = sceneManager;
|
||||
mRootNode = rootNode;
|
||||
|
||||
if (defaultAmbient)
|
||||
mSceneManager->setAmbientLight (*defaultAmbient);
|
||||
else
|
||||
mSceneManager->setAmbientLight (Ogre::ColourValue (0.2, 0.2, 0.2, 1));
|
||||
mLightSource = new osg::LightSource;
|
||||
|
||||
osg::ref_ptr<osg::Light> light (new osg::Light);
|
||||
light->setPosition(osg::Vec4f(0.f, 0.f, 1.f, 0.f));
|
||||
light->setAmbient(osg::Vec4f(0.f, 0.f, 0.f, 1.f));
|
||||
light->setDiffuse(osg::Vec4f(0.2f, 0.2f, 0.2f, 1.f));
|
||||
light->setSpecular(osg::Vec4f(0.f, 0.f, 0.f, 0.f));
|
||||
light->setConstantAttenuation(1.f);
|
||||
|
||||
mLight = mSceneManager->createLight();
|
||||
mLight->setType (Ogre::Light::LT_DIRECTIONAL);
|
||||
mLight->setDirection (Ogre::Vector3 (0, 0, -1));
|
||||
mLight->setDiffuseColour (Ogre::ColourValue (0.2, 0.2, 0.2));
|
||||
mLightSource->setLight(light);
|
||||
|
||||
mRootNode->addChild(mLightSource);
|
||||
}
|
||||
|
||||
void CSVRender::LightingNight::deactivate()
|
||||
{
|
||||
if (mLight)
|
||||
{
|
||||
mSceneManager->destroyLight (mLight);
|
||||
mLight = 0;
|
||||
}
|
||||
if (mRootNode && mLightSource.get())
|
||||
mRootNode->removeChild(mLightSource);
|
||||
}
|
||||
|
||||
void CSVRender::LightingNight::setDefaultAmbient (const Ogre::ColourValue& colour)
|
||||
osg::Vec4f CSVRender::LightingNight::getAmbientColour(osg::Vec4f *defaultAmbient)
|
||||
{
|
||||
mSceneManager->setAmbientLight (colour);
|
||||
if (defaultAmbient)
|
||||
return *defaultAmbient;
|
||||
else
|
||||
return osg::Vec4f(0.2f, 0.2f, 0.2f, 1.f);
|
||||
}
|
||||
|
@ -1,463 +0,0 @@
|
||||
#include "mousestate.hpp"
|
||||
|
||||
#include <OgreSceneNode.h>
|
||||
#include <OgreSceneManager.h>
|
||||
#include <OgreEntity.h>
|
||||
#include <OgreMeshManager.h>
|
||||
|
||||
#include <QMouseEvent>
|
||||
#include <QElapsedTimer>
|
||||
#include <QObject>
|
||||
|
||||
#include "../../model/settings/usersettings.hpp"
|
||||
#include "../../model/world/commands.hpp"
|
||||
#include "../../model/world/idtable.hpp"
|
||||
#include "../../model/world/universalid.hpp"
|
||||
#include "../world/physicssystem.hpp"
|
||||
|
||||
#include "elements.hpp"
|
||||
#include "worldspacewidget.hpp"
|
||||
|
||||
namespace CSVRender
|
||||
{
|
||||
// mouse picking
|
||||
// FIXME: need to virtualise mouse buttons
|
||||
//
|
||||
// State machine:
|
||||
//
|
||||
// [default] mousePressEvent->check if the mouse is pointing at an object
|
||||
// if yes, create collision planes then go to [grab]
|
||||
// else check for terrain
|
||||
//
|
||||
// [grab] mouseReleaseEvent->if same button and new obj, go to [edit]
|
||||
// mouseMoveEvent->if same button, go to [drag]
|
||||
// other mouse events or buttons, go back to [default] (i.e. like 'cancel')
|
||||
//
|
||||
// [drag] mouseReleaseEvent->if same button, place the object at the new
|
||||
// location, update the document then go to [edit]
|
||||
// mouseMoveEvent->update position to the user based on ray to the collision
|
||||
// planes and render the object at the new location, but do not update
|
||||
// the document yet
|
||||
//
|
||||
// [edit] TODO, probably fine positional adjustments or rotations; clone/delete?
|
||||
//
|
||||
//
|
||||
// press press (obj)
|
||||
// [default] --------> [grab] <-------------------- [edit]
|
||||
// ^ (obj) | | ------> [drag] -----> ^
|
||||
// | | | move ^ | release |
|
||||
// | | | | | |
|
||||
// | | | +-+ |
|
||||
// | | | move |
|
||||
// +----------------+ +--------------------------+
|
||||
// release release
|
||||
// (same obj) (new obj)
|
||||
//
|
||||
//
|
||||
|
||||
MouseState::MouseState(WorldspaceWidget *parent)
|
||||
: mMouseState(Mouse_Default), mParent(parent), mPhysics(parent->mDocument.getPhysics())
|
||||
, mSceneManager(parent->getSceneManager()), mOldPos(0,0), mCurrentObj(""), mGrabbedSceneNode("")
|
||||
, mMouseEventTimer(0), mPlane(0), mOrigObjPos(Ogre::Vector3()), mOrigMousePos(Ogre::Vector3())
|
||||
, mCurrentMousePos(Ogre::Vector3()), mOffset(0.0f), mIdTableModel(0), mColIndexPosX(0)
|
||||
, mColIndexPosY(0), mColIndexPosZ(0)
|
||||
{
|
||||
const CSMWorld::RefCollection& references = mParent->mDocument.getData().getReferences();
|
||||
|
||||
mColIndexPosX = references.findColumnIndex(CSMWorld::Columns::ColumnId_PositionXPos);
|
||||
mColIndexPosY = references.findColumnIndex(CSMWorld::Columns::ColumnId_PositionYPos);
|
||||
mColIndexPosZ = references.findColumnIndex(CSMWorld::Columns::ColumnId_PositionZPos);
|
||||
|
||||
mIdTableModel = static_cast<CSMWorld::IdTable *>(
|
||||
mParent->mDocument.getData().getTableModel(CSMWorld::UniversalId::Type_Reference));
|
||||
|
||||
mMouseEventTimer = new QElapsedTimer();
|
||||
mMouseEventTimer->invalidate();
|
||||
|
||||
std::pair<Ogre::Vector3, Ogre::Vector3> planeRes = planeAxis();
|
||||
mPlane = new Ogre::Plane(planeRes.first, 0);
|
||||
Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().createPlane("mouse",
|
||||
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
||||
*mPlane,
|
||||
300000,300000, // FIXME: use far clip dist?
|
||||
1,1, // segments
|
||||
true, // normals
|
||||
1, // numTexCoordSets
|
||||
1,1, // uTile, vTile
|
||||
planeRes.second // upVector
|
||||
);
|
||||
}
|
||||
|
||||
MouseState::~MouseState ()
|
||||
{
|
||||
delete mMouseEventTimer;
|
||||
delete mPlane;
|
||||
}
|
||||
|
||||
void MouseState::mouseMoveEvent (QMouseEvent *event)
|
||||
{
|
||||
switch(mMouseState)
|
||||
{
|
||||
case Mouse_Grab:
|
||||
{
|
||||
// check if min elapsed time to stop false detection of drag
|
||||
if(!mMouseEventTimer->isValid() || !mMouseEventTimer->hasExpired(100)) // ms
|
||||
break;
|
||||
|
||||
mMouseEventTimer->invalidate();
|
||||
mMouseState = Mouse_Drag;
|
||||
|
||||
/* FALL_THROUGH */
|
||||
}
|
||||
case Mouse_Drag:
|
||||
{
|
||||
if(event->pos() != mOldPos) // TODO: maybe don't update less than a quantum?
|
||||
{
|
||||
mOldPos = event->pos();
|
||||
|
||||
// ray test against the plane to provide feedback to the user the
|
||||
// relative movement of the object on the x-y plane
|
||||
std::pair<bool, Ogre::Vector3> planeResult = mousePositionOnPlane(event->pos(), *mPlane);
|
||||
if(planeResult.first)
|
||||
{
|
||||
if(mGrabbedSceneNode != "")
|
||||
{
|
||||
std::pair<Ogre::Vector3, Ogre::Vector3> planeRes = planeAxis();
|
||||
Ogre::Vector3 pos = mOrigObjPos + planeRes.first*mOffset;
|
||||
mSceneManager->getSceneNode(mGrabbedSceneNode)->setPosition(pos+planeResult.second-mOrigMousePos);
|
||||
mCurrentMousePos = planeResult.second;
|
||||
mPhysics->moveSceneNodes(mGrabbedSceneNode, pos+planeResult.second-mOrigMousePos);
|
||||
updateSceneWidgets();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Mouse_Edit:
|
||||
case Mouse_Default:
|
||||
{
|
||||
break; // error event, ignore
|
||||
}
|
||||
/* NO_DEFAULT_CASE */
|
||||
}
|
||||
}
|
||||
|
||||
void MouseState::mousePressEvent (QMouseEvent *event)
|
||||
{
|
||||
switch(mMouseState)
|
||||
{
|
||||
case Mouse_Grab:
|
||||
case Mouse_Drag:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case Mouse_Edit:
|
||||
case Mouse_Default:
|
||||
{
|
||||
if(event->buttons() & Qt::RightButton)
|
||||
{
|
||||
std::pair<std::string, Ogre::Vector3> result = objectUnderCursor(event->x(), event->y());
|
||||
if(result.first == "")
|
||||
break;
|
||||
|
||||
mGrabbedSceneNode = result.first;
|
||||
// ray test agaist the plane to get a starting position of the
|
||||
// mouse in relation to the object position
|
||||
std::pair<Ogre::Vector3, Ogre::Vector3> planeRes = planeAxis();
|
||||
mPlane->redefine(planeRes.first, result.second);
|
||||
std::pair<bool, Ogre::Vector3> planeResult = mousePositionOnPlane(event->pos(), *mPlane);
|
||||
if(planeResult.first)
|
||||
{
|
||||
mOrigMousePos = planeResult.second;
|
||||
mCurrentMousePos = planeResult.second;
|
||||
mOffset = 0.0f;
|
||||
}
|
||||
|
||||
mOrigObjPos = mSceneManager->getSceneNode(mGrabbedSceneNode)->getPosition();
|
||||
mMouseEventTimer->start();
|
||||
|
||||
mMouseState = Mouse_Grab;
|
||||
}
|
||||
break;
|
||||
}
|
||||
/* NO_DEFAULT_CASE */
|
||||
}
|
||||
}
|
||||
|
||||
void MouseState::mouseReleaseEvent (QMouseEvent *event)
|
||||
{
|
||||
switch(mMouseState)
|
||||
{
|
||||
case Mouse_Grab:
|
||||
{
|
||||
std::pair<std::string, Ogre::Vector3> result = objectUnderCursor(event->x(), event->y());
|
||||
if(result.first != "")
|
||||
{
|
||||
if(result.first == mCurrentObj)
|
||||
{
|
||||
// unselect object
|
||||
mMouseState = Mouse_Default;
|
||||
mCurrentObj = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
// select object
|
||||
mMouseState = Mouse_Edit;
|
||||
mCurrentObj = result.first;
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Mouse_Drag:
|
||||
{
|
||||
// final placement
|
||||
std::pair<bool, Ogre::Vector3> planeResult = mousePositionOnPlane(event->pos(), *mPlane);
|
||||
if(planeResult.first)
|
||||
{
|
||||
if(mGrabbedSceneNode != "")
|
||||
{
|
||||
std::pair<Ogre::Vector3, Ogre::Vector3> planeRes = planeAxis();
|
||||
Ogre::Vector3 pos = mOrigObjPos+planeRes.first*mOffset+planeResult.second-mOrigMousePos;
|
||||
// use the saved scene node name since the physics model has not moved yet
|
||||
std::string referenceId = mPhysics->sceneNodeToRefId(mGrabbedSceneNode);
|
||||
|
||||
mParent->mDocument.getUndoStack().beginMacro (QObject::tr("Move Object"));
|
||||
mParent->mDocument.getUndoStack().push(new CSMWorld::ModifyCommand(*mIdTableModel,
|
||||
mIdTableModel->getModelIndex(referenceId, mColIndexPosX), pos.x));
|
||||
mParent->mDocument.getUndoStack().push(new CSMWorld::ModifyCommand(*mIdTableModel,
|
||||
mIdTableModel->getModelIndex(referenceId, mColIndexPosY), pos.y));
|
||||
mParent->mDocument.getUndoStack().push(new CSMWorld::ModifyCommand(*mIdTableModel,
|
||||
mIdTableModel->getModelIndex(referenceId, mColIndexPosZ), pos.z));
|
||||
mParent->mDocument.getUndoStack().endMacro();
|
||||
|
||||
// FIXME: highlight current object?
|
||||
//mCurrentObj = mGrabbedSceneNode; // FIXME: doesn't work?
|
||||
mCurrentObj = ""; // whether the object is selected
|
||||
|
||||
mMouseState = Mouse_Edit;
|
||||
|
||||
// reset states
|
||||
mCurrentMousePos = Ogre::Vector3(); // mouse pos to use in wheel event
|
||||
mOrigMousePos = Ogre::Vector3(); // starting pos of mouse in world space
|
||||
mOrigObjPos = Ogre::Vector3(); // starting pos of object in world space
|
||||
mGrabbedSceneNode = ""; // id of the object
|
||||
mOffset = 0.0f; // used for z-axis movement
|
||||
mOldPos = QPoint(0, 0); // to calculate relative movement of mouse
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Mouse_Edit:
|
||||
case Mouse_Default:
|
||||
{
|
||||
// probably terrain, check
|
||||
std::pair<std::string, Ogre::Vector3> result = terrainUnderCursor(event->x(), event->y());
|
||||
if(result.first != "")
|
||||
{
|
||||
// FIXME: terrain editing goes here
|
||||
}
|
||||
break;
|
||||
}
|
||||
/* NO_DEFAULT_CASE */
|
||||
}
|
||||
mMouseEventTimer->invalidate();
|
||||
}
|
||||
|
||||
void MouseState::mouseDoubleClickEvent (QMouseEvent *event)
|
||||
{
|
||||
event->ignore();
|
||||
//mPhysics->toggleDebugRendering(mSceneManager);
|
||||
//mParent->flagAsModified();
|
||||
}
|
||||
|
||||
bool MouseState::wheelEvent (QWheelEvent *event)
|
||||
{
|
||||
switch(mMouseState)
|
||||
{
|
||||
case Mouse_Grab:
|
||||
mMouseState = Mouse_Drag;
|
||||
|
||||
/* FALL_THROUGH */
|
||||
case Mouse_Drag:
|
||||
{
|
||||
// move the object along the z axis during Mouse_Drag or Mouse_Grab
|
||||
if (event->delta())
|
||||
{
|
||||
// seems positive is up and negative is down
|
||||
mOffset += (event->delta()/1); // FIXME: arbitrary number, make config option?
|
||||
|
||||
std::pair<Ogre::Vector3, Ogre::Vector3> planeRes = planeAxis();
|
||||
Ogre::Vector3 pos = mOrigObjPos + planeRes.first*mOffset;
|
||||
mSceneManager->getSceneNode(mGrabbedSceneNode)->setPosition(pos+mCurrentMousePos-mOrigMousePos);
|
||||
mPhysics->moveSceneNodes(mGrabbedSceneNode, pos+mCurrentMousePos-mOrigMousePos);
|
||||
updateSceneWidgets();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Mouse_Edit:
|
||||
case Mouse_Default:
|
||||
{
|
||||
return false;
|
||||
}
|
||||
/* NO_DEFAULT_CASE */
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void MouseState::cancelDrag()
|
||||
{
|
||||
switch(mMouseState)
|
||||
{
|
||||
case Mouse_Grab:
|
||||
case Mouse_Drag:
|
||||
{
|
||||
// cancel operation & return the object to the original position
|
||||
mSceneManager->getSceneNode(mGrabbedSceneNode)->setPosition(mOrigObjPos);
|
||||
// update all SceneWidgets and their SceneManagers
|
||||
mPhysics->moveSceneNodes(mGrabbedSceneNode, mOrigObjPos);
|
||||
updateSceneWidgets();
|
||||
|
||||
// reset states
|
||||
mMouseState = Mouse_Default;
|
||||
mCurrentMousePos = Ogre::Vector3();
|
||||
mOrigMousePos = Ogre::Vector3();
|
||||
mOrigObjPos = Ogre::Vector3();
|
||||
mGrabbedSceneNode = "";
|
||||
mCurrentObj = "";
|
||||
mOldPos = QPoint(0, 0);
|
||||
mMouseEventTimer->invalidate();
|
||||
mOffset = 0.0f;
|
||||
|
||||
break;
|
||||
}
|
||||
case Mouse_Edit:
|
||||
case Mouse_Default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
/* NO_DEFAULT_CASE */
|
||||
}
|
||||
}
|
||||
|
||||
//plane Z, upvector Y, mOffset z : x-y plane, wheel up/down
|
||||
//plane Y, upvector X, mOffset y : y-z plane, wheel left/right
|
||||
//plane X, upvector Y, mOffset x : x-z plane, wheel closer/further
|
||||
std::pair<Ogre::Vector3, Ogre::Vector3> MouseState::planeAxis()
|
||||
{
|
||||
const bool screenCoord = true;
|
||||
Ogre::Vector3 dir = getCamera()->getDerivedDirection();
|
||||
|
||||
QString wheelDir = "Closer/Further";
|
||||
if(wheelDir == "Left/Right")
|
||||
{
|
||||
if(screenCoord)
|
||||
return std::make_pair(getCamera()->getDerivedRight(), getCamera()->getDerivedUp());
|
||||
else
|
||||
return std::make_pair(Ogre::Vector3::UNIT_Y, Ogre::Vector3::UNIT_Z);
|
||||
}
|
||||
else if(wheelDir == "Up/Down")
|
||||
{
|
||||
if(screenCoord)
|
||||
return std::make_pair(getCamera()->getDerivedUp(), Ogre::Vector3(-dir.x, -dir.y, -dir.z));
|
||||
else
|
||||
return std::make_pair(Ogre::Vector3::UNIT_Z, Ogre::Vector3::UNIT_X);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(screenCoord)
|
||||
return std::make_pair(Ogre::Vector3(-dir.x, -dir.y, -dir.z), getCamera()->getDerivedRight());
|
||||
else
|
||||
return std::make_pair(Ogre::Vector3::UNIT_X, Ogre::Vector3::UNIT_Y);
|
||||
}
|
||||
}
|
||||
|
||||
std::pair<bool, Ogre::Vector3> MouseState::mousePositionOnPlane(const QPoint &pos, const Ogre::Plane &plane)
|
||||
{
|
||||
// using a really small value seems to mess up with the projections
|
||||
float nearClipDistance = getCamera()->getNearClipDistance(); // save existing
|
||||
getCamera()->setNearClipDistance(10.0f); // arbitrary number
|
||||
Ogre::Ray mouseRay = getCamera()->getCameraToViewportRay(
|
||||
(float) pos.x() / getViewport()->getActualWidth(),
|
||||
(float) pos.y() / getViewport()->getActualHeight());
|
||||
getCamera()->setNearClipDistance(nearClipDistance); // restore
|
||||
std::pair<bool, float> planeResult = mouseRay.intersects(plane);
|
||||
|
||||
if(planeResult.first)
|
||||
return std::make_pair(true, mouseRay.getPoint(planeResult.second));
|
||||
else
|
||||
return std::make_pair(false, Ogre::Vector3()); // should only happen if the plane is too small
|
||||
}
|
||||
|
||||
std::pair<std::string, Ogre::Vector3> MouseState::terrainUnderCursor(const int mouseX, const int mouseY)
|
||||
{
|
||||
if(!getViewport())
|
||||
return std::make_pair("", Ogre::Vector3());
|
||||
|
||||
float x = (float) mouseX / getViewport()->getActualWidth();
|
||||
float y = (float) mouseY / getViewport()->getActualHeight();
|
||||
|
||||
std::pair<std::string, Ogre::Vector3> result = mPhysics->castRay(x, y, mSceneManager, getCamera());
|
||||
if(result.first != "")
|
||||
{
|
||||
// FIXME: is there a better way to distinguish terrain from objects?
|
||||
QString name = QString(result.first.c_str());
|
||||
if(name.contains(QRegExp("^HeightField")))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return std::make_pair("", Ogre::Vector3());
|
||||
}
|
||||
|
||||
std::pair<std::string, Ogre::Vector3> MouseState::objectUnderCursor(const int mouseX, const int mouseY)
|
||||
{
|
||||
if(!getViewport())
|
||||
return std::make_pair("", Ogre::Vector3());
|
||||
|
||||
float x = (float) mouseX / getViewport()->getActualWidth();
|
||||
float y = (float) mouseY / getViewport()->getActualHeight();
|
||||
|
||||
std::pair<std::string, Ogre::Vector3> result = mPhysics->castRay(x, y, mSceneManager, getCamera());
|
||||
if(result.first != "")
|
||||
{
|
||||
// NOTE: anything not terrain is assumed to be an object
|
||||
QString name = QString(result.first.c_str());
|
||||
if(!name.contains(QRegExp("^HeightField")))
|
||||
{
|
||||
uint32_t visibilityMask = getViewport()->getVisibilityMask();
|
||||
bool ignoreObjects = !(visibilityMask & (uint32_t)CSVRender::Element_Reference);
|
||||
|
||||
if(!ignoreObjects && mSceneManager->hasSceneNode(result.first))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return std::make_pair("", Ogre::Vector3());
|
||||
}
|
||||
|
||||
void MouseState::updateSceneWidgets()
|
||||
{
|
||||
std::map<Ogre::SceneManager*, CSVRender::SceneWidget *> sceneWidgets = mPhysics->sceneWidgets();
|
||||
|
||||
std::map<Ogre::SceneManager*, CSVRender::SceneWidget *>::iterator iter = sceneWidgets.begin();
|
||||
for(; iter != sceneWidgets.end(); ++iter)
|
||||
{
|
||||
(*iter).second->updateScene();
|
||||
}
|
||||
}
|
||||
|
||||
Ogre::Camera *MouseState::getCamera()
|
||||
{
|
||||
return mParent->getCamera();
|
||||
}
|
||||
|
||||
Ogre::Viewport *MouseState::getViewport()
|
||||
{
|
||||
return mParent->getCamera()->getViewport();
|
||||
}
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
#ifndef OPENCS_VIEW_MOUSESTATE_H
|
||||
#define OPENCS_VIEW_MOUSESTATE_H
|
||||
|
||||
#include <map>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <QPoint>
|
||||
#include <OgreVector3.h>
|
||||
|
||||
class QElapsedTimer;
|
||||
class QMouseEvent;
|
||||
class QWheelEvent;
|
||||
|
||||
namespace Ogre
|
||||
{
|
||||
class Plane;
|
||||
class SceneManager;
|
||||
class Camera;
|
||||
class Viewport;
|
||||
}
|
||||
|
||||
namespace CSVWorld
|
||||
{
|
||||
class PhysicsSystem;
|
||||
}
|
||||
|
||||
namespace CSMWorld
|
||||
{
|
||||
class IdTable;
|
||||
}
|
||||
|
||||
namespace CSVRender
|
||||
{
|
||||
class WorldspaceWidget;
|
||||
|
||||
class MouseState
|
||||
{
|
||||
enum MouseStates
|
||||
{
|
||||
Mouse_Grab,
|
||||
Mouse_Drag,
|
||||
Mouse_Edit,
|
||||
Mouse_Default
|
||||
};
|
||||
MouseStates mMouseState;
|
||||
|
||||
WorldspaceWidget *mParent;
|
||||
boost::shared_ptr<CSVWorld::PhysicsSystem> mPhysics;
|
||||
Ogre::SceneManager *mSceneManager; // local copy
|
||||
|
||||
QPoint mOldPos;
|
||||
std::string mCurrentObj;
|
||||
std::string mGrabbedSceneNode;
|
||||
QElapsedTimer *mMouseEventTimer;
|
||||
Ogre::Plane *mPlane;
|
||||
Ogre::Vector3 mOrigObjPos;
|
||||
Ogre::Vector3 mOrigMousePos;
|
||||
Ogre::Vector3 mCurrentMousePos;
|
||||
float mOffset;
|
||||
|
||||
CSMWorld::IdTable *mIdTableModel;
|
||||
int mColIndexPosX;
|
||||
int mColIndexPosY;
|
||||
int mColIndexPosZ;
|
||||
|
||||
public:
|
||||
|
||||
MouseState(WorldspaceWidget *parent);
|
||||
~MouseState();
|
||||
|
||||
void mouseMoveEvent (QMouseEvent *event);
|
||||
void mousePressEvent (QMouseEvent *event);
|
||||
void mouseReleaseEvent (QMouseEvent *event);
|
||||
void mouseDoubleClickEvent (QMouseEvent *event);
|
||||
bool wheelEvent (QWheelEvent *event);
|
||||
|
||||
void cancelDrag();
|
||||
|
||||
private:
|
||||
|
||||
std::pair<bool, Ogre::Vector3> mousePositionOnPlane(const QPoint &pos, const Ogre::Plane &plane);
|
||||
std::pair<std::string, Ogre::Vector3> terrainUnderCursor(const int mouseX, const int mouseY);
|
||||
std::pair<std::string, Ogre::Vector3> objectUnderCursor(const int mouseX, const int mouseY);
|
||||
std::pair<Ogre::Vector3, Ogre::Vector3> planeAxis();
|
||||
void updateSceneWidgets();
|
||||
|
||||
Ogre::Camera *getCamera(); // friend access
|
||||
Ogre::Viewport *getViewport(); // friend access
|
||||
};
|
||||
}
|
||||
|
||||
#endif // OPENCS_VIEW_MOUSESTATE_H
|
@ -1,24 +0,0 @@
|
||||
|
||||
#include "navigation.hpp"
|
||||
|
||||
float CSVRender::Navigation::getFactor (bool mouse) const
|
||||
{
|
||||
float factor = mFastModeFactor;
|
||||
|
||||
if (mouse)
|
||||
factor /= 2; /// \todo make this configurable
|
||||
|
||||
return factor;
|
||||
}
|
||||
|
||||
CSVRender::Navigation::Navigation()
|
||||
: mFastModeFactor(1)
|
||||
{
|
||||
}
|
||||
|
||||
CSVRender::Navigation::~Navigation() {}
|
||||
|
||||
void CSVRender::Navigation::setFastModeFactor (float factor)
|
||||
{
|
||||
mFastModeFactor = factor;
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
#ifndef OPENCS_VIEW_NAVIGATION_H
|
||||
#define OPENCS_VIEW_NAVIGATION_H
|
||||
|
||||
class QPoint;
|
||||
|
||||
namespace Ogre
|
||||
{
|
||||
class Camera;
|
||||
}
|
||||
|
||||
namespace CSVRender
|
||||
{
|
||||
class Navigation
|
||||
{
|
||||
float mFastModeFactor;
|
||||
|
||||
protected:
|
||||
|
||||
float getFactor (bool mouse) const;
|
||||
|
||||
public:
|
||||
|
||||
Navigation();
|
||||
virtual ~Navigation();
|
||||
|
||||
void setFastModeFactor (float factor);
|
||||
///< Set currently applying fast mode factor.
|
||||
|
||||
virtual bool activate (Ogre::Camera *camera) = 0;
|
||||
///< \return Update required?
|
||||
|
||||
virtual bool wheelMoved (int delta) = 0;
|
||||
///< \return Update required?
|
||||
|
||||
virtual bool mouseMoved (const QPoint& delta, int mode) = 0;
|
||||
///< \param mode: 0: default mouse key, 1: default mouse key and modifier key 1
|
||||
/// \return Update required?
|
||||
|
||||
virtual bool handleMovementKeys (int vertical, int horizontal) = 0;
|
||||
///< \return Update required?
|
||||
|
||||
virtual bool handleRollKeys (int delta) = 0;
|
||||
///< \return Update required?
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -1,86 +0,0 @@
|
||||
|
||||
#include "navigation1st.hpp"
|
||||
|
||||
#include <OgreCamera.h>
|
||||
|
||||
#include <QPoint>
|
||||
|
||||
CSVRender::Navigation1st::Navigation1st() : mCamera (0) {}
|
||||
|
||||
bool CSVRender::Navigation1st::activate (Ogre::Camera *camera)
|
||||
{
|
||||
mCamera = camera;
|
||||
mCamera->setFixedYawAxis (true, Ogre::Vector3::UNIT_Z);
|
||||
|
||||
Ogre::Radian pitch = mCamera->getOrientation().getPitch();
|
||||
|
||||
Ogre::Radian limit (Ogre::Math::PI/2-0.5);
|
||||
|
||||
if (pitch>limit)
|
||||
mCamera->pitch (-(pitch-limit));
|
||||
else if (pitch<-limit)
|
||||
mCamera->pitch (pitch-limit);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CSVRender::Navigation1st::wheelMoved (int delta)
|
||||
{
|
||||
mCamera->move (getFactor (true) * mCamera->getDirection() * delta);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CSVRender::Navigation1st::mouseMoved (const QPoint& delta, int mode)
|
||||
{
|
||||
if (mode==0)
|
||||
{
|
||||
// turn camera
|
||||
if (delta.x())
|
||||
mCamera->yaw (Ogre::Degree (getFactor (true) * delta.x()));
|
||||
|
||||
if (delta.y())
|
||||
{
|
||||
Ogre::Radian oldPitch = mCamera->getOrientation().getPitch();
|
||||
float deltaPitch = getFactor (true) * delta.y();
|
||||
Ogre::Radian newPitch = oldPitch + Ogre::Degree (deltaPitch);
|
||||
|
||||
if ((deltaPitch>0 && newPitch<Ogre::Radian(Ogre::Math::PI-0.5)) ||
|
||||
(deltaPitch<0 && newPitch>Ogre::Radian(0.5)))
|
||||
{
|
||||
mCamera->pitch (Ogre::Degree (deltaPitch));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (mode==1)
|
||||
{
|
||||
// pan camera
|
||||
if (delta.x())
|
||||
mCamera->move (getFactor (true) * mCamera->getDerivedRight() * delta.x());
|
||||
|
||||
if (delta.y())
|
||||
mCamera->move (getFactor (true) * -mCamera->getDerivedUp() * delta.y());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CSVRender::Navigation1st::handleMovementKeys (int vertical, int horizontal)
|
||||
{
|
||||
if (vertical)
|
||||
mCamera->move (getFactor (false) * mCamera->getDirection() * vertical);
|
||||
|
||||
if (horizontal)
|
||||
mCamera->move (getFactor (true) * mCamera->getDerivedRight() * horizontal);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CSVRender::Navigation1st::handleRollKeys (int delta)
|
||||
{
|
||||
// we don't roll this way in 1st person mode
|
||||
return false;
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
#ifndef OPENCS_VIEW_NAVIGATION1ST_H
|
||||
#define OPENCS_VIEW_NAVIGATION1ST_H
|
||||
|
||||
#include "navigation.hpp"
|
||||
|
||||
namespace CSVRender
|
||||
{
|
||||
/// \brief First person-like camera controls
|
||||
class Navigation1st : public Navigation
|
||||
{
|
||||
Ogre::Camera *mCamera;
|
||||
|
||||
public:
|
||||
|
||||
Navigation1st();
|
||||
|
||||
virtual bool activate (Ogre::Camera *camera);
|
||||
///< \return Update required?
|
||||
|
||||
virtual bool wheelMoved (int delta);
|
||||
///< \return Update required?
|
||||
|
||||
virtual bool mouseMoved (const QPoint& delta, int mode);
|
||||
///< \param mode: 0: default mouse key, 1: default mouse key and modifier key 1
|
||||
/// \return Update required?
|
||||
|
||||
virtual bool handleMovementKeys (int vertical, int horizontal);
|
||||
///< \return Update required?
|
||||
|
||||
virtual bool handleRollKeys (int delta);
|
||||
///< \return Update required?
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -1,66 +0,0 @@
|
||||
|
||||
#include "navigationfree.hpp"
|
||||
|
||||
#include <OgreCamera.h>
|
||||
|
||||
#include <QPoint>
|
||||
|
||||
CSVRender::NavigationFree::NavigationFree() : mCamera (0) {}
|
||||
|
||||
bool CSVRender::NavigationFree::activate (Ogre::Camera *camera)
|
||||
{
|
||||
mCamera = camera;
|
||||
mCamera->setFixedYawAxis (false);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CSVRender::NavigationFree::wheelMoved (int delta)
|
||||
{
|
||||
mCamera->move (getFactor (true) * mCamera->getDirection() * delta);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CSVRender::NavigationFree::mouseMoved (const QPoint& delta, int mode)
|
||||
{
|
||||
if (mode==0)
|
||||
{
|
||||
// turn camera
|
||||
if (delta.x())
|
||||
mCamera->yaw (Ogre::Degree (getFactor (true) * delta.x()));
|
||||
|
||||
if (delta.y())
|
||||
mCamera->pitch (Ogre::Degree (getFactor (true) * delta.y()));
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (mode==1)
|
||||
{
|
||||
// pan camera
|
||||
if (delta.x())
|
||||
mCamera->move (getFactor (true) * mCamera->getDerivedRight() * delta.x());
|
||||
|
||||
if (delta.y())
|
||||
mCamera->move (getFactor (true) * -mCamera->getDerivedUp() * delta.y());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CSVRender::NavigationFree::handleMovementKeys (int vertical, int horizontal)
|
||||
{
|
||||
if (vertical)
|
||||
mCamera->move (getFactor (false) * mCamera->getDerivedUp() * vertical);
|
||||
|
||||
if (horizontal)
|
||||
mCamera->move (getFactor (true) * mCamera->getDerivedRight() * horizontal);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CSVRender::NavigationFree::handleRollKeys (int delta)
|
||||
{
|
||||
mCamera->roll (Ogre::Degree (getFactor (false) * delta));
|
||||
return true;
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
#ifndef OPENCS_VIEW_NAVIGATIONFREE_H
|
||||
#define OPENCS_VIEW_NAVIGATIONFREE_H
|
||||
|
||||
#include "navigation.hpp"
|
||||
|
||||
namespace CSVRender
|
||||
{
|
||||
/// \brief Free camera controls
|
||||
class NavigationFree : public Navigation
|
||||
{
|
||||
Ogre::Camera *mCamera;
|
||||
|
||||
public:
|
||||
|
||||
NavigationFree();
|
||||
|
||||
virtual bool activate (Ogre::Camera *camera);
|
||||
///< \return Update required?
|
||||
|
||||
virtual bool wheelMoved (int delta);
|
||||
///< \return Update required?
|
||||
|
||||
virtual bool mouseMoved (const QPoint& delta, int mode);
|
||||
///< \param mode: 0: default mouse key, 1: default mouse key and modifier key 1
|
||||
/// \return Update required?
|
||||
|
||||
virtual bool handleMovementKeys (int vertical, int horizontal);
|
||||
///< \return Update required?
|
||||
|
||||
virtual bool handleRollKeys (int delta);
|
||||
///< \return Update required?
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -1,100 +0,0 @@
|
||||
|
||||
#include "navigationorbit.hpp"
|
||||
|
||||
#include <OgreCamera.h>
|
||||
|
||||
#include <QPoint>
|
||||
|
||||
void CSVRender::NavigationOrbit::rotateCamera (const Ogre::Vector3& diff)
|
||||
{
|
||||
Ogre::Vector3 pos = mCamera->getPosition();
|
||||
|
||||
float distance = (pos-mCentre).length();
|
||||
|
||||
Ogre::Vector3 direction = (pos+diff)-mCentre;
|
||||
direction.normalise();
|
||||
|
||||
mCamera->setPosition (mCentre + direction*distance);
|
||||
mCamera->lookAt (mCentre);
|
||||
}
|
||||
|
||||
CSVRender::NavigationOrbit::NavigationOrbit() : mCamera (0), mCentre (0, 0, 0), mDistance (100)
|
||||
{}
|
||||
|
||||
bool CSVRender::NavigationOrbit::activate (Ogre::Camera *camera)
|
||||
{
|
||||
mCamera = camera;
|
||||
mCamera->setFixedYawAxis (false);
|
||||
|
||||
if ((mCamera->getPosition()-mCentre).length()<mDistance)
|
||||
{
|
||||
// move camera out of the centre area
|
||||
Ogre::Vector3 direction = mCentre-mCamera->getPosition();
|
||||
direction.normalise();
|
||||
|
||||
if (direction.length()==0)
|
||||
direction = Ogre::Vector3 (1, 0, 0);
|
||||
|
||||
mCamera->setPosition (mCentre - direction * mDistance);
|
||||
}
|
||||
|
||||
mCamera->lookAt (mCentre);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CSVRender::NavigationOrbit::wheelMoved (int delta)
|
||||
{
|
||||
Ogre::Vector3 diff = getFactor (true) * mCamera->getDirection() * delta;
|
||||
|
||||
Ogre::Vector3 pos = mCamera->getPosition();
|
||||
|
||||
if (delta>0 && diff.length()>=(pos-mCentre).length()-mDistance)
|
||||
{
|
||||
pos = mCentre-(mCamera->getDirection() * mDistance);
|
||||
}
|
||||
else
|
||||
{
|
||||
pos += diff;
|
||||
}
|
||||
|
||||
mCamera->setPosition (pos);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CSVRender::NavigationOrbit::mouseMoved (const QPoint& delta, int mode)
|
||||
{
|
||||
Ogre::Vector3 diff =
|
||||
getFactor (true) * -mCamera->getDerivedRight() * delta.x()
|
||||
+ getFactor (true) * mCamera->getDerivedUp() * delta.y();
|
||||
|
||||
if (mode==0)
|
||||
{
|
||||
rotateCamera (diff);
|
||||
return true;
|
||||
}
|
||||
else if (mode==1)
|
||||
{
|
||||
mCamera->move (diff);
|
||||
mCentre += diff;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CSVRender::NavigationOrbit::handleMovementKeys (int vertical, int horizontal)
|
||||
{
|
||||
rotateCamera (
|
||||
- getFactor (false) * -mCamera->getDerivedRight() * horizontal
|
||||
+ getFactor (false) * mCamera->getDerivedUp() * vertical);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CSVRender::NavigationOrbit::handleRollKeys (int delta)
|
||||
{
|
||||
mCamera->roll (Ogre::Degree (getFactor (false) * delta));
|
||||
return true;
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
#ifndef OPENCS_VIEW_NAVIGATIONORBIT_H
|
||||
#define OPENCS_VIEW_NAVIGATIONORBIT_H
|
||||
|
||||
#include "navigation.hpp"
|
||||
|
||||
#include <OgreVector3.h>
|
||||
|
||||
namespace CSVRender
|
||||
{
|
||||
/// \brief Orbiting camera controls
|
||||
class NavigationOrbit : public Navigation
|
||||
{
|
||||
Ogre::Camera *mCamera;
|
||||
Ogre::Vector3 mCentre;
|
||||
int mDistance;
|
||||
|
||||
void rotateCamera (const Ogre::Vector3& diff);
|
||||
///< Rotate camera around centre.
|
||||
|
||||
public:
|
||||
|
||||
NavigationOrbit();
|
||||
|
||||
virtual bool activate (Ogre::Camera *camera);
|
||||
///< \return Update required?
|
||||
|
||||
virtual bool wheelMoved (int delta);
|
||||
///< \return Update required?
|
||||
|
||||
virtual bool mouseMoved (const QPoint& delta, int mode);
|
||||
///< \param mode: 0: default mouse key, 1: default mouse key and modifier key 1
|
||||
/// \return Update required?
|
||||
|
||||
virtual bool handleMovementKeys (int vertical, int horizontal);
|
||||
///< \return Update required?
|
||||
|
||||
virtual bool handleRollKeys (int delta);
|
||||
///< \return Update required?
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -1,52 +0,0 @@
|
||||
#include "overlaymask.hpp"
|
||||
|
||||
#include <OgreOverlayManager.h>
|
||||
#include <OgreOverlayContainer.h>
|
||||
|
||||
#include "textoverlay.hpp"
|
||||
#include "../../model/world/cellcoordinates.hpp"
|
||||
|
||||
namespace CSVRender
|
||||
{
|
||||
|
||||
// ideas from http://www.ogre3d.org/forums/viewtopic.php?f=5&t=44828#p486334
|
||||
OverlayMask::OverlayMask(std::map<CSMWorld::CellCoordinates, TextOverlay *> &overlays, Ogre::Viewport* viewport)
|
||||
: mTextOverlays(overlays), mViewport(viewport)
|
||||
{
|
||||
}
|
||||
|
||||
OverlayMask::~OverlayMask()
|
||||
{
|
||||
}
|
||||
|
||||
void OverlayMask::setViewport(Ogre::Viewport *viewport)
|
||||
{
|
||||
mViewport = viewport;
|
||||
}
|
||||
|
||||
void OverlayMask::preViewportUpdate(const Ogre::RenderTargetViewportEvent &event)
|
||||
{
|
||||
if(event.source == mViewport)
|
||||
{
|
||||
Ogre::OverlayManager &overlayMgr = Ogre::OverlayManager::getSingleton();
|
||||
for(Ogre::OverlayManager::OverlayMapIterator iter = overlayMgr.getOverlayIterator();
|
||||
iter.hasMoreElements();)
|
||||
{
|
||||
Ogre::Overlay* item = iter.getNext();
|
||||
for(Ogre::Overlay::Overlay2DElementsIterator it = item->get2DElementsIterator();
|
||||
it.hasMoreElements();)
|
||||
{
|
||||
Ogre::OverlayContainer* container = it.getNext();
|
||||
if(container) container->hide();
|
||||
}
|
||||
}
|
||||
|
||||
std::map<CSMWorld::CellCoordinates, TextOverlay *>::iterator it = mTextOverlays.begin();
|
||||
for(; it != mTextOverlays.end(); ++it)
|
||||
{
|
||||
it->second->show(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
#ifndef OPENCS_VIEW_OVERLAYMASK_H
|
||||
#define OPENCS_VIEW_OVERLAYMASK_H
|
||||
|
||||
#include <OgreRenderTargetListener.h>
|
||||
|
||||
namespace Ogre
|
||||
{
|
||||
class Viewport;
|
||||
class RendertargetViewportEvent;
|
||||
}
|
||||
|
||||
namespace CSMWorld
|
||||
{
|
||||
class CellCoordinates;
|
||||
}
|
||||
|
||||
namespace CSVRender
|
||||
{
|
||||
class TextOverlay;
|
||||
|
||||
class OverlayMask : public Ogre::RenderTargetListener
|
||||
{
|
||||
|
||||
std::map<CSMWorld::CellCoordinates, TextOverlay *> &mTextOverlays;
|
||||
Ogre::Viewport* mViewport;
|
||||
|
||||
public:
|
||||
|
||||
OverlayMask(std::map<CSMWorld::CellCoordinates, TextOverlay *> &overlays,
|
||||
Ogre::Viewport* viewport);
|
||||
|
||||
virtual ~OverlayMask();
|
||||
|
||||
void setViewport(Ogre::Viewport *viewport);
|
||||
|
||||
protected:
|
||||
|
||||
virtual void preViewportUpdate(const Ogre::RenderTargetViewportEvent &event);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // OPENCS_VIEW_OVERLAYMASK_H
|
@ -1,34 +0,0 @@
|
||||
#include "overlaysystem.hpp"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include <OgreOverlaySystem.h>
|
||||
|
||||
namespace CSVRender
|
||||
{
|
||||
OverlaySystem *OverlaySystem::mOverlaySystemInstance = 0;
|
||||
|
||||
OverlaySystem::OverlaySystem()
|
||||
{
|
||||
assert(!mOverlaySystemInstance);
|
||||
mOverlaySystemInstance = this;
|
||||
mOverlaySystem = new Ogre::OverlaySystem();
|
||||
}
|
||||
|
||||
OverlaySystem::~OverlaySystem()
|
||||
{
|
||||
delete mOverlaySystem;
|
||||
}
|
||||
|
||||
OverlaySystem &OverlaySystem::instance()
|
||||
{
|
||||
assert(mOverlaySystemInstance);
|
||||
return *mOverlaySystemInstance;
|
||||
}
|
||||
|
||||
Ogre::OverlaySystem *OverlaySystem::get()
|
||||
{
|
||||
return mOverlaySystem;
|
||||
}
|
||||
}
|
||||
|
@ -1,26 +0,0 @@
|
||||
#ifndef OPENCS_VIEW_OVERLAYSYSTEM_H
|
||||
#define OPENCS_VIEW_OVERLAYSYSTEM_H
|
||||
|
||||
namespace Ogre
|
||||
{
|
||||
class OverlaySystem;
|
||||
}
|
||||
|
||||
namespace CSVRender
|
||||
{
|
||||
class OverlaySystem
|
||||
{
|
||||
Ogre::OverlaySystem *mOverlaySystem;
|
||||
static OverlaySystem *mOverlaySystemInstance;
|
||||
|
||||
public:
|
||||
|
||||
OverlaySystem();
|
||||
~OverlaySystem();
|
||||
static OverlaySystem &instance();
|
||||
|
||||
Ogre::OverlaySystem *get();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // OPENCS_VIEW_OVERLAYSYSTEM_H
|
@ -1,359 +0,0 @@
|
||||
#include "textoverlay.hpp"
|
||||
|
||||
#include <OgreCamera.h>
|
||||
#include <OgreMaterialManager.h>
|
||||
#include <OgreTechnique.h>
|
||||
|
||||
#include <OgreOverlayManager.h>
|
||||
#include <OgreOverlayContainer.h>
|
||||
#include <OgreFontManager.h>
|
||||
#include <OgreTextAreaOverlayElement.h>
|
||||
#include <OgreEntity.h>
|
||||
#include <OgreViewport.h>
|
||||
#include <OgreRoot.h>
|
||||
#include <OgreHardwarePixelBuffer.h>
|
||||
|
||||
namespace CSVRender
|
||||
{
|
||||
|
||||
// Things to do:
|
||||
// - configurable font size in pixels (automatically calulate everything else from it)
|
||||
// - configurable texture to use
|
||||
// - try material script
|
||||
// - decide whether to use QPaint (http://www.ogre3d.org/tikiwiki/Ogre+overlays+using+Qt)
|
||||
|
||||
// http://www.ogre3d.org/tikiwiki/ObjectTextDisplay
|
||||
// http://www.ogre3d.org/tikiwiki/MovableTextOverlay
|
||||
// http://www.ogre3d.org/tikiwiki/Creating+dynamic+textures
|
||||
// http://www.ogre3d.org/tikiwiki/ManualObject
|
||||
TextOverlay::TextOverlay(const Ogre::MovableObject* obj, const Ogre::Camera* camera, const Ogre::String& id)
|
||||
: mOverlay(0), mCaption(""), mDesc(""), mObj(obj), mCamera(camera), mFontHeight(16), mId(id)
|
||||
, mEnabled(true), mOnScreen(false), mInstance(0) // FIXME: make font height configurable
|
||||
{
|
||||
if(id == "" || !camera || !obj)
|
||||
throw std::runtime_error("TextOverlay could not be created.");
|
||||
|
||||
// setup font
|
||||
Ogre::FontManager &fontMgr = Ogre::FontManager::getSingleton();
|
||||
if (fontMgr.resourceExists("DejaVuLGC"))
|
||||
mFont = fontMgr.getByName("DejaVuLGC","General");
|
||||
else
|
||||
{
|
||||
mFont = fontMgr.create("DejaVuLGC","General");
|
||||
mFont->setType(Ogre::FT_TRUETYPE);
|
||||
mFont->setSource("DejaVuLGCSansMono.ttf");
|
||||
mFont->setTrueTypeSize(mFontHeight);
|
||||
mFont->setTrueTypeResolution(96);
|
||||
}
|
||||
if(!mFont.isNull())
|
||||
mFont->load();
|
||||
else
|
||||
throw std::runtime_error("TextOverlay font not loaded.");
|
||||
|
||||
// setup overlay
|
||||
Ogre::OverlayManager &overlayMgr = Ogre::OverlayManager::getSingleton();
|
||||
mOverlay = overlayMgr.getByName("CellIDPanel"+mId+Ogre::StringConverter::toString(mInstance));
|
||||
// FIXME: this logic is badly broken as it is possible to delete an earlier instance
|
||||
while(mOverlay != NULL)
|
||||
{
|
||||
mInstance++;
|
||||
mOverlay = overlayMgr.getByName("CellIDPanel"+mId+Ogre::StringConverter::toString(mInstance));
|
||||
}
|
||||
mOverlay = overlayMgr.create("CellIDPanel"+mId+Ogre::StringConverter::toString(mInstance));
|
||||
|
||||
// create texture
|
||||
Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().getByName("DynamicTransBlue");
|
||||
if(texture.isNull())
|
||||
{
|
||||
texture = Ogre::TextureManager::getSingleton().createManual(
|
||||
"DynamicTransBlue", // name
|
||||
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
||||
Ogre::TEX_TYPE_2D, // type
|
||||
8, 8, // width & height
|
||||
0, // number of mipmaps
|
||||
Ogre::PF_BYTE_BGRA, // pixel format
|
||||
Ogre::TU_DEFAULT); // usage; should be TU_DYNAMIC_WRITE_ONLY_DISCARDABLE for
|
||||
// textures updated very often (e.g. each frame)
|
||||
|
||||
Ogre::HardwarePixelBufferSharedPtr pixelBuffer = texture->getBuffer();
|
||||
pixelBuffer->lock(Ogre::HardwareBuffer::HBL_NORMAL);
|
||||
const Ogre::PixelBox& pixelBox = pixelBuffer->getCurrentLock();
|
||||
|
||||
Ogre::uint8* pDest = static_cast<Ogre::uint8*>(pixelBox.data);
|
||||
|
||||
// Fill in some pixel data. This will give a semi-transparent blue,
|
||||
// but this is of course dependent on the chosen pixel format.
|
||||
for (size_t j = 0; j < 8; j++)
|
||||
{
|
||||
for(size_t i = 0; i < 8; i++)
|
||||
{
|
||||
*pDest++ = 255; // B
|
||||
*pDest++ = 0; // G
|
||||
*pDest++ = 0; // R
|
||||
*pDest++ = 63; // A
|
||||
}
|
||||
|
||||
pDest += pixelBox.getRowSkip() * Ogre::PixelUtil::getNumElemBytes(pixelBox.format);
|
||||
}
|
||||
pixelBuffer->unlock();
|
||||
}
|
||||
|
||||
// setup material for containers
|
||||
Ogre::MaterialPtr mQuadMaterial = Ogre::MaterialManager::getSingleton().getByName(
|
||||
"TransOverlayMaterial");
|
||||
if(mQuadMaterial.isNull())
|
||||
{
|
||||
Ogre::MaterialPtr mQuadMaterial = Ogre::MaterialManager::getSingleton().create(
|
||||
"TransOverlayMaterial",
|
||||
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true );
|
||||
Ogre::Pass *pass = mQuadMaterial->getTechnique( 0 )->getPass( 0 );
|
||||
pass->setLightingEnabled( false );
|
||||
pass->setDepthWriteEnabled( false );
|
||||
pass->setSceneBlending( Ogre::SBT_TRANSPARENT_ALPHA );
|
||||
|
||||
Ogre::TextureUnitState *tex = pass->createTextureUnitState("MyCustomState", 0);
|
||||
tex->setTextureName("DynamicTransBlue");
|
||||
tex->setTextureFiltering( Ogre::TFO_ANISOTROPIC );
|
||||
mQuadMaterial->load();
|
||||
}
|
||||
|
||||
mContainer = static_cast<Ogre::OverlayContainer*>(overlayMgr.createOverlayElement(
|
||||
"Panel", "container"+mId +"#"+Ogre::StringConverter::toString(mInstance)));
|
||||
mContainer->setMaterialName("TransOverlayMaterial");
|
||||
mOverlay->add2D(mContainer);
|
||||
|
||||
// setup text area overlay element
|
||||
mElement = static_cast<Ogre::TextAreaOverlayElement*>(overlayMgr.createOverlayElement(
|
||||
"TextArea", "text"+mId +"#"+Ogre::StringConverter::toString(mInstance)));
|
||||
mElement->setMetricsMode(Ogre::GMM_RELATIVE);
|
||||
mElement->setDimensions(1.0, 1.0);
|
||||
mElement->setMetricsMode(Ogre::GMM_PIXELS);
|
||||
mElement->setPosition(2*fontHeight()/3, 1.3*fontHeight()/3); // 1.3 & 2 = fudge factor
|
||||
|
||||
mElement->setFontName("DejaVuLGC");
|
||||
mElement->setCharHeight(fontHeight()); // NOTE: seems that this is required as well as font->setTrueTypeSize()
|
||||
mElement->setHorizontalAlignment(Ogre::GHA_LEFT);
|
||||
//mElement->setColour(Ogre::ColourValue(1.0, 1.0, 1.0)); // R, G, B
|
||||
mElement->setColour(Ogre::ColourValue(1.0, 1.0, 0)); // yellow
|
||||
|
||||
mContainer->addChild(mElement);
|
||||
mOverlay->show();
|
||||
}
|
||||
|
||||
void TextOverlay::getScreenCoordinates(const Ogre::Vector3& position, Ogre::Real& x, Ogre::Real& y)
|
||||
{
|
||||
Ogre::Vector3 hcsPosition = mCamera->getProjectionMatrix() * (mCamera->getViewMatrix() * position);
|
||||
|
||||
x = 1.0f - ((hcsPosition.x * 0.5f) + 0.5f); // 0 <= x <= 1 // left := 0,right := 1
|
||||
y = ((hcsPosition.y * 0.5f) + 0.5f); // 0 <= y <= 1 // bottom := 0,top := 1
|
||||
}
|
||||
|
||||
void TextOverlay::getMinMaxEdgesOfAABBIn2D(float& MinX, float& MinY, float& MaxX, float& MaxY,
|
||||
bool top)
|
||||
{
|
||||
MinX = 0, MinY = 0, MaxX = 0, MaxY = 0;
|
||||
float X[4]; // the 2D dots of the AABB in screencoordinates
|
||||
float Y[4];
|
||||
|
||||
if(!mObj->isInScene())
|
||||
return;
|
||||
|
||||
const Ogre::AxisAlignedBox &AABB = mObj->getWorldBoundingBox(true); // the AABB of the target
|
||||
Ogre::Vector3 cornersOfAABB[4];
|
||||
if(top)
|
||||
{
|
||||
cornersOfAABB[0] = AABB.getCorner(Ogre::AxisAlignedBox::FAR_LEFT_TOP);
|
||||
cornersOfAABB[1] = AABB.getCorner(Ogre::AxisAlignedBox::FAR_RIGHT_TOP);
|
||||
cornersOfAABB[2] = AABB.getCorner(Ogre::AxisAlignedBox::NEAR_LEFT_TOP);
|
||||
cornersOfAABB[3] = AABB.getCorner(Ogre::AxisAlignedBox::NEAR_RIGHT_TOP);
|
||||
}
|
||||
else
|
||||
{
|
||||
cornersOfAABB[0] = AABB.getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM);
|
||||
cornersOfAABB[1] = AABB.getCorner(Ogre::AxisAlignedBox::FAR_RIGHT_BOTTOM);
|
||||
cornersOfAABB[2] = AABB.getCorner(Ogre::AxisAlignedBox::NEAR_LEFT_BOTTOM);
|
||||
cornersOfAABB[3] = AABB.getCorner(Ogre::AxisAlignedBox::NEAR_RIGHT_BOTTOM);
|
||||
}
|
||||
|
||||
//The normal vector of the plane. This points directly infront of the camera.
|
||||
Ogre::Vector3 cameraPlainNormal = mCamera->getDerivedOrientation().zAxis();
|
||||
|
||||
//the plane that devides the space before and behind the camera.
|
||||
Ogre::Plane CameraPlane = Ogre::Plane(cameraPlainNormal, mCamera->getDerivedPosition());
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
X[i] = 0;
|
||||
Y[i] = 0;
|
||||
|
||||
getScreenCoordinates(cornersOfAABB[i],X[i],Y[i]); // transfor into 2d dots
|
||||
|
||||
if (CameraPlane.getSide(cornersOfAABB[i]) == Ogre::Plane::NEGATIVE_SIDE)
|
||||
{
|
||||
if (i == 0) // accept the first set of values, no matter how bad it might be.
|
||||
{
|
||||
MinX = X[i];
|
||||
MinY = Y[i];
|
||||
MaxX = X[i];
|
||||
MaxY = Y[i];
|
||||
}
|
||||
else // now compare if you get "better" values
|
||||
{
|
||||
if (MinX > X[i]) MinX = X[i];
|
||||
if (MinY > Y[i]) MinY = Y[i];
|
||||
if (MaxX < X[i]) MaxX = X[i];
|
||||
if (MaxY < Y[i]) MaxY = Y[i];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MinX = 0;
|
||||
MinY = 0;
|
||||
MaxX = 0;
|
||||
MaxY = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TextOverlay::~TextOverlay()
|
||||
{
|
||||
Ogre::OverlayManager::OverlayMapIterator iter = Ogre::OverlayManager::getSingleton().getOverlayIterator();
|
||||
if(!iter.hasMoreElements())
|
||||
mOverlay->hide();
|
||||
|
||||
Ogre::OverlayManager *overlayMgr = Ogre::OverlayManager::getSingletonPtr();
|
||||
mContainer->removeChild("text"+mId+"#"+Ogre::StringConverter::toString(mInstance));
|
||||
mOverlay->remove2D(mContainer);
|
||||
|
||||
if(!iter.hasMoreElements())
|
||||
overlayMgr->destroy(mOverlay);
|
||||
}
|
||||
|
||||
void TextOverlay::show(bool show)
|
||||
{
|
||||
if(show && mOnScreen)
|
||||
mContainer->show();
|
||||
else
|
||||
mContainer->hide();
|
||||
}
|
||||
|
||||
void TextOverlay::enable(bool enable)
|
||||
{
|
||||
if(enable == mOverlay->isVisible())
|
||||
return;
|
||||
|
||||
mEnabled = enable;
|
||||
if(enable)
|
||||
mOverlay->show();
|
||||
else
|
||||
mOverlay->hide();
|
||||
}
|
||||
|
||||
bool TextOverlay::isEnabled()
|
||||
{
|
||||
return mEnabled;
|
||||
}
|
||||
|
||||
void TextOverlay::setCaption(const Ogre::String& text)
|
||||
{
|
||||
if(mCaption == text)
|
||||
return;
|
||||
|
||||
mCaption = text;
|
||||
mElement->setCaption(text);
|
||||
}
|
||||
|
||||
void TextOverlay::setDesc(const Ogre::String& text)
|
||||
{
|
||||
if(mDesc == text)
|
||||
return;
|
||||
|
||||
mDesc = text;
|
||||
mElement->setCaption(mCaption + ((text == "") ? "" : ("\n" + text)));
|
||||
}
|
||||
|
||||
Ogre::FontPtr TextOverlay::getFont()
|
||||
{
|
||||
return mFont;
|
||||
}
|
||||
|
||||
int TextOverlay::textWidth()
|
||||
{
|
||||
float captionWidth = 0;
|
||||
float descWidth = 0;
|
||||
|
||||
for(Ogre::String::const_iterator i = mCaption.begin(); i < mCaption.end(); ++i)
|
||||
{
|
||||
if(*i == 0x0020)
|
||||
captionWidth += getFont()->getGlyphAspectRatio(0x0030);
|
||||
else
|
||||
captionWidth += getFont()->getGlyphAspectRatio(*i);
|
||||
}
|
||||
|
||||
for(Ogre::String::const_iterator i = mDesc.begin(); i < mDesc.end(); ++i)
|
||||
{
|
||||
if(*i == 0x0020)
|
||||
descWidth += getFont()->getGlyphAspectRatio(0x0030);
|
||||
else
|
||||
descWidth += getFont()->getGlyphAspectRatio(*i);
|
||||
}
|
||||
|
||||
captionWidth *= fontHeight();
|
||||
descWidth *= fontHeight();
|
||||
|
||||
return (int) std::max(captionWidth, descWidth);
|
||||
}
|
||||
|
||||
int TextOverlay::fontHeight()
|
||||
{
|
||||
return mFontHeight;
|
||||
}
|
||||
|
||||
void TextOverlay::update()
|
||||
{
|
||||
float min_x, max_x, min_y, max_y;
|
||||
getMinMaxEdgesOfAABBIn2D(min_x, min_y, max_x, max_y, false);
|
||||
|
||||
if ((min_x>0.0) && (max_x<1.0) && (min_y>0.0) && (max_y<1.0))
|
||||
{
|
||||
mOnScreen = true;
|
||||
mContainer->show();
|
||||
}
|
||||
else
|
||||
{
|
||||
mOnScreen = false;
|
||||
mContainer->hide();
|
||||
return;
|
||||
}
|
||||
|
||||
getMinMaxEdgesOfAABBIn2D(min_x, min_y, max_x, max_y);
|
||||
|
||||
Ogre::OverlayManager &overlayMgr = Ogre::OverlayManager::getSingleton();
|
||||
float viewportWidth = std::max(overlayMgr.getViewportWidth(), 1); // zero at the start
|
||||
float viewportHeight = std::max(overlayMgr.getViewportHeight(), 1); // zero at the start
|
||||
|
||||
int width = fontHeight()*2/3 + textWidth() + fontHeight()*2/3; // add margins
|
||||
int height = fontHeight()/3 + fontHeight() + fontHeight()/3;
|
||||
if(mDesc != "")
|
||||
height = fontHeight()/3 + 2*fontHeight() + fontHeight()/3;
|
||||
|
||||
float relTextWidth = width / viewportWidth;
|
||||
float relTextHeight = height / viewportHeight;
|
||||
|
||||
float posX = 1 - (min_x + max_x + relTextWidth)/2;
|
||||
float posY = 1 - max_y - (relTextHeight-fontHeight()/3/viewportHeight);
|
||||
|
||||
mContainer->setMetricsMode(Ogre::GMM_RELATIVE);
|
||||
mContainer->setPosition(posX, posY);
|
||||
mContainer->setDimensions(relTextWidth, relTextHeight);
|
||||
|
||||
mPos = QRect(posX*viewportWidth, posY*viewportHeight, width, height);
|
||||
}
|
||||
|
||||
QRect TextOverlay::container()
|
||||
{
|
||||
return mPos;
|
||||
}
|
||||
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
#ifndef OPENCS_VIEW_TEXTOVERLAY_H
|
||||
#define OPENCS_VIEW_TEXTOVERLAY_H
|
||||
|
||||
#include <QRect>
|
||||
|
||||
#include <OgreString.h>
|
||||
#include <OgreFont.h>
|
||||
|
||||
namespace Ogre
|
||||
{
|
||||
class MovableObject;
|
||||
class Camera;
|
||||
class Font;
|
||||
class Overlay;
|
||||
class OverlayContainer;
|
||||
class TextAreaOverlayElement;
|
||||
}
|
||||
|
||||
namespace CSVRender
|
||||
{
|
||||
|
||||
class TextOverlay
|
||||
{
|
||||
Ogre::Overlay* mOverlay;
|
||||
Ogre::OverlayContainer* mContainer;
|
||||
Ogre::TextAreaOverlayElement* mElement;
|
||||
Ogre::String mCaption;
|
||||
Ogre::String mDesc;
|
||||
|
||||
const Ogre::MovableObject* mObj;
|
||||
const Ogre::Camera* mCamera;
|
||||
Ogre::FontPtr mFont;
|
||||
int mFontHeight; // in pixels
|
||||
Ogre::String mId;
|
||||
QRect mPos;
|
||||
|
||||
bool mEnabled;
|
||||
bool mOnScreen;
|
||||
int mInstance;
|
||||
|
||||
Ogre::FontPtr getFont();
|
||||
int textWidth();
|
||||
int fontHeight();
|
||||
void getScreenCoordinates(const Ogre::Vector3& position, Ogre::Real& x, Ogre::Real& y);
|
||||
void getMinMaxEdgesOfAABBIn2D(float& MinX, float& MinY, float& MaxX, float& MaxY,
|
||||
bool top = true);
|
||||
|
||||
public:
|
||||
|
||||
TextOverlay(const Ogre::MovableObject* obj, const Ogre::Camera* camera, const Ogre::String &id);
|
||||
virtual ~TextOverlay();
|
||||
|
||||
void enable(bool enable); // controlled from scene widget toolbar visibility mask
|
||||
void show(bool show); // for updating from render target listener
|
||||
bool isEnabled();
|
||||
void setCaption(const Ogre::String& text);
|
||||
void setDesc(const Ogre::String& text);
|
||||
void update();
|
||||
QRect container(); // for detection of mouse click on the overlay
|
||||
Ogre::String getCaption() { return mCaption; } // FIXME: debug
|
||||
Ogre::String getDesc() { return mDesc; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // OPENCS_VIEW_TEXTOVERLAY_H
|
@ -0,0 +1,28 @@
|
||||
#include "completerpopup.hpp"
|
||||
|
||||
CSVWidget::CompleterPopup::CompleterPopup(QWidget *parent)
|
||||
: QListView(parent)
|
||||
{
|
||||
setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
}
|
||||
|
||||
int CSVWidget::CompleterPopup::sizeHintForRow(int row) const
|
||||
{
|
||||
if (model() == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (row < 0 || row >= model()->rowCount())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
ensurePolished();
|
||||
QModelIndex index = model()->index(row, modelColumn());
|
||||
QStyleOptionViewItem option = viewOptions();
|
||||
QAbstractItemDelegate *delegate = itemDelegate(index);
|
||||
return delegate->sizeHint(option, index).height();
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
#ifndef CSV_WIDGET_COMPLETERPOPUP_HPP
|
||||
#define CSV_WIDGET_COMPLETERPOPUP_HPP
|
||||
|
||||
#include <QListView>
|
||||
|
||||
namespace CSVWidget
|
||||
{
|
||||
class CompleterPopup : public QListView
|
||||
{
|
||||
public:
|
||||
CompleterPopup(QWidget *parent = 0);
|
||||
|
||||
virtual int sizeHintForRow(int row) const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,39 @@
|
||||
#include "idcompletiondelegate.hpp"
|
||||
|
||||
#include "../../model/world/idcompletionmanager.hpp"
|
||||
|
||||
CSVWorld::IdCompletionDelegate::IdCompletionDelegate(CSMWorld::CommandDispatcher *dispatcher,
|
||||
CSMDoc::Document& document,
|
||||
QObject *parent)
|
||||
: CommandDelegate(dispatcher, document, parent)
|
||||
{}
|
||||
|
||||
QWidget *CSVWorld::IdCompletionDelegate::createEditor(QWidget *parent,
|
||||
const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
return createEditor(parent, option, index, getDisplayTypeFromIndex(index));
|
||||
}
|
||||
|
||||
QWidget *CSVWorld::IdCompletionDelegate::createEditor(QWidget *parent,
|
||||
const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index,
|
||||
CSMWorld::ColumnBase::Display display) const
|
||||
{
|
||||
if (!index.data(Qt::EditRole).isValid() && !index.data(Qt::DisplayRole).isValid())
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CSMWorld::IdCompletionManager &completionManager = getDocument().getIdCompletionManager();
|
||||
DropLineEdit *editor = new DropLineEdit(parent);
|
||||
editor->setCompleter(completionManager.getCompleter(display).get());
|
||||
return editor;
|
||||
}
|
||||
|
||||
CSVWorld::CommandDelegate *CSVWorld::IdCompletionDelegateFactory::makeDelegate(CSMWorld::CommandDispatcher *dispatcher,
|
||||
CSMDoc::Document& document,
|
||||
QObject *parent) const
|
||||
{
|
||||
return new IdCompletionDelegate(dispatcher, document, parent);
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
#ifndef CSV_WORLD_IDCOMPLETIONDELEGATE_HPP
|
||||
#define CSV_WORLD_IDCOMPLETIONDELEGATE_HPP
|
||||
|
||||
#include "util.hpp"
|
||||
|
||||
namespace CSVWorld
|
||||
{
|
||||
/// \brief Enables the Id completion for a column
|
||||
class IdCompletionDelegate : public CommandDelegate
|
||||
{
|
||||
public:
|
||||
IdCompletionDelegate(CSMWorld::CommandDispatcher *dispatcher,
|
||||
CSMDoc::Document& document,
|
||||
QObject *parent);
|
||||
|
||||
virtual QWidget *createEditor (QWidget *parent,
|
||||
const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const;
|
||||
|
||||
virtual QWidget *createEditor (QWidget *parent,
|
||||
const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index,
|
||||
CSMWorld::ColumnBase::Display display) const;
|
||||
};
|
||||
|
||||
class IdCompletionDelegateFactory : public CommandDelegateFactory
|
||||
{
|
||||
public:
|
||||
virtual CommandDelegate *makeDelegate(CSMWorld::CommandDispatcher *dispatcher,
|
||||
CSMDoc::Document& document,
|
||||
QObject *parent) const;
|
||||
///< The ownership of the returned CommandDelegate is transferred to the caller.
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -1,324 +0,0 @@
|
||||
#include "physicssystem.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <OgreRay.h>
|
||||
#include <OgreCamera.h>
|
||||
#include <OgreSceneManager.h>
|
||||
|
||||
#include <openengine/bullet/physic.hpp>
|
||||
#include <components/nifbullet/bulletnifloader.hpp>
|
||||
#include "../../model/settings/usersettings.hpp"
|
||||
#include "../render/elements.hpp"
|
||||
|
||||
namespace CSVWorld
|
||||
{
|
||||
PhysicsSystem::PhysicsSystem()
|
||||
{
|
||||
// Create physics. shapeLoader is deleted by the physic engine
|
||||
NifBullet::ManualBulletShapeLoader* shapeLoader = new NifBullet::ManualBulletShapeLoader(true);
|
||||
mEngine = new OEngine::Physic::PhysicEngine(shapeLoader);
|
||||
}
|
||||
|
||||
PhysicsSystem::~PhysicsSystem()
|
||||
{
|
||||
delete mEngine;
|
||||
}
|
||||
|
||||
// looks up the scene manager based on the scene node name (inefficient)
|
||||
// NOTE: referenceId is assumed to be unique per document
|
||||
// NOTE: searching is done here rather than after rayTest, hence slower to load but
|
||||
// faster to find (guessing, not verified w/ perf test)
|
||||
void PhysicsSystem::addObject(const std::string &mesh,
|
||||
const std::string &sceneNodeName, const std::string &referenceId, float scale,
|
||||
const Ogre::Vector3 &position, const Ogre::Quaternion &rotation, bool placeable)
|
||||
{
|
||||
Ogre::SceneManager *sceneManager = findSceneManager(sceneNodeName);
|
||||
if(sceneManager)
|
||||
{
|
||||
// update maps (NOTE: sometimes replaced)
|
||||
mSceneNodeToRefId[sceneNodeName] = referenceId;
|
||||
mSceneNodeToMesh[sceneNodeName] = mesh;
|
||||
mRefIdToSceneNode[referenceId][sceneManager] = sceneNodeName;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Attempt to add an object without a corresponding SceneManager: "
|
||||
+ referenceId + " : " + sceneNodeName << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// update physics, only one physics model per referenceId
|
||||
if(mEngine->getRigidBody(referenceId, true) == NULL)
|
||||
{
|
||||
mEngine->createAndAdjustRigidBody(mesh,
|
||||
referenceId, scale, position, rotation,
|
||||
0, // scaledBoxTranslation
|
||||
0, // boxRotation
|
||||
true, // raycasting
|
||||
placeable);
|
||||
}
|
||||
}
|
||||
|
||||
// normal delete (e.g closing a scene subview or ~Object())
|
||||
// the scene node is destroyed so the mappings should be removed
|
||||
//
|
||||
// TODO: should think about using some kind of reference counting within RigidBody
|
||||
void PhysicsSystem::removeObject(const std::string &sceneNodeName)
|
||||
{
|
||||
std::string referenceId = mSceneNodeToRefId[sceneNodeName];
|
||||
|
||||
if(referenceId != "")
|
||||
{
|
||||
mSceneNodeToRefId.erase(sceneNodeName);
|
||||
mSceneNodeToMesh.erase(sceneNodeName);
|
||||
|
||||
// find which SceneManager has this object
|
||||
Ogre::SceneManager *sceneManager = findSceneManager(sceneNodeName);
|
||||
if(!sceneManager)
|
||||
{
|
||||
std::cerr << "Attempt to remove an object without a corresponding SceneManager: "
|
||||
+ sceneNodeName << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// illustration: erase the object "K" from the object map
|
||||
//
|
||||
// RidigBody SubView Ogre
|
||||
// --------------- -------------- -------------
|
||||
// ReferenceId "A" (SceneManager X SceneNode "J")
|
||||
// (SceneManager Y SceneNode "K") <--- erase
|
||||
// (SceneManager Z SceneNode "L")
|
||||
//
|
||||
// ReferenceId "B" (SceneManager X SceneNode "M")
|
||||
// (SceneManager Y SceneNode "N") <--- notice not deleted
|
||||
// (SceneManager Z SceneNode "O")
|
||||
std::map<std::string, std::map<Ogre::SceneManager *, std::string> >::iterator itRef =
|
||||
mRefIdToSceneNode.begin();
|
||||
for(; itRef != mRefIdToSceneNode.end(); ++itRef)
|
||||
{
|
||||
if((*itRef).second.find(sceneManager) != (*itRef).second.end())
|
||||
{
|
||||
(*itRef).second.erase(sceneManager);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// check whether the physics model should be deleted
|
||||
if(mRefIdToSceneNode.find(referenceId) == mRefIdToSceneNode.end())
|
||||
{
|
||||
mEngine->removeRigidBody(referenceId);
|
||||
mEngine->deleteRigidBody(referenceId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Object::clear() is called when reference data is changed. It clears all
|
||||
// contents of the SceneNode and removes the physics object
|
||||
//
|
||||
// A new physics object will be created and assigned to this sceneNodeName by
|
||||
// Object::update()
|
||||
void PhysicsSystem::removePhysicsObject(const std::string &sceneNodeName)
|
||||
{
|
||||
std::string referenceId = mSceneNodeToRefId[sceneNodeName];
|
||||
|
||||
if(referenceId != "")
|
||||
{
|
||||
mEngine->removeRigidBody(referenceId);
|
||||
mEngine->deleteRigidBody(referenceId);
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsSystem::replaceObject(const std::string &sceneNodeName, float scale,
|
||||
const Ogre::Vector3 &position, const Ogre::Quaternion &rotation, bool placeable)
|
||||
{
|
||||
std::string referenceId = mSceneNodeToRefId[sceneNodeName];
|
||||
std::string mesh = mSceneNodeToMesh[sceneNodeName];
|
||||
|
||||
if(referenceId != "")
|
||||
{
|
||||
// delete the physics object
|
||||
mEngine->removeRigidBody(referenceId);
|
||||
mEngine->deleteRigidBody(referenceId);
|
||||
|
||||
// create a new physics object
|
||||
mEngine->createAndAdjustRigidBody(mesh, referenceId, scale, position, rotation,
|
||||
0, 0, true, placeable);
|
||||
|
||||
// update other scene managers if they have the referenceId
|
||||
// FIXME: rotation or scale not updated
|
||||
moveSceneNodeImpl(sceneNodeName, referenceId, position);
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: adjustRigidBody() seems to lose objects, work around by deleting and recreating objects
|
||||
void PhysicsSystem::moveObject(const std::string &sceneNodeName,
|
||||
const Ogre::Vector3 &position, const Ogre::Quaternion &rotation)
|
||||
{
|
||||
mEngine->adjustRigidBody(mEngine->getRigidBody(sceneNodeName, true /*raycasting*/),
|
||||
position, rotation);
|
||||
}
|
||||
|
||||
void PhysicsSystem::moveSceneNodeImpl(const std::string sceneNodeName,
|
||||
const std::string referenceId, const Ogre::Vector3 &position)
|
||||
{
|
||||
std::map<Ogre::SceneManager *, CSVRender::SceneWidget *>::const_iterator iter = mSceneWidgets.begin();
|
||||
for(; iter != mSceneWidgets.end(); ++iter)
|
||||
{
|
||||
std::string name = refIdToSceneNode(referenceId, (*iter).first);
|
||||
if(name != sceneNodeName && (*iter).first->hasSceneNode(name))
|
||||
{
|
||||
(*iter).first->getSceneNode(name)->setPosition(position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsSystem::moveSceneNodes(const std::string sceneNodeName, const Ogre::Vector3 &position)
|
||||
{
|
||||
moveSceneNodeImpl(sceneNodeName, sceneNodeToRefId(sceneNodeName), position);
|
||||
}
|
||||
|
||||
void PhysicsSystem::addHeightField(Ogre::SceneManager *sceneManager,
|
||||
float* heights, int x, int y, float yoffset, float triSize, float sqrtVerts)
|
||||
{
|
||||
std::string name = "HeightField_"
|
||||
+ QString::number(x).toStdString() + "_" + QString::number(y).toStdString();
|
||||
|
||||
if(mTerrain.find(name) == mTerrain.end())
|
||||
mEngine->addHeightField(heights, x, y, yoffset, triSize, sqrtVerts);
|
||||
|
||||
mTerrain.insert(std::pair<std::string, Ogre::SceneManager *>(name, sceneManager));
|
||||
}
|
||||
|
||||
void PhysicsSystem::removeHeightField(Ogre::SceneManager *sceneManager, int x, int y)
|
||||
{
|
||||
std::string name = "HeightField_"
|
||||
+ QString::number(x).toStdString() + "_" + QString::number(y).toStdString();
|
||||
|
||||
if(mTerrain.count(name) == 1)
|
||||
mEngine->removeHeightField(x, y);
|
||||
|
||||
std::multimap<std::string, Ogre::SceneManager *>::iterator iter = mTerrain.begin();
|
||||
for(; iter != mTerrain.end(); ++iter)
|
||||
{
|
||||
if((*iter).second == sceneManager)
|
||||
{
|
||||
mTerrain.erase(iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// sceneMgr: to lookup the scene node name from the object's referenceId
|
||||
// camera: primarily used to get the visibility mask for the viewport
|
||||
//
|
||||
// returns the found object's scene node name and its position in the world space
|
||||
//
|
||||
// WARNING: far clip distance is a global setting, if it changes in future
|
||||
// this method will need to be updated
|
||||
std::pair<std::string, Ogre::Vector3> PhysicsSystem::castRay(float mouseX,
|
||||
float mouseY, Ogre::SceneManager *sceneMgr, Ogre::Camera *camera)
|
||||
{
|
||||
// NOTE: there could be more than one camera for the scene manager
|
||||
// TODO: check whether camera belongs to sceneMgr
|
||||
if(!sceneMgr || !camera || !camera->getViewport())
|
||||
return std::make_pair("", Ogre::Vector3(0,0,0)); // FIXME: this should be an exception
|
||||
|
||||
// using a really small value seems to mess up with the projections
|
||||
float nearClipDistance = camera->getNearClipDistance(); // save existing
|
||||
camera->setNearClipDistance(10.0f); // arbitrary number
|
||||
Ogre::Ray ray = camera->getCameraToViewportRay(mouseX, mouseY);
|
||||
camera->setNearClipDistance(nearClipDistance); // restore
|
||||
|
||||
Ogre::Vector3 from = ray.getOrigin();
|
||||
CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance();
|
||||
float farClipDist = userSettings.setting("Scene/far clip distance", QString("300000")).toFloat();
|
||||
Ogre::Vector3 to = ray.getPoint(farClipDist);
|
||||
|
||||
btVector3 _from, _to;
|
||||
_from = btVector3(from.x, from.y, from.z);
|
||||
_to = btVector3(to.x, to.y, to.z);
|
||||
|
||||
uint32_t visibilityMask = camera->getViewport()->getVisibilityMask();
|
||||
bool ignoreHeightMap = !(visibilityMask & (uint32_t)CSVRender::Element_Terrain);
|
||||
bool ignoreObjects = !(visibilityMask & (uint32_t)CSVRender::Element_Reference);
|
||||
|
||||
Ogre::Vector3 norm; // not used
|
||||
std::pair<std::string, float> result =
|
||||
mEngine->rayTest(_from, _to, !ignoreObjects, ignoreHeightMap, &norm);
|
||||
|
||||
// result.first is the object's referenceId
|
||||
if(result.first == "")
|
||||
return std::make_pair("", Ogre::Vector3(0,0,0));
|
||||
else
|
||||
{
|
||||
std::string name = refIdToSceneNode(result.first, sceneMgr);
|
||||
if(name == "")
|
||||
name = result.first;
|
||||
else
|
||||
name = refIdToSceneNode(result.first, sceneMgr);
|
||||
|
||||
return std::make_pair(name, ray.getPoint(farClipDist*result.second));
|
||||
}
|
||||
}
|
||||
|
||||
std::string PhysicsSystem::refIdToSceneNode(std::string referenceId, Ogre::SceneManager *sceneMgr)
|
||||
{
|
||||
return mRefIdToSceneNode[referenceId][sceneMgr];
|
||||
}
|
||||
|
||||
std::string PhysicsSystem::sceneNodeToRefId(std::string sceneNodeName)
|
||||
{
|
||||
return mSceneNodeToRefId[sceneNodeName];
|
||||
}
|
||||
|
||||
void PhysicsSystem::addSceneManager(Ogre::SceneManager *sceneMgr, CSVRender::SceneWidget *sceneWidget)
|
||||
{
|
||||
mSceneWidgets[sceneMgr] = sceneWidget;
|
||||
|
||||
mEngine->createDebugDraw(sceneMgr);
|
||||
}
|
||||
|
||||
std::map<Ogre::SceneManager*, CSVRender::SceneWidget *> PhysicsSystem::sceneWidgets()
|
||||
{
|
||||
return mSceneWidgets;
|
||||
}
|
||||
|
||||
void PhysicsSystem::removeSceneManager(Ogre::SceneManager *sceneMgr)
|
||||
{
|
||||
mEngine->removeDebugDraw(sceneMgr);
|
||||
|
||||
mSceneWidgets.erase(sceneMgr);
|
||||
}
|
||||
|
||||
Ogre::SceneManager *PhysicsSystem::findSceneManager(std::string sceneNodeName)
|
||||
{
|
||||
std::map<Ogre::SceneManager *, CSVRender::SceneWidget *>::const_iterator iter = mSceneWidgets.begin();
|
||||
for(; iter != mSceneWidgets.end(); ++iter)
|
||||
{
|
||||
if((*iter).first->hasSceneNode(sceneNodeName))
|
||||
{
|
||||
return (*iter).first;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void PhysicsSystem::toggleDebugRendering(Ogre::SceneManager *sceneMgr)
|
||||
{
|
||||
// FIXME: should check if sceneMgr is in the list
|
||||
if(!sceneMgr)
|
||||
return;
|
||||
|
||||
CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance();
|
||||
if(!(userSettings.setting("debug/mouse-picking", QString("false")) == "true" ? true : false))
|
||||
{
|
||||
std::cerr << "Turn on mouse-picking debug option to see collision shapes." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
mEngine->toggleDebugRendering(sceneMgr);
|
||||
mEngine->stepDebug(sceneMgr);
|
||||
}
|
||||
}
|
@ -1,94 +0,0 @@
|
||||
#ifndef CSV_WORLD_PHYSICSSYSTEM_H
|
||||
#define CSV_WORLD_PHYSICSSYSTEM_H
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
namespace Ogre
|
||||
{
|
||||
class Vector3;
|
||||
class Quaternion;
|
||||
class SceneManager;
|
||||
class Camera;
|
||||
}
|
||||
|
||||
namespace OEngine
|
||||
{
|
||||
namespace Physic
|
||||
{
|
||||
class PhysicEngine;
|
||||
}
|
||||
}
|
||||
|
||||
namespace CSVRender
|
||||
{
|
||||
class SceneWidget;
|
||||
}
|
||||
|
||||
namespace CSVWorld
|
||||
{
|
||||
class PhysicsSystem
|
||||
{
|
||||
std::map<std::string, std::string> mSceneNodeToRefId;
|
||||
std::map<std::string, std::map<Ogre::SceneManager *, std::string> > mRefIdToSceneNode;
|
||||
std::map<std::string, std::string> mSceneNodeToMesh;
|
||||
std::map<Ogre::SceneManager*, CSVRender::SceneWidget *> mSceneWidgets;
|
||||
OEngine::Physic::PhysicEngine* mEngine;
|
||||
std::multimap<std::string, Ogre::SceneManager *> mTerrain;
|
||||
|
||||
public:
|
||||
|
||||
PhysicsSystem();
|
||||
~PhysicsSystem();
|
||||
|
||||
void addSceneManager(Ogre::SceneManager *sceneMgr, CSVRender::SceneWidget * scene);
|
||||
|
||||
void removeSceneManager(Ogre::SceneManager *sceneMgr);
|
||||
|
||||
void addObject(const std::string &mesh,
|
||||
const std::string &sceneNodeName, const std::string &referenceId, float scale,
|
||||
const Ogre::Vector3 &position, const Ogre::Quaternion &rotation,
|
||||
bool placeable=false);
|
||||
|
||||
void removeObject(const std::string &sceneNodeName);
|
||||
void removePhysicsObject(const std::string &sceneNodeName);
|
||||
|
||||
void replaceObject(const std::string &sceneNodeName,
|
||||
float scale, const Ogre::Vector3 &position,
|
||||
const Ogre::Quaternion &rotation, bool placeable=false);
|
||||
|
||||
void moveObject(const std::string &sceneNodeName,
|
||||
const Ogre::Vector3 &position, const Ogre::Quaternion &rotation);
|
||||
|
||||
void moveSceneNodes(const std::string sceneNodeName, const Ogre::Vector3 &position);
|
||||
|
||||
void addHeightField(Ogre::SceneManager *sceneManager,
|
||||
float* heights, int x, int y, float yoffset, float triSize, float sqrtVerts);
|
||||
|
||||
void removeHeightField(Ogre::SceneManager *sceneManager, int x, int y);
|
||||
|
||||
void toggleDebugRendering(Ogre::SceneManager *sceneMgr);
|
||||
|
||||
// return the object's SceneNode name and position for the given SceneManager
|
||||
std::pair<std::string, Ogre::Vector3> castRay(float mouseX,
|
||||
float mouseY, Ogre::SceneManager *sceneMgr, Ogre::Camera *camera);
|
||||
|
||||
std::string sceneNodeToRefId(std::string sceneNodeName);
|
||||
|
||||
// for multi-scene manager per physics engine
|
||||
std::map<Ogre::SceneManager*, CSVRender::SceneWidget *> sceneWidgets();
|
||||
|
||||
private:
|
||||
|
||||
void moveSceneNodeImpl(const std::string sceneNodeName,
|
||||
const std::string referenceId, const Ogre::Vector3 &position);
|
||||
|
||||
void updateSelectionHighlight(std::string sceneNode, const Ogre::Vector3 &position);
|
||||
|
||||
std::string refIdToSceneNode(std::string referenceId, Ogre::SceneManager *sceneMgr);
|
||||
|
||||
Ogre::SceneManager *findSceneManager(std::string sceneNodeName);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CSV_WORLD_PHYSICSSYSTEM_H
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue