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
This commit is contained in:
Nathan Jeffords 2013-01-07 23:00:00 -08:00
parent 86f691d3d5
commit 0108be2e4f
3 changed files with 33 additions and 21 deletions

View file

@ -43,7 +43,7 @@ namespace MWWorld
return mEngine; 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); btVector3 dir(0, 1, 0);
dir = dir.rotate(btVector3(1, 0, 0), mPlayerData.pitch); dir = dir.rotate(btVector3(1, 0, 0), mPlayerData.pitch);
@ -56,11 +56,14 @@ namespace MWWorld
mPlayerData.eyepos.z); mPlayerData.eyepos.z);
origin += dir * 5; origin += dir * 5;
btVector3 dest = origin + dir * 500; btVector3 dest = origin + dir * queryDistance;
return mEngine->rayTest(origin, dest); 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); btVector3 dir(0, 1, 0);
dir = dir.rotate(btVector3(1, 0, 0), mPlayerData.pitch); dir = dir.rotate(btVector3(1, 0, 0), mPlayerData.pitch);
@ -73,22 +76,32 @@ namespace MWWorld
mPlayerData.eyepos.z); mPlayerData.eyepos.z);
origin += dir * 5; origin += dir * 5;
btVector3 dest = origin + dir * 500; btVector3 dest = origin + dir * queryDistance;
return mEngine->rayTest2(origin, dest); 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); Ray ray = mRender.getCamera()->getCameraToViewportRay(mouseX, mouseY);
Ogre::Vector3 from = ray.getOrigin(); 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; btVector3 _from, _to;
// OGRE to MW coordinates // OGRE to MW coordinates
_from = btVector3(from.x, -from.z, from.y); _from = btVector3(from.x, -from.z, from.y);
_to = btVector3(to.x, -to.z, to.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) void PhysicsSystem::setCurrentWater(bool hasWater, int waterHeight)
@ -110,7 +123,7 @@ namespace MWWorld
Ray centerRay = mRender.getCamera()->getCameraToViewportRay( Ray centerRay = mRender.getCamera()->getCameraToViewportRay(
mRender.getViewport()->getWidth()/2, mRender.getViewport()->getWidth()/2,
mRender.getViewport()->getHeight()/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; return result;
} }
@ -118,7 +131,7 @@ namespace MWWorld
{ {
//get a ray pointing to the center of the viewport //get a ray pointing to the center of the viewport
Ray centerRay = mRender.getCamera()->getCameraToViewportRay(mouseX, mouseY); 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; return result;
} }

View file

@ -41,14 +41,13 @@ namespace MWWorld
bool toggleCollisionMode(); 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);
btVector3 getRayPoint(float extent, float mouseX, float mouseY); 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 // cast ray, return true if it hit something
bool castRay(const Ogre::Vector3& from, const Ogre::Vector3& to); bool castRay(const Ogre::Vector3& from, const Ogre::Vector3& to);

View file

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