1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-05 17:45:34 +00:00

Starting to introduce pmove

This commit is contained in:
Jason Hooks 2012-09-15 18:17:42 -04:00
parent f586f53a42
commit f6384574da
3 changed files with 25 additions and 15 deletions

View file

@ -2,6 +2,7 @@
#include <btBulletDynamicsCommon.h> #include <btBulletDynamicsCommon.h>
#include <btBulletCollisionCommon.h> #include <btBulletCollisionCommon.h>
#include <BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h> #include <BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h>
#include "pmove.h"
#include <components/nifbullet/bullet_nif_loader.hpp> #include <components/nifbullet/bullet_nif_loader.hpp>
#include "CMotionState.h" #include "CMotionState.h"
#include "OgreRoot.h" #include "OgreRoot.h"
@ -33,6 +34,7 @@ namespace Physic
Ogre::Quaternion inverse = mBoxRotation.Inverse(); Ogre::Quaternion inverse = mBoxRotation.Inverse();
mBoxRotationInverse = btQuaternion(inverse.x, inverse.y, inverse.z,inverse.w); mBoxRotationInverse = btQuaternion(inverse.x, inverse.y, inverse.z,inverse.w);
mEngine->addRigidBody(mBody, false); //Add rigid body to dynamics world, but do not add to object map mEngine->addRigidBody(mBody, false); //Add rigid body to dynamics world, but do not add to object map
pmove = new playerMove;
} }
PhysicActor::~PhysicActor() PhysicActor::~PhysicActor()
@ -41,6 +43,7 @@ namespace Physic
mEngine->dynamicsWorld->removeRigidBody(mBody); mEngine->dynamicsWorld->removeRigidBody(mBody);
delete mBody; delete mBody;
} }
delete pmove;
} }
void PhysicActor::setGravity(float gravity) void PhysicActor::setGravity(float gravity)
@ -210,8 +213,8 @@ namespace Physic
delete hf_it->second.mBody; delete hf_it->second.mBody;
} }
RigidBodyContainer::iterator rb_it = RigidBodyMap.begin(); RigidBodyContainer::iterator rb_it = ObjectMap.begin();
for (; rb_it != RigidBodyMap.end(); ++rb_it) for (; rb_it != ObjectMap.end(); ++rb_it)
{ {
if (rb_it->second != NULL) if (rb_it->second != NULL)
{ {
@ -380,22 +383,22 @@ namespace Physic
} }
body->setActivationState(DISABLE_DEACTIVATION); body->setActivationState(DISABLE_DEACTIVATION);
if(addToMap){ if(addToMap){
RigidBody* oldBody = RigidBodyMap[body->mName]; RigidBody* oldBody = ObjectMap[body->mName];
if (oldBody != NULL) if (oldBody != NULL)
{ {
dynamicsWorld->removeRigidBody(oldBody); dynamicsWorld->removeRigidBody(oldBody);
delete oldBody; delete oldBody;
} }
RigidBodyMap[body->mName] = body; ObjectMap[body->mName] = body;
} }
} }
} }
void PhysicEngine::removeRigidBody(std::string name) void PhysicEngine::removeRigidBody(std::string name)
{ {
RigidBodyContainer::iterator it = RigidBodyMap.find(name); RigidBodyContainer::iterator it = ObjectMap.find(name);
if (it != RigidBodyMap.end() ) if (it != ObjectMap.end() )
{ {
RigidBody* body = it->second; RigidBody* body = it->second;
if(body != NULL) if(body != NULL)
@ -414,8 +417,8 @@ namespace Physic
void PhysicEngine::deleteRigidBody(std::string name) void PhysicEngine::deleteRigidBody(std::string name)
{ {
RigidBodyContainer::iterator it = RigidBodyMap.find(name); RigidBodyContainer::iterator it = ObjectMap.find(name);
if (it != RigidBodyMap.end() ) if (it != ObjectMap.end() )
{ {
RigidBody* body = it->second; RigidBody* body = it->second;
//btScaledBvhTriangleMeshShape* scaled = dynamic_cast<btScaledBvhTriangleMeshShape*> (body->getCollisionShape()); //btScaledBvhTriangleMeshShape* scaled = dynamic_cast<btScaledBvhTriangleMeshShape*> (body->getCollisionShape());
@ -428,16 +431,16 @@ namespace Physic
{ {
delete scaled; delete scaled;
}*/ }*/
RigidBodyMap.erase(it); ObjectMap.erase(it);
} }
} }
RigidBody* PhysicEngine::getRigidBody(std::string name) RigidBody* PhysicEngine::getRigidBody(std::string name)
{ {
RigidBodyContainer::iterator it = RigidBodyMap.find(name); RigidBodyContainer::iterator it = ObjectMap.find(name);
if (it != RigidBodyMap.end() ) if (it != ObjectMap.end() )
{ {
RigidBody* body = RigidBodyMap[name]; RigidBody* body = ObjectMap[name];
return body; return body;
} }
else else
@ -483,7 +486,6 @@ namespace Physic
} }
PhysicActorMap.erase(it); PhysicActorMap.erase(it);
} }
//std::cout << "ok";
} }
PhysicActor* PhysicEngine::getCharacter(std::string name) PhysicActor* PhysicEngine::getCharacter(std::string name)

