confine move marker drags to a single axis

move
Marc Zinnschlag 9 years ago
parent a19ac72215
commit c2a8be9048

@ -27,7 +27,7 @@ int CSVRender::InstanceMode::getSubModeFromId (const std::string& id) const
CSVRender::InstanceMode::InstanceMode (WorldspaceWidget *worldspaceWidget, QWidget *parent) CSVRender::InstanceMode::InstanceMode (WorldspaceWidget *worldspaceWidget, QWidget *parent)
: EditMode (worldspaceWidget, QIcon (":placeholder"), Mask_Reference, "Instance editing", : EditMode (worldspaceWidget, QIcon (":placeholder"), Mask_Reference, "Instance editing",
parent), mSubMode (0), mSelectionMode (0), mDragMode (DragMode_None) parent), mSubMode (0), mSelectionMode (0), mDragMode (DragMode_None), mDragAxis (0)
{ {
} }
@ -151,8 +151,6 @@ bool CSVRender::InstanceMode::primaryEditStartDrag (osg::ref_ptr<TagBase> tag)
if (selection.empty()) if (selection.empty())
return false; return false;
// \todo check for sub-mode
for (std::vector<osg::ref_ptr<TagBase> >::iterator iter (selection.begin()); for (std::vector<osg::ref_ptr<TagBase> >::iterator iter (selection.begin());
iter!=selection.end(); ++iter) iter!=selection.end(); ++iter)
{ {
@ -162,6 +160,14 @@ bool CSVRender::InstanceMode::primaryEditStartDrag (osg::ref_ptr<TagBase> tag)
} }
} }
// \todo check for sub-mode
if (CSVRender::ObjectMarkerTag *objectTag = dynamic_cast<CSVRender::ObjectMarkerTag *> (tag.get()))
{
mDragAxis = objectTag->mAxis;
mDragMode = DragMode_MoveAxis;
}
else
mDragMode = DragMode_Move; mDragMode = DragMode_Move;
return true; return true;
@ -174,10 +180,6 @@ bool CSVRender::InstanceMode::secondaryEditStartDrag (osg::ref_ptr<TagBase> tag)
} }
void CSVRender::InstanceMode::drag (int diffX, int diffY, double speedFactor) void CSVRender::InstanceMode::drag (int diffX, int diffY, double speedFactor)
{
switch (mDragMode)
{
case DragMode_Move:
{ {
osg::Vec3f eye; osg::Vec3f eye;
osg::Vec3f centre; osg::Vec3f centre;
@ -193,6 +195,20 @@ void CSVRender::InstanceMode::drag (int diffX, int diffY, double speedFactor)
if (diffX) if (diffX)
offset += ((centre-eye) ^ up) * diffX * speedFactor; offset += ((centre-eye) ^ up) * diffX * speedFactor;
switch (mDragMode)
{
case DragMode_MoveAxis:
{
for (int i=0; i<3; ++i)
if (i!=mDragAxis)
offset[i] = 0;
// Fall through
}
case DragMode_Move:
{
std::vector<osg::ref_ptr<TagBase> > selection = std::vector<osg::ref_ptr<TagBase> > selection =
getWorldspaceWidget().getEdited (Mask_Reference); getWorldspaceWidget().getEdited (Mask_Reference);
@ -226,7 +242,10 @@ void CSVRender::InstanceMode::dragCompleted()
switch (mDragMode) switch (mDragMode)
{ {
case DragMode_Move: description = "Move Instances"; break; case DragMode_Move:
case DragMode_MoveAxis:
description = "Move Instances"; break;
case DragMode_None: break; case DragMode_None: break;
} }

@ -19,13 +19,15 @@ namespace CSVRender
enum DragMode enum DragMode
{ {
DragMode_None, DragMode_None,
DragMode_Move DragMode_Move,
DragMode_MoveAxis
}; };
CSVWidget::SceneToolMode *mSubMode; CSVWidget::SceneToolMode *mSubMode;
InstanceSelectionMode *mSelectionMode; InstanceSelectionMode *mSelectionMode;
DragMode mDragMode; DragMode mDragMode;
int mDragAxis;
int getSubModeFromId (const std::string& id) const; int getSubModeFromId (const std::string& id) const;

@ -55,7 +55,7 @@ QString CSVRender::ObjectTag::getToolTip (bool hideBasics) const
CSVRender::ObjectMarkerTag::ObjectMarkerTag (Object* object, int axis) CSVRender::ObjectMarkerTag::ObjectMarkerTag (Object* object, int axis)
: TagBase (Mask_Reference), mObject (object), mAxis (axis) : ObjectTag (object), mAxis (axis)
{} {}
@ -287,9 +287,9 @@ osg::Vec3f CSVRender::Object::getMarkerPosition (float x, float y, float z, int
{ {
switch (axis) switch (axis)
{ {
case 0: return osg::Vec3f (x, y, z); case 2: return osg::Vec3f (x, y, z);
case 1: return osg::Vec3f (z, x, y); case 0: return osg::Vec3f (z, x, y);
case 2: return osg::Vec3f (y, z, x); case 1: return osg::Vec3f (y, z, x);
default: default:

@ -55,13 +55,12 @@ namespace CSVRender
virtual QString getToolTip (bool hideBasics) const; virtual QString getToolTip (bool hideBasics) const;
}; };
class ObjectMarkerTag : public TagBase class ObjectMarkerTag : public ObjectTag
{ {
public: public:
ObjectMarkerTag (Object* object, int axis); ObjectMarkerTag (Object* object, int axis);
Object* mObject;
int mAxis; int mAxis;
}; };

Loading…
Cancel
Save