diff --git a/PlanePlugin.cc b/PlanePlugin.cc index 1ad02b4d62545d62010dc4a6d36b362b3933440a..89017be7af52edb3f14b39548eb89fd6935f5ed6 100644 --- a/PlanePlugin.cc +++ b/PlanePlugin.cc @@ -182,11 +182,9 @@ void PlanePlugin::slotMouseEvent(QMouseEvent *_event) { origPlane_ = curPlane_->plane(); QPoint position = _event->pos(); - std::cerr << "old plane pos: " << origPlane_.position << std::endl; - /// view coords in screenspace, with flipped y-axis at depth of /// plane - ACG::Vec3d viewCoords = ACG::Vec3d( + const auto viewCoords = ACG::Vec3d( position.x(), PluginFunctions::viewerProperties().glState().context_height() - position.y(), @@ -194,7 +192,7 @@ void PlanePlugin::slotMouseEvent(QMouseEvent *_event) { viewStartCoord_ = viewCoords; - // Example for getting the viewing Ray + /// obtain the ray for intersecting with the quad/plane ACG::Vec3d origin; PluginFunctions::viewerProperties().glState().viewing_ray( position.x(), @@ -202,26 +200,18 @@ void PlanePlugin::slotMouseEvent(QMouseEvent *_event) { position.y(), origin, viewDirection_); - /// obtain the 4 corners of the plane - std::vector<ACG::Vec3d> corners; + /// compute intersection { - corners.reserve(4); const auto center = curPlane_->plane().position; const auto xdir = curPlane_->plane().xDirection / 2.; const auto ydir = curPlane_->plane().yDirection / 2.; - corners.emplace_back(ACG::Vec3f{center + xdir + ydir}); - corners.emplace_back(ACG::Vec3f{center + xdir - ydir}); - corners.emplace_back(ACG::Vec3f{center - xdir - ydir}); - corners.emplace_back(ACG::Vec3f{center - xdir + ydir}); - } - - /// compute intersection - { + const auto p0 = center + xdir + ydir; + const auto p1 = center + xdir - ydir; + const auto p2 = center - xdir - ydir; double u = -1, v = -1, w = -1; - rayPlaneIntersection(origin, viewDirection_, corners[0], - corners[1], corners[2], u, v); + rayPlaneIntersection(origin, viewDirection_, p0, p1, p2, u, v); w = 1 - (u + v); - result_ = (w * corners[0]) + (u * corners[1]) + (v * corners[2]); + result_ = (w * p0) + (u * p1) + (v * p2); } if (target_idx == 0) @@ -230,23 +220,17 @@ void PlanePlugin::slotMouseEvent(QMouseEvent *_event) { // We hit a corner so start dragging dragging_ = true; pickedCorner_ = target_idx; - - // std::cerr << "Picked a plane and id: " << target_idx - // << std::endl; } } } - // std::cerr << "Mouse_Down" << std::endl; break; } case QEvent::MouseMove: { - // std::cerr << "Mouse_Move" << std::endl; // We are actually dragging a corner if (dragging_ && curPlane_) { - // std::cerr << "Dragging!" << std::endl; QPoint position = _event->pos(); @@ -284,39 +268,27 @@ void PlanePlugin::slotMouseEvent(QMouseEvent *_event) { currWorldPos_ = (w * p0) + (u * p1) + (v * p2); } + /// relative to plane + const auto currWorldPos = currWorldPos_ - plane.position; + const auto result = result_ - plane.position; + /// update vector in worldspace - const auto worldSpaceUpdate = (currWorldPos_ - result_) / 2.; + const auto worldSpaceUpdate = (currWorldPos - result) / 2.; - const auto distClickOrigin = result_; + const auto distClickOrigin = result; /// scale by half updates length - auto transformation = ACG::GLMatrixf(ACG::Matrix4x4f()); - transformation.identity(); // init auto scale = (worldSpaceUpdate + distClickOrigin) / distClickOrigin; scale[2] = 1; /// we dont do anything in z-dir const auto xscale = scale[0] * plane.xDirection.length(); const auto yscale = scale[1] * plane.yDirection.length(); plane.setSize(xscale, yscale); - std::cerr << "scale: " << scale << std::endl; - plane.position += worldSpaceUpdate / 2.; + plane.position += worldSpaceUpdate; curPlane_->plane() = plane; /// overwrite plane - /// 0 corner - if (pickedCorner_ == 1) { - } - /// x corner - if (pickedCorner_ == 2) { - } - /// xy corner - if (pickedCorner_ == 3) { - } - /// y corner - if (pickedCorner_ == 4) { - } - if (lastObjId_ > 0) emit updatedObject(lastObjId_, UPDATE_GEOMETRY); else