Starting to implement new PhysicActor

actorid
Jason Hooks 13 years ago
parent 2efceba1fc
commit 23777033fd

@ -89,7 +89,7 @@ namespace MWClass
{ {
const std::string model = getModel(ptr); const std::string model = getModel(ptr);
if(!model.empty()){ if(!model.empty()){
physics.insertObjectPhysics(ptr, model); physics.insertActorPhysics(ptr, model);
} }
MWBase::Environment::get().getMechanicsManager()->addActor (ptr); MWBase::Environment::get().getMechanicsManager()->addActor (ptr);
} }

@ -125,7 +125,7 @@ namespace MWClass
void Npc::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const void Npc::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
{ {
physics.insertObjectPhysics(ptr, getModel(ptr)); physics.insertActorPhysics(ptr, getModel(ptr));
MWBase::Environment::get().getMechanicsManager()->addActor(ptr); MWBase::Environment::get().getMechanicsManager()->addActor(ptr);
} }
@ -294,7 +294,7 @@ namespace MWClass
{ {
Ogre::Vector3 vector (0, 0, 0); Ogre::Vector3 vector (0, 0, 0);
vector.x = - getMovementSettings (ptr).mLeftRight * 127; vector.x = getMovementSettings (ptr).mLeftRight * 127;
vector.y = getMovementSettings (ptr).mForwardBackward * 127; vector.y = getMovementSettings (ptr).mForwardBackward * 127;
vector.z = getMovementSettings(ptr).mUpDown * 127; vector.z = getMovementSettings(ptr).mUpDown * 127;

@ -266,6 +266,7 @@ RenderingManager::rotateObject(
float *f = ptr.getRefData().getPosition().rot; float *f = ptr.getRefData().getPosition().rot;
rot.x += f[0], rot.y += f[1], rot.z += f[2]; rot.x += f[0], rot.y += f[1], rot.z += f[2];
} }
if (!isPlayer && isActive) { if (!isPlayer && isActive) {
Ogre::Quaternion xr(Ogre::Radian(rot.x), Ogre::Vector3::UNIT_X); Ogre::Quaternion xr(Ogre::Radian(rot.x), Ogre::Vector3::UNIT_X);
Ogre::Quaternion yr(Ogre::Radian(rot.y), Ogre::Vector3::UNIT_Y); Ogre::Quaternion yr(Ogre::Radian(rot.y), Ogre::Vector3::UNIT_Y);
@ -273,6 +274,7 @@ RenderingManager::rotateObject(
ptr.getRefData().getBaseNode()->setOrientation(xr * yr * zr); ptr.getRefData().getBaseNode()->setOrientation(xr * yr * zr);
} }
return force; return force;
} }

