Fix bug induced by previous commit (player orientation wasn't stored correctly), and fix NPC not beeing able to move with certain angles (like angle Z 70) because the trace function was hitting NPC own hitboxes. The solution prposed here is a little hacky, but i works. Need a little clean up(mBody shouldn't be public)

actorid
gus 12 years ago
parent e1882dce32
commit 7fb2ff18a3

@ -99,7 +99,7 @@ namespace MWWorld
if(!physicActor || !physicActor->getCollisionMode())
{
// FIXME: This works, but it's inconcsistent with how the rotations are applied elsewhere. Why?
return position + (Ogre::Quaternion(Ogre::Radian(-refpos.rot[2]), Ogre::Vector3::UNIT_Z)*
return position + (Ogre::Quaternion(Ogre::Radian( refpos.rot[2]), Ogre::Vector3::UNIT_Z)*
Ogre::Quaternion(Ogre::Radian( refpos.rot[1]), Ogre::Vector3::UNIT_Y)*
Ogre::Quaternion(Ogre::Radian( refpos.rot[0]), Ogre::Vector3::UNIT_X)) *
movement;
@ -109,12 +109,13 @@ namespace MWWorld
bool onground = false;
float remainingTime = time;
bool isInterior = !ptr.getCell()->isExterior();
Ogre::Vector3 halfExtents = physicActor->getHalfExtents();
Ogre::Vector3 halfExtents = physicActor->getHalfExtents();// + Vector3(1,1,1);
physicActor->mBody->translate(btVector3(0,0,1000));
Ogre::Vector3 velocity;
if(!gravity)
{
velocity = (Ogre::Quaternion(Ogre::Radian(-refpos.rot[2]), Ogre::Vector3::UNIT_Z)*
velocity = (Ogre::Quaternion(Ogre::Radian( refpos.rot[2]), Ogre::Vector3::UNIT_Z)*
Ogre::Quaternion(Ogre::Radian( refpos.rot[1]), Ogre::Vector3::UNIT_Y)*
Ogre::Quaternion(Ogre::Radian( refpos.rot[0]), Ogre::Vector3::UNIT_X)) *
movement / time;
@ -127,9 +128,7 @@ namespace MWWorld
if(trace.fraction < 1.0f && getSlope(trace.planenormal) <= sMaxSlope)
onground = true;
}
velocity = Ogre::Quaternion(Ogre::Radian(-refpos.rot[2]), Ogre::Vector3::UNIT_Z) *
movement / time;
velocity = Ogre::Quaternion(Ogre::Radian(refpos.rot[2]), Ogre::Vector3::UNIT_Z)*movement / time;
velocity.z += physicActor->getVerticalForce();
}
@ -148,6 +147,7 @@ namespace MWWorld
// trace to where character would go if there were no obstructions
newtrace(&trace, newPosition, newPosition+clippedVelocity*remainingTime, halfExtents, isInterior, engine);
newPosition = trace.endpos;
//std::cout << newPosition.x << " ";
remainingTime = remainingTime * (1.0f-trace.fraction);
// check for obstructions
@ -191,7 +191,8 @@ namespace MWWorld
}
physicActor->setOnGround(onground);
physicActor->setVerticalForce(!onground ? clippedVelocity.z - time*627.2f : 0.0f);
physicActor->mBody->translate(btVector3(0,0,-1000));
//std::cout << position.x << " " << newPosition.x << " " << position.y << " " << newPosition.y << std::endl;
return newPosition;
}
};

@ -129,9 +129,10 @@ namespace Physic
void operator delete (void * Data) { _aligned_free (Data); }
#endif
OEngine::Physic::RigidBody* mBody;
private:
OEngine::Physic::RigidBody* mBody;
Ogre::Vector3 mBoxScaledTranslation;
btQuaternion mBoxRotationInverse;
Ogre::Quaternion mBoxRotation;

@ -8,6 +8,7 @@
#include "physic.hpp"
#define BIT(x) (1<<(x))
enum traceWorldType
{
@ -24,6 +25,14 @@ enum collaborativePhysicsType
Both_Physics = 3 // This object has both kinds of physics (example: activators)
};
enum collisiontypes {
COL_NOTHING = 0, //<Collide with nothing
COL_WORLD = BIT(0), //<Collide with world objects
COL_ACTOR_INTERNAL = BIT(1), //<Collide internal capsule
COL_ACTOR_EXTERNAL = BIT(2), //<collide with external capsule
COL_RAYCASTING = BIT(3)
};
void newtrace(traceResults *results, const Ogre::Vector3& start, const Ogre::Vector3& end, const Ogre::Vector3& BBHalfExtents, bool isInterior, OEngine::Physic::PhysicEngine *enginePass) //Traceobj was a Aedra Object
{
const btVector3 btstart(start.x, start.y, start.z + BBHalfExtents.z);
@ -36,7 +45,7 @@ void newtrace(traceResults *results, const Ogre::Vector3& start, const Ogre::Vec
const btTransform to(btrot, btend);
btCollisionWorld::ClosestConvexResultCallback newTraceCallback(btstart, btend);
newTraceCallback.m_collisionFilterMask = Only_Collision;
newTraceCallback.m_collisionFilterMask = COL_WORLD|COL_RAYCASTING;
enginePass->dynamicsWorld->convexSweepTest(&newshape, from, to, newTraceCallback);

Loading…
Cancel
Save