mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-25 08:39:41 +00:00
Added a simplistic snap to closest object or terrain.
This commit is contained in:
parent
1504119da7
commit
407edc770c
3 changed files with 89 additions and 12 deletions
|
@ -242,18 +242,23 @@ namespace CSVRender
|
||||||
if(result.first != "" && // don't allow pathgrid points under the cursor
|
if(result.first != "" && // don't allow pathgrid points under the cursor
|
||||||
!QString(refId.c_str()).contains(QRegExp("^Pathgrid")))
|
!QString(refId.c_str()).contains(QRegExp("^Pathgrid")))
|
||||||
{
|
{
|
||||||
// drop (does not work if placed below the object/terrain)
|
// snap (defaults to 300 or less)
|
||||||
// maybe look for closest object/terrain in both directions?
|
// FIXME: sticks to the underside of the object if snapping up
|
||||||
std::pair<std::string, float> res = mPhysics->distToGround(pos, getCamera());
|
std::pair<std::string, float> res =
|
||||||
|
mPhysics->distToClosest(pos, getCamera(), 500);
|
||||||
if(res.first != "")
|
if(res.first != "")
|
||||||
|
{
|
||||||
pos.z -= res.second;
|
pos.z -= res.second;
|
||||||
// FIXME: rather than just updating at the end, should
|
// FIXME: rather than just updating at the end, should
|
||||||
// consider providing visual feedback of terrain height
|
// consider providing visual feedback of terrain height
|
||||||
// while dragging the pathgrid point (maybe check whether
|
// while dragging the pathgrid point (maybe check whether
|
||||||
// the object is a pathgrid point at the begging and set
|
// the object is a pathgrid point at the begging and set
|
||||||
// a flag?)
|
// a flag?)
|
||||||
placeObject(mGrabbedSceneNode, pos); // result.second
|
placeObject(mGrabbedSceneNode, pos); // result.second
|
||||||
mParent->pathgridMoved(referenceId, pos); // result.second
|
mParent->pathgridMoved(referenceId, pos); // result.second
|
||||||
|
}
|
||||||
|
else
|
||||||
|
cancelDrag();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
cancelDrag(); // FIXME: does not allow editing if terrain not visible
|
cancelDrag(); // FIXME: does not allow editing if terrain not visible
|
||||||
|
|
|
@ -281,7 +281,7 @@ namespace CSVWorld
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<std::string, float> PhysicsSystem::distToGround(Ogre::Vector3 &position,
|
std::pair<std::string, float> PhysicsSystem::distToGround(const Ogre::Vector3 &position,
|
||||||
Ogre::Camera *camera)
|
Ogre::Camera *camera)
|
||||||
{
|
{
|
||||||
btVector3 _from, _to;
|
btVector3 _from, _to;
|
||||||
|
@ -318,6 +318,74 @@ namespace CSVWorld
|
||||||
return std::make_pair(result.first, 300000*result.second);
|
return std::make_pair(result.first, 300000*result.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: remove code duplication
|
||||||
|
std::pair<std::string, float> PhysicsSystem::distToClosest(const Ogre::Vector3 &position,
|
||||||
|
Ogre::Camera *camera, const float limit)
|
||||||
|
{
|
||||||
|
uint32_t visibilityMask = camera->getViewport()->getVisibilityMask();
|
||||||
|
bool ignoreHeightMap = !(visibilityMask & (uint32_t)CSVRender::Element_Terrain);
|
||||||
|
bool ignoreObjects = !(visibilityMask & (uint32_t)CSVRender::Element_Reference);
|
||||||
|
bool ignorePathgrid = !(visibilityMask & (uint32_t)CSVRender::Element_Pathgrid);
|
||||||
|
|
||||||
|
short mask = OEngine::Physic::CollisionType_Raycasting;
|
||||||
|
|
||||||
|
btVector3 _from, _to;
|
||||||
|
_from = btVector3(position.x, position.y, position.z);
|
||||||
|
_to = btVector3(position.x, position.y, position.z-limit);
|
||||||
|
|
||||||
|
std::pair<std::string, float> resDown = std::make_pair("", -1);
|
||||||
|
std::vector<std::pair<float, std::string> > objectsDown = mEngine->rayTest2(_from, _to, mask);
|
||||||
|
|
||||||
|
for (std::vector<std::pair<float, std::string> >::iterator it = objectsDown.begin();
|
||||||
|
it != objectsDown.end(); ++it)
|
||||||
|
{
|
||||||
|
if(ignorePathgrid && QString((*it).second.c_str()).contains(QRegExp("^Pathgrid")))
|
||||||
|
continue;
|
||||||
|
else if(ignoreObjects && QString((*it).second.c_str()).contains(QRegExp("^ref#")))
|
||||||
|
continue;
|
||||||
|
else if(ignoreHeightMap && QString((*it).second.c_str()).contains(QRegExp("^Height")))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
resDown = std::make_pair((*it).second, (*it).first);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
_to = btVector3(position.x, position.y, position.z+limit);
|
||||||
|
std::pair<std::string, float> resUp = std::make_pair("", -1);
|
||||||
|
std::vector<std::pair<float, std::string> > objectsUp = mEngine->rayTest2(_from, _to, mask);
|
||||||
|
|
||||||
|
for (std::vector<std::pair<float, std::string> >::iterator it = objectsDown.begin();
|
||||||
|
it != objectsDown.end(); ++it)
|
||||||
|
{
|
||||||
|
if(ignorePathgrid && QString((*it).second.c_str()).contains(QRegExp("^Pathgrid")))
|
||||||
|
continue;
|
||||||
|
else if(ignoreObjects && QString((*it).second.c_str()).contains(QRegExp("^ref#")))
|
||||||
|
continue;
|
||||||
|
else if(ignoreHeightMap && QString((*it).second.c_str()).contains(QRegExp("^Height")))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
resUp = std::make_pair((*it).second, (*it).first);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(resDown.first != "")
|
||||||
|
{
|
||||||
|
if(resUp.first != "")
|
||||||
|
{
|
||||||
|
if(fabs(resUp.second) < fabs(resDown.second))
|
||||||
|
return std::make_pair(resUp.first, -limit*resUp.second);
|
||||||
|
else
|
||||||
|
return std::make_pair(resDown.first, limit*resDown.second);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return std::make_pair(resDown.first, limit*resDown.second);
|
||||||
|
}
|
||||||
|
else if(resUp.first != "")
|
||||||
|
return std::make_pair(resUp.first, -limit*resUp.second);
|
||||||
|
else
|
||||||
|
return std::make_pair("", -1);
|
||||||
|
}
|
||||||
|
|
||||||
std::string PhysicsSystem::refIdToSceneNode(std::string referenceId, Ogre::SceneManager *sceneMgr)
|
std::string PhysicsSystem::refIdToSceneNode(std::string referenceId, Ogre::SceneManager *sceneMgr)
|
||||||
{
|
{
|
||||||
return mRefIdToSceneNode[referenceId][sceneMgr];
|
return mRefIdToSceneNode[referenceId][sceneMgr];
|
||||||
|
|
|
@ -73,7 +73,11 @@ namespace CSVWorld
|
||||||
std::pair<std::string, Ogre::Vector3> castRay(float mouseX,
|
std::pair<std::string, Ogre::Vector3> castRay(float mouseX,
|
||||||
float mouseY, Ogre::SceneManager *sceneMgr, Ogre::Camera *camera);
|
float mouseY, Ogre::SceneManager *sceneMgr, Ogre::Camera *camera);
|
||||||
|
|
||||||
std::pair<std::string, float> distToGround(Ogre::Vector3 &position, Ogre::Camera *camera);
|
std::pair<std::string, float> distToGround(const Ogre::Vector3 &position,
|
||||||
|
Ogre::Camera *camera);
|
||||||
|
|
||||||
|
std::pair<std::string, float> distToClosest(const Ogre::Vector3 &position,
|
||||||
|
Ogre::Camera *camera, const float limit = 300.0f);
|
||||||
|
|
||||||
std::string sceneNodeToRefId(std::string sceneNodeName);
|
std::string sceneNodeToRefId(std::string sceneNodeName);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue