mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 06:53:53 +00:00
Fix tracing down
This commit is contained in:
parent
6e9f15793d
commit
1aa92067c2
3 changed files with 46 additions and 12 deletions
|
@ -92,22 +92,18 @@ namespace MWWorld
|
||||||
if (!physicActor)
|
if (!physicActor)
|
||||||
return position;
|
return position;
|
||||||
|
|
||||||
const Ogre::Vector3 halfExtents = physicActor->getHalfExtents();
|
|
||||||
Ogre::Vector3 newPosition = position+Ogre::Vector3(0.0f, 0.0f, halfExtents.z);
|
|
||||||
|
|
||||||
const int maxHeight = 200.f;
|
const int maxHeight = 200.f;
|
||||||
OEngine::Physic::ActorTracer tracer;
|
OEngine::Physic::ActorTracer tracer;
|
||||||
tracer.doTrace(physicActor->getCollisionBody(), newPosition, newPosition-Ogre::Vector3(0,0,maxHeight), engine);
|
tracer.findGround(physicActor->getCollisionBody(), position, position-Ogre::Vector3(0,0,maxHeight), engine);
|
||||||
if(tracer.mFraction >= 1.0f)
|
if(tracer.mFraction >= 1.0f)
|
||||||
|
{
|
||||||
|
physicActor->setOnGround(false);
|
||||||
return position;
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
physicActor->setOnGround(getSlope(tracer.mPlaneNormal) <= sMaxSlope);
|
physicActor->setOnGround(getSlope(tracer.mPlaneNormal) <= sMaxSlope);
|
||||||
|
|
||||||
newPosition = tracer.mEndPos;
|
return tracer.mEndPos;
|
||||||
newPosition.z -= halfExtents.z;
|
|
||||||
newPosition.z += 2.0f;
|
|
||||||
|
|
||||||
return newPosition;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Ogre::Vector3 move(const MWWorld::Ptr &ptr, const Ogre::Vector3 &movement, float time,
|
static Ogre::Vector3 move(const MWWorld::Ptr &ptr, const Ogre::Vector3 &movement, float time,
|
||||||
|
|
|
@ -65,9 +65,8 @@ void ActorTracer::doTrace(btCollisionObject *actor, const Ogre::Vector3 &start,
|
||||||
to.setOrigin(btend);
|
to.setOrigin(btend);
|
||||||
|
|
||||||
ClosestNotMeConvexResultCallback newTraceCallback(actor, btstart-btend, btScalar(0.0));
|
ClosestNotMeConvexResultCallback newTraceCallback(actor, btstart-btend, btScalar(0.0));
|
||||||
newTraceCallback.m_collisionFilterMask = OEngine::Physic::CollisionType_World |
|
newTraceCallback.m_collisionFilterMask = CollisionType_World | CollisionType_HeightMap |
|
||||||
OEngine::Physic::CollisionType_HeightMap |
|
CollisionType_Actor;
|
||||||
OEngine::Physic::CollisionType_Actor;
|
|
||||||
|
|
||||||
btCollisionShape *shape = actor->getCollisionShape();
|
btCollisionShape *shape = actor->getCollisionShape();
|
||||||
assert(shape->isConvex());
|
assert(shape->isConvex());
|
||||||
|
@ -90,5 +89,42 @@ void ActorTracer::doTrace(btCollisionObject *actor, const Ogre::Vector3 &start,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ActorTracer::findGround(btCollisionObject *actor, const Ogre::Vector3 &start, const Ogre::Vector3 &end, const PhysicEngine *enginePass)
|
||||||
|
{
|
||||||
|
const btVector3 btstart(start.x, start.y, start.z+1.0f);
|
||||||
|
const btVector3 btend(end.x, end.y, end.z+1.0f);
|
||||||
|
|
||||||
|
const btTransform &trans = actor->getWorldTransform();
|
||||||
|
btTransform from(trans.getBasis(), btstart);
|
||||||
|
btTransform to(trans.getBasis(), btend);
|
||||||
|
|
||||||
|
ClosestNotMeConvexResultCallback newTraceCallback(actor, btstart-btend, btScalar(0.0));
|
||||||
|
newTraceCallback.m_collisionFilterMask = CollisionType_World | CollisionType_HeightMap |
|
||||||
|
CollisionType_Actor;
|
||||||
|
|
||||||
|
const btBoxShape *shape = dynamic_cast<btBoxShape*>(actor->getCollisionShape());
|
||||||
|
assert(shape);
|
||||||
|
|
||||||
|
btVector3 halfExtents = shape->getHalfExtentsWithMargin();
|
||||||
|
halfExtents[2] = 1.0f;
|
||||||
|
btBoxShape box(halfExtents);
|
||||||
|
|
||||||
|
enginePass->dynamicsWorld->convexSweepTest(&box, from, to, newTraceCallback);
|
||||||
|
if(newTraceCallback.hasHit())
|
||||||
|
{
|
||||||
|
const btVector3& tracehitnormal = newTraceCallback.m_hitNormalWorld;
|
||||||
|
mFraction = newTraceCallback.m_closestHitFraction;
|
||||||
|
mPlaneNormal = Ogre::Vector3(tracehitnormal.x(), tracehitnormal.y(), tracehitnormal.z());
|
||||||
|
mEndPos = (end-start)*mFraction + start;
|
||||||
|
mEndPos[2] -= 1.0f;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mEndPos = end;
|
||||||
|
mPlaneNormal = Ogre::Vector3(0.0f, 0.0f, 1.0f);
|
||||||
|
mFraction = 1.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,8 @@ namespace Physic
|
||||||
|
|
||||||
void doTrace(btCollisionObject *actor, const Ogre::Vector3 &start, const Ogre::Vector3 &end,
|
void doTrace(btCollisionObject *actor, const Ogre::Vector3 &start, const Ogre::Vector3 &end,
|
||||||
const PhysicEngine *enginePass);
|
const PhysicEngine *enginePass);
|
||||||
|
void findGround(btCollisionObject *actor, const Ogre::Vector3 &start, const Ogre::Vector3 &end,
|
||||||
|
const PhysicEngine *enginePass);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue