updated MWWorld::PhysicsSystem::getFacedXXX functions

* changed the names and return values to be consistent
 * made the distance to search a parameter
 * change the distance returned to world units instead of percentage of query distance
actorid
Nathan Jeffords 12 years ago
parent 86f691d3d5
commit 0108be2e4f

@ -43,7 +43,7 @@ namespace MWWorld
return mEngine;
}
std::pair<std::string, float> PhysicsSystem::getFacedHandle (MWWorld::World& world)
std::pair<float, std::string> PhysicsSystem::getFacedHandle (MWWorld::World& world, float queryDistance)
{
btVector3 dir(0, 1, 0);
dir = dir.rotate(btVector3(1, 0, 0), mPlayerData.pitch);
@ -56,11 +56,14 @@ namespace MWWorld
mPlayerData.eyepos.z);
origin += dir * 5;
btVector3 dest = origin + dir * 500;
return mEngine->rayTest(origin, dest);
btVector3 dest = origin + dir * queryDistance;
std::pair <std::string, float> result;
/*auto*/ result = mEngine->rayTest(origin, dest);
result.second *= queryDistance;
return std::make_pair (result.second, result.first);
}
std::vector < std::pair <float, std::string> > PhysicsSystem::getFacedObjects ()
std::vector < std::pair <float, std::string> > PhysicsSystem::getFacedHandles (float queryDistance)
{
btVector3 dir(0, 1, 0);
dir = dir.rotate(btVector3(1, 0, 0), mPlayerData.pitch);
@ -73,22 +76,32 @@ namespace MWWorld
mPlayerData.eyepos.z);
origin += dir * 5;
btVector3 dest = origin + dir * 500;
return mEngine->rayTest2(origin, dest);
btVector3 dest = origin + dir * queryDistance;
std::vector < std::pair <float, std::string> > results;
/* auto */ results = mEngine->rayTest2(origin, dest);
std::vector < std::pair <float, std::string> >::iterator i;
for (/* auto */ i = results.begin (); i != results.end (); ++i)
i->first *= queryDistance;
return results;
}
std::vector < std::pair <float, std::string> > PhysicsSystem::getFacedObjects (float mouseX, float mouseY)
std::vector < std::pair <float, std::string> > PhysicsSystem::getFacedHandles (float mouseX, float mouseY, float queryDistance)
{
Ray ray = mRender.getCamera()->getCameraToViewportRay(mouseX, mouseY);
Ogre::Vector3 from = ray.getOrigin();
Ogre::Vector3 to = ray.getPoint(500); /// \todo make this distance (ray length) configurable
Ogre::Vector3 to = ray.getPoint(queryDistance);
btVector3 _from, _to;
// OGRE to MW coordinates
_from = btVector3(from.x, -from.z, from.y);
_to = btVector3(to.x, -to.z, to.y);
return mEngine->rayTest2(_from,_to);
std::vector < std::pair <float, std::string> > results;
/* auto */ results = mEngine->rayTest2(_from,_to);
std::vector < std::pair <float, std::string> >::iterator i;
for (/* auto */ i = results.begin (); i != results.end (); ++i)
i->first *= queryDistance;
return results;
}
void PhysicsSystem::setCurrentWater(bool hasWater, int waterHeight)
@ -110,7 +123,7 @@ namespace MWWorld
Ray centerRay = mRender.getCamera()->getCameraToViewportRay(
mRender.getViewport()->getWidth()/2,
mRender.getViewport()->getHeight()/2);
btVector3 result(centerRay.getPoint(500*extent).x,-centerRay.getPoint(500*extent).z,centerRay.getPoint(500*extent).y); /// \todo make this distance (ray length) configurable
btVector3 result(centerRay.getPoint(extent).x,-centerRay.getPoint(extent).z,centerRay.getPoint(extent).y);
return result;
}
@ -118,7 +131,7 @@ namespace MWWorld
{
//get a ray pointing to the center of the viewport
Ray centerRay = mRender.getCamera()->getCameraToViewportRay(mouseX, mouseY);
btVector3 result(centerRay.getPoint(500*extent).x,-centerRay.getPoint(500*extent).z,centerRay.getPoint(500*extent).y); /// \todo make this distance (ray length) configurable
btVector3 result(centerRay.getPoint(extent).x,-centerRay.getPoint(extent).z,centerRay.getPoint(extent).y);
return result;
}

@ -41,14 +41,13 @@ namespace MWWorld
bool toggleCollisionMode();
std::pair<std::string, float> getFacedHandle (MWWorld::World& world);
std::pair<float, std::string> getFacedHandle (MWWorld::World& world, float queryDistance);
std::vector < std::pair <float, std::string> > getFacedHandles (float queryDistance);
std::vector < std::pair <float, std::string> > getFacedHandles (float mouseX, float mouseY, float queryDistance);
btVector3 getRayPoint(float extent);
btVector3 getRayPoint(float extent, float mouseX, float mouseY);
std::vector < std::pair <float, std::string> > getFacedObjects ();
std::vector < std::pair <float, std::string> > getFacedObjects (float mouseX, float mouseY);
// cast ray, return true if it hit something
bool castRay(const Ogre::Vector3& from, const Ogre::Vector3& to);

@ -577,13 +577,13 @@ namespace MWWorld
{
if (!mRendering->occlusionQuerySupported())
{
std::pair<std::string, float> result = mPhysics->getFacedHandle (*this);
std::pair<float, std::string> result = mPhysics->getFacedHandle (*this, 500);
if (result.first.empty() ||
result.second>getStore().get<ESM::GameSetting>().find ("iMaxActivateDist")->getInt())
if (result.second.empty() ||
result.first>getStore().get<ESM::GameSetting>().find ("iMaxActivateDist")->getInt())
return "";
return result.first;
return result.second;
}
else
{
@ -979,11 +979,11 @@ namespace MWWorld
{
float x, y;
MWBase::Environment::get().getWindowManager()->getMousePosition(x, y);
results = mPhysics->getFacedObjects(x, y);
results = mPhysics->getFacedHandles(x, y, 500);
}
else
{
results = mPhysics->getFacedObjects();
results = mPhysics->getFacedHandles(500);
}
// ignore the player and other things we're not interested in

Loading…
Cancel
Save