@ -201,8 +201,7 @@ namespace MWWorld
playerphysics->ps.viewangles.y = playerphysics->ps.viewangles.y =
Ogre::Radian(mPlayerData.yaw).valueDegrees() + 90; Ogre::Radian(mPlayerData.yaw).valueDegrees() + 90;
pm_ref.rightmove = iter->second.x;
pm_ref.rightmove = -iter->second.x;
pm_ref.forwardmove = -iter->second.y; pm_ref.forwardmove = -iter->second.y;
pm_ref.upmove = iter->second.z; pm_ref.upmove = iter->second.z;
} }
@ -215,6 +214,7 @@ namespace MWWorld
{ {
Pmove(playerphysics); Pmove(playerphysics);
std::vector< std::pair<std::string, Ogre::Vector3> > response; std::vector< std::pair<std::string, Ogre::Vector3> > response;
for(std::map<std::string,OEngine::Physic::PhysicActor*>::iterator it = mEngine->PhysicActorMap.begin(); it != mEngine->PhysicActorMap.end();it++) for(std::map<std::string,OEngine::Physic::PhysicActor*>::iterator it = mEngine->PhysicActorMap.begin(); it != mEngine->PhysicActorMap.end();it++)
{ {
@ -224,6 +224,7 @@ namespace MWWorld
if(it->first == "player"){ if(it->first == "player"){
coord = playerphysics->ps.origin ; coord = playerphysics->ps.origin ;
} }
@ -257,8 +258,9 @@ namespace MWWorld
const Ogre::Vector3& position, float scale, const Ogre::Quaternion& rotation) const Ogre::Vector3& position, float scale, const Ogre::Quaternion& rotation)
{ {
//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.
std::cout << "NPC position" << position << "\n";
mEngine->addCharacter(handle, mesh, position, scale, rotation); mEngine->addCharacter(handle, mesh, position, scale, rotation);
OEngine::Physic::PhysicActor* act = mEngine->getCharacter(handle);
} }

@ -189,7 +189,9 @@ namespace MWWorld
mPlayer = new MWWorld::Player (mStore.npcs.find ("player"), *this); mPlayer = new MWWorld::Player (mStore.npcs.find ("player"), *this);
mRendering->attachCameraTo(mPlayer->getPlayer()); mRendering->attachCameraTo(mPlayer->getPlayer());
mPhysics->addActor (mPlayer->getPlayer().getRefData().getHandle(), "", Ogre::Vector3 (0, 0, 0), 0, Ogre::Quaternion::ZERO); std::string playerCollisionFile = "meshes\\base_anim.nif"; //This is used to make a collision shape for our player
//We will need to support the 1st person file too in the future
mPhysics->addActor (mPlayer->getPlayer().getRefData().getHandle(), playerCollisionFile, Ogre::Vector3 (0, 0, 0), 1, Ogre::Quaternion::ZERO);
// global variables // global variables
mGlobalVariables = new Globals (mStore); mGlobalVariables = new Globals (mStore);

@ -27,12 +27,12 @@ namespace Physic
}; };
PhysicActor::PhysicActor(std::string name, std::string mesh, PhysicEngine* engine, Ogre::Vector3 position, Ogre::Quaternion rotation, float scale): PhysicActor::PhysicActor(std::string name, std::string mesh, PhysicEngine* engine, Ogre::Vector3 position, Ogre::Quaternion rotation, float scale):
mName(name), mEngine(engine), mMesh(mesh), mBoxTranslation(Ogre::Vector3::ZERO), mBoxRotation(Ogre::Quaternion::ZERO), mBody(0) mName(name), mEngine(engine), mMesh(mesh), mBoxTranslation(Ogre::Vector3::ZERO), mBoxRotation(Ogre::Quaternion::ZERO), mBody(0), collisionMode(false)
{ {
Ogre::Vector3 test;
// The capsule is at the origin mBody = mEngine->createAndAdjustRigidBody(mesh, mName, scale, position, rotation, &test);
btTransform transform; std::cout << "Test" << test << "\n";
transform.setIdentity(); mEngine->addRigidBody(mBody, false); //Add rigid body to dynamics world, but do not add to object map
} }
@ -51,7 +51,7 @@ namespace Physic
void PhysicActor::enableCollisions(bool collision) void PhysicActor::enableCollisions(bool collision)
{ {
collisionMode = collision;
} }
void PhysicActor::setVerticalVelocity(float z) void PhysicActor::setVerticalVelocity(float z)
@ -61,7 +61,7 @@ namespace Physic
bool PhysicActor::getCollisionMode() bool PhysicActor::getCollisionMode()
{ {
return false; return collisionMode;
} }
void PhysicActor::setWalkDirection(const btVector3& mvt) void PhysicActor::setWalkDirection(const btVector3& mvt)
@ -79,12 +79,12 @@ namespace Physic
btVector3 PhysicActor::getPosition(void) btVector3 PhysicActor::getPosition(void)
{ {
return btVector3(0,0,0);//return internalGhostObject->getWorldTransform().getOrigin() -mTranslation; return mBody->getWorldTransform().getOrigin();//return internalGhostObject->getWorldTransform().getOrigin() -mTranslation;
} }
btQuaternion PhysicActor::getRotation(void) btQuaternion PhysicActor::getRotation(void)
{ {
return btQuaternion(0,0,0);//return btQuaternion::internalGhostObject->getWorldTransform().getRotation(); return mBody->getWorldTransform().getRotation();//return btQuaternion::internalGhostObject->getWorldTransform().getRotation();
} }
void PhysicActor::setPosition(const btVector3& pos) void PhysicActor::setPosition(const btVector3& pos)
@ -290,7 +290,8 @@ namespace Physic
mHeightFieldMap.erase(name); mHeightFieldMap.erase(name);
} }
void PhysicEngine::adjustRigidBody(BulletShapePtr shape, RigidBody* body, float scale, Ogre::Vector3 position, Ogre::Quaternion rotation){ void PhysicEngine::adjustRigidBody(BulletShapePtr shape, RigidBody* body, float scale, Ogre::Vector3 position, Ogre::Quaternion rotation,
Ogre::Vector3 scaledBoxPosition, Ogre::Quaternion boxRotation){
btTransform tr; btTransform tr;
btBoxShape* box = dynamic_cast<btBoxShape*>(body->getCollisionShape()); btBoxShape* box = dynamic_cast<btBoxShape*>(body->getCollisionShape());
if(box != NULL){ if(box != NULL){
@ -317,8 +318,11 @@ namespace Physic
adjustRigidBody(shape, body, scale, position, rotation); adjustRigidBody(shape, body, scale, position, rotation);
} }
RigidBody* PhysicEngine::createAndAdjustRigidBody(std::string mesh,std::string name,float scale, Ogre::Vector3 position, Ogre::Quaternion rotation) RigidBody* PhysicEngine::createAndAdjustRigidBody(std::string mesh,std::string name,float scale, Ogre::Vector3 position, Ogre::Quaternion rotation,
Ogre::Vector3* scaledBoxPosition, Ogre::Quaternion* boxRotation)
{ {
if(scaledBoxPosition != 0)
*scaledBoxPosition = Ogre::Vector3(0, 5, 0);
std::string sid = (boost::format("%07.3f") % scale).str(); std::string sid = (boost::format("%07.3f") % scale).str();
std::string outputstring = mesh + sid; std::string outputstring = mesh + sid;
//std::cout << "The string" << outputstring << "\n"; //std::cout << "The string" << outputstring << "\n";
@ -348,7 +352,7 @@ namespace Physic
} }
void PhysicEngine::addRigidBody(RigidBody* body) void PhysicEngine::addRigidBody(RigidBody* body, bool addToMap)
{ {
if(body) if(body)
{ {
@ -361,6 +365,7 @@ namespace Physic
dynamicsWorld->addRigidBody(body,COL_RAYCASTING,COL_RAYCASTING|COL_WORLD); dynamicsWorld->addRigidBody(body,COL_RAYCASTING,COL_RAYCASTING|COL_WORLD);
} }
body->setActivationState(DISABLE_DEACTIVATION); body->setActivationState(DISABLE_DEACTIVATION);
if(addToMap){
RigidBody* oldBody = RigidBodyMap[body->mName]; RigidBody* oldBody = RigidBodyMap[body->mName];
if (oldBody != NULL) if (oldBody != NULL)
{ {
@ -371,6 +376,7 @@ namespace Physic
RigidBodyMap[body->mName] = body; RigidBodyMap[body->mName] = body;
} }
} }
}
void PhysicEngine::removeRigidBody(std::string name) void PhysicEngine::removeRigidBody(std::string name)
{ {

@ -92,6 +92,7 @@ namespace Physic
OEngine::Physic::RigidBody* mBody; OEngine::Physic::RigidBody* mBody;
Ogre::Vector3 mBoxTranslation; Ogre::Vector3 mBoxTranslation;
Ogre::Quaternion mBoxRotation; Ogre::Quaternion mBoxRotation;
bool collisionMode;
std::string mMesh; std::string mMesh;
PhysicEngine* mEngine; PhysicEngine* mEngine;
}; };
@ -138,18 +139,18 @@ namespace Physic
~PhysicEngine(); ~PhysicEngine();
/** /**
* Create a RigidBody.It does not add it to the simulation, but it does add it to the rigidBody Map, * Creates a RigidBody. It does not add it to the simulation.
* so you can get it with the getRigidBody function. * After created, the body is set to the correct rotation, position, and scale
After created, the body is set to the correct rotation, position, and scale
*/ */
RigidBody* createAndAdjustRigidBody(std::string mesh,std::string name,float scale, Ogre::Vector3 position, Ogre::Quaternion rotation); RigidBody* createAndAdjustRigidBody(std::string mesh,std::string name,float scale, Ogre::Vector3 position, Ogre::Quaternion rotation,
Ogre::Vector3* scaledBoxPosition = 0, Ogre::Quaternion* boxRotation = 0);
/** /**
* Adjusts a rigid body to the right position and rotation * Adjusts a rigid body to the right position and rotation
*/ */
void adjustRigidBody(BulletShapePtr shape, RigidBody* body, float scale, Ogre::Vector3 position, Ogre::Quaternion rotation); void adjustRigidBody(BulletShapePtr shape, RigidBody* body, float scale, Ogre::Vector3 position, Ogre::Quaternion rotation,
Ogre::Vector3 scaledBoxPosition = Ogre::Vector3::ZERO, Ogre::Quaternion boxRotation = Ogre::Quaternion::ZERO);
/** /**
Mainly used to (but not limited to) adjust rigid bodies based on box shapes to the right position and rotation. Mainly used to (but not limited to) adjust rigid bodies based on box shapes to the right position and rotation.
*/ */
@ -169,7 +170,7 @@ namespace Physic
/** /**
* Add a RigidBody to the simulation * Add a RigidBody to the simulation
*/ */
void addRigidBody(RigidBody* body); void addRigidBody(RigidBody* body, bool addToMap = true);
/** /**
* Remove a RigidBody from the simulation. It does not delete it, and does not remove it from the RigidBodyMap. * Remove a RigidBody from the simulation. It does not delete it, and does not remove it from the RigidBodyMap.

@ -36,8 +36,7 @@ void newtrace(traceResults* const results, const Ogre::Vector3& start, const Ogr
//Ogre::Vector3 endReplace = startReplace; //Ogre::Vector3 endReplace = startReplace;
//endReplace.z -= .25; //endReplace.z -= .25;
const bool hasHit = NewPhysicsTrace<collisionWorldTrace>(&out, start, end, BBHalfExtents, Ogre::Vector3(0.0f, 0.0f, 0.0f), isInterior, enginePass);
const bool hasHit = NewPhysicsTrace<collisionWorldTrace>(&out, start, end, BBHalfExtents, Ogre::Vector3(0.0f, 0.0f,0.0f), isInterior, enginePass);
if (out.fraction < 0.001f) if (out.fraction < 0.001f)
results->startsolid = true; results->startsolid = true;

Loading…
Cancel
Save