mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-20 15:40:32 +00:00
Use collision boxes to calculate dropping height, variable naming
This commit is contained in:
parent
b8e6257beb
commit
035d5205d9
@ -7,6 +7,7 @@
|
||||
|
||||
#include "../../model/prefs/state.hpp"
|
||||
|
||||
#include <osg/ComputeBoundsVisitor>
|
||||
#include <osg/Group>
|
||||
#include <osg/Vec3d>
|
||||
#include <osgUtil/LineSegmentIntersector>
|
||||
@ -704,7 +705,6 @@ void CSVRender::InstanceMode::dropInstance(DropMode dropMode, CSVRender::Object*
|
||||
|
||||
osg::Vec3d start = point;
|
||||
osg::Vec3d end = point;
|
||||
start.z() += 1.0f;
|
||||
end.z() = std::numeric_limits<float>::min();
|
||||
|
||||
osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector (new osgUtil::LineSegmentIntersector(
|
||||
@ -730,14 +730,12 @@ void CSVRender::InstanceMode::dropInstance(DropMode dropMode, CSVRender::Object*
|
||||
}
|
||||
}
|
||||
|
||||
float CSVRender::InstanceMode::getDropHeight(DropMode dropMode, CSVRender::Object* object)
|
||||
float CSVRender::InstanceMode::getDropHeight(DropMode dropMode, CSVRender::Object* object, float objectHeight)
|
||||
{
|
||||
const osg::Vec3d& point = object->getPosition().asVec3();
|
||||
osg::ref_ptr<osg::Group> objectNode = object->getRootNode();
|
||||
|
||||
osg::Vec3d start = point;
|
||||
osg::Vec3d end = point;
|
||||
start.z() += 1.0f;
|
||||
end.z() = std::numeric_limits<float>::min();
|
||||
|
||||
osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector (new osgUtil::LineSegmentIntersector(
|
||||
@ -754,9 +752,8 @@ float CSVRender::InstanceMode::getDropHeight(DropMode dropMode, CSVRender::Objec
|
||||
it != intersector->getIntersections().end(); ++it)
|
||||
{
|
||||
osgUtil::LineSegmentIntersector::Intersection intersection = *it;
|
||||
ESM::Position position = object->getPosition();
|
||||
float dropHeight = intersection.getWorldIntersectPoint().z();
|
||||
return position.pos[2] - dropHeight;
|
||||
float collisionLevel = intersection.getWorldIntersectPoint().z();
|
||||
return point.z() - collisionLevel + objectHeight;
|
||||
}
|
||||
|
||||
return 0.0f;
|
||||
@ -793,13 +790,25 @@ void CSVRender::InstanceMode::handleDropMethod(DropMode dropMode, QString comman
|
||||
CSMWorld::CommandMacro macro (undoStack, commandMsg);
|
||||
|
||||
std::vector<osg::Node::NodeMask> oldMasks;
|
||||
std::vector<float> objectHeights;
|
||||
for(osg::ref_ptr<TagBase> tag: selection)
|
||||
{
|
||||
if (CSVRender::ObjectTag *objectTag = dynamic_cast<CSVRender::ObjectTag *> (tag.get()))
|
||||
{
|
||||
osg::ref_ptr<osg::Group> objectNode = objectTag->mObject->getRootNode();
|
||||
oldMasks.emplace_back(objectNode->getNodeMask());
|
||||
objectNode->setNodeMask(SceneUtil::Mask_Disabled);
|
||||
osg::ref_ptr<osg::Group> objectNodeWithGUI = objectTag->mObject->getRootNode();
|
||||
osg::ref_ptr<osg::Group> objectNodeWithoutGUI = objectTag->mObject->getBaseNode();
|
||||
|
||||
osg::ComputeBoundsVisitor computeBounds;
|
||||
computeBounds.setTraversalMask(SceneUtil::Mask_EditorReference);
|
||||
objectNodeWithoutGUI->accept(computeBounds);
|
||||
osg::BoundingBox bounds = computeBounds.getBoundingBox();
|
||||
float boundingBoxOffset = 0.0f;
|
||||
if (bounds.valid()) boundingBoxOffset = bounds.zMin();
|
||||
|
||||
objectHeights.emplace_back(boundingBoxOffset);
|
||||
oldMasks.emplace_back(objectNodeWithGUI->getNodeMask());
|
||||
|
||||
objectNodeWithGUI->setNodeMask(SceneUtil::Mask_Disabled);
|
||||
}
|
||||
}
|
||||
|
||||
@ -811,11 +820,13 @@ void CSVRender::InstanceMode::handleDropMethod(DropMode dropMode, QString comman
|
||||
case Collision:
|
||||
{
|
||||
float smallestDropHeight = std::numeric_limits<float>::max();
|
||||
int counter = 0;
|
||||
for(osg::ref_ptr<TagBase> tag: selection)
|
||||
if (CSVRender::ObjectTag *objectTag = dynamic_cast<CSVRender::ObjectTag *> (tag.get()))
|
||||
{
|
||||
float thisDrop = getDropHeight(dropMode, objectTag->mObject);
|
||||
float thisDrop = getDropHeight(dropMode, objectTag->mObject, objectHeights[counter]);
|
||||
if (thisDrop < smallestDropHeight) smallestDropHeight = thisDrop;
|
||||
counter++;
|
||||
}
|
||||
for(osg::ref_ptr<TagBase> tag: selection)
|
||||
if (CSVRender::ObjectTag *objectTag = dynamic_cast<CSVRender::ObjectTag *> (tag.get()))
|
||||
@ -852,8 +863,8 @@ void CSVRender::InstanceMode::handleDropMethod(DropMode dropMode, QString comman
|
||||
{
|
||||
if (CSVRender::ObjectTag *objectTag = dynamic_cast<CSVRender::ObjectTag *> (tag.get()))
|
||||
{
|
||||
osg::ref_ptr<osg::Group> objectNode = objectTag->mObject->getRootNode();
|
||||
objectNode->setNodeMask(oldMasks[counter]);
|
||||
osg::ref_ptr<osg::Group> objectNodeWithGUI = objectTag->mObject->getRootNode();
|
||||
objectNodeWithGUI->setNodeMask(oldMasks[counter]);
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ namespace CSVRender
|
||||
osg::Vec3f getSelectionCenter(const std::vector<osg::ref_ptr<TagBase> >& selection) const;
|
||||
osg::Vec3f getScreenCoords(const osg::Vec3f& pos);
|
||||
void dropInstance(DropMode dropMode, CSVRender::Object* object);
|
||||
float getDropHeight(DropMode dropMode, CSVRender::Object* object);
|
||||
float getDropHeight(DropMode dropMode, CSVRender::Object* object, float objectHeight);
|
||||
|
||||
public:
|
||||
|
||||
|
@ -482,6 +482,11 @@ osg::ref_ptr<osg::Group> CSVRender::Object::getRootNode()
|
||||
return mRootNode;
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::Group> CSVRender::Object::getBaseNode()
|
||||
{
|
||||
return mBaseNode;
|
||||
}
|
||||
|
||||
bool CSVRender::Object::referenceableDataChanged (const QModelIndex& topLeft,
|
||||
const QModelIndex& bottomRight)
|
||||
{
|
||||
|
@ -146,9 +146,12 @@ namespace CSVRender
|
||||
|
||||
bool getSelected() const;
|
||||
|
||||
/// For direct altering of object rendering
|
||||
/// Get object node with GUI graphics
|
||||
osg::ref_ptr<osg::Group> getRootNode();
|
||||
|
||||
/// Get object node without GUI graphics
|
||||
osg::ref_ptr<osg::Group> getBaseNode();
|
||||
|
||||
/// \return Did this call result in a modification of the visual representation of
|
||||
/// this object?
|
||||
bool referenceableDataChanged (const QModelIndex& topLeft,
|
||||
|
Loading…
x
Reference in New Issue
Block a user