1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-03-30 09:06:43 +00:00

Experimental, compiles but does not work.

This commit is contained in:
cc9cii 2014-10-18 06:16:48 +11:00
parent 5f11ccc298
commit 03a30c3f1d
12 changed files with 178 additions and 15 deletions

View file

@ -68,7 +68,7 @@ opencs_units (view/world
opencs_units_noqt (view/world opencs_units_noqt (view/world
subviews enumdelegate vartypedelegate recordstatusdelegate idtypedelegate datadisplaydelegate subviews enumdelegate vartypedelegate recordstatusdelegate idtypedelegate datadisplaydelegate
scripthighlighter idvalidator dialoguecreator scripthighlighter idvalidator dialoguecreator physicssystem
) )
opencs_units (view/widget opencs_units (view/widget
@ -165,7 +165,7 @@ qt4_wrap_ui(OPENCS_UI_HDR ${OPENCS_UI})
qt4_wrap_cpp(OPENCS_MOC_SRC ${OPENCS_HDR_QT}) qt4_wrap_cpp(OPENCS_MOC_SRC ${OPENCS_HDR_QT})
qt4_add_resources(OPENCS_RES_SRC ${OPENCS_RES}) qt4_add_resources(OPENCS_RES_SRC ${OPENCS_RES})
include_directories(${CMAKE_CURRENT_BINARY_DIR}) include_directories(${CMAKE_CURRENT_BINARY_DIR} ${BULLET_INCLUDE_DIRS})
if(APPLE) if(APPLE)
set (OPENCS_MAC_ICON ${CMAKE_SOURCE_DIR}/files/mac/opencs.icns) set (OPENCS_MAC_ICON ${CMAKE_SOURCE_DIR}/files/mac/opencs.icns)
@ -175,6 +175,7 @@ endif(APPLE)
add_executable(opencs add_executable(opencs
MACOSX_BUNDLE MACOSX_BUNDLE
${OENGINE_BULLET}
${OPENCS_SRC} ${OPENCS_SRC}
${OPENCS_UI_HDR} ${OPENCS_UI_HDR}
${OPENCS_MOC_SRC} ${OPENCS_MOC_SRC}
@ -203,6 +204,7 @@ target_link_libraries(opencs
${OGRE_STATIC_PLUGINS} ${OGRE_STATIC_PLUGINS}
${SHINY_LIBRARIES} ${SHINY_LIBRARIES}
${Boost_LIBRARIES} ${Boost_LIBRARIES}
${BULLET_LIBRARIES}
${QT_LIBRARIES} ${QT_LIBRARIES}
components components
) )

View file

@ -10,6 +10,8 @@
#include "../../model/world/columns.hpp" #include "../../model/world/columns.hpp"
#include "../../model/world/data.hpp" #include "../../model/world/data.hpp"
#include "../world/physicssystem.hpp"
#include "elements.hpp" #include "elements.hpp"
#include "terrainstorage.hpp" #include "terrainstorage.hpp"
@ -49,7 +51,7 @@ bool CSVRender::Cell::addObjects (int start, int end)
std::string id = Misc::StringUtils::lowerCase (references.data ( std::string id = Misc::StringUtils::lowerCase (references.data (
references.index (i, idColumn)).toString().toUtf8().constData()); references.index (i, idColumn)).toString().toUtf8().constData());
mObjects.insert (std::make_pair (id, new Object (mData, mCellNode, id, false))); mObjects.insert (std::make_pair (id, new Object (mData, mCellNode, id, false, mPhysics)));
modified = true; modified = true;
} }
} }
@ -58,8 +60,8 @@ bool CSVRender::Cell::addObjects (int start, int end)
} }
CSVRender::Cell::Cell (CSMWorld::Data& data, Ogre::SceneManager *sceneManager, CSVRender::Cell::Cell (CSMWorld::Data& data, Ogre::SceneManager *sceneManager,
const std::string& id, const Ogre::Vector3& origin) const std::string& id, CSVWorld::PhysicsSystem *physics, const Ogre::Vector3& origin)
: mData (data), mId (Misc::StringUtils::lowerCase (id)) : mData (data), mId (Misc::StringUtils::lowerCase (id)), mPhysics(physics)
{ {
mCellNode = sceneManager->getRootSceneNode()->createChildSceneNode(); mCellNode = sceneManager->getRootSceneNode()->createChildSceneNode();
mCellNode->setPosition (origin); mCellNode->setPosition (origin);
@ -82,6 +84,9 @@ CSVRender::Cell::Cell (CSMWorld::Data& data, Ogre::SceneManager *sceneManager,
mTerrain->loadCell(esmLand->mX, mTerrain->loadCell(esmLand->mX,
esmLand->mY); esmLand->mY);
} }
std::cout << "cell pos" + std::to_string(mCellNode->getPosition().x)
+ ", " + std::to_string(mCellNode->getPosition().y)
+ ", " + std::to_string(mCellNode->getPosition().z) << std::endl;
} }
CSVRender::Cell::~Cell() CSVRender::Cell::~Cell()

