mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 20:19:57 +00:00
Rotations: move doors via Rotation rather than LocalRotation
Now LocalRotation is unneeded, will remove in next commit.
This commit is contained in:
parent
8aacbc398f
commit
6405049add
4 changed files with 26 additions and 23 deletions
|
@ -159,16 +159,17 @@ namespace MWClass
|
|||
boost::shared_ptr<MWWorld::Action> action(new MWWorld::ActionDoor(ptr));
|
||||
int doorstate = getDoorState(ptr);
|
||||
bool opening = true;
|
||||
float doorRot = ptr.getRefData().getPosition().rot[2] - ptr.getCellRef().getPosition().rot[2];
|
||||
if (doorstate == 1)
|
||||
opening = false;
|
||||
if (doorstate == 0 && ptr.getRefData().getLocalRotation().rot[2] != 0)
|
||||
if (doorstate == 0 && doorRot != 0)
|
||||
opening = false;
|
||||
|
||||
if (opening)
|
||||
{
|
||||
MWBase::Environment::get().getSoundManager()->fadeOutSound3D(ptr,
|
||||
closeSound, 0.5f);
|
||||
float offset = ptr.getRefData().getLocalRotation().rot[2]/ 3.14159265f * 2.0f;
|
||||
float offset = doorRot/ 3.14159265f * 2.0f;
|
||||
action->setSoundOffset(offset);
|
||||
action->setSound(openSound);
|
||||
}
|
||||
|
@ -176,7 +177,7 @@ namespace MWClass
|
|||
{
|
||||
MWBase::Environment::get().getSoundManager()->fadeOutSound3D(ptr,
|
||||
openSound, 0.5f);
|
||||
float offset = 1.0f - ptr.getRefData().getLocalRotation().rot[2]/ 3.14159265f * 2.0f;
|
||||
float offset = 1.0f - doorRot/ 3.14159265f * 2.0f;
|
||||
//most if not all door have closing bang somewhere in the middle of the sound,
|
||||
//so we divide offset by two
|
||||
action->setSoundOffset(offset * 0.5f);
|
||||
|
|
|
@ -28,15 +28,15 @@ namespace MWMechanics
|
|||
//
|
||||
// Limitation: there can be false detections, and does not test whether the
|
||||
// actor is facing the door.
|
||||
bool proximityToDoor(const MWWorld::Ptr& actor, float minSqr, bool closed)
|
||||
bool proximityToDoor(const MWWorld::Ptr& actor, float minSqr)
|
||||
{
|
||||
if(getNearbyDoor(actor, minSqr, closed)!=MWWorld::Ptr())
|
||||
if(getNearbyDoor(actor, minSqr)!=MWWorld::Ptr())
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
MWWorld::Ptr getNearbyDoor(const MWWorld::Ptr& actor, float minSqr, bool closed)
|
||||
MWWorld::Ptr getNearbyDoor(const MWWorld::Ptr& actor, float minSqr)
|
||||
{
|
||||
MWWorld::CellStore *cell = actor.getCell();
|
||||
|
||||
|
@ -60,9 +60,8 @@ namespace MWMechanics
|
|||
for (; it != refList.end(); ++it)
|
||||
{
|
||||
MWWorld::LiveCellRef<ESM::Door>& ref = *it;
|
||||
if((pos - ref.mData.getPosition().asVec3()).length2() < minSqr)
|
||||
if((closed && ref.mData.getLocalRotation().rot[2] == 0) ||
|
||||
(!closed && ref.mData.getLocalRotation().rot[2] >= 1))
|
||||
if((pos - ref.mData.getPosition().asVec3()).length2() < minSqr
|
||||
&& ref.mData.getPosition().rot[2] == ref.mRef.getPosition().rot[2])
|
||||
{
|
||||
return MWWorld::Ptr(&ref, actor.getCell()); // found, stop searching
|
||||
}
|
||||
|
|
|
@ -17,14 +17,12 @@ namespace MWMechanics
|
|||
|
||||
/// tests actor's proximity to a closed door by default
|
||||
bool proximityToDoor(const MWWorld::Ptr& actor,
|
||||
float minSqr = MIN_DIST_TO_DOOR_SQUARED,
|
||||
bool closed = true);
|
||||
float minSqr = MIN_DIST_TO_DOOR_SQUARED);
|
||||
|
||||
/// Returns door pointer within range. No guarentee is given as too which one
|
||||
/** \return Pointer to the door, or NULL if none exists **/
|
||||
MWWorld::Ptr getNearbyDoor(const MWWorld::Ptr& actor,
|
||||
float minSqr = MIN_DIST_TO_DOOR_SQUARED,
|
||||
bool closed = true);
|
||||
float minSqr = MIN_DIST_TO_DOOR_SQUARED);
|
||||
|
||||
class ObstacleCheck
|
||||
{
|
||||
|
|
|
@ -1402,12 +1402,17 @@ namespace MWWorld
|
|||
}
|
||||
else
|
||||
{
|
||||
float oldRot = osg::RadiansToDegrees(it->first.getRefData().getLocalRotation().rot[2]);
|
||||
float diff = duration * 90.f;
|
||||
float targetRot = std::min(std::max(0.f, oldRot + diff * (it->second == 1 ? 1 : -1)), 90.f);
|
||||
localRotateObject(it->first, 0, 0, targetRot);
|
||||
const ESM::Position& objPos = it->first.getRefData().getPosition();
|
||||
float oldRot = osg::RadiansToDegrees(objPos.rot[2]);
|
||||
|
||||
bool reached = (targetRot == 90.f && it->second) || targetRot == 0.f;
|
||||
float minRot = osg::RadiansToDegrees(it->first.getCellRef().getPosition().rot[2]);
|
||||
float maxRot = minRot + 90.f;
|
||||
|
||||
float diff = duration * 90.f;
|
||||
float targetRot = std::min(std::max(minRot, oldRot + diff * (it->second == 1 ? 1 : -1)), maxRot);
|
||||
rotateObject(it->first, objPos.rot[0], objPos.rot[1], targetRot);
|
||||
|
||||
bool reached = (targetRot == maxRot && it->second) || targetRot == minRot;
|
||||
|
||||
/// \todo should use convexSweepTest here
|
||||
std::vector<MWWorld::Ptr> collisions = mPhysics->getCollisions(it->first, MWPhysics::CollisionType_Actor, MWPhysics::CollisionType_Actor);
|
||||
|
@ -1424,7 +1429,7 @@ namespace MWWorld
|
|||
}
|
||||
|
||||
// we need to undo the rotation
|
||||
localRotateObject(it->first, 0, 0, oldRot);
|
||||
rotateObject(it->first, objPos.rot[0], objPos.rot[1], oldRot);
|
||||
reached = false;
|
||||
}
|
||||
}
|
||||
|
@ -2103,7 +2108,7 @@ namespace MWWorld
|
|||
switch (state)
|
||||
{
|
||||
case 0:
|
||||
if (door.getRefData().getLocalRotation().rot[2] == 0)
|
||||
if (door.getRefData().getPosition().rot[2] == door.getCellRef().getPosition().rot[2])
|
||||
state = 1; // if closed, then open
|
||||
else
|
||||
state = 2; // if open, then close
|
||||
|
|
Loading…
Reference in a new issue