Basic collision with npcs

actorid
Jason Hooks 13 years ago
parent 7375035fef
commit cacf0bd10d

@ -140,7 +140,7 @@ namespace MWClass
std::string smodel = "meshes\\base_anim.nif";
if(beast)
smodel = "meshes\\base_animkna.nif";
physics.insertActorPhysics(ptr, smodel);
physics.insertObjectPhysics(ptr, smodel);
MWBase::Environment::get().getMechanicsManager()->addActor (ptr);

@ -161,7 +161,7 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, OEngine::Render::OgreRendere
textmappings = NIFLoader::getSingletonPtr()->getTextIndices(smodel);
insert->attachObject(base);
if(isFemale)
insert->scale(race->data.height.female, race->data.height.female, race->data.height.female);
else

@ -156,10 +156,11 @@ namespace MWWorld
act->setWalkDirection(btVector3(0,0,0));
}
playerMove::playercmd& pm_ref = playerphysics->cmd;
//playerphysics->ps.snappingImplemented = false;
pm_ref.rightmove = 0;
pm_ref.forwardmove = 0;
pm_ref.upmove = 0;
//playerphysics->ps.move_type = PM_NOCLIP;
for (std::vector<std::pair<std::string, Ogre::Vector3> >::const_iterator iter (actors.begin());
@ -175,12 +176,14 @@ namespace MWWorld
Ogre::Quaternion yawQuat = yawNode->getOrientation();
Ogre::Quaternion pitchQuat = pitchNode->getOrientation();
playerphysics->ps.viewangles.x = pitchQuat.getPitch().valueDegrees();
playerphysics->ps.viewangles.y = yawQuat.getYaw().valueDegrees() *-1 + 90;
playerphysics->ps.viewangles.y = yawQuat.getYaw().valueDegrees() * -1 + 90;
if(playerphysics->ps.viewangles.y < 0)
playerphysics->ps.viewangles.y += 360;
Ogre::Quaternion quat = yawNode->getOrientation();
Ogre::Vector3 dir1(iter->second.x,iter->second.z,-iter->second.y);
@ -213,7 +216,7 @@ namespace MWWorld
Ogre::Vector3 coord(newPos.x(), newPos.y(), newPos.z());
if(it->first == "player"){
coord = playerphysics->ps.origin;
coord = playerphysics->ps.origin ;
}
@ -242,7 +245,12 @@ namespace MWWorld
OEngine::Physic::RigidBody* body = mEngine->createRigidBody(mesh,handle,scale);
mEngine->addRigidBody(body);
btTransform tr;
tr.setOrigin(btVector3(position.x,position.y,position.z));
btBoxShape* box = dynamic_cast<btBoxShape*>(body->getCollisionShape());
if(box != NULL){
tr.setOrigin(btVector3(position.x,position.y,position.z + box->getHalfExtentsWithMargin().getZ()));
}
else
tr.setOrigin(btVector3(position.x,position.y,position.z));
tr.setRotation(btQuaternion(rotation.x,rotation.y,rotation.z,rotation.w));
body->setWorldTransform(tr);
}

@ -136,6 +136,7 @@ void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource)
cShape = static_cast<BulletShape *>(resource);
resourceName = cShape->getName();
cShape->collide = false;
mBoundingBox = NULL;
mTriMesh = new btTriangleMesh();
@ -199,9 +200,13 @@ void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource)
delete m_meshInterface;
}
};
currentShape = new TriangleMeshShape(mTriMesh,true);
cShape->Shape = currentShape;
if(mBoundingBox != NULL)
cShape->Shape = mBoundingBox;
else
{
currentShape = new TriangleMeshShape(mTriMesh,true);
cShape->Shape = currentShape;
}
}
bool ManualBulletShapeLoader::hasRootCollisionNode(Nif::Node* node)
@ -289,7 +294,15 @@ void ManualBulletShapeLoader::handleNode(Nif::Node *node, int flags,
final.scale *= trafo->scale;
}
if(node->hasBounds)
{
btVector3 getHalf = getbtVector(*(node->boundXYZ));
//getHalf.setX(getHalf.getX() / 2);
//getHalf.setY(getHalf.getY() / 2);
//getHalf.setZ(getHalf.getZ() / 2);
const btVector3 boxsize = getHalf;
mBoundingBox = new btBoxShape(boxsize);
}
// For NiNodes, loop through children
if (node->recType == Nif::RC_NiNode)

