mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 09:35:28 +00:00
Use the position of the actor to determine if they're swimming
This commit is contained in:
parent
3fa65f21dd
commit
ca24a809fc
@ -107,8 +107,7 @@ namespace MWWorld
|
|||||||
}
|
}
|
||||||
|
|
||||||
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,
|
||||||
bool isSwimming, bool isFlying, float waterlevel,
|
bool isFlying, float waterlevel, OEngine::Physic::PhysicEngine *engine)
|
||||||
OEngine::Physic::PhysicEngine *engine)
|
|
||||||
{
|
{
|
||||||
const ESM::Position &refpos = ptr.getRefData().getPosition();
|
const ESM::Position &refpos = ptr.getRefData().getPosition();
|
||||||
Ogre::Vector3 position(refpos.pos);
|
Ogre::Vector3 position(refpos.pos);
|
||||||
@ -135,11 +134,11 @@ namespace MWWorld
|
|||||||
bool isOnGround = false;
|
bool isOnGround = false;
|
||||||
Ogre::Vector3 inertia(0.0f);
|
Ogre::Vector3 inertia(0.0f);
|
||||||
Ogre::Vector3 velocity;
|
Ogre::Vector3 velocity;
|
||||||
if(isSwimming || isFlying)
|
if(position.z < waterlevel || isFlying)
|
||||||
{
|
{
|
||||||
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[1]), Ogre::Vector3::UNIT_Y)*
|
||||||
Ogre::Quaternion(Ogre::Radian( refpos.rot[0]), Ogre::Vector3::UNIT_X)) *
|
Ogre::Quaternion(Ogre::Radian( refpos.rot[0]), Ogre::Vector3::UNIT_X)) *
|
||||||
movement;
|
movement;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -173,7 +172,7 @@ namespace MWWorld
|
|||||||
{
|
{
|
||||||
Ogre::Vector3 nextpos = newPosition + velocity*remainingTime;
|
Ogre::Vector3 nextpos = newPosition + velocity*remainingTime;
|
||||||
|
|
||||||
if(isSwimming && !isFlying &&
|
if(newPosition.z < waterlevel && !isFlying &&
|
||||||
nextpos.z > waterlevel && newPosition.z <= waterlevel)
|
nextpos.z > waterlevel && newPosition.z <= waterlevel)
|
||||||
{
|
{
|
||||||
const Ogre::Vector3 down(0,0,-1);
|
const Ogre::Vector3 down(0,0,-1);
|
||||||
@ -197,7 +196,7 @@ namespace MWWorld
|
|||||||
|
|
||||||
// We hit something. Try to step up onto it.
|
// We hit something. Try to step up onto it.
|
||||||
if(stepMove(colobj, newPosition, velocity, remainingTime, engine))
|
if(stepMove(colobj, newPosition, velocity, remainingTime, engine))
|
||||||
isOnGround = !(isSwimming || isFlying); // Only on the ground if there's gravity
|
isOnGround = !(newPosition.z < waterlevel || isFlying); // Only on the ground if there's gravity
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Can't move this way, try to find another spot along the plane
|
// Can't move this way, try to find another spot along the plane
|
||||||
@ -208,7 +207,7 @@ namespace MWWorld
|
|||||||
|
|
||||||
// Do not allow sliding upward if there is gravity. Stepping will have taken
|
// Do not allow sliding upward if there is gravity. Stepping will have taken
|
||||||
// care of that.
|
// care of that.
|
||||||
if(!(isSwimming || isFlying))
|
if(!(newPosition.z < waterlevel || isFlying))
|
||||||
velocity.z = std::min(velocity.z, 0.0f);
|
velocity.z = std::min(velocity.z, 0.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -225,7 +224,7 @@ namespace MWWorld
|
|||||||
isOnGround = false;
|
isOnGround = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isOnGround || isSwimming || isFlying)
|
if(isOnGround || newPosition.z < waterlevel || isFlying)
|
||||||
physicActor->setInertialForce(Ogre::Vector3(0.0f));
|
physicActor->setInertialForce(Ogre::Vector3(0.0f));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -590,15 +589,13 @@ namespace MWWorld
|
|||||||
for(;iter != mMovementQueue.end();iter++)
|
for(;iter != mMovementQueue.end();iter++)
|
||||||
{
|
{
|
||||||
float waterlevel = -std::numeric_limits<float>::max();
|
float waterlevel = -std::numeric_limits<float>::max();
|
||||||
const MWWorld::CellStore *cellstore = iter->first.getCell();
|
const ESM::Cell *cell = iter->first.getCell()->mCell;
|
||||||
if(cellstore->mCell->hasWater())
|
if(cell->hasWater())
|
||||||
waterlevel = cellstore->mCell->mWater;
|
waterlevel = cell->mWater;
|
||||||
|
|
||||||
Ogre::Vector3 newpos;
|
Ogre::Vector3 newpos = MovementSolver::move(iter->first, iter->second, mTimeAccum,
|
||||||
newpos = MovementSolver::move(iter->first, iter->second, mTimeAccum,
|
world->isFlying(iter->first),
|
||||||
world->isSwimming(iter->first),
|
waterlevel, mEngine);
|
||||||
world->isFlying(iter->first),
|
|
||||||
waterlevel, mEngine);
|
|
||||||
mMovementResults.push_back(std::make_pair(iter->first, newpos));
|
mMovementResults.push_back(std::make_pair(iter->first, newpos));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user