mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-29 04:06:40 +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));
|
boost::shared_ptr<MWWorld::Action> action(new MWWorld::ActionDoor(ptr));
|
||||||
int doorstate = getDoorState(ptr);
|
int doorstate = getDoorState(ptr);
|
||||||
bool opening = true;
|
bool opening = true;
|
||||||
|
float doorRot = ptr.getRefData().getPosition().rot[2] - ptr.getCellRef().getPosition().rot[2];
|
||||||
if (doorstate == 1)
|
if (doorstate == 1)
|
||||||
opening = false;
|
opening = false;
|
||||||
if (doorstate == 0 && ptr.getRefData().getLocalRotation().rot[2] != 0)
|
if (doorstate == 0 && doorRot != 0)
|
||||||
opening = false;
|
opening = false;
|
||||||
|
|
||||||
if (opening)
|
if (opening)
|
||||||
{
|
{
|
||||||
MWBase::Environment::get().getSoundManager()->fadeOutSound3D(ptr,
|
MWBase::Environment::get().getSoundManager()->fadeOutSound3D(ptr,
|
||||||
closeSound, 0.5f);
|
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->setSoundOffset(offset);
|
||||||
action->setSound(openSound);
|
action->setSound(openSound);
|
||||||
}
|
}
|
||||||
|
@ -176,7 +177,7 @@ namespace MWClass
|
||||||
{
|
{
|
||||||
MWBase::Environment::get().getSoundManager()->fadeOutSound3D(ptr,
|
MWBase::Environment::get().getSoundManager()->fadeOutSound3D(ptr,
|
||||||
openSound, 0.5f);
|
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,
|
//most if not all door have closing bang somewhere in the middle of the sound,
|
||||||
//so we divide offset by two
|
//so we divide offset by two
|
||||||
action->setSoundOffset(offset * 0.5f);
|
action->setSoundOffset(offset * 0.5f);
|
||||||
|
|
|
@ -28,15 +28,15 @@ namespace MWMechanics
|
||||||
//
|
//
|
||||||
// Limitation: there can be false detections, and does not test whether the
|
// Limitation: there can be false detections, and does not test whether the
|
||||||
// actor is facing the door.
|
// 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;
|
return true;
|
||||||
else
|
else
|
||||||
return false;
|
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();
|
MWWorld::CellStore *cell = actor.getCell();
|
||||||
|
|
||||||
|
@ -60,9 +60,8 @@ namespace MWMechanics
|
||||||
for (; it != refList.end(); ++it)
|
for (; it != refList.end(); ++it)
|
||||||
{
|
{
|
||||||
MWWorld::LiveCellRef<ESM::Door>& ref = *it;
|
MWWorld::LiveCellRef<ESM::Door>& ref = *it;
|
||||||
if((pos - ref.mData.getPosition().asVec3()).length2() < minSqr)
|
if((pos - ref.mData.getPosition().asVec3()).length2() < minSqr
|
||||||
if((closed && ref.mData.getLocalRotation().rot[2] == 0) ||
|
&& ref.mData.getPosition().rot[2] == ref.mRef.getPosition().rot[2])
|
||||||
(!closed && ref.mData.getLocalRotation().rot[2] >= 1))
|
|
||||||
{
|
{
|
||||||
return MWWorld::Ptr(&ref, actor.getCell()); // found, stop searching
|
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
|
/// tests actor's proximity to a closed door by default
|
||||||
bool proximityToDoor(const MWWorld::Ptr& actor,
|
bool proximityToDoor(const MWWorld::Ptr& actor,
|
||||||
float minSqr = MIN_DIST_TO_DOOR_SQUARED,
|
float minSqr = MIN_DIST_TO_DOOR_SQUARED);
|
||||||
bool closed = true);
|
|
||||||
|
|
||||||
/// Returns door pointer within range. No guarentee is given as too which one
|
/// Returns door pointer within range. No guarentee is given as too which one
|
||||||
/** \return Pointer to the door, or NULL if none exists **/
|
/** \return Pointer to the door, or NULL if none exists **/
|
||||||
MWWorld::Ptr getNearbyDoor(const MWWorld::Ptr& actor,
|
MWWorld::Ptr getNearbyDoor(const MWWorld::Ptr& actor,
|
||||||
float minSqr = MIN_DIST_TO_DOOR_SQUARED,
|
float minSqr = MIN_DIST_TO_DOOR_SQUARED);
|
||||||
bool closed = true);
|
|
||||||
|
|
||||||
class ObstacleCheck
|
class ObstacleCheck
|
||||||
{
|
{
|
||||||
|
|
|
@ -1402,12 +1402,17 @@ namespace MWWorld
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
float oldRot = osg::RadiansToDegrees(it->first.getRefData().getLocalRotation().rot[2]);
|
const ESM::Position& objPos = it->first.getRefData().getPosition();
|
||||||
float diff = duration * 90.f;
|
float oldRot = osg::RadiansToDegrees(objPos.rot[2]);
|
||||||
float targetRot = std::min(std::max(0.f, oldRot + diff * (it->second == 1 ? 1 : -1)), 90.f);
|
|
||||||
localRotateObject(it->first, 0, 0, targetRot);
|
|
||||||
|
|
||||||
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
|
/// \todo should use convexSweepTest here
|
||||||
std::vector<MWWorld::Ptr> collisions = mPhysics->getCollisions(it->first, MWPhysics::CollisionType_Actor, MWPhysics::CollisionType_Actor);
|
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
|
// we need to undo the rotation
|
||||||
localRotateObject(it->first, 0, 0, oldRot);
|
rotateObject(it->first, objPos.rot[0], objPos.rot[1], oldRot);
|
||||||
reached = false;
|
reached = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2103,7 +2108,7 @@ namespace MWWorld
|
||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
case 0:
|
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
|
state = 1; // if closed, then open
|
||||||
else
|
else
|
||||||
state = 2; // if open, then close
|
state = 2; // if open, then close
|
||||||
|
|
Loading…
Reference in a new issue