From 6aaedff86a2371774ecab1b26aed6d8a031b63de Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Thu, 25 Nov 2010 15:44:56 -0500 Subject: [PATCH] Preliminary NPCs --- apps/openmw/mwrender/cellimp.hpp | 11 +++++++++- apps/openmw/mwrender/exterior.cpp | 35 +++++++++++++++++++++++++++++++ apps/openmw/mwrender/exterior.hpp | 5 +++++ apps/openmw/mwrender/interior.cpp | 30 ++++++++++++++++++++++++++ apps/openmw/mwrender/interior.hpp | 7 +++++-- 5 files changed, 85 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwrender/cellimp.hpp b/apps/openmw/mwrender/cellimp.hpp index bc6f2874a..8ba158408 100644 --- a/apps/openmw/mwrender/cellimp.hpp +++ b/apps/openmw/mwrender/cellimp.hpp @@ -6,6 +6,13 @@ #include "components/esm_store/cell_store.hpp" #include "../mwworld/refdata.hpp" +#include + +namespace Ogre +{ + class SceneNode; + class Vector3; +} namespace ESM { @@ -16,7 +23,6 @@ namespace MWWorld { class Environment; } - namespace MWRender { /// Base class for cell render, that implements inserting references into a cell in a @@ -31,9 +37,12 @@ namespace MWRender /// start inserting a new reference. virtual void insertBegin (ESM::CellRef &ref) = 0; + virtual void rotateMesh(Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName[], int elements) = 0; /// 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) = 0; virtual void insertMesh(const std::string &mesh) = 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 58c783d72..5603460a4 100644 --- a/apps/openmw/mwrender/exterior.cpp +++ b/apps/openmw/mwrender/exterior.cpp @@ -57,8 +57,43 @@ void ExteriorCellRender::insertBegin (ESM::CellRef &ref) insert->setOrientation(xr*yr*zr); } + +void ExteriorCellRender::rotateMesh(Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName[], int elements) +{ + assert(insert); + Ogre::SceneNode *parent = insert; + //std::cout << "ELEMENTS:" << elements; + for (int i = 0; i < elements; i++){ + if(sceneNodeName[i] != "" && parent->getChild(sceneNodeName[i])) + parent = dynamic_cast (parent->getChild(sceneNodeName[i])); + } + parent->rotate(axis, angle); +} + +void ExteriorCellRender::insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements){ + assert (insert); + //insert-> + Ogre::SceneNode *parent = insert; + for (int i = 0; i < elements; i++){ + if(sceneParent[i] != "" && parent->getChild(sceneParent[i])) + parent = dynamic_cast (parent->getChild(sceneParent[i])); + } + + npcPart = parent->createChildSceneNode(sceneNodeName); + NIFLoader::load(mesh); + MovableObject *ent = scene.getMgr()->createEntity(mesh); + + npcPart->translate(vec); + npcPart->rotate(axis, angle); + // npcPart->translate(vec); + //npcPart->rotate(axis, angle); + npcPart->attachObject(ent); + //npcPart-> + +} // insert a mesh related to the most recent insertBegin call. + void ExteriorCellRender::insertMesh(const std::string &mesh) { assert (insert); diff --git a/apps/openmw/mwrender/exterior.hpp b/apps/openmw/mwrender/exterior.hpp index 7de027672..64bd8c623 100644 --- a/apps/openmw/mwrender/exterior.hpp +++ b/apps/openmw/mwrender/exterior.hpp @@ -5,6 +5,7 @@ #include "cellimp.hpp" #include "OgreColourValue.h" +#include namespace Ogre { @@ -53,6 +54,7 @@ namespace MWRender Ogre::SceneNode *base; Ogre::SceneNode *insert; + Ogre::SceneNode *npcPart; // 0 normal, 1 more bright, 2 max int ambientMode; @@ -63,7 +65,9 @@ namespace MWRender virtual void insertBegin (ESM::CellRef &ref); /// 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); + virtual void rotateMesh(Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName[], int elements); /// insert a light related to the most recent insertBegin call. virtual void insertLight(float r, float g, float b, float radius); @@ -78,6 +82,7 @@ namespace MWRender void configureFog(); void setAmbientMode(); + public: diff --git a/apps/openmw/mwrender/interior.cpp b/apps/openmw/mwrender/interior.cpp index 1e88ecab4..676b51f18 100644 --- a/apps/openmw/mwrender/interior.cpp +++ b/apps/openmw/mwrender/interior.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "mwscene.hpp" @@ -58,6 +59,35 @@ void InteriorCellRender::insertBegin (ESM::CellRef &ref) } // insert a mesh related to the most recent insertBegin call. +void InteriorCellRender::rotateMesh(Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName[], int elements) +{ + assert(insert); + Ogre::SceneNode *parent = insert; + //std::cout << "ELEMENTS:" << elements; + for (int i = 0; i < elements; i++){ + if(sceneNodeName[i] != "" && parent->getChild(sceneNodeName[i])) + parent = dynamic_cast (parent->getChild(sceneNodeName[i])); + } + parent->rotate(axis, angle); +} +void InteriorCellRender::insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements){ + + assert (insert); + //insert-> + Ogre::SceneNode *parent = insert; + for (int i = 0; i < elements; i++){ + if(sceneParent[i] != "" && parent->getChild(sceneParent[i])) + parent = dynamic_cast (parent->getChild(sceneParent[i])); + } + + npcPart = parent->createChildSceneNode(sceneNodeName); + NIFLoader::load(mesh); + MovableObject *ent = scene.getMgr()->createEntity(mesh); + + npcPart->translate(vec); + npcPart->rotate(axis, angle); + npcPart->attachObject(ent); +} void InteriorCellRender::insertMesh(const std::string &mesh) { diff --git a/apps/openmw/mwrender/interior.hpp b/apps/openmw/mwrender/interior.hpp index ba5089eb5..1b64b0fdb 100644 --- a/apps/openmw/mwrender/interior.hpp +++ b/apps/openmw/mwrender/interior.hpp @@ -5,6 +5,7 @@ #include "cellimp.hpp" #include "OgreColourValue.h" +#include namespace Ogre { @@ -53,6 +54,7 @@ namespace MWRender Ogre::SceneNode *base; Ogre::SceneNode *insert; + Ogre::SceneNode *npcPart; // 0 normal, 1 more bright, 2 max int ambientMode; @@ -61,10 +63,10 @@ namespace MWRender /// start inserting a new reference. virtual void insertBegin (ESM::CellRef &ref); - + virtual void rotateMesh(Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName[], int elements); /// insert a mesh related to the most recent insertBegin call. 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); /// insert a light related to the most recent insertBegin call. virtual void insertLight(float r, float g, float b, float radius); @@ -79,6 +81,7 @@ namespace MWRender void setAmbientMode(); + public: InteriorCellRender(ESMS::CellStore &_cell, MWWorld::Environment& environment,