View file

@ -9,6 +9,8 @@
#include "BulletShapeLoader.h" #include "BulletShapeLoader.h"
#include "BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h" #include "BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h"
class btRigidBody; class btRigidBody;
class btBroadphaseInterface; class btBroadphaseInterface;
class btDefaultCollisionConfiguration; class btDefaultCollisionConfiguration;
@ -16,6 +18,7 @@ class btSequentialImpulseConstraintSolver;
class btCollisionDispatcher; class btCollisionDispatcher;
class btDiscreteDynamicsWorld; class btDiscreteDynamicsWorld;
class btHeightfieldTerrainShape; class btHeightfieldTerrainShape;
struct playerMove;
namespace BtOgre namespace BtOgre
{ {
@ -27,6 +30,7 @@ namespace MWWorld
class World; class World;
} }
namespace OEngine { namespace OEngine {
namespace Physic namespace Physic
{ {
@ -109,6 +113,7 @@ namespace Physic
private: private:
OEngine::Physic::RigidBody* mBody; OEngine::Physic::RigidBody* mBody;
Ogre::Vector3 mBoxScaledTranslation; Ogre::Vector3 mBoxScaledTranslation;
btQuaternion mBoxRotationInverse; btQuaternion mBoxRotationInverse;
@ -117,6 +122,8 @@ namespace Physic
std::string mMesh; std::string mMesh;
PhysicEngine* mEngine; PhysicEngine* mEngine;
std::string mName; std::string mName;
playerMove* pmove;
}; };
/** /**
@ -284,7 +291,7 @@ namespace Physic
HeightFieldContainer mHeightFieldMap; HeightFieldContainer mHeightFieldMap;
typedef std::map<std::string,RigidBody*> RigidBodyContainer; typedef std::map<std::string,RigidBody*> RigidBodyContainer;
RigidBodyContainer RigidBodyMap; RigidBodyContainer ObjectMap;
typedef std::map<std::string, PhysicActor*> PhysicActorContainer; typedef std::map<std::string, PhysicActor*> PhysicActorContainer;
PhysicActorContainer PhysicActorMap; PhysicActorContainer PhysicActorMap;
@ -293,6 +300,7 @@ namespace Physic
BtOgre::DebugDrawer* mDebugDrawer; BtOgre::DebugDrawer* mDebugDrawer;
bool isDebugCreated; bool isDebugCreated;
bool mDebugActive; bool mDebugActive;
}; };

View file

@ -5,8 +5,8 @@
#include <btBulletDynamicsCommon.h> #include <btBulletDynamicsCommon.h>
#include <btBulletCollisionCommon.h> #include <btBulletCollisionCommon.h>
#include <components/nifbullet/bullet_nif_loader.hpp> #include <components/nifbullet/bullet_nif_loader.hpp>
#include <openengine/bullet/pmove.h>
#include <openengine/bullet/physic.hpp> #include <openengine/bullet/physic.hpp>
#include "pmove.h"
enum traceWorldType enum traceWorldType