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

cleans up. second scaling is still broken

parent 3c58e05b
No related branches found
No related tags found
1 merge request!2Plane interaction
......@@ -181,6 +181,8 @@ 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(
......@@ -223,9 +225,9 @@ void PlanePlugin::slotMouseEvent(QMouseEvent *_event) {
return;
}
std::cerr << "intersection found at: " << result_ << std::endl;
std::cerr << "target_idx: " << target_idx << std::endl;
// std::cerr << "intersection found at: " << result_ <<
// std::endl; std::cerr << "target_idx: " << target_idx
// << std::endl;
// ACG::Vec3d test = curPlane_->plane().position -
// 0.5 * curPlane_->plane().xDirection
......@@ -241,27 +243,31 @@ void PlanePlugin::slotMouseEvent(QMouseEvent *_event) {
dragging_ = true;
pickedCorner_ = target_idx;
std::cerr << "Picked a plane and id: " << target_idx << std::endl;
// std::cerr << "Picked a plane and id: " << target_idx
// << std::endl;
}
}
}
std::cerr << "Mouse_Down" << std::endl;
// std::cerr << "Mouse_Down" << std::endl;
break;
}
case QEvent::MouseMove: {
std::cerr << "Mouse_Move" << std::endl;
// std::cerr << "Mouse_Move" << std::endl;
// We are actually dragging a corner
if (dragging_ && curPlane_) {
std::cerr << "Dragging!" << std::endl;
// std::cerr << "Dragging!" << std::endl;
QPoint position = _event->pos();
/// matrix to transform points from image plane to curPlane_
auto plane = origPlane_;
/// get the world position of the projected cursor by intersecting plane
/// equation with ray
{
/// view coords in worldspace, with flipped y-axis
const auto viewCoord = ACG::Vec3d(
position.x(),
......@@ -269,12 +275,10 @@ void PlanePlugin::slotMouseEvent(QMouseEvent *_event) {
position.y(),
.5);
/// get the world position by intersecting plane equation with ray
ACG::Vec3d origin;
ACG::Vec3d dir;
PluginFunctions::viewerProperties().glState().viewing_ray(
viewCoord[0], viewCoord[1], origin, dir);
{
double u = -3.1415926539, v = -3.1415926539;
const auto center = plane.position;
const auto xdir = plane.xDirection / 2.;
......@@ -292,25 +296,17 @@ void PlanePlugin::slotMouseEvent(QMouseEvent *_event) {
currWorldPos_ = (w * p0) + (u * p1) + (v * p2);
}
/// update vector in worldspace
const auto worldSpaceUpdate = (currWorldPos_ - result_) / 2.;
/// update to corresponding corner later
/// vector to clicked corner. update to corresponding corner later
const auto distClickOrigin = plane.position + (.5f * plane.xDirection) +
(.5f * plane.yDirection);
/// we want to scale our plane, we will do so in 3 steps:
/// 1. translate to origin
/// 2. rotate to be planar
/// 3. scale
/// 4. rotate back
/// 5. translate back to updated target position (old origin +
/// .5*updatevector
/// 1. transform to origin
auto transform = ACG::GLMatrixf(ACG::Matrix4x4f());
transform.identity();
transform.translate(ACG::Vec3f{-plane.position});
auto transformation = ACG::GLMatrixf(ACG::Matrix4x4f());
transformation.identity(); // init
transformation.translate(ACG::Vec3f{-plane.position});
/// 2. rotate to be planar
// const auto n0 = ACG::Vec3f{plane.normal};
// const auto x = n0.dot(viewDirection_);
......@@ -321,28 +317,20 @@ void PlanePlugin::slotMouseEvent(QMouseEvent *_event) {
// transform.rotate(angle, n0.cross(n1));
/// 3. scale by half updates length
/// todo: adjust to screen space
auto scale =
ACG::Vec3f{(worldSpaceUpdate + distClickOrigin) / distClickOrigin};
scale[2] = 1; /// we dont do anything in z-dir
transform.scale(scale);
transform.translate(ACG::Vec3f{plane.position});
transformation.scale(scale);
/// 4. rotate back
// transform.rotate(-angle, n0.cross(n1));
/// 4. translate back. translation is pretty annoying, so we just
plane.transform(transform);
/// overwrite the position attribute itself, as compensating this in the
/// transformation is a PITA
transformation.translate(ACG::Vec3f{plane.position});
plane.transform(transformation);
plane.position += worldSpaceUpdate;
// std::cerr << "worldSpaceUpdate: " << worldSpaceUpdate <<
// std::endl; std::cerr << "[world] start pos: " << result_ <<
// std::endl; std::cerr << "[world] curr pos: " << currWorldPos_
// << std::endl; std::cerr << "[world] plane.pos: " <<
// plane.position << std::endl; std::cerr << "scale: " << scale
// << std::endl;
std::cerr << "[world] start pos: " << result_ << std::endl;
std::cerr << "[world] curr pos: " << currWorldPos_ << std::endl;
std::cerr << "scale: " << scale << std::endl;
std::cerr << "new plane pos: " << plane.position << std::endl;
std::cerr << "delta: " << worldSpaceUpdate << "\n\n\n\n\n" << std::endl;
curPlane_->plane() = plane; /// overwrite plane
......@@ -361,6 +349,8 @@ void PlanePlugin::slotMouseEvent(QMouseEvent *_event) {
if (lastObjId_ > 0)
emit updatedObject(lastObjId_, UPDATE_GEOMETRY);
else
std::cerr << "COULD NOT UPDATE OBJECT" << std::endl;
}
break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment