adding physics when insertering objects into the OGRE scene

This commit is contained in:
Marc Zinnschlag 2011-01-29 17:33:48 +01:00
parent 6a14ea8ec3
commit 88b0908104
23 changed files with 80 additions and 10 deletions

View file

@ -23,6 +23,7 @@ namespace MWClass
{ {
MWRender::Rendering rendering (cellRender, ref->ref); MWRender::Rendering rendering (cellRender, ref->ref);
cellRender.insertMesh ("meshes\\" + model); cellRender.insertMesh ("meshes\\" + model);
cellRender.insertObjectPhysics();
ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); ref->mData.setHandle (rendering.end (ref->mData.isEnabled()));
} }
} }

View file

@ -26,6 +26,7 @@ namespace MWClass
{ {
MWRender::Rendering rendering (cellRender, ref->ref); MWRender::Rendering rendering (cellRender, ref->ref);
cellRender.insertMesh ("meshes\\" + model); cellRender.insertMesh ("meshes\\" + model);
cellRender.insertObjectPhysics();
ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); ref->mData.setHandle (rendering.end (ref->mData.isEnabled()));
} }
} }

View file

@ -26,6 +26,7 @@ namespace MWClass
{ {
MWRender::Rendering rendering (cellRender, ref->ref); MWRender::Rendering rendering (cellRender, ref->ref);
cellRender.insertMesh ("meshes\\" + model); cellRender.insertMesh ("meshes\\" + model);
cellRender.insertObjectPhysics();
ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); ref->mData.setHandle (rendering.end (ref->mData.isEnabled()));
} }
} }

View file

@ -26,6 +26,7 @@ namespace MWClass
{ {
MWRender::Rendering rendering (cellRender, ref->ref); MWRender::Rendering rendering (cellRender, ref->ref);
cellRender.insertMesh ("meshes\\" + model); cellRender.insertMesh ("meshes\\" + model);
cellRender.insertObjectPhysics();
ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); ref->mData.setHandle (rendering.end (ref->mData.isEnabled()));
} }
} }

View file

@ -26,6 +26,7 @@ namespace MWClass
{ {
MWRender::Rendering rendering (cellRender, ref->ref); MWRender::Rendering rendering (cellRender, ref->ref);
cellRender.insertMesh ("meshes\\" + model); cellRender.insertMesh ("meshes\\" + model);
cellRender.insertObjectPhysics();
ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); ref->mData.setHandle (rendering.end (ref->mData.isEnabled()));
} }
} }

View file

@ -23,6 +23,7 @@ namespace MWClass
{ {
MWRender::Rendering rendering (cellRender, ref->ref); MWRender::Rendering rendering (cellRender, ref->ref);
cellRender.insertMesh ("meshes\\" + model); cellRender.insertMesh ("meshes\\" + model);
cellRender.insertObjectPhysics();
ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); ref->mData.setHandle (rendering.end (ref->mData.isEnabled()));
} }
} }

View file

@ -35,6 +35,7 @@ namespace MWClass
{ {
MWRender::Rendering rendering (cellRender, ref->ref); MWRender::Rendering rendering (cellRender, ref->ref);
cellRender.insertMesh ("meshes\\" + model); cellRender.insertMesh ("meshes\\" + model);
cellRender.insertActorPhysics();
ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); ref->mData.setHandle (rendering.end (ref->mData.isEnabled()));
} }
} }

View file

@ -30,6 +30,7 @@ namespace MWClass
{ {
MWRender::Rendering rendering (cellRender, ref->ref); MWRender::Rendering rendering (cellRender, ref->ref);
cellRender.insertMesh ("meshes\\" + model); cellRender.insertMesh ("meshes\\" + model);
cellRender.insertObjectPhysics();
ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); ref->mData.setHandle (rendering.end (ref->mData.isEnabled()));
} }
} }

View file

@ -26,6 +26,7 @@ namespace MWClass
{ {
MWRender::Rendering rendering (cellRender, ref->ref); MWRender::Rendering rendering (cellRender, ref->ref);
cellRender.insertMesh ("meshes\\" + model); cellRender.insertMesh ("meshes\\" + model);
cellRender.insertObjectPhysics();
ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); ref->mData.setHandle (rendering.end (ref->mData.isEnabled()));
} }
} }

View file

@ -31,6 +31,7 @@ namespace MWClass
MWRender::Rendering rendering (cellRender, ref->ref); MWRender::Rendering rendering (cellRender, ref->ref);
cellRender.insertMesh ("meshes\\" + model); cellRender.insertMesh ("meshes\\" + model);
cellRender.insertObjectPhysics();
// Extract the color and convert to floating point // Extract the color and convert to floating point
const int color = ref->base->data.color; const int color = ref->base->data.color;

View file

@ -26,6 +26,7 @@ namespace MWClass
{ {
MWRender::Rendering rendering (cellRender, ref->ref); MWRender::Rendering rendering (cellRender, ref->ref);
cellRender.insertMesh ("meshes\\" + model); cellRender.insertMesh ("meshes\\" + model);
cellRender.insertObjectPhysics();
ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); ref->mData.setHandle (rendering.end (ref->mData.isEnabled()));
} }
} }

View file

@ -26,6 +26,7 @@ namespace MWClass
{ {
MWRender::Rendering rendering (cellRender, ref->ref); MWRender::Rendering rendering (cellRender, ref->ref);
cellRender.insertMesh ("meshes\\" + model); cellRender.insertMesh ("meshes\\" + model);
cellRender.insertObjectPhysics();
ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); ref->mData.setHandle (rendering.end (ref->mData.isEnabled()));
} }
} }

View file