View file

@ -23,6 +23,11 @@ namespace CSMWorld
class Data; class Data;
} }
namespace CSVWorld
{
class PhysicsSystem;
}
namespace CSVRender namespace CSVRender
{ {
class Cell class Cell
@ -32,6 +37,7 @@ namespace CSVRender
Ogre::SceneNode *mCellNode; Ogre::SceneNode *mCellNode;
std::map<std::string, Object *> mObjects; std::map<std::string, Object *> mObjects;
std::auto_ptr<Terrain::TerrainGrid> mTerrain; std::auto_ptr<Terrain::TerrainGrid> mTerrain;
CSVWorld::PhysicsSystem *mPhysics;
/// Ignored if cell does not have an object with the given ID. /// Ignored if cell does not have an object with the given ID.
/// ///
@ -46,7 +52,8 @@ namespace CSVRender
public: public:
Cell (CSMWorld::Data& data, Ogre::SceneManager *sceneManager, Cell (CSMWorld::Data& data, Ogre::SceneManager *sceneManager,
const std::string& id, const Ogre::Vector3& origin = Ogre::Vector3 (0, 0, 0)); const std::string& id, CSVWorld::PhysicsSystem *physics,
const Ogre::Vector3& origin = Ogre::Vector3 (0, 0, 0));
~Cell(); ~Cell();

View file

@ -9,6 +9,8 @@
#include "../../model/world/ref.hpp" #include "../../model/world/ref.hpp"
#include "../../model/world/refidcollection.hpp" #include "../../model/world/refidcollection.hpp"
#include "../world/physicssystem.hpp"
#include "elements.hpp" #include "elements.hpp"
void CSVRender::Object::clearSceneNode (Ogre::SceneNode *node) void CSVRender::Object::clearSceneNode (Ogre::SceneNode *node)
@ -73,6 +75,12 @@ void CSVRender::Object::update()
{ {
mObject = NifOgre::Loader::createObjects (mBase, "Meshes\\" + model); mObject = NifOgre::Loader::createObjects (mBase, "Meshes\\" + model);
mObject->setVisibilityFlags (Element_Reference); mObject->setVisibilityFlags (Element_Reference);
bool placeable = true; // FIXME
mPhysics->addObject("meshes\\" + model, mBase->getName(), /*scale*/1,
mBase->getPosition(), mBase->getOrientation(), 0, 0, false, placeable);
mPhysics->addObject("meshes\\" + model, mBase->getName(), /*scale*/1,
mBase->getPosition(), mBase->getOrientation(), 0, 0, true, placeable); // FIXME: why again with raycasting?
} }
} }
@ -110,8 +118,9 @@ const CSMWorld::CellRef& CSVRender::Object::getReference() const
} }
CSVRender::Object::Object (const CSMWorld::Data& data, Ogre::SceneNode *cellNode, CSVRender::Object::Object (const CSMWorld::Data& data, Ogre::SceneNode *cellNode,
const std::string& id, bool referenceable, bool forceBaseToZero) const std::string& id, bool referenceable, CSVWorld::PhysicsSystem* physics,
: mData (data), mBase (0), mForceBaseToZero (forceBaseToZero) bool forceBaseToZero)
: mData (data), mBase (0), mForceBaseToZero (forceBaseToZero), mPhysics(physics)
{ {
mBase = cellNode->createChildSceneNode(); mBase = cellNode->createChildSceneNode();
@ -214,4 +223,4 @@ std::string CSVRender::Object::getReferenceId() const
std::string CSVRender::Object::getReferenceableId() const std::string CSVRender::Object::getReferenceableId() const
{ {
return mReferenceableId; return mReferenceableId;
} }

View file

@ -16,6 +16,11 @@ namespace CSMWorld
class CellRef; class CellRef;
} }
namespace CSVWorld
{
class PhysicsSystem;
}
namespace CSVRender namespace CSVRender
{ {
class Object class Object
@ -26,6 +31,7 @@ namespace CSVRender
Ogre::SceneNode *mBase; Ogre::SceneNode *mBase;
NifOgre::ObjectScenePtr mObject; NifOgre::ObjectScenePtr mObject;
bool mForceBaseToZero; bool mForceBaseToZero;
CSVWorld::PhysicsSystem *mPhysics;
/// Not implemented /// Not implemented
Object (const Object&); Object (const Object&);
@ -51,7 +57,8 @@ namespace CSVRender
public: public:
Object (const CSMWorld::Data& data, Ogre::SceneNode *cellNode, Object (const CSMWorld::Data& data, Ogre::SceneNode *cellNode,
const std::string& id, bool referenceable, bool forceBaseToZero = false); const std::string& id, bool referenceable,
CSVWorld::PhysicsSystem *physics = NULL, bool forceBaseToZero = false);
/// \param forceBaseToZero If this is a reference ignore the coordinates and place /// \param forceBaseToZero If this is a reference ignore the coordinates and place
/// it at 0, 0, 0 instead. /// it at 0, 0, 0 instead.
@ -77,4 +84,4 @@ namespace CSVRender
}; };
} }
#endif #endif

