Skip to content
Snippets Groups Projects

Implements clamping for creation of Planes using the dragging tool.

Merged Zain Selman requested to merge clamped_planes into master
Files
2
@@ -39,18 +39,15 @@
* *
\*===========================================================================*/
#include "QtPlaneSelect.hh"
#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <ACG/Scenegraph/GlutPrimitiveNode.hh>
#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#define PLUGINFUNCTIONS_C
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <ACG/QtWidgets/QtColorTranslator.hh>
/*******************************************************************************
Initialization and de initialization
*******************************************************************************/
@@ -139,7 +136,10 @@ void QtPlaneSelect::slotMouseEvent(QMouseEvent* event)
planeNode_ = new PlaneNode(plane_,PluginFunctions::getRootNode(),"PolyLine generation Plane" );
}
setPlaneAndSize(sourcePoint3D,ACG::Vec3d(event->pos().x(), height-event->pos().y()-1.0, 0.0));
/// remember the 2d click position (for clamping)
sourcePoint2D = ACG::Vec3d(event->pos().x(), height - event->pos().y() - 1.0, 0.0);
setPlaneAndSize(sourcePoint3D, sourcePoint2D);
planeNode_->show();
emit nodeVisChangedProxy(planeNode_->id());
@@ -191,27 +191,50 @@ void QtPlaneSelect::setPlaneAndSize(const ACG::Vec3d& _sourcePoint3D,const ACG::
{
ACG::Vec3d source2D = glState.project( _sourcePoint3D );
source2D[2] = 0.;
source2D[2] = 0;
const ACG::Vec3d diff = source2D - _target2D;
ACG::Vec3d diff = source2D - _target2D;
ACG::Vec3d ortho{0., 0., 0.};
if (clamp_)
{
constexpr auto clamp_angle = M_PI / 12.; /// angle (15°) at which we clamp in radians
const auto newTarget = _target2D - source2D; /// center towards origin
const auto angle = std::atan2(newTarget[1], newTarget[0]); /// compute angle in CCW dir to the x-axis
const auto remainder = std::fmod(angle, clamp_angle); /// difference to next multiple of clamped angle
/// compute corrected angle
double corrected_angle = .0;
if (remainder < clamp_angle / 2.)
corrected_angle = angle - remainder; /// if we are at the lower half, clamp down
else
corrected_angle = angle + (clamp_angle - remainder); /// if we are at the upper half, clamp up
const auto radius = diff.length();
const auto newTarget2D = ACG::Vec3d{std::round(radius * std::cos(corrected_angle)), std::round(radius * std::sin(corrected_angle)), 0.} + source2D;
const auto newDiff = source2D - newTarget2D;
ortho = ACG::Vec3d{-newDiff[1], newDiff[0], 0.};
}
else
//diff.normalize( ); <- this is bad
ACG::Vec3d ortho(-diff[1], diff[0], 0 );
ortho = ACG::Vec3d{-diff[1], diff[0], 0.};
/// construct two vectors in the plane, orthogonally to each other
const auto left = glState.unproject(source2D + ortho * 10. + ACG::Vec3d{0., 0., 0.});
const auto right = glState.unproject(source2D - ortho * 10. + ACG::Vec3d{0., 0., 0.});
ACG::Vec3d left = glState.unproject( source2D+ortho*10 + ACG::Vec3d(0,0,0) );
ACG::Vec3d right= glState.unproject( source2D-ortho*10 + ACG::Vec3d(0,0,0) );
const auto leftvec = (left - sourcePoint3D).normalized();
const auto rightvec = (right - sourcePoint3D).normalized();
ACG::Vec3d leftvec = left-sourcePoint3D;
leftvec.normalize( );
ACG::Vec3d rightvec = right-sourcePoint3D;
rightvec.normalize( );
/// compute normal vector
normal_ = cross(rightvec, leftvec);
normal_.normalize();
normal = cross( rightvec, leftvec );
normal.normalize( );
// std::cout << "computed normal: " << normal_ << std::endl;
ACG::Vec3d sourcePoint3Df(sourcePoint3D);
ACG::Vec3d normald(normal);
/// create plane using point and normal
const auto sourcePoint3Df(sourcePoint3D);
const auto normald(normal_);
plane_.setPlane(sourcePoint3Df,normald);
plane_.setSize(PluginFunctions::sceneRadius(),PluginFunctions::sceneRadius());
planeNode_->update();
Loading