Rotations: move doors via Rotation rather than LocalRotation

Now LocalRotation is unneeded, will remove in next commit.
pull/802/head
scrawl 9 years ago
parent 8aacbc398f
commit 6405049add

@ -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,12 +60,11 @@ 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))
{
return MWWorld::Ptr(&ref, actor.getCell()); // found, stop searching
}
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
}
}
return MWWorld::Ptr(); // none found
}

@ -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]);
const ESM::Position& objPos = it->first.getRefData().getPosition();
float oldRot = osg::RadiansToDegrees(objPos.rot[2]);
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(0.f, oldRot + diff * (it->second == 1 ? 1 : -1)), 90.f);
localRotateObject(it->first, 0, 0, targetRot);
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 == 90.f && it->second) || targetRot == 0.f;
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…
Cancel
Save