mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-24 23:23:51 +00:00
Simplistic drop-to-ground functionality for pathgrid points.
This commit is contained in:
parent
2412d127b0
commit
48ecea7103
3 changed files with 51 additions and 5 deletions
|
@ -236,12 +236,17 @@ namespace CSVRender
|
|||
// move pathgrid point, but don't save yet (need pathgrid
|
||||
// table feature & its data structure to be completed)
|
||||
// FIXME: need to signal PathgridPoint object of change
|
||||
//std::pair<std::string, Ogre::Vector3> result =
|
||||
//anyUnderCursor(event->x(), event->y());
|
||||
//std::string refId = mPhysics->sceneNodeToRefId(result.first);
|
||||
//if(result.first != "" && // don't allow pathgrid points under the cursor
|
||||
//!QString(refId.c_str()).contains(QRegExp("^Pathgrid")))
|
||||
std::pair<std::string, Ogre::Vector3> result =
|
||||
anyUnderCursor(event->x(), event->y());
|
||||
std::string refId = mPhysics->sceneNodeToRefId(result.first);
|
||||
if(result.first != "" && // don't allow pathgrid points under the cursor
|
||||
!QString(refId.c_str()).contains(QRegExp("^Pathgrid")))
|
||||
{
|
||||
// drop (does not work if placed below the object/terrain)
|
||||
// maybe look for closest object/terrain in both directions?
|
||||
std::pair<std::string, float> res = mPhysics->distToGround(pos, getCamera());
|
||||
if(res.first != "")
|
||||
pos.z -= res.second;
|
||||
// FIXME: rather than just updating at the end, should
|
||||
// consider providing visual feedback of terrain height
|
||||
// while dragging the pathgrid point (maybe check whether
|
||||
|
@ -250,6 +255,8 @@ namespace CSVRender
|
|||
placeObject(mGrabbedSceneNode, pos); // result.second
|
||||
mParent->pathgridMoved(referenceId, pos); // result.second
|
||||
}
|
||||
else
|
||||
cancelDrag();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -281,6 +281,43 @@ namespace CSVWorld
|
|||
}
|
||||
}
|
||||
|
||||
std::pair<std::string, float> PhysicsSystem::distToGround(Ogre::Vector3 &position,
|
||||
Ogre::Camera *camera)
|
||||
{
|
||||
btVector3 _from, _to;
|
||||
_from = btVector3(position.x, position.y, position.z);
|
||||
_to = btVector3(position.x, position.y, position.z-300000);
|
||||
|
||||
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);
|
||||
|
||||
std::pair<std::string, float> result = std::make_pair("", -1);
|
||||
short mask = OEngine::Physic::CollisionType_Raycasting;
|
||||
std::vector<std::pair<float, std::string> > objects = mEngine->rayTest2(_from, _to, mask);
|
||||
|
||||
for (std::vector<std::pair<float, std::string> >::iterator it = objects.begin();
|
||||
it != objects.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;
|
||||
|
||||
result = std::make_pair((*it).second, (*it).first);
|
||||
break;
|
||||
}
|
||||
|
||||
// result.first is the object's referenceId
|
||||
if(result.first == "")
|
||||
return std::make_pair("", -1);
|
||||
else
|
||||
return std::make_pair(result.first, 300000*result.second);
|
||||
}
|
||||
|
||||
std::string PhysicsSystem::refIdToSceneNode(std::string referenceId, Ogre::SceneManager *sceneMgr)
|
||||
{
|
||||
return mRefIdToSceneNode[referenceId][sceneMgr];
|
||||
|
|
|
@ -73,6 +73,8 @@ namespace CSVWorld
|
|||
std::pair<std::string, Ogre::Vector3> castRay(float mouseX,
|
||||
float mouseY, Ogre::SceneManager *sceneMgr, Ogre::Camera *camera);
|
||||
|
||||
std::pair<std::string, float> distToGround(Ogre::Vector3 &position, Ogre::Camera *camera);
|
||||
|
||||
std::string sceneNodeToRefId(std::string sceneNodeName);
|
||||
|
||||
// for multi-scene manager per physics engine
|
||||
|
|
Loading…
Reference in a new issue