diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 79876224d..816b8d732 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -86,6 +86,7 @@ opencs_units (view/widget opencs_units (view/render scenewidget worldspacewidget pagedworldspacewidget unpagedworldspacewidget previewwidget editmode instancemode instanceselectionmode instancemovemode + orbitcameramode ) opencs_units_noqt (view/render diff --git a/apps/opencs/view/render/orbitcameramode.cpp b/apps/opencs/view/render/orbitcameramode.cpp new file mode 100644 index 000000000..e6f3612c6 --- /dev/null +++ b/apps/opencs/view/render/orbitcameramode.cpp @@ -0,0 +1,37 @@ +#include "orbitcameramode.hpp" + +#include + +#include "worldspacewidget.hpp" + +namespace CSVRender +{ + OrbitCameraMode::OrbitCameraMode(WorldspaceWidget* worldspaceWidget, const QIcon& icon, const QString& tooltip, + QWidget* parent) + : ModeButton(icon, tooltip, parent) + , mWorldspaceWidget(worldspaceWidget) + , mCenterOnSelection(0) + { + } + + void OrbitCameraMode::activate(CSVWidget::SceneToolbar* toolbar) + { + mCenterOnSelection = new QAction("Center on selected object", this); + connect(mCenterOnSelection, SIGNAL(triggered()), this, SLOT(centerSelection())); + } + + bool OrbitCameraMode::createContextMenu(QMenu* menu) + { + if (menu) + { + menu->addAction(mCenterOnSelection); + } + + return true; + } + + void OrbitCameraMode::centerSelection() + { + mWorldspaceWidget->centerOrbitCameraOnSelection(); + } +} diff --git a/apps/opencs/view/render/orbitcameramode.hpp b/apps/opencs/view/render/orbitcameramode.hpp new file mode 100644 index 000000000..cd8387084 --- /dev/null +++ b/apps/opencs/view/render/orbitcameramode.hpp @@ -0,0 +1,33 @@ +#ifndef CSV_RENDER_ORBITCAMERAPICKMODE_H +#define CSV_RENDER_ORBITCAMERAPICKMODE_H + +#include "../widget/modebutton.hpp" + +namespace CSVRender +{ + class WorldspaceWidget; + + class OrbitCameraMode : public CSVWidget::ModeButton + { + Q_OBJECT + + public: + + OrbitCameraMode(WorldspaceWidget* worldspaceWidget, const QIcon& icon, const QString& tooltip = "", + QWidget* parent = 0); + + virtual void activate(CSVWidget::SceneToolbar* toolbar); + virtual bool createContextMenu(QMenu* menu); + + private: + + WorldspaceWidget* mWorldspaceWidget; + QAction* mCenterOnSelection; + + private slots: + + void centerSelection(); + }; +} + +#endif diff --git a/apps/opencs/view/render/worldspacewidget.cpp b/apps/opencs/view/render/worldspacewidget.cpp index 3cd2c4093..927ce545f 100644 --- a/apps/opencs/view/render/worldspacewidget.cpp +++ b/apps/opencs/view/render/worldspacewidget.cpp @@ -19,6 +19,8 @@ #include "../../model/prefs/state.hpp" +#include "../render/orbitcameramode.hpp" + #include "../widget/scenetoolmode.hpp" #include "../widget/scenetooltoggle2.hpp" #include "../widget/scenetoolrun.hpp" @@ -27,6 +29,7 @@ #include "mask.hpp" #include "editmode.hpp" #include "instancemode.hpp" +#include "cameracontroller.hpp" CSVRender::WorldspaceWidget::WorldspaceWidget (CSMDoc::Document& document, QWidget* parent) : SceneWidget (document.getData().getResourceSystem(), parent, 0, false), mSceneElements(0), mRun(0), mDocument(document), @@ -99,6 +102,19 @@ void CSVRender::WorldspaceWidget::selectDefaultNavigationMode() selectNavigationMode("1st"); } +void CSVRender::WorldspaceWidget::centerOrbitCameraOnSelection() +{ + std::vector > selection = getSelection(~0); + + for (std::vector >::iterator it = selection.begin(); it!=selection.end(); ++it) + { + if (CSVRender::ObjectTag *objectTag = dynamic_cast (it->get())) + { + mOrbitCamControl->setCenter(objectTag->mObject->getPosition().asVec3()); + } + } +} + CSVWidget::SceneToolMode *CSVRender::WorldspaceWidget::makeNavigationSelector ( CSVWidget::SceneToolbar *parent) { @@ -123,15 +139,17 @@ CSVWidget::SceneToolMode *CSVRender::WorldspaceWidget::makeNavigationSelector ( "
  • Roll camera with Q and E keys
  • " "
  • Hold shift to speed up movement
  • " ""); - tool->addButton (":scenetoolbar/orbiting-camera", "orbit", - "Orbiting Camera" - "
    • Always facing the centre point
    • " - "
    • Rotate around the centre point via WASD or by moving the mouse while holding the left button
    • " - "
    • Mouse wheel moves camera away or towards centre point but can not pass through it
    • " - "
    • Roll camera with Q and E keys
    • " - "
    • Strafing (also vertically) by holding the left mouse button and control (includes relocation of the centre point)
    • " - "
    • Hold shift to speed up movement
    • " - "
    "); + tool->addButton( + new CSVRender::OrbitCameraMode(this, QIcon(":scenetoolbar/orbiting-camera"), + "Orbiting Camera" + "
    • Always facing the centre point
    • " + "
    • Rotate around the centre point via WASD or by moving the mouse while holding the left button
    • " + "
    • Mouse wheel moves camera away or towards centre point but can not pass through it
    • " + "
    • Roll camera with Q and E keys
    • " + "
    • Strafing (also vertically) by holding the left mouse button and control (includes relocation of the centre point)
    • " + "
    • Hold shift to speed up movement
    • " + "
    ", tool), + "orbit"); connect (tool, SIGNAL (modeChanged (const std::string&)), this, SLOT (selectNavigationMode (const std::string&))); diff --git a/apps/opencs/view/render/worldspacewidget.hpp b/apps/opencs/view/render/worldspacewidget.hpp index 36aae0329..b18123944 100644 --- a/apps/opencs/view/render/worldspacewidget.hpp +++ b/apps/opencs/view/render/worldspacewidget.hpp @@ -97,6 +97,8 @@ namespace CSVRender void selectDefaultNavigationMode(); + void centerOrbitCameraOnSelection(); + static DropType getDropType(const std::vector& data); virtual dropRequirments getDropRequirements(DropType type) const;