Simplified doors, now they will stop after hitting an obstacle instead of trying to back off.

This commit is contained in:
scrawl 2013-07-07 03:52:17 +02:00
parent de5898c953
commit 744c5804ed

View file

@ -1113,11 +1113,6 @@ namespace MWWorld
float targetRot = std::min(std::max(0.f, oldRot + diff * (it->second ? 1 : -1)), 90.f); float targetRot = std::min(std::max(0.f, oldRot + diff * (it->second ? 1 : -1)), 90.f);
localRotateObject(it->first, 0, 0, targetRot); localRotateObject(it->first, 0, 0, targetRot);
// AABB of the door
Ogre::Vector3 min,max;
mPhysics->getObjectAABB(it->first, min, max);
Ogre::Vector3 dimensions = max-min;
/// \todo should use convexSweepTest here /// \todo should use convexSweepTest here
std::vector<std::string> collisions = mPhysics->getCollisions(it->first); std::vector<std::string> collisions = mPhysics->getCollisions(it->first);
for (std::vector<std::string>::iterator cit = collisions.begin(); cit != collisions.end(); ++cit) for (std::vector<std::string>::iterator cit = collisions.begin(); cit != collisions.end(); ++cit)
@ -1125,23 +1120,8 @@ namespace MWWorld
MWWorld::Ptr ptr = getPtrViaHandle(*cit); MWWorld::Ptr ptr = getPtrViaHandle(*cit);
if (MWWorld::Class::get(ptr).isActor()) if (MWWorld::Class::get(ptr).isActor())
{ {
// we collided with an actor, we need to undo the rotation and push the door away from the actor // we collided with an actor, we need to undo the rotation
localRotateObject(it->first, 0, 0, oldRot);
// figure out on which side of the door the actor we collided with is
Ogre::Vector3 relativePos = it->first.getRefData().getBaseNode()->
convertWorldToLocalPosition(ptr.getRefData().getBaseNode()->_getDerivedPosition());
float axisToCheck;
if (dimensions.x > dimensions.y)
axisToCheck = relativePos.y * boost::math::sign((min+max).y);
else
axisToCheck = relativePos.x * boost::math::sign((min+max).x);
if (axisToCheck >= 0)
targetRot = std::min(std::max(0.f, oldRot + diff*0.5f), 90.f);
else
targetRot = std::min(std::max(0.f, oldRot - diff*0.5f), 90.f);
localRotateObject(it->first, 0, 0, targetRot);
break; break;
} }
} }