forked from teamnwah/openmw-tes3coop
Some physics cleanup
Gets rid of some unneeded/unused variables, and halves the 'on ground' offset.
This commit is contained in:
parent
b0f8045c72
commit
7770203dff
1 changed files with 16 additions and 20 deletions
|
@ -45,23 +45,23 @@ namespace MWWorld
|
||||||
const Ogre::Vector3 &velocity, float &remainingTime,
|
const Ogre::Vector3 &velocity, float &remainingTime,
|
||||||
OEngine::Physic::PhysicEngine *engine)
|
OEngine::Physic::PhysicEngine *engine)
|
||||||
{
|
{
|
||||||
OEngine::Physic::ActorTracer tracer;
|
OEngine::Physic::ActorTracer tracer, stepper;
|
||||||
tracer.doTrace(colobj, position, position+Ogre::Vector3(0.0f,0.0f,sStepSize), engine);
|
|
||||||
if(tracer.mFraction == 0.0f)
|
stepper.doTrace(colobj, position, position+Ogre::Vector3(0.0f,0.0f,sStepSize), engine);
|
||||||
|
if(stepper.mFraction == 0.0f)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
tracer.doTrace(colobj, tracer.mEndPos, tracer.mEndPos + velocity*remainingTime, engine);
|
tracer.doTrace(colobj, stepper.mEndPos, stepper.mEndPos + velocity*remainingTime, engine);
|
||||||
if(tracer.mFraction < std::numeric_limits<float>::epsilon() ||
|
if(tracer.mFraction < std::numeric_limits<float>::epsilon() ||
|
||||||
(tracer.mFraction < 1.0f && getSlope(tracer.mPlaneNormal) > sMaxSlope))
|
(tracer.mFraction < 1.0f && getSlope(tracer.mPlaneNormal) > sMaxSlope))
|
||||||
return false;
|
return false;
|
||||||
float movefrac = tracer.mFraction;
|
|
||||||
|
|
||||||
tracer.doTrace(colobj, tracer.mEndPos, tracer.mEndPos-Ogre::Vector3(0.0f,0.0f,sStepSize), engine);
|
stepper.doTrace(colobj, tracer.mEndPos, tracer.mEndPos-Ogre::Vector3(0.0f,0.0f,sStepSize), engine);
|
||||||
if(getSlope(tracer.mPlaneNormal) <= sMaxSlope)
|
if(getSlope(stepper.mPlaneNormal) <= 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.
|
||||||
position = tracer.mEndPos;
|
position = stepper.mEndPos;
|
||||||
remainingTime *= (1.0f-movefrac);
|
remainingTime *= (1.0f-tracer.mFraction);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,9 +132,7 @@ namespace MWWorld
|
||||||
position.z += halfExtents.z;
|
position.z += halfExtents.z;
|
||||||
|
|
||||||
OEngine::Physic::ActorTracer tracer;
|
OEngine::Physic::ActorTracer tracer;
|
||||||
bool wasOnGround = false;
|
|
||||||
bool isOnGround = false;
|
bool isOnGround = false;
|
||||||
const Ogre::Quaternion orient; // Don't rotate actor collision boxes
|
|
||||||
Ogre::Vector3 inertia(0.0f);
|
Ogre::Vector3 inertia(0.0f);
|
||||||
Ogre::Vector3 velocity;
|
Ogre::Vector3 velocity;
|
||||||
if(!gravity)
|
if(!gravity)
|
||||||
|
@ -146,11 +144,10 @@ namespace MWWorld
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tracer.doTrace(colobj, position, position-Ogre::Vector3(0,0,4), engine);
|
|
||||||
if(tracer.mFraction < 1.0f && getSlope(tracer.mPlaneNormal) <= sMaxSlope)
|
|
||||||
{
|
|
||||||
wasOnGround = true;
|
|
||||||
if(!(movement.z > 0.0f))
|
if(!(movement.z > 0.0f))
|
||||||
|
{
|
||||||
|
tracer.doTrace(colobj, position, position-Ogre::Vector3(0,0,2), engine);
|
||||||
|
if(tracer.mFraction < 1.0f && getSlope(tracer.mPlaneNormal) <= sMaxSlope)
|
||||||
isOnGround = true;
|
isOnGround = true;
|
||||||
}
|
}
|
||||||
inertia = physicActor->getInertialForce();
|
inertia = physicActor->getInertialForce();
|
||||||
|
@ -164,7 +161,6 @@ namespace MWWorld
|
||||||
velocity.z = std::max(0.0f, velocity.z);
|
velocity.z = std::max(0.0f, velocity.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Ogre::Vector3 up(0.0f, 0.0f, 1.0f);
|
|
||||||
Ogre::Vector3 newPosition = position;
|
Ogre::Vector3 newPosition = position;
|
||||||
float remainingTime = time;
|
float remainingTime = time;
|
||||||
for(int iterations = 0;iterations < sMaxIterations && remainingTime > 0.01f;++iterations)
|
for(int iterations = 0;iterations < sMaxIterations && remainingTime > 0.01f;++iterations)
|
||||||
|
@ -201,23 +197,23 @@ namespace MWWorld
|
||||||
|
|
||||||
if(isOnGround)
|
if(isOnGround)
|
||||||
{
|
{
|
||||||
tracer.doTrace(colobj, newPosition, newPosition-Ogre::Vector3(0,0,sStepSize+4.0f), engine);
|
tracer.doTrace(colobj, newPosition, newPosition-Ogre::Vector3(0,0,sStepSize+2.0f), engine);
|
||||||
if(tracer.mFraction < 1.0f && getSlope(tracer.mPlaneNormal) <= sMaxSlope)
|
if(tracer.mFraction < 1.0f && getSlope(tracer.mPlaneNormal) <= sMaxSlope)
|
||||||
newPosition.z = tracer.mEndPos.z + 2.0f;
|
newPosition.z = tracer.mEndPos.z + 1.0f;
|
||||||
else
|
else
|
||||||
isOnGround = false;
|
isOnGround = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
physicActor->setOnGround(isOnGround);
|
|
||||||
if(isOnGround)
|
if(isOnGround)
|
||||||
physicActor->setInertialForce(Ogre::Vector3(0.0f));
|
physicActor->setInertialForce(Ogre::Vector3(0.0f));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(wasOnGround)
|
if(physicActor->getOnGround())
|
||||||
inertia = velocity;
|
inertia = velocity;
|
||||||
inertia.z -= time*627.2f;
|
inertia.z -= time*627.2f;
|
||||||
physicActor->setInertialForce(inertia);
|
physicActor->setInertialForce(inertia);
|
||||||
}
|
}
|
||||||
|
physicActor->setOnGround(isOnGround);
|
||||||
|
|
||||||
newPosition.z -= halfExtents.z;
|
newPosition.z -= halfExtents.z;
|
||||||
return newPosition;
|
return newPosition;
|
||||||
|
|
Loading…
Reference in a new issue