@ -258,6 +258,9 @@ namespace MWClass
cellRender.insertMesh (hairModel, Ogre::Vector3( 0, -1, 0), axis, Ogre::Radian(0), npcName + "hair", neckandup, neckNumbers); cellRender.insertMesh (hairModel, Ogre::Vector3( 0, -1, 0), axis, Ogre::Radian(0), npcName + "hair", neckandup, neckNumbers);
ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); 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 void Npc::enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const

View file

@ -26,6 +26,7 @@ namespace MWClass
{ {
MWRender::Rendering rendering (cellRender, ref->ref); MWRender::Rendering rendering (cellRender, ref->ref);
cellRender.insertMesh ("meshes\\" + model); cellRender.insertMesh ("meshes\\" + model);
cellRender.insertObjectPhysics();
ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); ref->mData.setHandle (rendering.end (ref->mData.isEnabled()));
} }
} }

View file

@ -26,6 +26,7 @@ namespace MWClass
{ {
MWRender::Rendering rendering (cellRender, ref->ref); MWRender::Rendering rendering (cellRender, ref->ref);
cellRender.insertMesh ("meshes\\" + model); cellRender.insertMesh ("meshes\\" + model);
cellRender.insertObjectPhysics();
ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); ref->mData.setHandle (rendering.end (ref->mData.isEnabled()));
} }
} }

View file

@ -26,6 +26,7 @@ namespace MWClass
{ {
MWRender::Rendering rendering (cellRender, ref->ref); MWRender::Rendering rendering (cellRender, ref->ref);
cellRender.insertMesh ("meshes\\" + model); cellRender.insertMesh ("meshes\\" + model);
cellRender.insertObjectPhysics();
ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); ref->mData.setHandle (rendering.end (ref->mData.isEnabled()));
} }
} }

View file

@ -21,6 +21,7 @@ namespace MWClass
{ {
MWRender::Rendering rendering (cellRender, ref->ref); MWRender::Rendering rendering (cellRender, ref->ref);
cellRender.insertMesh ("meshes\\" + model); cellRender.insertMesh ("meshes\\" + model);
cellRender.insertObjectPhysics();
ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); ref->mData.setHandle (rendering.end (ref->mData.isEnabled()));
} }
} }

View file

@ -26,6 +26,7 @@ namespace MWClass
{ {
MWRender::Rendering rendering (cellRender, ref->ref); MWRender::Rendering rendering (cellRender, ref->ref);
cellRender.insertMesh ("meshes\\" + model); cellRender.insertMesh ("meshes\\" + model);
cellRender.insertObjectPhysics();
ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); ref->mData.setHandle (rendering.end (ref->mData.isEnabled()));
} }
} }

View file

@ -45,6 +45,9 @@ namespace MWRender
virtual void scaleMesh(Ogre::Vector3 axis, std::string sceneNodeName[], int elements) = 0; 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. /// insert a light related to the most recent insertBegin call.
virtual void insertLight(float r, float g, float b, float radius) = 0; virtual void insertLight(float r, float g, float b, float radius) = 0;

View file

@ -58,6 +58,8 @@ void ExteriorCellRender::insertBegin (ESM::CellRef &ref)
// Rotates first around z, then y, then x // Rotates first around z, then y, then x
mInsert->setOrientation(xr*yr*zr); mInsert->setOrientation(xr*yr*zr);
mInsertMesh.clear();
} }
@ -202,6 +204,22 @@ void ExteriorCellRender::insertMesh(const std::string &mesh)
NIFLoader::load(mesh); NIFLoader::load(mesh);
MovableObject *ent = mScene.getMgr()->createEntity(mesh); MovableObject *ent = mScene.getMgr()->createEntity(mesh);
mInsert->attachObject(ent); 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. // insert a light related to the most recent insertBegin call.

View file

@ -54,6 +54,7 @@ namespace MWRender
Ogre::SceneNode *mBase; Ogre::SceneNode *mBase;
Ogre::SceneNode *mInsert; Ogre::SceneNode *mInsert;
std::string mInsertMesh;
Ogre::SceneNode *mNpcPart; Ogre::SceneNode *mNpcPart;
// 0 normal, 1 more bright, 2 max // 0 normal, 1 more bright, 2 max
@ -72,6 +73,10 @@ namespace MWRender
virtual void rotateMesh(Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName[], int elements); 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 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. /// insert a light related to the most recent insertBegin call.
virtual void insertLight(float r, float g, float b, float radius); virtual void insertLight(float r, float g, float b, float radius);

View file

@ -60,6 +60,8 @@ void InteriorCellRender::insertBegin (ESM::CellRef &ref)
// Rotates first around z, then y, then x // Rotates first around z, then y, then x
insert->setOrientation(xr*yr*zr); insert->setOrientation(xr*yr*zr);
mInsertMesh.clear();
} }
// insert a mesh related to the most recent insertBegin call. // insert a mesh related to the most recent insertBegin call.
@ -185,6 +187,22 @@ void InteriorCellRender::insertMesh(const std::string &mesh)
NIFLoader::load(mesh); NIFLoader::load(mesh);
MovableObject *ent = scene.getMgr()->createEntity(mesh); MovableObject *ent = scene.getMgr()->createEntity(mesh);
insert->attachObject(ent); 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. // insert a light related to the most recent insertBegin call.

View file

@ -54,6 +54,7 @@ namespace MWRender
Ogre::SceneNode *base; Ogre::SceneNode *base;
Ogre::SceneNode *insert; Ogre::SceneNode *insert;
std::string mInsertMesh;
Ogre::SceneNode *npcPart; Ogre::SceneNode *npcPart;
// 0 normal, 1 more bright, 2 max // 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);
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);
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, 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. /// insert a light related to the most recent insertBegin call.
virtual void insertLight(float r, float g, float b, float radius); virtual void insertLight(float r, float g, float b, float radius);