@ -126,6 +126,7 @@ private:
BulletShape* cShape;//current shape
btTriangleMesh *mTriMesh;
btBoxShape *mBoundingBox;
btBvhTriangleMeshShape* currentShape;//the shape curently under construction
};

@ -344,7 +344,9 @@ namespace Physic
BulletShapeManager::getSingletonPtr()->load(outputstring,"General");
BulletShapePtr shape = BulletShapeManager::getSingleton().getByName(outputstring,"General");
shape->Shape->setLocalScaling( btVector3(scale,scale,scale));
//btScaledBvhTriangleMeshShape* scaled = new btScaledBvhTriangleMeshShape(dynamic_cast<btBvhTriangleMeshShape*> (shape->Shape), btVector3(scale,scale,scale));
//
//create the motionState
CMotionState* newMotionState = new CMotionState(this,name);

@ -449,7 +449,7 @@ int PM_StepSlideMove( bool gravity )
//pm->trace (&trace, start_o, pm->mins, pm->maxs, down, pm->ps->clientNum, pm->tracemask);
//tracefunc(&trace, start_o, down, , 0, pml.scene);
//tracefunc(&trace, *(const D3DXVECTOR3* const)&start_o, *(const D3DXVECTOR3* const)&down, D3DXVECTOR3(0.0f, -STEPSIZE, 0.0f), 0, pml.traceObj);
newtrace(&trace, start_o, down, halfExtents, Ogre::Math::DegreesToRadians(pm->ps.viewangles.y), pm->isInterior, pm->mEngine);
newtrace(&trace, down, start_o, halfExtents, Ogre::Math::DegreesToRadians(pm->ps.viewangles.y), pm->isInterior, pm->mEngine);
// up = vec3(0, 0, 1)
//VectorSet(up, 0, 0, 1);

@ -55,7 +55,7 @@ static const Ogre::Vector3 halfExtents(14.64f * 2, 14.24f * 2, 33.25f * 2);
#define CONTENTS_FOG 64
static const float pm_accelerate = 10.0f;
static const float pm_stopspeed = 100.0f;
static const float pm_friction = 12.0f;
static const float pm_friction = 6.0f;
static const float pm_flightfriction = 3.0f;
static const float pm_waterfriction = 1.0f;
static const float pm_airaccelerate = 1.0f;

@ -13,7 +13,8 @@
void newtrace(traceResults* const results, const Ogre::Vector3& start, const Ogre::Vector3& end, const Ogre::Vector3& BBHalfExtents, const float rotation, bool isInterior, OEngine::Physic::PhysicEngine* enginePass) //Traceobj was a Aedra Object
{
static float lastyaw = 0.0f;
static float lastpitch = 0.0f;
//if (!traceobj)
// return;
@ -21,10 +22,12 @@ void newtrace(traceResults* const results, const Ogre::Vector3& start, const Ogr
// return;
const Ogre::Vector3 rayDir = end - start;
// Nudge starting point backwards
//const Position3D nudgestart = start + (rayDir * -0.1f); // by 10% (isn't that too much?)
//const Position3D nudgestart = start;
NewPhysTraceResults out;
//std::cout << "Starting trace\n";
@ -32,7 +35,7 @@ void newtrace(traceResults* const results, const Ogre::Vector3& start, const Ogr
//Ogre::Vector3 endReplace = startReplace;
//endReplace.z -= .25;
const bool hasHit = NewPhysicsTrace<collisionWorldTrace>(&out, start, end, BBHalfExtents, Ogre::Vector3(0.0f, 0.0, rotation), 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)
results->startsolid = true;

@ -9,7 +9,6 @@
#include <openengine/bullet/physic.hpp>
enum traceWorldType
{
collisionWorldTrace = 1,

Loading…
Cancel
Save