From 88b09081043727f9e2cd131d9678c4cf51da959a Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 29 Jan 2011 17:33:48 +0100 Subject: [PATCH] adding physics when insertering objects into the OGRE scene --- apps/openmw/mwclass/activator.cpp | 1 + apps/openmw/mwclass/apparatus.cpp | 1 + apps/openmw/mwclass/armor.cpp | 1 + apps/openmw/mwclass/book.cpp | 1 + apps/openmw/mwclass/clothing.cpp | 1 + apps/openmw/mwclass/container.cpp | 1 + apps/openmw/mwclass/creature.cpp | 1 + apps/openmw/mwclass/door.cpp | 1 + apps/openmw/mwclass/ingredient.cpp | 1 + apps/openmw/mwclass/light.cpp | 1 + apps/openmw/mwclass/lockpick.cpp | 1 + apps/openmw/mwclass/misc.cpp | 1 + apps/openmw/mwclass/npc.cpp | 3 +++ apps/openmw/mwclass/potion.cpp | 1 + apps/openmw/mwclass/probe.cpp | 1 + apps/openmw/mwclass/repair.cpp | 1 + apps/openmw/mwclass/static.cpp | 1 + apps/openmw/mwclass/weapon.cpp | 1 + apps/openmw/mwrender/cellimp.hpp | 3 +++ apps/openmw/mwrender/exterior.cpp | 28 +++++++++++++++++++++++----- apps/openmw/mwrender/exterior.hpp | 9 +++++++-- apps/openmw/mwrender/interior.cpp | 24 +++++++++++++++++++++--- apps/openmw/mwrender/interior.hpp | 6 ++++++ 23 files changed, 80 insertions(+), 10 deletions(-) diff --git a/apps/openmw/mwclass/activator.cpp b/apps/openmw/mwclass/activator.cpp index 6c96811d8..7a72ddb8c 100644 --- a/apps/openmw/mwclass/activator.cpp +++ b/apps/openmw/mwclass/activator.cpp @@ -23,6 +23,7 @@ namespace MWClass { MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); + cellRender.insertObjectPhysics(); ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } diff --git a/apps/openmw/mwclass/apparatus.cpp b/apps/openmw/mwclass/apparatus.cpp index 1d4afc096..2dbeae360 100644 --- a/apps/openmw/mwclass/apparatus.cpp +++ b/apps/openmw/mwclass/apparatus.cpp @@ -26,6 +26,7 @@ namespace MWClass { MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); + cellRender.insertObjectPhysics(); ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } diff --git a/apps/openmw/mwclass/armor.cpp b/apps/openmw/mwclass/armor.cpp index 1217d56a6..d63795641 100644 --- a/apps/openmw/mwclass/armor.cpp +++ b/apps/openmw/mwclass/armor.cpp @@ -26,6 +26,7 @@ namespace MWClass { MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); + cellRender.insertObjectPhysics(); ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } diff --git a/apps/openmw/mwclass/book.cpp b/apps/openmw/mwclass/book.cpp index 3679eb7ee..964ccbdfe 100644 --- a/apps/openmw/mwclass/book.cpp +++ b/apps/openmw/mwclass/book.cpp @@ -26,6 +26,7 @@ namespace MWClass { MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); + cellRender.insertObjectPhysics(); ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } diff --git a/apps/openmw/mwclass/clothing.cpp b/apps/openmw/mwclass/clothing.cpp index 07ded0264..a264f2a1c 100644 --- a/apps/openmw/mwclass/clothing.cpp +++ b/apps/openmw/mwclass/clothing.cpp @@ -26,6 +26,7 @@ namespace MWClass { MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); + cellRender.insertObjectPhysics(); ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } diff --git a/apps/openmw/mwclass/container.cpp b/apps/openmw/mwclass/container.cpp index ea61508b8..1da55e6f6 100644 --- a/apps/openmw/mwclass/container.cpp +++ b/apps/openmw/mwclass/container.cpp @@ -23,6 +23,7 @@ namespace MWClass { MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); + cellRender.insertObjectPhysics(); ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 0d358441a..8cde67671 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -35,6 +35,7 @@ namespace MWClass { MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); + cellRender.insertActorPhysics(); ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } diff --git a/apps/openmw/mwclass/door.cpp b/apps/openmw/mwclass/door.cpp index 4f294ce87..8a34d3abe 100644 --- a/apps/openmw/mwclass/door.cpp +++ b/apps/openmw/mwclass/door.cpp @@ -30,6 +30,7 @@ namespace MWClass { MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); + cellRender.insertObjectPhysics(); ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } diff --git a/apps/openmw/mwclass/ingredient.cpp b/apps/openmw/mwclass/ingredient.cpp index e4ea509f9..c88e1794b 100644 --- a/apps/openmw/mwclass/ingredient.cpp +++ b/apps/openmw/mwclass/ingredient.cpp @@ -26,6 +26,7 @@ namespace MWClass { MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); + cellRender.insertObjectPhysics(); ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } diff --git a/apps/openmw/mwclass/light.cpp b/apps/openmw/mwclass/light.cpp index de5c06a73..159196eb2 100644 --- a/apps/openmw/mwclass/light.cpp +++ b/apps/openmw/mwclass/light.cpp @@ -31,6 +31,7 @@ namespace MWClass MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); + cellRender.insertObjectPhysics(); // Extract the color and convert to floating point const int color = ref->base->data.color; diff --git a/apps/openmw/mwclass/lockpick.cpp b/apps/openmw/mwclass/lockpick.cpp index 3b08ff199..9a4b98b43 100644 --- a/apps/openmw/mwclass/lockpick.cpp +++ b/apps/openmw/mwclass/lockpick.cpp @@ -26,6 +26,7 @@ namespace MWClass { MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); + cellRender.insertObjectPhysics(); ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } diff --git a/apps/openmw/mwclass/misc.cpp b/apps/openmw/mwclass/misc.cpp index d4ffdce38..f9995b77f 100644 --- a/apps/openmw/mwclass/misc.cpp +++ b/apps/openmw/mwclass/misc.cpp @@ -26,6 +26,7 @@ namespace MWClass { MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); + cellRender.insertObjectPhysics(); ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index bc933b918..bd7aeb413 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -258,6 +258,9 @@ namespace MWClass cellRender.insertMesh (hairModel, Ogre::Vector3( 0, -1, 0), axis, Ogre::Radian(0), npcName + "hair", neckandup, neckNumbers); ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); + + cellRender.insertActorPhysics(); + ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } void Npc::enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const diff --git a/apps/openmw/mwclass/potion.cpp b/apps/openmw/mwclass/potion.cpp index e163473f7..6c9889a7b 100644 --- a/apps/openmw/mwclass/potion.cpp +++ b/apps/openmw/mwclass/potion.cpp @@ -26,6 +26,7 @@ namespace MWClass { MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); + cellRender.insertObjectPhysics(); ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } diff --git a/apps/openmw/mwclass/probe.cpp b/apps/openmw/mwclass/probe.cpp index 9188ae9ea..028d8b5e3 100644 --- a/apps/openmw/mwclass/probe.cpp +++ b/apps/openmw/mwclass/probe.cpp @@ -26,6 +26,7 @@ namespace MWClass { MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); + cellRender.insertObjectPhysics(); ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } diff --git a/apps/openmw/mwclass/repair.cpp b/apps/openmw/mwclass/repair.cpp index 7b42bc95c..b9b5036fb 100644 --- a/apps/openmw/mwclass/repair.cpp +++ b/apps/openmw/mwclass/repair.cpp @@ -26,6 +26,7 @@ namespace MWClass { MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); + cellRender.insertObjectPhysics(); ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } diff --git a/apps/openmw/mwclass/static.cpp b/apps/openmw/mwclass/static.cpp index 33e3e0ed4..851b4d7bf 100644 --- a/apps/openmw/mwclass/static.cpp +++ b/apps/openmw/mwclass/static.cpp @@ -21,6 +21,7 @@ namespace MWClass { MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); + cellRender.insertObjectPhysics(); ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp index 4c14e58ea..a985a7e42 100644 --- a/apps/openmw/mwclass/weapon.cpp +++ b/apps/openmw/mwclass/weapon.cpp @@ -26,6 +26,7 @@ namespace MWClass { MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); + cellRender.insertObjectPhysics(); ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } diff --git a/apps/openmw/mwrender/cellimp.hpp b/apps/openmw/mwrender/cellimp.hpp index 91676e11c..272bfeeab 100644 --- a/apps/openmw/mwrender/cellimp.hpp +++ b/apps/openmw/mwrender/cellimp.hpp @@ -45,6 +45,9 @@ namespace MWRender virtual void scaleMesh(Ogre::Vector3 axis, std::string sceneNodeName[], int elements) = 0; + virtual void insertObjectPhysics() = 0; + + virtual void insertActorPhysics() = 0; /// insert a light related to the most recent insertBegin call. virtual void insertLight(float r, float g, float b, float radius) = 0; diff --git a/apps/openmw/mwrender/exterior.cpp b/apps/openmw/mwrender/exterior.cpp index cd2a7680d..c1d7641b8 100644 --- a/apps/openmw/mwrender/exterior.cpp +++ b/apps/openmw/mwrender/exterior.cpp @@ -58,6 +58,8 @@ void ExteriorCellRender::insertBegin (ESM::CellRef &ref) // Rotates first around z, then y, then x mInsert->setOrientation(xr*yr*zr); + + mInsertMesh.clear(); } @@ -81,18 +83,18 @@ void ExteriorCellRender::insertMesh(const std::string &mesh, Ogre::Vector3 vec, if(sceneParent[i] != "" && parent->getChild(sceneParent[i])) parent = dynamic_cast (parent->getChild(sceneParent[i])); } - + mNpcPart = parent->createChildSceneNode(sceneNodeName); NIFLoader::load(mesh); MovableObject *ent = mScene.getMgr()->createEntity(mesh); - + mNpcPart->translate(vec); mNpcPart->rotate(axis, angle); // mNpcPart->translate(vec); //mNpcPart->rotate(axis, angle); mNpcPart->attachObject(ent); //mNpcPart-> - + } */ void ExteriorCellRender::insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements) @@ -108,7 +110,7 @@ void ExteriorCellRender::insertMesh(const std::string &mesh, Ogre::Vector3 vec, if(sceneParent[i] != "" && parent->getChild(sceneParent[i])) parent = dynamic_cast (parent->getChild(sceneParent[i])); } - + mNpcPart = parent->createChildSceneNode(sceneNodeName); MeshPtr good2 = NIFLoader::load(mesh); @@ -120,7 +122,7 @@ void ExteriorCellRender::insertMesh(const std::string &mesh, Ogre::Vector3 vec, mNpcPart->rotate(axis, angle); } else{ - + mNpcPart->rotate(axis, angle); mNpcPart->translate(vec); } @@ -202,6 +204,22 @@ void ExteriorCellRender::insertMesh(const std::string &mesh) NIFLoader::load(mesh); MovableObject *ent = mScene.getMgr()->createEntity(mesh); mInsert->attachObject(ent); + + if (mInsertMesh.empty()) + mInsertMesh = mesh; +} + +void ExteriorCellRender::insertObjectPhysics() +{ + if (!mInsertMesh.empty()) + mScene.addObject (mInsert->getName(), mInsertMesh, mInsert->getOrientation(), + mInsert->getScale().x, mInsert->getPosition()); +} + +void ExteriorCellRender::insertActorPhysics() +{ + if (!mInsertMesh.empty()) + mScene.addActor (mInsert->getName(), mInsertMesh, mInsert->getPosition()); } // insert a light related to the most recent insertBegin call. diff --git a/apps/openmw/mwrender/exterior.hpp b/apps/openmw/mwrender/exterior.hpp index 67d41bcac..93491f263 100644 --- a/apps/openmw/mwrender/exterior.hpp +++ b/apps/openmw/mwrender/exterior.hpp @@ -54,6 +54,7 @@ namespace MWRender Ogre::SceneNode *mBase; Ogre::SceneNode *mInsert; + std::string mInsertMesh; Ogre::SceneNode *mNpcPart; // 0 normal, 1 more bright, 2 max @@ -67,11 +68,15 @@ namespace MWRender /// insert a mesh related to the most recent insertBegin call. virtual void insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements); virtual void insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements, bool translateFirst); - + virtual void insertMesh(const std::string &mesh); virtual void rotateMesh(Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName[], int elements); virtual void scaleMesh(Ogre::Vector3 axis, std::string sceneNodeName[], int elements); + virtual void insertObjectPhysics(); + + virtual void insertActorPhysics(); + /// insert a light related to the most recent insertBegin call. virtual void insertLight(float r, float g, float b, float radius); @@ -85,7 +90,7 @@ namespace MWRender void configureFog(); void setAmbientMode(); - + public: diff --git a/apps/openmw/mwrender/interior.cpp b/apps/openmw/mwrender/interior.cpp index 6e1f0d297..e096b7757 100644 --- a/apps/openmw/mwrender/interior.cpp +++ b/apps/openmw/mwrender/interior.cpp @@ -60,6 +60,8 @@ void InteriorCellRender::insertBegin (ESM::CellRef &ref) // Rotates first around z, then y, then x insert->setOrientation(xr*yr*zr); + + mInsertMesh.clear(); } // insert a mesh related to the most recent insertBegin call. @@ -100,7 +102,7 @@ void InteriorCellRender::insertMesh(const std::string &mesh, Ogre::Vector3 vec, if(sceneParent[i] != "" && parent->getChild(sceneParent[i])) parent = dynamic_cast (parent->getChild(sceneParent[i])); } - + npcPart = parent->createChildSceneNode(sceneNodeName); //npcPart->showBoundingBox(true); @@ -108,7 +110,7 @@ void InteriorCellRender::insertMesh(const std::string &mesh, Ogre::Vector3 vec, MovableObject *ent = scene.getMgr()->createEntity(mesh); //ent->extr - + // MovableObject *ent2 = scene.getMgr()->createEntity(bounds // ); //ent-> @@ -119,7 +121,7 @@ void InteriorCellRender::insertMesh(const std::string &mesh, Ogre::Vector3 vec, npcPart->rotate(axis, angle); } else{ - + npcPart->rotate(axis, angle); npcPart->translate(vec); } @@ -185,6 +187,22 @@ void InteriorCellRender::insertMesh(const std::string &mesh) NIFLoader::load(mesh); MovableObject *ent = scene.getMgr()->createEntity(mesh); insert->attachObject(ent); + + if (mInsertMesh.empty()) + mInsertMesh = mesh; +} + +void InteriorCellRender::insertObjectPhysics() +{ + if (!mInsertMesh.empty()) + scene.addObject (insert->getName(), mInsertMesh, insert->getOrientation(), + insert->getScale().x, insert->getPosition()); +} + +void InteriorCellRender::insertActorPhysics() +{ + if (!mInsertMesh.empty()) + scene.addActor (insert->getName(), mInsertMesh, insert->getPosition()); } // insert a light related to the most recent insertBegin call. diff --git a/apps/openmw/mwrender/interior.hpp b/apps/openmw/mwrender/interior.hpp index a38943521..7c4b2aaf1 100644 --- a/apps/openmw/mwrender/interior.hpp +++ b/apps/openmw/mwrender/interior.hpp @@ -54,6 +54,7 @@ namespace MWRender Ogre::SceneNode *base; Ogre::SceneNode *insert; + std::string mInsertMesh; Ogre::SceneNode *npcPart; // 0 normal, 1 more bright, 2 max @@ -69,6 +70,11 @@ namespace MWRender virtual void insertMesh(const std::string &mesh); virtual void insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements); virtual void insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements, bool translateFirst); + + virtual void insertObjectPhysics(); + + virtual void insertActorPhysics(); + /// insert a light related to the most recent insertBegin call. virtual void insertLight(float r, float g, float b, float radius);