From 2c894acd98ed593c8433e29443f84035a2c74297 Mon Sep 17 00:00:00 2001 From: Aesylwinn Date: Fri, 18 Mar 2016 16:06:35 -0400 Subject: [PATCH] Create a visual representation of the center of the orbit camera. For debugging purposes. --- apps/opencs/view/render/cameracontroller.cpp | 24 +++++++++++++++++++- apps/opencs/view/render/cameracontroller.hpp | 7 +++++- apps/opencs/view/render/scenewidget.cpp | 2 +- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/apps/opencs/view/render/cameracontroller.cpp b/apps/opencs/view/render/cameracontroller.cpp index f1ed5635b..74f72938f 100644 --- a/apps/opencs/view/render/cameracontroller.cpp +++ b/apps/opencs/view/render/cameracontroller.cpp @@ -3,8 +3,12 @@ #include #include +#include +#include #include #include +#include +#include namespace CSVRender { @@ -261,7 +265,7 @@ namespace CSVRender Orbit Camera Controller */ - OrbitCameraController::OrbitCameraController() + OrbitCameraController::OrbitCameraController(osg::Group* group) : mInitialized(false) , mFast(false) , mLeft(false) @@ -271,7 +275,10 @@ namespace CSVRender , mRollLeft(false) , mRollRight(false) , mCenter(0,0,0) + , mCenterNode(new osg::PositionAttitudeTransform()) { + group->addChild(mCenterNode); + createShape(); } bool OrbitCameraController::handleKeyEvent(QKeyEvent* event, bool pressed) @@ -383,6 +390,8 @@ namespace CSVRender if (mRollRight) roll(rotDist); + mCenterNode->setPosition(mCenter); + lookAtCenter(); // Normalize the matrix to counter drift @@ -409,6 +418,19 @@ namespace CSVRender mInitialized = true; } + void OrbitCameraController::createShape() + { + const float boxWidth = 100; + + osg::ref_ptr box = new osg::Box(osg::Vec3f(0, 0, 0), boxWidth); + osg::ref_ptr drawable = new osg::ShapeDrawable(box); + drawable->setColor(osg::Vec4f(0.f, 0.9f, 0.f, 1.f)); + + osg::ref_ptr geode = new osg::Geode(); + geode->addChild(drawable); + mCenterNode->addChild(geode); + } + void OrbitCameraController::rotateHorizontal(double value) { osg::Vec3d position = getCamera()->getViewMatrix().getTrans(); diff --git a/apps/opencs/view/render/cameracontroller.hpp b/apps/opencs/view/render/cameracontroller.hpp index 156b1cb56..6c89d20f7 100644 --- a/apps/opencs/view/render/cameracontroller.hpp +++ b/apps/opencs/view/render/cameracontroller.hpp @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -12,6 +13,7 @@ class QKeyEvent; namespace osg { class Camera; + class Group; } namespace CSVRender @@ -97,7 +99,7 @@ namespace CSVRender { public: - OrbitCameraController(); + OrbitCameraController(osg::Group* group); bool handleKeyEvent(QKeyEvent* event, bool pressed); bool handleMouseMoveEvent(std::string mode, int x, int y); @@ -109,6 +111,7 @@ namespace CSVRender void onActivate(); void initialize(); + void createShape(); void rotateHorizontal(double value); void rotateVertical(double value); @@ -121,6 +124,8 @@ namespace CSVRender bool mInitialized; bool mFast, mLeft, mRight, mUp, mDown, mRollLeft, mRollRight; osg::Vec3d mCenter; + + osg::ref_ptr mCenterNode; }; } diff --git a/apps/opencs/view/render/scenewidget.cpp b/apps/opencs/view/render/scenewidget.cpp index 27c828ec4..dc0041c0f 100644 --- a/apps/opencs/view/render/scenewidget.cpp +++ b/apps/opencs/view/render/scenewidget.cpp @@ -164,7 +164,7 @@ SceneWidget::SceneWidget(boost::shared_ptr resourceSys , mPrevMouseX(0) , mPrevMouseY(0) , mFreeCamControl(new FreeCameraController()) - , mOrbitCamControl(new OrbitCameraController()) + , mOrbitCamControl(new OrbitCameraController(mRootNode)) , mCurrentCamControl(mFreeCamControl.get()) , mCamPositionSet(false) {