mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 21:53:51 +00:00
Simplify newtrace a bit
This commit is contained in:
parent
617158afcd
commit
fe6fa9ebe7
3 changed files with 18 additions and 50 deletions
|
@ -34,18 +34,18 @@ namespace MWWorld
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
static bool stepMove(Ogre::Vector3& position, const Ogre::Vector3 &velocity, float remainingTime,
|
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)
|
OEngine::Physic::PhysicEngine *engine)
|
||||||
{
|
{
|
||||||
traceResults trace; // no initialization needed
|
traceResults trace; // no initialization needed
|
||||||
|
|
||||||
newtrace(&trace, position+Ogre::Vector3(0.0f,0.0f,sStepSize),
|
newtrace(&trace, position+Ogre::Vector3(0.0f,0.0f,sStepSize),
|
||||||
position+Ogre::Vector3(0.0f,0.0f,sStepSize)+velocity*remainingTime,
|
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))
|
if(trace.fraction == 0.0f || (trace.fraction != 1.0f && getSlope(trace.planenormal) > sMaxSlope))
|
||||||
return false;
|
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)
|
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.
|
// 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;
|
bool onground = false;
|
||||||
float remainingTime = time;
|
float remainingTime = time;
|
||||||
bool isInterior = !ptr.getCell()->isExterior();
|
bool isInterior = !ptr.getCell()->isExterior();
|
||||||
float verticalRotation = physicActor->getRotation().getYaw().valueDegrees();
|
|
||||||
Ogre::Vector3 halfExtents = physicActor->getHalfExtents();
|
Ogre::Vector3 halfExtents = physicActor->getHalfExtents();
|
||||||
|
|
||||||
Ogre::Vector3 velocity;
|
Ogre::Vector3 velocity;
|
||||||
|
@ -120,7 +119,7 @@ namespace MWWorld
|
||||||
{
|
{
|
||||||
if(!(movement.z > 0.0f))
|
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)
|
if(trace.fraction < 1.0f && getSlope(trace.planenormal) <= sMaxSlope)
|
||||||
onground = true;
|
onground = true;
|
||||||
}
|
}
|
||||||
|
@ -145,7 +144,7 @@ namespace MWWorld
|
||||||
int iterations = 0;
|
int iterations = 0;
|
||||||
do {
|
do {
|
||||||
// trace to where character would go if there were no obstructions
|
// 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;
|
newPosition = trace.endpos;
|
||||||
currentNormal = trace.planenormal;
|
currentNormal = trace.planenormal;
|
||||||
remainingTime = remainingTime * (1.0f-trace.fraction);
|
remainingTime = remainingTime * (1.0f-trace.fraction);
|
||||||
|
@ -157,7 +156,7 @@ namespace MWWorld
|
||||||
if(getSlope(currentNormal) > sMaxSlope || currentNormal == lastNormal)
|
if(getSlope(currentNormal) > sMaxSlope || currentNormal == lastNormal)
|
||||||
{
|
{
|
||||||
if((gravity && !onground) ||
|
if((gravity && !onground) ||
|
||||||
!stepMove(newPosition, velocity, remainingTime, verticalRotation, halfExtents, isInterior, engine))
|
!stepMove(newPosition, velocity, remainingTime, halfExtents, isInterior, engine))
|
||||||
{
|
{
|
||||||
Ogre::Vector3 resultantDirection = currentNormal.crossProduct(up);
|
Ogre::Vector3 resultantDirection = currentNormal.crossProduct(up);
|
||||||
resultantDirection.normalise();
|
resultantDirection.normalise();
|
||||||
|
@ -182,7 +181,7 @@ namespace MWWorld
|
||||||
|
|
||||||
if(onground)
|
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)
|
if(trace.fraction < 1.0f && getSlope(trace.planenormal) <= sMaxSlope)
|
||||||
newPosition.z = trace.endpos.z + 2.0f;
|
newPosition.z = trace.endpos.z + 2.0f;
|
||||||
else
|
else
|
||||||
|
|
|
@ -24,21 +24,11 @@ enum collaborativePhysicsType
|
||||||
Both_Physics = 3 // This object has both kinds of physics (example: activators)
|
Both_Physics = 3 // This object has both kinds of physics (example: activators)
|
||||||
};
|
};
|
||||||
|
|
||||||
struct NewPhysTraceResults
|
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
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
const btVector3 btstart(start.x, start.y, start.z + BBHalfExtents.z);
|
const btVector3 btstart(start.x, start.y, start.z + BBHalfExtents.z);
|
||||||
const btVector3 btend(end.x, end.y, end.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 btBoxShape newshape(btVector3(BBHalfExtents.x, BBHalfExtents.y, BBHalfExtents.z));
|
||||||
//const btCapsuleShapeZ newshape(BBHalfExtents.x, BBHalfExtents.z * 2 - BBHalfExtents.x * 2);
|
//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);
|
const btTransform to(btrot, btend);
|
||||||
|
|
||||||
btCollisionWorld::ClosestConvexResultCallback newTraceCallback(btstart, btend);
|
btCollisionWorld::ClosestConvexResultCallback newTraceCallback(btstart, btend);
|
||||||
|
|
||||||
newTraceCallback.m_collisionFilterMask = Only_Collision;
|
newTraceCallback.m_collisionFilterMask = Only_Collision;
|
||||||
|
|
||||||
enginePass->dynamicsWorld->convexSweepTest(&newshape, from, to, newTraceCallback);
|
enginePass->dynamicsWorld->convexSweepTest(&newshape, from, to, newTraceCallback);
|
||||||
|
|
||||||
// Copy the hit data over to our trace results struct:
|
// Copy the hit data over to our trace results struct:
|
||||||
out->fraction = newTraceCallback.m_closestHitFraction;
|
if(newTraceCallback.hasHit())
|
||||||
|
{
|
||||||
const btVector3& tracehitnormal = newTraceCallback.m_hitNormalWorld;
|
const btVector3& tracehitnormal = newTraceCallback.m_hitNormalWorld;
|
||||||
out->hitNormal.x = tracehitnormal.x();
|
results->fraction = newTraceCallback.m_closestHitFraction;
|
||||||
out->hitNormal.y = tracehitnormal.y();
|
results->planenormal = Ogre::Vector3(tracehitnormal.x(), tracehitnormal.y(), tracehitnormal.z());
|
||||||
out->hitNormal.z = tracehitnormal.z();
|
results->endpos = (end-start)*results->fraction + start;
|
||||||
|
}
|
||||||
const btVector3& tracehitpos = newTraceCallback.m_hitPointWorld;
|
else
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
results->endpos = end;
|
results->endpos = end;
|
||||||
results->planenormal = Ogre::Vector3(0.0f, 0.0f, 1.0f);
|
results->planenormal = Ogre::Vector3(0.0f, 0.0f, 1.0f);
|
||||||
results->fraction = 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;
|
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
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue