Skip to content
Snippets Groups Projects
Commit 54ebdf56 authored by Zain Selman's avatar Zain Selman :speech_balloon:
Browse files

cleans up. the jittering is not completely gone

parent 4eed6032
No related branches found
No related tags found
1 merge request!2Plane interaction
...@@ -182,11 +182,9 @@ void PlanePlugin::slotMouseEvent(QMouseEvent *_event) { ...@@ -182,11 +182,9 @@ void PlanePlugin::slotMouseEvent(QMouseEvent *_event) {
origPlane_ = curPlane_->plane(); origPlane_ = curPlane_->plane();
QPoint position = _event->pos(); QPoint position = _event->pos();
std::cerr << "old plane pos: " << origPlane_.position << std::endl;
/// view coords in screenspace, with flipped y-axis at depth of /// view coords in screenspace, with flipped y-axis at depth of
/// plane /// plane
ACG::Vec3d viewCoords = ACG::Vec3d( const auto viewCoords = ACG::Vec3d(
position.x(), position.x(),
PluginFunctions::viewerProperties().glState().context_height() - PluginFunctions::viewerProperties().glState().context_height() -
position.y(), position.y(),
...@@ -194,7 +192,7 @@ void PlanePlugin::slotMouseEvent(QMouseEvent *_event) { ...@@ -194,7 +192,7 @@ void PlanePlugin::slotMouseEvent(QMouseEvent *_event) {
viewStartCoord_ = viewCoords; viewStartCoord_ = viewCoords;
// Example for getting the viewing Ray /// obtain the ray for intersecting with the quad/plane
ACG::Vec3d origin; ACG::Vec3d origin;
PluginFunctions::viewerProperties().glState().viewing_ray( PluginFunctions::viewerProperties().glState().viewing_ray(
position.x(), position.x(),
...@@ -202,26 +200,18 @@ void PlanePlugin::slotMouseEvent(QMouseEvent *_event) { ...@@ -202,26 +200,18 @@ void PlanePlugin::slotMouseEvent(QMouseEvent *_event) {
position.y(), position.y(),
origin, viewDirection_); origin, viewDirection_);
/// obtain the 4 corners of the plane /// compute intersection
std::vector<ACG::Vec3d> corners;
{ {
corners.reserve(4);
const auto center = curPlane_->plane().position; const auto center = curPlane_->plane().position;
const auto xdir = curPlane_->plane().xDirection / 2.; const auto xdir = curPlane_->plane().xDirection / 2.;
const auto ydir = curPlane_->plane().yDirection / 2.; const auto ydir = curPlane_->plane().yDirection / 2.;
corners.emplace_back(ACG::Vec3f{center + xdir + ydir}); const auto p0 = center + xdir + ydir;
corners.emplace_back(ACG::Vec3f{center + xdir - ydir}); const auto p1 = center + xdir - ydir;
corners.emplace_back(ACG::Vec3f{center - xdir - ydir}); const auto p2 = center - xdir - ydir;
corners.emplace_back(ACG::Vec3f{center - xdir + ydir});
}
/// compute intersection
{
double u = -1, v = -1, w = -1; double u = -1, v = -1, w = -1;
rayPlaneIntersection(origin, viewDirection_, corners[0], rayPlaneIntersection(origin, viewDirection_, p0, p1, p2, u, v);
corners[1], corners[2], u, v);
w = 1 - (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) if (target_idx == 0)
...@@ -230,23 +220,17 @@ void PlanePlugin::slotMouseEvent(QMouseEvent *_event) { ...@@ -230,23 +220,17 @@ void PlanePlugin::slotMouseEvent(QMouseEvent *_event) {
// We hit a corner so start dragging // We hit a corner so start dragging
dragging_ = true; dragging_ = true;
pickedCorner_ = target_idx; pickedCorner_ = target_idx;
// std::cerr << "Picked a plane and id: " << target_idx
// << std::endl;
} }
} }
} }
// std::cerr << "Mouse_Down" << std::endl;
break; break;
} }
case QEvent::MouseMove: { case QEvent::MouseMove: {
// std::cerr << "Mouse_Move" << std::endl;
// We are actually dragging a corner // We are actually dragging a corner
if (dragging_ && curPlane_) { if (dragging_ && curPlane_) {
// std::cerr << "Dragging!" << std::endl;
QPoint position = _event->pos(); QPoint position = _event->pos();
...@@ -284,39 +268,27 @@ void PlanePlugin::slotMouseEvent(QMouseEvent *_event) { ...@@ -284,39 +268,27 @@ void PlanePlugin::slotMouseEvent(QMouseEvent *_event) {
currWorldPos_ = (w * p0) + (u * p1) + (v * p2); 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 /// 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 /// scale by half updates length
auto transformation = ACG::GLMatrixf(ACG::Matrix4x4f());
transformation.identity(); // init
auto scale = (worldSpaceUpdate + distClickOrigin) / distClickOrigin; auto scale = (worldSpaceUpdate + distClickOrigin) / distClickOrigin;
scale[2] = 1; /// we dont do anything in z-dir scale[2] = 1; /// we dont do anything in z-dir
const auto xscale = scale[0] * plane.xDirection.length(); const auto xscale = scale[0] * plane.xDirection.length();
const auto yscale = scale[1] * plane.yDirection.length(); const auto yscale = scale[1] * plane.yDirection.length();
plane.setSize(xscale, yscale); plane.setSize(xscale, yscale);
std::cerr << "scale: " << scale << std::endl;
plane.position += worldSpaceUpdate / 2.; plane.position += worldSpaceUpdate;
curPlane_->plane() = plane; /// overwrite plane 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) if (lastObjId_ > 0)
emit updatedObject(lastObjId_, UPDATE_GEOMETRY); emit updatedObject(lastObjId_, UPDATE_GEOMETRY);
else else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment