forked from mirror/openmw-tes3mp
Whitespace changes only tabs->spaces and removal of traling space (including mangle and openengline)
This commit is contained in:
parent
b22234109d
commit
6aa1f3efdd
12 changed files with 454 additions and 454 deletions
|
@ -60,7 +60,7 @@ namespace OMW
|
||||||
boost::filesystem::path mDataDir;
|
boost::filesystem::path mDataDir;
|
||||||
boost::filesystem::path mResDir;
|
boost::filesystem::path mResDir;
|
||||||
OEngine::Render::OgreRenderer mOgre;
|
OEngine::Render::OgreRenderer mOgre;
|
||||||
OEngine::Physic::PhysicEngine* mPhysicEngine;
|
OEngine::Physic::PhysicEngine* mPhysicEngine;
|
||||||
std::string mCellName;
|
std::string mCellName;
|
||||||
std::string mMaster;
|
std::string mMaster;
|
||||||
bool mShowFPS;
|
bool mShowFPS;
|
||||||
|
|
|
@ -20,37 +20,37 @@ using namespace MWRender;
|
||||||
using namespace Ogre;
|
using namespace Ogre;
|
||||||
|
|
||||||
MWScene::MWScene(OEngine::Render::OgreRenderer &_rend , OEngine::Physic::PhysicEngine* physEng)
|
MWScene::MWScene(OEngine::Render::OgreRenderer &_rend , OEngine::Physic::PhysicEngine* physEng)
|
||||||
: rend(_rend)
|
: rend(_rend)
|
||||||
{
|
{
|
||||||
eng = physEng;
|
eng = physEng;
|
||||||
rend.createScene("PlayerCam", 55, 5);
|
rend.createScene("PlayerCam", 55, 5);
|
||||||
|
|
||||||
// Set default mipmap level (NB some APIs ignore this)
|
// Set default mipmap level (NB some APIs ignore this)
|
||||||
TextureManager::getSingleton().setDefaultNumMipmaps(5);
|
TextureManager::getSingleton().setDefaultNumMipmaps(5);
|
||||||
|
|
||||||
// Load resources
|
// Load resources
|
||||||
ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
|
ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
|
||||||
|
|
||||||
// Turn the entire scene (represented by the 'root' node) -90
|
// Turn the entire scene (represented by the 'root' node) -90
|
||||||
// degrees around the x axis. This makes Z go upwards, and Y go into
|
// degrees around the x axis. This makes Z go upwards, and Y go into
|
||||||
// the screen (when x is to the right.) This is the orientation that
|
// the screen (when x is to the right.) This is the orientation that
|
||||||
// Morrowind uses, and it automagically makes everything work as it
|
// Morrowind uses, and it automagically makes everything work as it
|
||||||
// should.
|
// should.
|
||||||
SceneNode *rt = rend.getScene()->getRootSceneNode();
|
SceneNode *rt = rend.getScene()->getRootSceneNode();
|
||||||
mwRoot = rt->createChildSceneNode();
|
mwRoot = rt->createChildSceneNode();
|
||||||
mwRoot->pitch(Degree(-90));
|
mwRoot->pitch(Degree(-90));
|
||||||
|
|
||||||
//used to obtain ingame information of ogre objects (which are faced or selected)
|
//used to obtain ingame information of ogre objects (which are faced or selected)
|
||||||
mRaySceneQuery = rend.getScene()->createRayQuery(Ray());
|
mRaySceneQuery = rend.getScene()->createRayQuery(Ray());
|
||||||
|
|
||||||
Ogre::SceneNode *playerNode = mwRoot->createChildSceneNode();
|
Ogre::SceneNode *playerNode = mwRoot->createChildSceneNode();
|
||||||
playerNode->pitch(Degree(90));
|
playerNode->pitch(Degree(90));
|
||||||
Ogre::SceneNode *cameraYawNode = playerNode->createChildSceneNode();
|
Ogre::SceneNode *cameraYawNode = playerNode->createChildSceneNode();
|
||||||
Ogre::SceneNode *cameraPitchNode = cameraYawNode->createChildSceneNode();
|
Ogre::SceneNode *cameraPitchNode = cameraYawNode->createChildSceneNode();
|
||||||
cameraPitchNode->attachObject(getCamera());
|
cameraPitchNode->attachObject(getCamera());
|
||||||
|
|
||||||
|
|
||||||
mPlayer = new MWRender::Player (getCamera(), playerNode->getName());
|
mPlayer = new MWRender::Player (getCamera(), playerNode->getName());
|
||||||
|
|
||||||
mFreeFly = true;
|
mFreeFly = true;
|
||||||
}
|
}
|
||||||
|
@ -82,8 +82,8 @@ void MWScene::doPhysics (float duration, MWWorld::World& world,
|
||||||
// stop changes to world from being reported back to the physics system
|
// stop changes to world from being reported back to the physics system
|
||||||
MWWorld::DoingPhysics scopeGuard;
|
MWWorld::DoingPhysics scopeGuard;
|
||||||
|
|
||||||
//set the DebugRenderingMode. To disable it,set it to 0
|
//set the DebugRenderingMode. To disable it,set it to 0
|
||||||
// eng->setDebugRenderingMode(1);
|
//eng->setDebugRenderingMode(1);
|
||||||
|
|
||||||
//set the walkdirection to 0 (no movement) for every actor)
|
//set the walkdirection to 0 (no movement) for every actor)
|
||||||
for(std::map<std::string,OEngine::Physic::PhysicActor*>::iterator it = eng->PhysicActorMap.begin(); it != eng->PhysicActorMap.end();it++)
|
for(std::map<std::string,OEngine::Physic::PhysicActor*>::iterator it = eng->PhysicActorMap.begin(); it != eng->PhysicActorMap.end();it++)
|
||||||
|
@ -95,7 +95,7 @@ void MWScene::doPhysics (float duration, MWWorld::World& world,
|
||||||
for (std::vector<std::pair<std::string, Ogre::Vector3> >::const_iterator iter (actors.begin());
|
for (std::vector<std::pair<std::string, Ogre::Vector3> >::const_iterator iter (actors.begin());
|
||||||
iter!=actors.end(); ++iter)
|
iter!=actors.end(); ++iter)
|
||||||
{
|
{
|
||||||
OEngine::Physic::PhysicActor* act = eng->getCharacter(iter->first);
|
OEngine::Physic::PhysicActor* act = eng->getCharacter(iter->first);
|
||||||
|
|
||||||
//dirty stuff to get the camera orientation. Must be changed!
|
//dirty stuff to get the camera orientation. Must be changed!
|
||||||
|
|
||||||
|
@ -117,46 +117,46 @@ void MWScene::doPhysics (float duration, MWWorld::World& world,
|
||||||
dir = 0.025*(quat*dir1);
|
dir = 0.025*(quat*dir1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//set the walk direction
|
//set the walk direction
|
||||||
act->setWalkDirection(btVector3(dir.x,-dir.z,dir.y));
|
act->setWalkDirection(btVector3(dir.x,-dir.z,dir.y));
|
||||||
}
|
}
|
||||||
eng->stepSimulation(duration);
|
eng->stepSimulation(duration);
|
||||||
|
|
||||||
for(std::map<std::string,OEngine::Physic::PhysicActor*>::iterator it = eng->PhysicActorMap.begin(); it != eng->PhysicActorMap.end();it++)
|
for(std::map<std::string,OEngine::Physic::PhysicActor*>::iterator it = eng->PhysicActorMap.begin(); it != eng->PhysicActorMap.end();it++)
|
||||||
{
|
{
|
||||||
OEngine::Physic::PhysicActor* act = it->second;
|
OEngine::Physic::PhysicActor* act = it->second;
|
||||||
btVector3 newPos = act->getPosition();
|
btVector3 newPos = act->getPosition();
|
||||||
MWWorld::Ptr ptr = world.getPtrViaHandle (it->first);
|
MWWorld::Ptr ptr = world.getPtrViaHandle (it->first);
|
||||||
world.moveObject (ptr, newPos.x(), newPos.y(), newPos.z());
|
world.moveObject (ptr, newPos.x(), newPos.y(), newPos.z());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MWScene::addObject (const std::string& handle, const std::string& mesh,
|
void MWScene::addObject (const std::string& handle, const std::string& mesh,
|
||||||
const Ogre::Quaternion& rotation, float scale, const Ogre::Vector3& position)
|
const Ogre::Quaternion& rotation, float scale, const Ogre::Vector3& position)
|
||||||
{
|
{
|
||||||
OEngine::Physic::RigidBody* body = eng->createRigidBody(mesh,handle);
|
OEngine::Physic::RigidBody* body = eng->createRigidBody(mesh,handle);
|
||||||
eng->addRigidBody(body);
|
eng->addRigidBody(body);
|
||||||
btTransform tr;
|
btTransform tr;
|
||||||
tr.setOrigin(btVector3(position.x,position.y,position.z));
|
tr.setOrigin(btVector3(position.x,position.y,position.z));
|
||||||
tr.setRotation(btQuaternion(rotation.x,rotation.y,rotation.z,rotation.w));
|
tr.setRotation(btQuaternion(rotation.x,rotation.y,rotation.z,rotation.w));
|
||||||
body->setWorldTransform(tr);
|
body->setWorldTransform(tr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MWScene::addActor (const std::string& handle, const std::string& mesh,
|
void MWScene::addActor (const std::string& handle, const std::string& mesh,
|
||||||
const Ogre::Vector3& position)
|
const Ogre::Vector3& position)
|
||||||
{
|
{
|
||||||
//TODO:optimize this. Searching the std::map isn't very efficient i think.
|
//TODO:optimize this. Searching the std::map isn't very efficient i think.
|
||||||
eng->addCharacter(handle);
|
eng->addCharacter(handle);
|
||||||
OEngine::Physic::PhysicActor* act = eng->getCharacter(handle);
|
OEngine::Physic::PhysicActor* act = eng->getCharacter(handle);
|
||||||
act->setPosition(btVector3(position.x,position.y,position.z));
|
act->setPosition(btVector3(position.x,position.y,position.z));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MWScene::removeObject (const std::string& handle)
|
void MWScene::removeObject (const std::string& handle)
|
||||||
{
|
{
|
||||||
//TODO:check if actor???
|
//TODO:check if actor???
|
||||||
eng->removeCharacter(handle);
|
eng->removeCharacter(handle);
|
||||||
eng->removeRigidBody(handle);
|
eng->removeRigidBody(handle);
|
||||||
eng->deleteRigidBody(handle);
|
eng->deleteRigidBody(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MWScene::moveObject (const std::string& handle, const Ogre::Vector3& position, bool updatePhysics)
|
void MWScene::moveObject (const std::string& handle, const Ogre::Vector3& position, bool updatePhysics)
|
||||||
|
|
|
@ -40,7 +40,7 @@ namespace MWRender
|
||||||
Ogre::SceneNode *mwRoot;
|
Ogre::SceneNode *mwRoot;
|
||||||
Ogre::RaySceneQuery *mRaySceneQuery;
|
Ogre::RaySceneQuery *mRaySceneQuery;
|
||||||
|
|
||||||
OEngine::Physic::PhysicEngine* eng;
|
OEngine::Physic::PhysicEngine* eng;
|
||||||
|
|
||||||
MWRender::Player *mPlayer;
|
MWRender::Player *mPlayer;
|
||||||
|
|
||||||
|
|
|
@ -412,7 +412,7 @@ namespace MWWorld
|
||||||
: mSkyManager (0), mScene (renderer,physEng), mPlayer (0), mCurrentCell (0), mGlobalVariables (0),
|
: mSkyManager (0), mScene (renderer,physEng), mPlayer (0), mCurrentCell (0), mGlobalVariables (0),
|
||||||
mSky (false), mCellChanged (false), mEnvironment (environment)
|
mSky (false), mCellChanged (false), mEnvironment (environment)
|
||||||
{
|
{
|
||||||
mPhysEngine = physEng;
|
mPhysEngine = physEng;
|
||||||
boost::filesystem::path masterPath (dataDir);
|
boost::filesystem::path masterPath (dataDir);
|
||||||
masterPath /= master;
|
masterPath /= master;
|
||||||
|
|
||||||
|
@ -437,7 +437,7 @@ namespace MWWorld
|
||||||
mSkyManager =
|
mSkyManager =
|
||||||
MWRender::SkyManager::create(renderer.getWindow(), mScene.getCamera(), resDir);
|
MWRender::SkyManager::create(renderer.getWindow(), mScene.getCamera(), resDir);
|
||||||
|
|
||||||
mPhysEngine = physEng;
|
mPhysEngine = physEng;
|
||||||
}
|
}
|
||||||
|
|
||||||
World::~World()
|
World::~World()
|
||||||
|
|
|
@ -75,7 +75,7 @@ namespace MWWorld
|
||||||
bool mCellChanged;
|
bool mCellChanged;
|
||||||
Environment& mEnvironment;
|
Environment& mEnvironment;
|
||||||
|
|
||||||
OEngine::Physic::PhysicEngine* mPhysEngine;
|
OEngine::Physic::PhysicEngine* mPhysEngine;
|
||||||
|
|
||||||
// not implemented
|
// not implemented
|
||||||
World (const World&);
|
World (const World&);
|
||||||
|
|
|
@ -24,23 +24,23 @@ namespace Interpreter
|
||||||
interpreter.installSegment5 (8, new OpNegateFloat);
|
interpreter.installSegment5 (8, new OpNegateFloat);
|
||||||
interpreter.installSegment5 (17, new OpIntToFloat1);
|
interpreter.installSegment5 (17, new OpIntToFloat1);
|
||||||
interpreter.installSegment5 (18, new OpFloatToInt1);
|
interpreter.installSegment5 (18, new OpFloatToInt1);
|
||||||
|
|
||||||
// local variables, global variables & literals
|
// local variables, global variables & literals
|
||||||
interpreter.installSegment5 (0, new OpStoreLocalShort);
|
interpreter.installSegment5 (0, new OpStoreLocalShort);
|
||||||
interpreter.installSegment5 (1, new OpStoreLocalLong);
|
interpreter.installSegment5 (1, new OpStoreLocalLong);
|
||||||
interpreter.installSegment5 (2, new OpStoreLocalFloat);
|
interpreter.installSegment5 (2, new OpStoreLocalFloat);
|
||||||
interpreter.installSegment5 (4, new OpFetchIntLiteral);
|
interpreter.installSegment5 (4, new OpFetchIntLiteral);
|
||||||
interpreter.installSegment5 (5, new OpFetchFloatLiteral);
|
interpreter.installSegment5 (5, new OpFetchFloatLiteral);
|
||||||
interpreter.installSegment5 (21, new OpFetchLocalShort);
|
interpreter.installSegment5 (21, new OpFetchLocalShort);
|
||||||
interpreter.installSegment5 (22, new OpFetchLocalLong);
|
interpreter.installSegment5 (22, new OpFetchLocalLong);
|
||||||
interpreter.installSegment5 (23, new OpFetchLocalFloat);
|
interpreter.installSegment5 (23, new OpFetchLocalFloat);
|
||||||
interpreter.installSegment5 (39, new OpStoreGlobalShort);
|
interpreter.installSegment5 (39, new OpStoreGlobalShort);
|
||||||
interpreter.installSegment5 (40, new OpStoreGlobalLong);
|
interpreter.installSegment5 (40, new OpStoreGlobalLong);
|
||||||
interpreter.installSegment5 (41, new OpStoreGlobalFloat);
|
interpreter.installSegment5 (41, new OpStoreGlobalFloat);
|
||||||
interpreter.installSegment5 (42, new OpFetchGlobalShort);
|
interpreter.installSegment5 (42, new OpFetchGlobalShort);
|
||||||
interpreter.installSegment5 (43, new OpFetchGlobalLong);
|
interpreter.installSegment5 (43, new OpFetchGlobalLong);
|
||||||
interpreter.installSegment5 (44, new OpFetchGlobalFloat);
|
interpreter.installSegment5 (44, new OpFetchGlobalFloat);
|
||||||
|
|
||||||
// math
|
// math
|
||||||
interpreter.installSegment5 (9, new OpAddInt<Type_Integer>);
|
interpreter.installSegment5 (9, new OpAddInt<Type_Integer>);
|
||||||
interpreter.installSegment5 (10, new OpAddInt<Type_Float>);
|
interpreter.installSegment5 (10, new OpAddInt<Type_Float>);
|
||||||
|
@ -50,57 +50,57 @@ namespace Interpreter
|
||||||
interpreter.installSegment5 (14, new OpMulInt<Type_Float>);
|
interpreter.installSegment5 (14, new OpMulInt<Type_Float>);
|
||||||
interpreter.installSegment5 (15, new OpDivInt<Type_Integer>);
|
interpreter.installSegment5 (15, new OpDivInt<Type_Integer>);
|
||||||
interpreter.installSegment5 (16, new OpDivInt<Type_Float>);
|
interpreter.installSegment5 (16, new OpDivInt<Type_Float>);
|
||||||
interpreter.installSegment5 (19, new OpSquareRoot);
|
interpreter.installSegment5 (19, new OpSquareRoot);
|
||||||
interpreter.installSegment5 (26,
|
interpreter.installSegment5 (26,
|
||||||
new OpCompare<Type_Integer, std::equal_to<Type_Integer> >);
|
new OpCompare<Type_Integer, std::equal_to<Type_Integer> >);
|
||||||
interpreter.installSegment5 (27,
|
interpreter.installSegment5 (27,
|
||||||
new OpCompare<Type_Integer, std::not_equal_to<Type_Integer> >);
|
new OpCompare<Type_Integer, std::not_equal_to<Type_Integer> >);
|
||||||
interpreter.installSegment5 (28,
|
interpreter.installSegment5 (28,
|
||||||
new OpCompare<Type_Integer, std::less<Type_Integer> >);
|
new OpCompare<Type_Integer, std::less<Type_Integer> >);
|
||||||
interpreter.installSegment5 (29,
|
interpreter.installSegment5 (29,
|
||||||
new OpCompare<Type_Integer, std::less_equal<Type_Integer> >);
|
new OpCompare<Type_Integer, std::less_equal<Type_Integer> >);
|
||||||
interpreter.installSegment5 (30,
|
interpreter.installSegment5 (30,
|
||||||
new OpCompare<Type_Integer, std::greater<Type_Integer> >);
|
new OpCompare<Type_Integer, std::greater<Type_Integer> >);
|
||||||
interpreter.installSegment5 (31,
|
interpreter.installSegment5 (31,
|
||||||
new OpCompare<Type_Integer, std::greater_equal<Type_Integer> >);
|
new OpCompare<Type_Integer, std::greater_equal<Type_Integer> >);
|
||||||
|
|
||||||
interpreter.installSegment5 (32,
|
interpreter.installSegment5 (32,
|
||||||
new OpCompare<Type_Float, std::equal_to<Type_Float> >);
|
new OpCompare<Type_Float, std::equal_to<Type_Float> >);
|
||||||
interpreter.installSegment5 (33,
|
interpreter.installSegment5 (33,
|
||||||
new OpCompare<Type_Float, std::not_equal_to<Type_Float> >);
|
new OpCompare<Type_Float, std::not_equal_to<Type_Float> >);
|
||||||
interpreter.installSegment5 (34,
|
interpreter.installSegment5 (34,
|
||||||
new OpCompare<Type_Float, std::less<Type_Float> >);
|
new OpCompare<Type_Float, std::less<Type_Float> >);
|
||||||
interpreter.installSegment5 (35,
|
interpreter.installSegment5 (35,
|
||||||
new OpCompare<Type_Float, std::less_equal<Type_Float> >);
|
new OpCompare<Type_Float, std::less_equal<Type_Float> >);
|
||||||
interpreter.installSegment5 (36,
|
interpreter.installSegment5 (36,
|
||||||
new OpCompare<Type_Float, std::greater<Type_Float> >);
|
new OpCompare<Type_Float, std::greater<Type_Float> >);
|
||||||
interpreter.installSegment5 (37,
|
interpreter.installSegment5 (37,
|
||||||
new OpCompare<Type_Float, std::greater_equal<Type_Float> >);
|
new OpCompare<Type_Float, std::greater_equal<Type_Float> >);
|
||||||
|
|
||||||
// control structures
|
// control structures
|
||||||
interpreter.installSegment5 (20, new OpReturn);
|
interpreter.installSegment5 (20, new OpReturn);
|
||||||
interpreter.installSegment5 (24, new OpSkipZero);
|
interpreter.installSegment5 (24, new OpSkipZero);
|
||||||
interpreter.installSegment5 (25, new OpSkipNonZero);
|
interpreter.installSegment5 (25, new OpSkipNonZero);
|
||||||
interpreter.installSegment0 (1, new OpJumpForward);
|
interpreter.installSegment0 (1, new OpJumpForward);
|
||||||
interpreter.installSegment0 (2, new OpJumpBackward);
|
interpreter.installSegment0 (2, new OpJumpBackward);
|
||||||
|
|
||||||
// misc
|
// misc
|
||||||
interpreter.installSegment3 (0, new OpMessageBox);
|
interpreter.installSegment3 (0, new OpMessageBox);
|
||||||
interpreter.installSegment5 (38, new OpMenuMode);
|
interpreter.installSegment5 (38, new OpMenuMode);
|
||||||
interpreter.installSegment5 (45, new OpRandom);
|
interpreter.installSegment5 (45, new OpRandom);
|
||||||
interpreter.installSegment5 (50, new OpGetSecondsPassed);
|
interpreter.installSegment5 (50, new OpGetSecondsPassed);
|
||||||
interpreter.installSegment5 (51, new OpEnable);
|
interpreter.installSegment5 (51, new OpEnable);
|
||||||
interpreter.installSegment5 (52, new OpDisable);
|
interpreter.installSegment5 (52, new OpDisable);
|
||||||
interpreter.installSegment5 (53, new OpGetDisabled);
|
interpreter.installSegment5 (53, new OpGetDisabled);
|
||||||
interpreter.installSegment5 (54, new OpEnableExplicit);
|
interpreter.installSegment5 (54, new OpEnableExplicit);
|
||||||
interpreter.installSegment5 (55, new OpDisableExplicit);
|
interpreter.installSegment5 (55, new OpDisableExplicit);
|
||||||
interpreter.installSegment5 (56, new OpGetDisabledExplicit);
|
interpreter.installSegment5 (56, new OpGetDisabledExplicit);
|
||||||
|
|
||||||
// script control
|
// script control
|
||||||
interpreter.installSegment5 (46, new OpScriptRunning);
|
interpreter.installSegment5 (46, new OpScriptRunning);
|
||||||
interpreter.installSegment5 (47, new OpStartScript);
|
interpreter.installSegment5 (47, new OpStartScript);
|
||||||
interpreter.installSegment5 (48, new OpStopScript);
|
interpreter.installSegment5 (48, new OpStopScript);
|
||||||
|
|
||||||
// spacial
|
// spacial
|
||||||
interpreter.installSegment5 (49, new OpGetDistance);
|
interpreter.installSegment5 (49, new OpGetDistance);
|
||||||
interpreter.installSegment5 (57, new OpGetDistanceExplicit);
|
interpreter.installSegment5 (57, new OpGetDistanceExplicit);
|
||||||
|
|
|
@ -92,8 +92,8 @@ void NIFFile::parse()
|
||||||
else if(rec == "NiRotatingParticles") { r = new NiRotatingParticles; r->recType = RC_NiRotatingParticles; }
|
else if(rec == "NiRotatingParticles") { r = new NiRotatingParticles; r->recType = RC_NiRotatingParticles; }
|
||||||
else if(rec == "NiAutoNormalParticles") { r = new NiAutoNormalParticles; r->recType = RC_NiAutoNormalParticles; }
|
else if(rec == "NiAutoNormalParticles") { r = new NiAutoNormalParticles; r->recType = RC_NiAutoNormalParticles; }
|
||||||
else if(rec == "NiCamera") { r = new NiCamera; r->recType = RC_NiCamera; }
|
else if(rec == "NiCamera") { r = new NiCamera; r->recType = RC_NiCamera; }
|
||||||
else if(rec == "RootCollisionNode"){ r = new NiNode; r->recType = RC_RootCollisionNode; }// a root collision node is exactly like a node
|
else if(rec == "RootCollisionNode"){ r = new NiNode; r->recType = RC_RootCollisionNode; }// a root collision node is exactly like a node
|
||||||
//that's why there is no need to create a new type
|
//that's why there is no need to create a new type
|
||||||
|
|
||||||
// Properties
|
// Properties
|
||||||
else if(rec == "NiTexturingProperty") { r = new NiTexturingProperty; r->recType = RC_NiTexturingProperty; }
|
else if(rec == "NiTexturingProperty") { r = new NiTexturingProperty; r->recType = RC_NiTexturingProperty; }
|
||||||
|
|
|
@ -54,264 +54,264 @@ using namespace Mangle::VFS;
|
||||||
//====================================================================================================
|
//====================================================================================================
|
||||||
Ogre::Matrix3 ManualBulletShapeLoader::getMatrix(Nif::Transformation* tr)
|
Ogre::Matrix3 ManualBulletShapeLoader::getMatrix(Nif::Transformation* tr)
|
||||||
{
|
{
|
||||||
Ogre::Matrix3 rot(tr->rotation.v[0].array[0],tr->rotation.v[0].array[1],tr->rotation.v[0].array[2],
|
Ogre::Matrix3 rot(tr->rotation.v[0].array[0],tr->rotation.v[0].array[1],tr->rotation.v[0].array[2],
|
||||||
tr->rotation.v[1].array[0],tr->rotation.v[1].array[1],tr->rotation.v[1].array[2],
|
tr->rotation.v[1].array[0],tr->rotation.v[1].array[1],tr->rotation.v[1].array[2],
|
||||||
tr->rotation.v[2].array[0],tr->rotation.v[2].array[1],tr->rotation.v[2].array[2]);
|
tr->rotation.v[2].array[0],tr->rotation.v[2].array[1],tr->rotation.v[2].array[2]);
|
||||||
return rot;
|
return rot;
|
||||||
}
|
}
|
||||||
Ogre::Vector3 ManualBulletShapeLoader::getVector(Nif::Transformation* tr)
|
Ogre::Vector3 ManualBulletShapeLoader::getVector(Nif::Transformation* tr)
|
||||||
{
|
{
|
||||||
Ogre::Vector3 vect3(tr->pos.array[0],tr->pos.array[1],tr->pos.array[2]);
|
Ogre::Vector3 vect3(tr->pos.array[0],tr->pos.array[1],tr->pos.array[2]);
|
||||||
return vect3;
|
return vect3;
|
||||||
}
|
}
|
||||||
|
|
||||||
btQuaternion ManualBulletShapeLoader::getbtQuat(Ogre::Matrix3 m)
|
btQuaternion ManualBulletShapeLoader::getbtQuat(Ogre::Matrix3 m)
|
||||||
{
|
{
|
||||||
Ogre::Quaternion oquat(m);
|
Ogre::Quaternion oquat(m);
|
||||||
btQuaternion quat;
|
btQuaternion quat;
|
||||||
quat.setW(oquat.w);
|
quat.setW(oquat.w);
|
||||||
quat.setX(oquat.x);
|
quat.setX(oquat.x);
|
||||||
quat.setY(oquat.y);
|
quat.setY(oquat.y);
|
||||||
quat.setZ(oquat.z);
|
quat.setZ(oquat.z);
|
||||||
return quat;
|
return quat;
|
||||||
}
|
}
|
||||||
|
|
||||||
btVector3 ManualBulletShapeLoader::getbtVector(Nif::Vector v)
|
btVector3 ManualBulletShapeLoader::getbtVector(Nif::Vector v)
|
||||||
{
|
{
|
||||||
btVector3 a(v.array[0],v.array[1],v.array[2]);
|
btVector3 a(v.array[0],v.array[1],v.array[2]);
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource)
|
void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource)
|
||||||
{
|
{
|
||||||
cShape = static_cast<BulletShape *>(resource);
|
cShape = static_cast<BulletShape *>(resource);
|
||||||
resourceName = cShape->getName();
|
resourceName = cShape->getName();
|
||||||
cShape->collide = false;
|
cShape->collide = false;
|
||||||
|
|
||||||
currentShape = new btCompoundShape();
|
currentShape = new btCompoundShape();
|
||||||
cShape->Shape = currentShape;
|
cShape->Shape = currentShape;
|
||||||
|
|
||||||
if (!vfs) vfs = new OgreVFS(resourceGroup);
|
if (!vfs) vfs = new OgreVFS(resourceGroup);
|
||||||
|
|
||||||
if (!vfs->isFile(resourceName))
|
if (!vfs->isFile(resourceName))
|
||||||
{
|
{
|
||||||
warn("File not found.");
|
warn("File not found.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the NIF. TODO: Wrap this in a try-catch block once we're out
|
// Load the NIF. TODO: Wrap this in a try-catch block once we're out
|
||||||
// of the early stages of development. Right now we WANT to catch
|
// of the early stages of development. Right now we WANT to catch
|
||||||
// every error as early and intrusively as possible, as it's most
|
// every error as early and intrusively as possible, as it's most
|
||||||
// likely a sign of incomplete code rather than faulty input.
|
// likely a sign of incomplete code rather than faulty input.
|
||||||
Nif::NIFFile nif(vfs->open(resourceName), resourceName);
|
Nif::NIFFile nif(vfs->open(resourceName), resourceName);
|
||||||
|
|
||||||
if (nif.numRecords() < 1)
|
if (nif.numRecords() < 1)
|
||||||
{
|
{
|
||||||
warn("Found no records in NIF.");
|
warn("Found no records in NIF.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// The first record is assumed to be the root node
|
// The first record is assumed to be the root node
|
||||||
Nif::Record *r = nif.getRecord(0);
|
Nif::Record *r = nif.getRecord(0);
|
||||||
assert(r != NULL);
|
assert(r != NULL);
|
||||||
|
|
||||||
Nif::Node *node = dynamic_cast<Nif::Node*>(r);
|
Nif::Node *node = dynamic_cast<Nif::Node*>(r);
|
||||||
|
|
||||||
if (node == NULL)
|
if (node == NULL)
|
||||||
{
|
{
|
||||||
warn("First record in file was not a node, but a " +
|
warn("First record in file was not a node, but a " +
|
||||||
r->recName.toString() + ". Skipping file.");
|
r->recName.toString() + ". Skipping file.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasCollisionNode = hasRootCollisionNode(node);
|
bool hasCollisionNode = hasRootCollisionNode(node);
|
||||||
|
|
||||||
//do a first pass
|
//do a first pass
|
||||||
handleNode(node,0,Ogre::Matrix3::IDENTITY,Ogre::Vector3::ZERO,1,hasCollisionNode,false,false);
|
handleNode(node,0,Ogre::Matrix3::IDENTITY,Ogre::Vector3::ZERO,1,hasCollisionNode,false,false);
|
||||||
|
|
||||||
//if collide = false, then it does a second pass which create a shape for raycasting.
|
//if collide = false, then it does a second pass which create a shape for raycasting.
|
||||||
if(cShape->collide == false)
|
if(cShape->collide == false)
|
||||||
{
|
{
|
||||||
handleNode(node,0,Ogre::Matrix3::IDENTITY,Ogre::Vector3::ZERO,1,hasCollisionNode,false,true);
|
handleNode(node,0,Ogre::Matrix3::IDENTITY,Ogre::Vector3::ZERO,1,hasCollisionNode,false,true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ManualBulletShapeLoader::hasRootCollisionNode(Nif::Node* node)
|
bool ManualBulletShapeLoader::hasRootCollisionNode(Nif::Node* node)
|
||||||
{
|
{
|
||||||
if (node->recType == Nif::RC_NiNode)
|
if (node->recType == Nif::RC_NiNode)
|
||||||
{
|
{
|
||||||
Nif::NodeList &list = ((Nif::NiNode*)node)->children;
|
Nif::NodeList &list = ((Nif::NiNode*)node)->children;
|
||||||
int n = list.length();
|
int n = list.length();
|
||||||
for (int i=0; i<n; i++)
|
for (int i=0; i<n; i++)
|
||||||
{
|
{
|
||||||
if (list.has(i))
|
if (list.has(i))
|
||||||
{
|
{
|
||||||
if(hasRootCollisionNode(&list[i])) return true;;
|
if(hasRootCollisionNode(&list[i])) return true;;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (node->recType == Nif::RC_NiTriShape)
|
else if (node->recType == Nif::RC_NiTriShape)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if(node->recType == Nif::RC_RootCollisionNode)
|
else if(node->recType == Nif::RC_RootCollisionNode)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ManualBulletShapeLoader::handleNode(Nif::Node *node, int flags,
|
void ManualBulletShapeLoader::handleNode(Nif::Node *node, int flags,
|
||||||
Ogre::Matrix3 parentRot,Ogre::Vector3 parentPos,float parentScale,bool hasCollisionNode,bool isCollisionNode,bool raycastingOnly)
|
Ogre::Matrix3 parentRot,Ogre::Vector3 parentPos,float parentScale,bool hasCollisionNode,bool isCollisionNode,bool raycastingOnly)
|
||||||
{
|
{
|
||||||
// Accumulate the flags from all the child nodes. This works for all
|
// Accumulate the flags from all the child nodes. This works for all
|
||||||
// the flags we currently use, at least.
|
// the flags we currently use, at least.
|
||||||
flags |= node->flags;
|
flags |= node->flags;
|
||||||
|
|
||||||
// Check for extra data
|
// Check for extra data
|
||||||
Nif::Extra *e = node;
|
Nif::Extra *e = node;
|
||||||
while (!e->extra.empty())
|
while (!e->extra.empty())
|
||||||
{
|
{
|
||||||
// Get the next extra data in the list
|
// Get the next extra data in the list
|
||||||
e = e->extra.getPtr();
|
e = e->extra.getPtr();
|
||||||
assert(e != NULL);
|
assert(e != NULL);
|
||||||
|
|
||||||
if (e->recType == Nif::RC_NiStringExtraData)
|
if (e->recType == Nif::RC_NiStringExtraData)
|
||||||
{
|
{
|
||||||
// String markers may contain important information
|
// String markers may contain important information
|
||||||
// affecting the entire subtree of this node
|
// affecting the entire subtree of this node
|
||||||
Nif::NiStringExtraData *sd = (Nif::NiStringExtraData*)e;
|
Nif::NiStringExtraData *sd = (Nif::NiStringExtraData*)e;
|
||||||
|
|
||||||
if (sd->string == "NCO" && !raycastingOnly)
|
if (sd->string == "NCO" && !raycastingOnly)
|
||||||
{
|
{
|
||||||
// No collision. Use an internal flag setting to mark this.
|
// No collision. Use an internal flag setting to mark this.
|
||||||
// We ignor this node!
|
// We ignor this node!
|
||||||
flags |= 0x800;
|
flags |= 0x800;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (sd->string == "MRK" && !raycastingOnly)
|
else if (sd->string == "MRK" && !raycastingOnly)
|
||||||
// Marker objects. These are only visible in the
|
// Marker objects. These are only visible in the
|
||||||
// editor. Until and unless we add an editor component to
|
// editor. Until and unless we add an editor component to
|
||||||
// the engine, just skip this entire node.
|
// the engine, just skip this entire node.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//transfo of parents node + curent node
|
//transfo of parents node + curent node
|
||||||
Ogre::Matrix3 finalRot;
|
Ogre::Matrix3 finalRot;
|
||||||
Ogre::Vector3 finalPos;
|
Ogre::Vector3 finalPos;
|
||||||
float finalScale;
|
float finalScale;
|
||||||
|
|
||||||
Nif::Transformation &final = *((Nif::Transformation*)node->trafo);
|
Nif::Transformation &final = *((Nif::Transformation*)node->trafo);
|
||||||
Ogre::Vector3 nodePos = getVector(&final);
|
Ogre::Vector3 nodePos = getVector(&final);
|
||||||
Ogre::Matrix3 nodeRot = getMatrix(&final);
|
Ogre::Matrix3 nodeRot = getMatrix(&final);
|
||||||
|
|
||||||
finalPos = nodePos + parentPos;
|
finalPos = nodePos + parentPos;
|
||||||
finalRot = parentRot*nodeRot;
|
finalRot = parentRot*nodeRot;
|
||||||
finalScale = final.scale*parentScale;
|
finalScale = final.scale*parentScale;
|
||||||
|
|
||||||
|
|
||||||
// For NiNodes, loop through children
|
// For NiNodes, loop through children
|
||||||
if (node->recType == Nif::RC_NiNode)
|
if (node->recType == Nif::RC_NiNode)
|
||||||
{
|
{
|
||||||
Nif::NodeList &list = ((Nif::NiNode*)node)->children;
|
Nif::NodeList &list = ((Nif::NiNode*)node)->children;
|
||||||
int n = list.length();
|
int n = list.length();
|
||||||
for (int i=0; i<n; i++)
|
for (int i=0; i<n; i++)
|
||||||
{
|
{
|
||||||
if (list.has(i))
|
if (list.has(i))
|
||||||
{
|
{
|
||||||
handleNode(&list[i], flags,finalRot,finalPos,finalScale,hasCollisionNode,isCollisionNode,raycastingOnly);
|
handleNode(&list[i], flags,finalRot,finalPos,finalScale,hasCollisionNode,isCollisionNode,raycastingOnly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (node->recType == Nif::RC_NiTriShape && (isCollisionNode || !hasCollisionNode))
|
else if (node->recType == Nif::RC_NiTriShape && (isCollisionNode || !hasCollisionNode))
|
||||||
{
|
{
|
||||||
cShape->collide = true;
|
cShape->collide = true;
|
||||||
handleNiTriShape(dynamic_cast<Nif::NiTriShape*>(node), flags,finalRot,finalPos,finalScale,raycastingOnly);
|
handleNiTriShape(dynamic_cast<Nif::NiTriShape*>(node), flags,finalRot,finalPos,finalScale,raycastingOnly);
|
||||||
}
|
}
|
||||||
else if(node->recType == Nif::RC_RootCollisionNode)
|
else if(node->recType == Nif::RC_RootCollisionNode)
|
||||||
{
|
{
|
||||||
Nif::NodeList &list = ((Nif::NiNode*)node)->children;
|
Nif::NodeList &list = ((Nif::NiNode*)node)->children;
|
||||||
int n = list.length();
|
int n = list.length();
|
||||||
for (int i=0; i<n; i++)
|
for (int i=0; i<n; i++)
|
||||||
{
|
{
|
||||||
if (list.has(i))
|
if (list.has(i))
|
||||||
handleNode(&list[i], flags,finalRot,finalPos,finalScale,hasCollisionNode,true,raycastingOnly);
|
handleNode(&list[i], flags,finalRot,finalPos,finalScale,hasCollisionNode,true,raycastingOnly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ManualBulletShapeLoader::handleNiTriShape(Nif::NiTriShape *shape, int flags,Ogre::Matrix3 parentRot,Ogre::Vector3 parentPos,float parentScale,
|
void ManualBulletShapeLoader::handleNiTriShape(Nif::NiTriShape *shape, int flags,Ogre::Matrix3 parentRot,Ogre::Vector3 parentPos,float parentScale,
|
||||||
bool raycastingOnly)
|
bool raycastingOnly)
|
||||||
{
|
{
|
||||||
assert(shape != NULL);
|
assert(shape != NULL);
|
||||||
btCollisionShape* NodeShape;
|
btCollisionShape* NodeShape;
|
||||||
|
|
||||||
// Interpret flags
|
// Interpret flags
|
||||||
bool hidden = (flags & 0x01) != 0; // Not displayed
|
bool hidden = (flags & 0x01) != 0; // Not displayed
|
||||||
bool collide = (flags & 0x02) != 0; // Use mesh for collision
|
bool collide = (flags & 0x02) != 0; // Use mesh for collision
|
||||||
bool bbcollide = (flags & 0x04) != 0; // Use bounding box for collision
|
bool bbcollide = (flags & 0x04) != 0; // Use bounding box for collision
|
||||||
|
|
||||||
// If the object was marked "NCO" earlier, it shouldn't collide with
|
// If the object was marked "NCO" earlier, it shouldn't collide with
|
||||||
// anything. So don't do anything.
|
// anything. So don't do anything.
|
||||||
if (flags & 0x800 && !raycastingOnly)
|
if (flags & 0x800 && !raycastingOnly)
|
||||||
{
|
{
|
||||||
collide = false;
|
collide = false;
|
||||||
bbcollide = false;
|
bbcollide = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!collide && !bbcollide && hidden && !raycastingOnly)
|
if (!collide && !bbcollide && hidden && !raycastingOnly)
|
||||||
// This mesh apparently isn't being used for anything, so don't
|
// This mesh apparently isn't being used for anything, so don't
|
||||||
// bother setting it up.
|
// bother setting it up.
|
||||||
return;
|
return;
|
||||||
|
|
||||||
btTransform tr;
|
btTransform tr;
|
||||||
tr.setRotation(getbtQuat(parentRot));
|
tr.setRotation(getbtQuat(parentRot));
|
||||||
tr.setOrigin(btVector3(parentPos.x,parentPos.y,parentPos.z));
|
tr.setOrigin(btVector3(parentPos.x,parentPos.y,parentPos.z));
|
||||||
|
|
||||||
// Bounding box collision isn't implemented, always use mesh for now.
|
// Bounding box collision isn't implemented, always use mesh for now.
|
||||||
/*if (bbcollide)
|
/*if (bbcollide)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
std::cout << "bbcolide?";
|
std::cout << "bbcolide?";
|
||||||
//TODO: check whether it's half box or not (is there a /2?)
|
//TODO: check whether it's half box or not (is there a /2?)
|
||||||
NodeShape = new btBoxShape(btVector3(shape->boundXYZ->array[0]/2.,shape->boundXYZ->array[1]/2.,shape->boundXYZ->array[2]/2.));
|
NodeShape = new btBoxShape(btVector3(shape->boundXYZ->array[0]/2.,shape->boundXYZ->array[1]/2.,shape->boundXYZ->array[2]/2.));
|
||||||
std::cout << "bbcolide12121212121";
|
std::cout << "bbcolide12121212121";
|
||||||
currentShape->addChildShape(tr,NodeShape);
|
currentShape->addChildShape(tr,NodeShape);
|
||||||
std::cout << "aaaaaaaaaaaaa";
|
std::cout << "aaaaaaaaaaaaa";
|
||||||
return;
|
return;
|
||||||
collide = true;
|
collide = true;
|
||||||
bbcollide = false;
|
bbcollide = false;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
/* Do in-place transformation.the only needed transfo is the scale. (maybe not in fact)
|
/* Do in-place transformation.the only needed transfo is the scale. (maybe not in fact)
|
||||||
*/
|
*/
|
||||||
btTriangleMesh *mTriMesh = new btTriangleMesh();
|
btTriangleMesh *mTriMesh = new btTriangleMesh();
|
||||||
|
|
||||||
Nif::NiTriShapeData *data = shape->data.getPtr();
|
Nif::NiTriShapeData *data = shape->data.getPtr();
|
||||||
|
|
||||||
float* vertices = (float*)data->vertices.ptr;
|
float* vertices = (float*)data->vertices.ptr;
|
||||||
unsigned short* triangles = (unsigned short*)data->triangles.ptr;
|
unsigned short* triangles = (unsigned short*)data->triangles.ptr;
|
||||||
|
|
||||||
for(unsigned int i=0; i < data->triangles.length; i = i+3)
|
for(unsigned int i=0; i < data->triangles.length; i = i+3)
|
||||||
{
|
{
|
||||||
btVector3 b1(vertices[triangles[i+0]*3]*parentScale,vertices[triangles[i+0]*3+1]*parentScale,vertices[triangles[i+0]*3+2]*parentScale);
|
btVector3 b1(vertices[triangles[i+0]*3]*parentScale,vertices[triangles[i+0]*3+1]*parentScale,vertices[triangles[i+0]*3+2]*parentScale);
|
||||||
btVector3 b2(vertices[triangles[i+1]*3]*parentScale,vertices[triangles[i+1]*3+1]*parentScale,vertices[triangles[i+1]*3+2]*parentScale);
|
btVector3 b2(vertices[triangles[i+1]*3]*parentScale,vertices[triangles[i+1]*3+1]*parentScale,vertices[triangles[i+1]*3+2]*parentScale);
|
||||||
btVector3 b3(vertices[triangles[i+2]*3]*parentScale,vertices[triangles[i+2]*3+1]*parentScale,vertices[triangles[i+2]*3+2]*parentScale);
|
btVector3 b3(vertices[triangles[i+2]*3]*parentScale,vertices[triangles[i+2]*3+1]*parentScale,vertices[triangles[i+2]*3+2]*parentScale);
|
||||||
mTriMesh->addTriangle(b1,b2,b3);
|
mTriMesh->addTriangle(b1,b2,b3);
|
||||||
}
|
}
|
||||||
NodeShape = new btBvhTriangleMeshShape(mTriMesh,true);
|
NodeShape = new btBvhTriangleMeshShape(mTriMesh,true);
|
||||||
currentShape->addChildShape(tr,NodeShape);
|
currentShape->addChildShape(tr,NodeShape);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ManualBulletShapeLoader::load(const std::string &name,const std::string &group)
|
void ManualBulletShapeLoader::load(const std::string &name,const std::string &group)
|
||||||
{
|
{
|
||||||
// Check if the resource already exists
|
// Check if the resource already exists
|
||||||
Ogre::ResourcePtr ptr = BulletShapeManager::getSingleton().getByName(name, group);
|
Ogre::ResourcePtr ptr = BulletShapeManager::getSingleton().getByName(name, group);
|
||||||
if (!ptr.isNull())
|
if (!ptr.isNull())
|
||||||
return;
|
return;
|
||||||
BulletShapeManager::getSingleton().create(name,group,true,this);
|
BulletShapeManager::getSingleton().create(name,group,true,this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,10 +52,10 @@ namespace Nif
|
||||||
|
|
||||||
namespace Mangle
|
namespace Mangle
|
||||||
{
|
{
|
||||||
namespace VFS
|
namespace VFS
|
||||||
{
|
{
|
||||||
class OgreVFS;
|
class OgreVFS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,64 +66,64 @@ class ManualBulletShapeLoader : public BulletShapeLoader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ManualBulletShapeLoader():resourceGroup("General"){vfs = 0;}
|
ManualBulletShapeLoader():resourceGroup("General"){vfs = 0;}
|
||||||
virtual ~ManualBulletShapeLoader() {}
|
virtual ~ManualBulletShapeLoader() {}
|
||||||
|
|
||||||
void warn(std::string msg)
|
void warn(std::string msg)
|
||||||
{
|
{
|
||||||
std::cerr << "NIFLoader: Warn:" << msg << "\n";
|
std::cerr << "NIFLoader: Warn:" << msg << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail(std::string msg)
|
void fail(std::string msg)
|
||||||
{
|
{
|
||||||
std::cerr << "NIFLoader: Fail: "<< msg << std::endl;
|
std::cerr << "NIFLoader: Fail: "<< msg << std::endl;
|
||||||
assert(1);
|
assert(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*This function should not be called manualy. Use load instead. (this is called by the BulletShapeManager when you use load).
|
*This function should not be called manualy. Use load instead. (this is called by the BulletShapeManager when you use load).
|
||||||
*/
|
*/
|
||||||
void loadResource(Ogre::Resource *resource);
|
void loadResource(Ogre::Resource *resource);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*This function load a new bulletShape from a NIF file into the BulletShapeManager.
|
*This function load a new bulletShape from a NIF file into the BulletShapeManager.
|
||||||
*When the file is loaded, you can then use BulletShapeManager::getByName() to retrive the bulletShape.
|
*When the file is loaded, you can then use BulletShapeManager::getByName() to retrive the bulletShape.
|
||||||
*Warning: this function will just crash if the resourceGroup doesn't exist!
|
*Warning: this function will just crash if the resourceGroup doesn't exist!
|
||||||
*/
|
*/
|
||||||
void load(const std::string &name,const std::string &group);
|
void load(const std::string &name,const std::string &group);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ogre::Matrix3 getMatrix(Nif::Transformation* tr);
|
Ogre::Matrix3 getMatrix(Nif::Transformation* tr);
|
||||||
|
|
||||||
Ogre::Vector3 getVector(Nif::Transformation* tr);
|
Ogre::Vector3 getVector(Nif::Transformation* tr);
|
||||||
|
|
||||||
btQuaternion getbtQuat(Ogre::Matrix3 m);
|
btQuaternion getbtQuat(Ogre::Matrix3 m);
|
||||||
|
|
||||||
btVector3 getbtVector(Nif::Vector v);
|
btVector3 getbtVector(Nif::Vector v);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*Parse a node.
|
*Parse a node.
|
||||||
*/
|
*/
|
||||||
void handleNode(Nif::Node *node, int flags,
|
void handleNode(Nif::Node *node, int flags,
|
||||||
Ogre::Matrix3 parentRot,Ogre::Vector3 parentPos,float parentScale,bool hasCollisionNode,bool isCollisionNode,bool raycastingOnly);
|
Ogre::Matrix3 parentRot,Ogre::Vector3 parentPos,float parentScale,bool hasCollisionNode,bool isCollisionNode,bool raycastingOnly);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*Helpler function
|
*Helpler function
|
||||||
*/
|
*/
|
||||||
bool hasRootCollisionNode(Nif::Node* node);
|
bool hasRootCollisionNode(Nif::Node* node);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*convert a NiTriShape to a bullet trishape.
|
*convert a NiTriShape to a bullet trishape.
|
||||||
*/
|
*/
|
||||||
void handleNiTriShape(Nif::NiTriShape *shape, int flags,Ogre::Matrix3 parentRot,Ogre::Vector3 parentPos,float parentScales,bool raycastingOnly);
|
void handleNiTriShape(Nif::NiTriShape *shape, int flags,Ogre::Matrix3 parentRot,Ogre::Vector3 parentPos,float parentScales,bool raycastingOnly);
|
||||||
|
|
||||||
Mangle::VFS::OgreVFS *vfs;
|
Mangle::VFS::OgreVFS *vfs;
|
||||||
|
|
||||||
std::string resourceName;
|
std::string resourceName;
|
||||||
std::string resourceGroup;
|
std::string resourceGroup;
|
||||||
|
|
||||||
BulletShape* cShape;//current shape
|
BulletShape* cShape;//current shape
|
||||||
btCompoundShape* currentShape;//the shape curently under construction
|
btCompoundShape* currentShape;//the shape curently under construction
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -17,7 +17,7 @@ public:
|
||||||
MyMotionState(const btTransform &initialpos, Ogre::SceneNode *node) {
|
MyMotionState(const btTransform &initialpos, Ogre::SceneNode *node) {
|
||||||
mVisibleobj = node;
|
mVisibleobj = node;
|
||||||
mPos1 = initialpos;
|
mPos1 = initialpos;
|
||||||
node->setPosition(initialpos.getOrigin().x(),initialpos.getOrigin().y(),initialpos.getOrigin().z());
|
node->setPosition(initialpos.getOrigin().x(),initialpos.getOrigin().y(),initialpos.getOrigin().z());
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~MyMotionState() {
|
virtual ~MyMotionState() {
|
||||||
|
@ -47,163 +47,163 @@ protected:
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//Ogre stuff
|
//Ogre stuff
|
||||||
|
|
||||||
Ogre::Root* pRoot = new Ogre::Root();
|
Ogre::Root* pRoot = new Ogre::Root();
|
||||||
pRoot->showConfigDialog();
|
pRoot->showConfigDialog();
|
||||||
|
|
||||||
BulletShapeManager* manag = new BulletShapeManager();
|
BulletShapeManager* manag = new BulletShapeManager();
|
||||||
|
|
||||||
Ogre::RenderWindow* win = pRoot->initialise(true,"test");
|
Ogre::RenderWindow* win = pRoot->initialise(true,"test");
|
||||||
Ogre::SceneManager* scmg = pRoot->createSceneManager(Ogre::ST_GENERIC,"MonGestionnaireDeScene");
|
Ogre::SceneManager* scmg = pRoot->createSceneManager(Ogre::ST_GENERIC,"MonGestionnaireDeScene");
|
||||||
Ogre::Camera* pCamera = scmg->createCamera("test");
|
Ogre::Camera* pCamera = scmg->createCamera("test");
|
||||||
Ogre::Viewport* pViewport = win->addViewport(pCamera);
|
Ogre::Viewport* pViewport = win->addViewport(pCamera);
|
||||||
pCamera->setPosition(-50,0,0);
|
pCamera->setPosition(-50,0,0);
|
||||||
pCamera->setFarClipDistance(10000);
|
pCamera->setFarClipDistance(10000);
|
||||||
pCamera->setNearClipDistance(1.);
|
pCamera->setNearClipDistance(1.);
|
||||||
pCamera->lookAt(0,0,0);
|
pCamera->lookAt(0,0,0);
|
||||||
//Ogre::ResourceGroupManager::getSingleton().addResourceLocation("C++/OgreSK/media/models","FileSystem","General");
|
//Ogre::ResourceGroupManager::getSingleton().addResourceLocation("C++/OgreSK/media/models","FileSystem","General");
|
||||||
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("","FileSystem","General");
|
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("","FileSystem","General");
|
||||||
/*Ogre::ResourceGroupManager::getSingleton().addResourceLocation("C++/OgreSK/media/materials/scripts","FileSystem","General");
|
/*Ogre::ResourceGroupManager::getSingleton().addResourceLocation("C++/OgreSK/media/materials/scripts","FileSystem","General");
|
||||||
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("C++/OgreSK/media/materials/textures","FileSystem","General");
|
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("C++/OgreSK/media/materials/textures","FileSystem","General");
|
||||||
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("C++/OgreSK/media/materials/programs","FileSystem","General");*/
|
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("C++/OgreSK/media/materials/programs","FileSystem","General");*/
|
||||||
|
|
||||||
|
|
||||||
//OIS stuff
|
//OIS stuff
|
||||||
OIS::ParamList pl;
|
OIS::ParamList pl;
|
||||||
size_t windowHnd = 0;
|
size_t windowHnd = 0;
|
||||||
std::ostringstream windowHndStr;
|
std::ostringstream windowHndStr;
|
||||||
win->getCustomAttribute("WINDOW", &windowHnd);
|
win->getCustomAttribute("WINDOW", &windowHnd);
|
||||||
windowHndStr << windowHnd;
|
windowHndStr << windowHnd;
|
||||||
pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
|
pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
|
||||||
OIS::InputManager *pInputManager = OIS::InputManager::createInputSystem( pl );
|
OIS::InputManager *pInputManager = OIS::InputManager::createInputSystem( pl );
|
||||||
OIS::Mouse *pMouse = static_cast<OIS::Mouse*>(pInputManager->createInputObject(OIS::OISMouse, false));
|
OIS::Mouse *pMouse = static_cast<OIS::Mouse*>(pInputManager->createInputObject(OIS::OISMouse, false));
|
||||||
OIS::Keyboard* pKeyboard = static_cast<OIS::Keyboard*>(pInputManager->createInputObject(OIS::OISKeyboard, false));
|
OIS::Keyboard* pKeyboard = static_cast<OIS::Keyboard*>(pInputManager->createInputObject(OIS::OISKeyboard, false));
|
||||||
unsigned int width, height, depth;
|
unsigned int width, height, depth;
|
||||||
int top, left;
|
int top, left;
|
||||||
win->getMetrics(width, height, depth, left, top);
|
win->getMetrics(width, height, depth, left, top);
|
||||||
const OIS::MouseState &ms = pMouse->getMouseState();
|
const OIS::MouseState &ms = pMouse->getMouseState();
|
||||||
ms.width = width;
|
ms.width = width;
|
||||||
ms.height = height;
|
ms.height = height;
|
||||||
|
|
||||||
|
|
||||||
//Ressources stuff
|
//Ressources stuff
|
||||||
addBSA("Morrowind.bsa");
|
addBSA("Morrowind.bsa");
|
||||||
//Ogre::ResourceGroupManager::getSingleton().createResourceGroup("general");
|
//Ogre::ResourceGroupManager::getSingleton().createResourceGroup("general");
|
||||||
|
|
||||||
Ogre::ResourcePtr ptr = BulletShapeManager::getSingleton().getByName(mesh,"General");
|
Ogre::ResourcePtr ptr = BulletShapeManager::getSingleton().getByName(mesh,"General");
|
||||||
ManualBulletShapeLoader* ShapeLoader = new ManualBulletShapeLoader();
|
ManualBulletShapeLoader* ShapeLoader = new ManualBulletShapeLoader();
|
||||||
|
|
||||||
ShapeLoader->load(mesh,"General");
|
ShapeLoader->load(mesh,"General");
|
||||||
//BulletShapeManager::getSingleton().unload(mesh);
|
//BulletShapeManager::getSingleton().unload(mesh);
|
||||||
//ShapeLoader->load(mesh,"General");
|
//ShapeLoader->load(mesh,"General");
|
||||||
|
|
||||||
NIFLoader::load(mesh);
|
NIFLoader::load(mesh);
|
||||||
|
|
||||||
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
|
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
|
||||||
//BulletShapeManager::getSingleton().
|
//BulletShapeManager::getSingleton().
|
||||||
BulletShapePtr shape = BulletShapeManager::getSingleton().getByName(mesh,"General");
|
BulletShapePtr shape = BulletShapeManager::getSingleton().getByName(mesh,"General");
|
||||||
BulletShapeManager::getSingleton().load(mesh,"General");
|
BulletShapeManager::getSingleton().load(mesh,"General");
|
||||||
BulletShapeManager::getSingleton().unload(mesh);
|
BulletShapeManager::getSingleton().unload(mesh);
|
||||||
BulletShapeManager::getSingleton().load(mesh,"General");
|
BulletShapeManager::getSingleton().load(mesh,"General");
|
||||||
BulletShapeManager::getSingleton().load(mesh,"General");
|
BulletShapeManager::getSingleton().load(mesh,"General");
|
||||||
//shape->load();
|
//shape->load();
|
||||||
//shape->unload();
|
//shape->unload();
|
||||||
//shape->load();
|
//shape->load();
|
||||||
|
|
||||||
//Bullet init
|
//Bullet init
|
||||||
btBroadphaseInterface* broadphase = new btDbvtBroadphase();
|
btBroadphaseInterface* broadphase = new btDbvtBroadphase();
|
||||||
|
|
||||||
// Set up the collision configuration and dispatcher
|
// Set up the collision configuration and dispatcher
|
||||||
btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
|
btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
|
||||||
btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
|
btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
|
||||||
|
|
||||||
// The actual physics solver
|
// The actual physics solver
|
||||||
btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;
|
btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;
|
||||||
|
|
||||||
// The world.
|
// The world.
|
||||||
btDiscreteDynamicsWorld* dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration);
|
btDiscreteDynamicsWorld* dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration);
|
||||||
dynamicsWorld->setGravity(btVector3(0,-10,0));
|
dynamicsWorld->setGravity(btVector3(0,-10,0));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//le sol?
|
//le sol?
|
||||||
Ogre::SceneNode *node = scmg->getRootSceneNode()->createChildSceneNode("node");
|
Ogre::SceneNode *node = scmg->getRootSceneNode()->createChildSceneNode("node");
|
||||||
Ogre::Entity *ent = scmg->createEntity("Mesh1",mesh);
|
Ogre::Entity *ent = scmg->createEntity("Mesh1",mesh);
|
||||||
node->attachObject(ent);
|
node->attachObject(ent);
|
||||||
MyMotionState* mst = new MyMotionState(btTransform::getIdentity(),node);
|
MyMotionState* mst = new MyMotionState(btTransform::getIdentity(),node);
|
||||||
|
|
||||||
btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI(0,mst,shape->Shape,btVector3(0,0,0));
|
btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI(0,mst,shape->Shape,btVector3(0,0,0));
|
||||||
btRigidBody* groundRigidBody = new btRigidBody(groundRigidBodyCI);
|
btRigidBody* groundRigidBody = new btRigidBody(groundRigidBodyCI);
|
||||||
dynamicsWorld->addRigidBody(groundRigidBody);
|
dynamicsWorld->addRigidBody(groundRigidBody);
|
||||||
|
|
||||||
//une balle:
|
//une balle:
|
||||||
Ogre::SceneNode *node2 = scmg->getRootSceneNode()->createChildSceneNode("node2");
|
Ogre::SceneNode *node2 = scmg->getRootSceneNode()->createChildSceneNode("node2");
|
||||||
Ogre::Entity *ent2 = scmg->createEntity("Mesh2","ogrehead.mesh");
|
Ogre::Entity *ent2 = scmg->createEntity("Mesh2","ogrehead.mesh");
|
||||||
node2->attachObject(ent2);
|
node2->attachObject(ent2);
|
||||||
node2->setPosition(0,500,0);
|
node2->setPosition(0,500,0);
|
||||||
btTransform iT;
|
btTransform iT;
|
||||||
iT.setIdentity();
|
iT.setIdentity();
|
||||||
iT.setOrigin(btVector3(0,5000,0));
|
iT.setOrigin(btVector3(0,5000,0));
|
||||||
MyMotionState* mst2 = new MyMotionState(btTransform::getIdentity(),node2);
|
MyMotionState* mst2 = new MyMotionState(btTransform::getIdentity(),node2);
|
||||||
|
|
||||||
btSphereShape* sphereshape = new btSphereShape(10);
|
btSphereShape* sphereshape = new btSphereShape(10);
|
||||||
btRigidBody::btRigidBodyConstructionInfo sphereCI(10,mst2,sphereshape,btVector3(0,0,0));
|
btRigidBody::btRigidBodyConstructionInfo sphereCI(10,mst2,sphereshape,btVector3(0,0,0));
|
||||||
btRigidBody* sphere = new btRigidBody(sphereCI);
|
btRigidBody* sphere = new btRigidBody(sphereCI);
|
||||||
dynamicsWorld->addRigidBody(sphere);
|
dynamicsWorld->addRigidBody(sphere);
|
||||||
|
|
||||||
|
|
||||||
//btOgre!
|
//btOgre!
|
||||||
BtOgre::DebugDrawer* mDebugDrawer = new BtOgre::DebugDrawer(scmg->getRootSceneNode(), dynamicsWorld);
|
BtOgre::DebugDrawer* mDebugDrawer = new BtOgre::DebugDrawer(scmg->getRootSceneNode(), dynamicsWorld);
|
||||||
dynamicsWorld->setDebugDrawer(mDebugDrawer);
|
dynamicsWorld->setDebugDrawer(mDebugDrawer);
|
||||||
|
|
||||||
Ogre::Timer timer;
|
Ogre::Timer timer;
|
||||||
timer.reset();
|
timer.reset();
|
||||||
bool cont = true;
|
bool cont = true;
|
||||||
while(cont)
|
while(cont)
|
||||||
{
|
{
|
||||||
if(timer.getMilliseconds()>30)
|
if(timer.getMilliseconds()>30)
|
||||||
{
|
{
|
||||||
pMouse->capture();
|
pMouse->capture();
|
||||||
pKeyboard->capture();
|
pKeyboard->capture();
|
||||||
|
|
||||||
Ogre::Vector3 a(0,0,0);
|
Ogre::Vector3 a(0,0,0);
|
||||||
|
|
||||||
if(pKeyboard->isKeyDown(OIS::KC_UP))
|
if(pKeyboard->isKeyDown(OIS::KC_UP))
|
||||||
{
|
{
|
||||||
a = a + Ogre::Vector3(0,0,-20);
|
a = a + Ogre::Vector3(0,0,-20);
|
||||||
}
|
}
|
||||||
if(pKeyboard->isKeyDown(OIS::KC_DOWN))
|
if(pKeyboard->isKeyDown(OIS::KC_DOWN))
|
||||||
{
|
{
|
||||||
a = a + Ogre::Vector3(0,0,20);
|
a = a + Ogre::Vector3(0,0,20);
|
||||||
}
|
}
|
||||||
if(pKeyboard->isKeyDown(OIS::KC_ESCAPE))
|
if(pKeyboard->isKeyDown(OIS::KC_ESCAPE))
|
||||||
{
|
{
|
||||||
cont = false;
|
cont = false;
|
||||||
}
|
}
|
||||||
OIS::MouseState MS = pMouse->getMouseState();
|
OIS::MouseState MS = pMouse->getMouseState();
|
||||||
pCamera->yaw(-Ogre::Degree(MS.X.rel));
|
pCamera->yaw(-Ogre::Degree(MS.X.rel));
|
||||||
pCamera->pitch(-Ogre::Degree(MS.Y.rel));
|
pCamera->pitch(-Ogre::Degree(MS.Y.rel));
|
||||||
pCamera->moveRelative(a);
|
pCamera->moveRelative(a);
|
||||||
|
|
||||||
pRoot->renderOneFrame();
|
pRoot->renderOneFrame();
|
||||||
mDebugDrawer->step();
|
mDebugDrawer->step();
|
||||||
timer.reset();
|
timer.reset();
|
||||||
dynamicsWorld->stepSimulation(0.03);
|
dynamicsWorld->stepSimulation(0.03);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cout << "cool";
|
std::cout << "cool";
|
||||||
delete manag;
|
delete manag;
|
||||||
delete pRoot;
|
delete pRoot;
|
||||||
char a;
|
char a;
|
||||||
std::cin >> a;
|
std::cin >> a;
|
||||||
}
|
}
|
||||||
catch(Ogre::Exception& e)
|
catch(Ogre::Exception& e)
|
||||||
{
|
{
|
||||||
std::cout << e.getFullDescription();
|
std::cout << e.getFullDescription();
|
||||||
char a;
|
char a;
|
||||||
std::cin >> a;
|
std::cin >> a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 590f9e83d8158970dcbef1c5078a1a04cd8f1a59
|
Subproject commit f3c9694bf249a34eae05f0304e6bfc120014ce8c
|
|
@ -1 +1 @@
|
||||||
Subproject commit 32b475432f3e1c8d7275d17da0d692c173f30478
|
Subproject commit 0f7d59b4fb742c6479d988f6fc4ec9cdb4330b53
|
Loading…
Reference in a new issue