From 4ef9981544b48677f28cc88de3d9b92c676030f3 Mon Sep 17 00:00:00 2001 From: Aesylwinn Date: Sun, 3 Apr 2016 16:30:50 -0400 Subject: [PATCH] Add ability to set orbit camera center outside of class. --- apps/opencs/view/render/cameracontroller.cpp | 18 ++++++++++++++++++ apps/opencs/view/render/cameracontroller.hpp | 2 ++ 2 files changed, 20 insertions(+) diff --git a/apps/opencs/view/render/cameracontroller.cpp b/apps/opencs/view/render/cameracontroller.cpp index 3967c983d..ab066033b 100644 --- a/apps/opencs/view/render/cameracontroller.cpp +++ b/apps/opencs/view/render/cameracontroller.cpp @@ -367,6 +367,11 @@ namespace CSVRender { } + osg::Vec3d OrbitCameraController::getCenter() const + { + return mCenter; + } + double OrbitCameraController::getOrbitSpeed() const { return mOrbitSpeed; @@ -382,6 +387,19 @@ namespace CSVRender return mPickingMask; } + void OrbitCameraController::setCenter(const osg::Vec3d& value) + { + osg::Vec3d eye, center, up; + getCamera()->getViewMatrixAsLookAt(eye, center, up); + + mCenter = value; + mDistance = (eye - mCenter).length(); + + getCamera()->setViewMatrixAsLookAt(eye, mCenter, up); + + mInitialized = true; + } + void OrbitCameraController::setOrbitSpeed(double value) { mOrbitSpeed = value; diff --git a/apps/opencs/view/render/cameracontroller.hpp b/apps/opencs/view/render/cameracontroller.hpp index 7c1f96e15..b1dcc320a 100644 --- a/apps/opencs/view/render/cameracontroller.hpp +++ b/apps/opencs/view/render/cameracontroller.hpp @@ -113,10 +113,12 @@ namespace CSVRender OrbitCameraController(); + osg::Vec3d getCenter() const; double getOrbitSpeed() const; double getOrbitSpeedMultiplier() const; unsigned int getPickingMask() const; + void setCenter(const osg::Vec3d& center); void setOrbitSpeed(double value); void setOrbitSpeedMultiplier(double value); void setPickingMask(unsigned int value);