Move updateCamera into Camera, renaming it to updateView, so that it can be called in both GUI and commandline mode. Signed-off-by: Herbert Poetzl --- diff --git a/src/Camera.cc b/src/Camera.cc index 14b4c1b7e..cb3547ca1 100644 --- a/src/Camera.cc +++ b/src/Camera.cc @@ -83,6 +83,36 @@ void Camera::resetView() setVpd(DEFAULT_DISTANCE); } +/*! + * Update the viewport camera by evaluating the special variables. If they + * are assigned on top-level, the values are used to change the camera + * rotation, translation and distance. + */ +void Camera::updateView(const std::shared_ptr ctx) +{ + double x, y, z; + const auto vpr = ctx->lookup_variable("$vpr"); + if (vpr->getVec3(x, y, z, 0.0)){ + setVpr(x, y, z); + }else{ + PRINTB("WARNING: Unable to convert $vpr=%s to a vec3 or vec2 of numbers", vpr->toEchoString()); + } + + const auto vpt = ctx->lookup_variable("$vpt"); + if (vpt->getVec3(x, y, z, 0.0)){ + setVpt(x, y, z); + }else{ + PRINTB("WARNING: Unable to convert $vpt=%s to a vec3 or vec2 of numbers", vpt->toEchoString()); + } + + const auto vpd = ctx->lookup_variable("$vpd"); + if (vpd->type() == Value::Type::NUMBER){ + setVpd(vpd->toDouble()); + }else{ + PRINTB("WARNING: Unable to convert $vpd=%s to a number", vpd->toEchoString()); + } +} + Eigen::Vector3d Camera::getVpt() const { return -object_trans; @@ -128,3 +158,4 @@ std::string Camera::statusText() const % viewer_distance; return fmt.str(); } + diff --git a/src/Camera.h b/src/Camera.h index 1a53dc5b2..a2524cb3a 100644 --- a/src/Camera.h +++ b/src/Camera.h @@ -17,6 +17,7 @@ projection, Perspective and Orthogonal. */ #include "linalg.h" +#include "modcontext.h" #include #include @@ -31,6 +32,7 @@ public: void zoom(int delta, bool relative); double zoomValue() const; void resetView(); + void updateView(const std::shared_ptr ctx); void viewAll(const BoundingBox &bbox); std::string statusText() const; diff --git a/src/MainWindow.h b/src/MainWindow.h index 6d0bf2f13..0258a4ba8 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -110,7 +110,6 @@ public: private: void initActionIcon(QAction *action, const char *darkResource, const char *lightResource); void handleFileDrop(const QString &filename); - void updateCamera(const std::shared_ptr ctx); void updateTemporalVariables(); void updateCompileResult(); void compile(bool reload, bool forcedone = false, bool rebuildParameterWidget=true); diff --git a/src/mainwin.cc b/src/mainwin.cc index 96b1d66ea..284592d6b 100755 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -1127,7 +1127,7 @@ void MainWindow::instantiateRoot() ContextHandle filectx{Context::create(top_ctx.ctx)}; this->absolute_root_node = this->root_module->instantiateWithFileContext(filectx.ctx, &this->root_inst, nullptr); - this->updateCamera(filectx.ctx); + this->qglview->cam.updateView(filectx.ctx); if (this->absolute_root_node) { // Do we have an explicit root node (! modifier)? @@ -1654,36 +1654,6 @@ void MainWindow::updateTemporalVariables() } -/*! - * Update the viewport camera by evaluating the special variables. If they - * are assigned on top-level, the values are used to change the camera - * rotation, translation and distance. - */ -void MainWindow::updateCamera(const std::shared_ptr ctx) -{ - double x, y, z; - const auto vpr = ctx->lookup_variable("$vpr"); - if (vpr->getVec3(x, y, z, 0.0)){ - qglview->cam.setVpr(x, y, z); - }else{ - PRINTB("UI-WARNING: Unable to convert $vpr=%s to a vec3 or vec2 of numbers", vpr->toEchoString()); - } - - const auto vpt = ctx->lookup_variable("$vpt"); - if (vpt->getVec3(x, y, z, 0.0)){ - qglview->cam.setVpt(x, y, z); - }else{ - PRINTB("UI-WARNING: Unable to convert $vpt=%s to a vec3 or vec2 of numbers", vpt->toEchoString()); - } - - const auto vpd = ctx->lookup_variable("$vpd"); - if (vpd->type() == Value::Type::NUMBER){ - qglview->cam.setVpd(vpd->toDouble()); - }else{ - PRINTB("UI-WARNING: Unable to convert $vpd=%s to a number", vpd->toEchoString()); - } -} - /*! Returns true if the current document is a file on disk and that file has new content. Returns false if a file on disk has disappeared or if we haven't yet saved.