View file

@ -21,6 +21,7 @@
#include "../../model/world/idtable.hpp" #include "../../model/world/idtable.hpp"
#include "../widget/scenetooltoggle.hpp" #include "../widget/scenetooltoggle.hpp"
#include "../world/physicssystem.hpp"
#include "elements.hpp" #include "elements.hpp"
@ -108,7 +109,8 @@ bool CSVRender::PagedWorldspaceWidget::adjustCells()
if (index > 0 && cells.getRecord (index).mState!=CSMWorld::RecordBase::State_Deleted && if (index > 0 && cells.getRecord (index).mState!=CSMWorld::RecordBase::State_Deleted &&
mCells.find (*iter)==mCells.end()) mCells.find (*iter)==mCells.end())
{ {
Cell *cell = new Cell (mDocument.getData(), getSceneManager(), iter->getId (mWorldspace)); Cell *cell = new Cell (mDocument.getData(), getSceneManager(),
iter->getId (mWorldspace), getPhysics());
mCells.insert (std::make_pair (*iter, cell)); mCells.insert (std::make_pair (*iter, cell));
float height = cell->getTerrainHeightAt(Ogre::Vector3( float height = cell->getTerrainHeightAt(Ogre::Vector3(
@ -191,6 +193,7 @@ void CSVRender::PagedWorldspaceWidget::mouseDoubleClickEvent (QMouseEvent *event
if(event->button() == Qt::RightButton) if(event->button() == Qt::RightButton)
{ {
std::cout << "double clicked" << std::endl; std::cout << "double clicked" << std::endl;
getPhysics()->toggleDebugRendering();
} }
} }

View file

@ -10,7 +10,7 @@
CSVRender::PreviewWidget::PreviewWidget (CSMWorld::Data& data, CSVRender::PreviewWidget::PreviewWidget (CSMWorld::Data& data,
const std::string& id, bool referenceable, QWidget *parent) const std::string& id, bool referenceable, QWidget *parent)
: SceneWidget (parent), mData (data), : SceneWidget (parent), mData (data),
mObject (data, getSceneManager()->getRootSceneNode(), id, referenceable, true) mObject (data, getSceneManager()->getRootSceneNode(), id, referenceable, getPhysics(), true)
{ {
setNavigation (&mOrbit); setNavigation (&mOrbit);

View file

@ -13,6 +13,8 @@
#include <OgreViewport.h> #include <OgreViewport.h>
#include <OgreOverlaySystem.h> #include <OgreOverlaySystem.h>
#include "../world/physicssystem.hpp"
#include "../widget/scenetoolmode.hpp" #include "../widget/scenetoolmode.hpp"
#include "../../model/settings/usersettings.hpp" #include "../../model/settings/usersettings.hpp"
@ -64,6 +66,8 @@ namespace CSVRender
mOverlaySystem = OverlaySystem::instance().get(); mOverlaySystem = OverlaySystem::instance().get();
mSceneMgr->addRenderQueueListener(mOverlaySystem); mSceneMgr->addRenderQueueListener(mOverlaySystem);
mPhysics = new CSVWorld::PhysicsSystem(mSceneMgr);
QTimer *timer = new QTimer (this); QTimer *timer = new QTimer (this);
connect (timer, SIGNAL (timeout()), this, SLOT (update())); connect (timer, SIGNAL (timeout()), this, SLOT (update()));
@ -171,6 +175,7 @@ namespace CSVRender
if (mSceneMgr) if (mSceneMgr)
Ogre::Root::getSingleton().destroySceneManager (mSceneMgr); Ogre::Root::getSingleton().destroySceneManager (mSceneMgr);
delete mPhysics;
} }
void SceneWidget::setVisibilityMask (unsigned int mask) void SceneWidget::setVisibilityMask (unsigned int mask)
@ -206,6 +211,11 @@ namespace CSVRender
return mViewport; return mViewport;
} }
CSVWorld::PhysicsSystem *SceneWidget::getPhysics()
{
return mPhysics;
}
Ogre::SceneManager *SceneWidget::getSceneManager() Ogre::SceneManager *SceneWidget::getSceneManager()
{ {
return mSceneMgr; return mSceneMgr;

View file

@ -25,6 +25,11 @@ namespace CSVWidget
class SceneToolbar; class SceneToolbar;
} }
namespace CSVWorld
{
class PhysicsSystem;
}
namespace CSVRender namespace CSVRender
{ {
class Navigation; class Navigation;
@ -58,6 +63,8 @@ namespace CSVRender
Ogre::Viewport *getViewport(); Ogre::Viewport *getViewport();
CSVWorld::PhysicsSystem *getPhysics();
Ogre::SceneManager *getSceneManager(); Ogre::SceneManager *getSceneManager();
Ogre::Camera *getCamera(); Ogre::Camera *getCamera();
@ -98,6 +105,7 @@ namespace CSVRender
Ogre::RenderWindow* mWindow; Ogre::RenderWindow* mWindow;
Ogre::Viewport *mViewport; Ogre::Viewport *mViewport;
Ogre::OverlaySystem *mOverlaySystem; Ogre::OverlaySystem *mOverlaySystem;
CSVWorld::PhysicsSystem *mPhysics;
Navigation *mNavigation; Navigation *mNavigation;
Lighting *mLighting; Lighting *mLighting;

View file

@ -56,7 +56,7 @@ CSVRender::UnpagedWorldspaceWidget::UnpagedWorldspaceWidget (const std::string&
update(); update();
mCell.reset (new Cell (document.getData(), getSceneManager(), mCellId)); mCell.reset (new Cell (document.getData(), getSceneManager(), mCellId, getPhysics()));
} }
void CSVRender::UnpagedWorldspaceWidget::cellDataChanged (const QModelIndex& topLeft, void CSVRender::UnpagedWorldspaceWidget::cellDataChanged (const QModelIndex& topLeft,
@ -98,7 +98,7 @@ bool CSVRender::UnpagedWorldspaceWidget::handleDrop (const std::vector<CSMWorld:
return false; return false;
mCellId = data.begin()->getId(); mCellId = data.begin()->getId();
mCell.reset (new Cell (getDocument().getData(), getSceneManager(), mCellId)); mCell.reset (new Cell (getDocument().getData(), getSceneManager(), mCellId, getPhysics()));
update(); update();
emit cellChanged(*data.begin()); emit cellChanged(*data.begin());

View file

@ -0,0 +1,64 @@
#include "physicssystem.hpp"
#include <openengine/bullet/physic.hpp>
//#include <openengine/bullet/BtOgreExtras.h>
//#include <openengine/ogre/renderer.hpp>
#include <components/nifbullet/bulletnifloader.hpp>
namespace CSVWorld
{
PhysicsSystem::PhysicsSystem(Ogre::SceneManager *sceneMgr)
{
// Create physics. shapeLoader is deleted by the physic engine
NifBullet::ManualBulletShapeLoader* shapeLoader = new NifBullet::ManualBulletShapeLoader();
mEngine = new OEngine::Physic::PhysicEngine(shapeLoader);
mEngine->setSceneManager(sceneMgr); // needed for toggleDebugRendering()
}
PhysicsSystem::~PhysicsSystem()
{
delete mEngine;
}
// OpenMW | OpenCS
// Ptr | ?
// ptr.getClass().getModel(ptr) | ? // see Object::update()
// ptr.getRefData().getBaseNode() | ?
// ptr.getCellRef().getScale() | ?
//
// getModel() returns the mesh; each class has its own implementation
//
//void PhysicsSystem::addObject (const Ptr& ptr, bool placeable)
void PhysicsSystem::addObject(const std::string &mesh,
const std::string &name,
float scale,
const Ogre::Vector3 &position,
const Ogre::Quaternion &rotation,
Ogre::Vector3* scaledBoxTranslation,
Ogre::Quaternion* boxRotation,
bool raycasting,
bool placeable)
{
#if 0
std::string mesh = ptr.getClass().getModel(ptr);
Ogre::SceneNode* node = ptr.getRefData().getBaseNode();
handleToMesh[node->getName()] = mesh;
mEngine->createAndAdjustRigidBody(
mesh, node->getName(), ptr.getCellRef().getScale(), node->getPosition(), node->getOrientation(), 0, 0, false, placeable);
mEngine->createAndAdjustRigidBody(
mesh, node->getName(), ptr.getCellRef().getScale(), node->getPosition(), node->getOrientation(), 0, 0, true, placeable);
#endif
mEngine->createAndAdjustRigidBody(mesh, name, scale, position, rotation,
0, 0, false, placeable);
mEngine->createAndAdjustRigidBody(mesh, name, scale, position, rotation,
0, 0, true, placeable);
}
void PhysicsSystem::toggleDebugRendering()
{
//mEngine->toggleDebugRendering();
mEngine->setDebugRenderingMode(1);
}
}

View file

@ -0,0 +1,48 @@
#ifndef CSV_WORLD_PHYSICSSYSTEM_H
#define CSV_WORLD_PHYSICSSYSTEM_H
#include <map>
namespace Ogre
{
class Vector3;
class Quaternion;
class SceneManager;
}
namespace OEngine
{
namespace Physic
{
class PhysicEngine;
}
}
namespace CSVWorld
{
class PhysicsSystem
{
std::map<std::string, std::string> handleToMesh;
OEngine::Physic::PhysicEngine* mEngine;
//Ogre::SceneManager *mSceneMgr;
public:
PhysicsSystem(Ogre::SceneManager *sceneMgr);
~PhysicsSystem();
void addObject(const std::string &mesh,
const std::string &name,
float scale,
const Ogre::Vector3 &position,
const Ogre::Quaternion &rotation,
Ogre::Vector3* scaledBoxTranslation = 0,
Ogre::Quaternion* boxRotation = 0,
bool raycasting=false,
bool placeable=false);
void toggleDebugRendering();
};
}
#endif // CSV_WORLD_PHYSICSSYSTEM_H