mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-09 21:42:13 +00:00
Simplify newtrace a bit
This commit is contained in:
parent
617158afcd
commit
fe6fa9ebe7
@ -34,18 +34,18 @@ namespace MWWorld
|
||||
{
|
||||
private:
|
||||
static bool stepMove(Ogre::Vector3& position, const Ogre::Vector3 &velocity, float remainingTime,
|
||||
float verticalRotation, const Ogre::Vector3 &halfExtents, bool isInterior,
|
||||
const Ogre::Vector3 &halfExtents, bool isInterior,
|
||||
OEngine::Physic::PhysicEngine *engine)
|
||||
{
|
||||
traceResults trace; // no initialization needed
|
||||
|
||||
newtrace(&trace, position+Ogre::Vector3(0.0f,0.0f,sStepSize),
|
||||
position+Ogre::Vector3(0.0f,0.0f,sStepSize)+velocity*remainingTime,
|
||||
halfExtents, verticalRotation, isInterior, engine);
|
||||
halfExtents, isInterior, engine);
|
||||
if(trace.fraction == 0.0f || (trace.fraction != 1.0f && getSlope(trace.planenormal) > sMaxSlope))
|
||||
return false;
|
||||
|
||||
newtrace(&trace, trace.endpos, trace.endpos-Ogre::Vector3(0.0f,0.0f,sStepSize), halfExtents, verticalRotation, isInterior, engine);
|
||||
newtrace(&trace, trace.endpos, trace.endpos-Ogre::Vector3(0.0f,0.0f,sStepSize), halfExtents, isInterior, engine);
|
||||
if(getSlope(trace.planenormal) < sMaxSlope)
|
||||
{
|
||||
// only step down onto semi-horizontal surfaces. don't step down onto the side of a house or a wall.
|
||||
@ -105,7 +105,6 @@ namespace MWWorld
|
||||
bool onground = false;
|
||||
float remainingTime = time;
|
||||
bool isInterior = !ptr.getCell()->isExterior();
|
||||
float verticalRotation = physicActor->getRotation().getYaw().valueDegrees();
|
||||
Ogre::Vector3 halfExtents = physicActor->getHalfExtents();
|
||||
|
||||
Ogre::Vector3 velocity;
|
||||
@ -120,7 +119,7 @@ namespace MWWorld
|
||||
{
|
||||
if(!(movement.z > 0.0f))
|
||||
{
|
||||
newtrace(&trace, position, position-Ogre::Vector3(0,0,4), halfExtents, verticalRotation, isInterior, engine);
|
||||
newtrace(&trace, position, position-Ogre::Vector3(0,0,4), halfExtents, isInterior, engine);
|
||||
if(trace.fraction < 1.0f && getSlope(trace.planenormal) <= sMaxSlope)
|
||||
onground = true;
|
||||
}
|
||||
@ -145,7 +144,7 @@ namespace MWWorld
|
||||
int iterations = 0;
|
||||
do {
|
||||
// trace to where character would go if there were no obstructions
|
||||
newtrace(&trace, newPosition, newPosition+clippedVelocity*remainingTime, halfExtents, verticalRotation, isInterior, engine);
|
||||
newtrace(&trace, newPosition, newPosition+clippedVelocity*remainingTime, halfExtents, isInterior, engine);
|
||||
newPosition = trace.endpos;
|
||||
currentNormal = trace.planenormal;
|
||||
remainingTime = remainingTime * (1.0f-trace.fraction);
|
||||
@ -157,7 +156,7 @@ namespace MWWorld
|
||||
if(getSlope(currentNormal) > sMaxSlope || currentNormal == lastNormal)
|
||||
{
|
||||
if((gravity && !onground) ||
|
||||
!stepMove(newPosition, velocity, remainingTime, verticalRotation, halfExtents, isInterior, engine))
|
||||
!stepMove(newPosition, velocity, remainingTime, halfExtents, isInterior, engine))
|
||||
{
|
||||
Ogre::Vector3 resultantDirection = currentNormal.crossProduct(up);
|
||||
resultantDirection.normalise();
|
||||
@ -182,7 +181,7 @@ namespace MWWorld
|
||||
|
||||
if(onground)
|
||||
{
|
||||
newtrace(&trace, newPosition, newPosition-Ogre::Vector3(0,0,sStepSize+4.0f), halfExtents, verticalRotation, isInterior, engine);
|
||||
newtrace(&trace, newPosition, newPosition-Ogre::Vector3(0,0,sStepSize+4.0f), halfExtents, isInterior, engine);
|
||||
if(trace.fraction < 1.0f && getSlope(trace.planenormal) <= sMaxSlope)
|
||||
newPosition.z = trace.endpos.z + 2.0f;
|
||||
else
|
||||
|
@ -24,21 +24,11 @@ enum collaborativePhysicsType
|
||||
Both_Physics = 3 // This object has both kinds of physics (example: activators)
|
||||
};
|
||||
|
||||
struct NewPhysTraceResults
|
||||
{
|
||||
Ogre::Vector3 endPos;
|
||||
Ogre::Vector3 hitNormal;
|
||||
float fraction;
|
||||
//const Object* hitObj;
|
||||
};
|
||||
|
||||
static bool NewPhysicsTrace(NewPhysTraceResults* const out, const Ogre::Vector3& start, const Ogre::Vector3& end,
|
||||
const Ogre::Vector3& BBHalfExtents, const Ogre::Vector3& rotation, bool isInterior,
|
||||
OEngine::Physic::PhysicEngine* enginePass)
|
||||
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);
|
||||
const btVector3 btend(end.x, end.y, end.z + BBHalfExtents.z);
|
||||
const btQuaternion btrot(rotation.y, rotation.x, rotation.z); //y, x, z
|
||||
const btQuaternion btrot(0.0f, 0.0f, 0.0f); //y, x, z
|
||||
|
||||
const btBoxShape newshape(btVector3(BBHalfExtents.x, BBHalfExtents.y, BBHalfExtents.z));
|
||||
//const btCapsuleShapeZ newshape(BBHalfExtents.x, BBHalfExtents.z * 2 - BBHalfExtents.x * 2);
|
||||
@ -46,43 +36,22 @@ static bool NewPhysicsTrace(NewPhysTraceResults* const out, const Ogre::Vector3&
|
||||
const btTransform to(btrot, btend);
|
||||
|
||||
btCollisionWorld::ClosestConvexResultCallback newTraceCallback(btstart, btend);
|
||||
|
||||
newTraceCallback.m_collisionFilterMask = Only_Collision;
|
||||
|
||||
enginePass->dynamicsWorld->convexSweepTest(&newshape, from, to, newTraceCallback);
|
||||
|
||||
// Copy the hit data over to our trace results struct:
|
||||
out->fraction = newTraceCallback.m_closestHitFraction;
|
||||
|
||||
const btVector3& tracehitnormal = newTraceCallback.m_hitNormalWorld;
|
||||
out->hitNormal.x = tracehitnormal.x();
|
||||
out->hitNormal.y = tracehitnormal.y();
|
||||
out->hitNormal.z = tracehitnormal.z();
|
||||
|
||||
const btVector3& tracehitpos = newTraceCallback.m_hitPointWorld;
|
||||
out->endPos.x = tracehitpos.x();
|
||||
out->endPos.y = tracehitpos.y();
|
||||
out->endPos.z = tracehitpos.z();
|
||||
|
||||
return newTraceCallback.hasHit();
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
{
|
||||
NewPhysTraceResults out;
|
||||
bool hasHit = NewPhysicsTrace(&out, start, end, BBHalfExtents, Ogre::Vector3(0.0f, 0.0f, 0.0f),
|
||||
isInterior, enginePass);
|
||||
if(!hasHit)
|
||||
if(newTraceCallback.hasHit())
|
||||
{
|
||||
const btVector3& tracehitnormal = newTraceCallback.m_hitNormalWorld;
|
||||
results->fraction = newTraceCallback.m_closestHitFraction;
|
||||
results->planenormal = Ogre::Vector3(tracehitnormal.x(), tracehitnormal.y(), tracehitnormal.z());
|
||||
results->endpos = (end-start)*results->fraction + start;
|
||||
}
|
||||
else
|
||||
{
|
||||
results->endpos = end;
|
||||
results->planenormal = Ogre::Vector3(0.0f, 0.0f, 1.0f);
|
||||
results->fraction = 1.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
results->fraction = out.fraction;
|
||||
results->planenormal = out.hitNormal;
|
||||
results->endpos = (end-start)*results->fraction + start;
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,6 @@ struct traceResults
|
||||
float fraction;
|
||||
};
|
||||
|
||||
void newtrace(traceResults* const results, const Ogre::Vector3& start, const Ogre::Vector3& end, const Ogre::Vector3& BBExtents, const float rotation, bool isInterior, OEngine::Physic::PhysicEngine* enginePass);
|
||||
void newtrace(traceResults *results, const Ogre::Vector3& start, const Ogre::Vector3& end, const Ogre::Vector3& BBHalfExtents, bool isInterior, OEngine::Physic::PhysicEngine* enginePass);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user