From 3c811a488f00b9b347b9b9a1f0ecd5f78f335f5e Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Fri, 28 Feb 2025 16:50:33 +0100 Subject: [PATCH] Add a new DashboardItem to show the camera orientation (#3542) --- .../cameraorientation.asset | 16 ++++ modules/base/CMakeLists.txt | 2 + modules/base/basemodule.cpp | 5 ++ .../dashboarditemcameraorientation.cpp | 77 +++++++++++++++++++ .../dashboarditemcameraorientation.h | 46 +++++++++++ 5 files changed, 146 insertions(+) create mode 100644 data/assets/examples/dashboarditem/dashboarditemcameraorientation/cameraorientation.asset create mode 100644 modules/base/dashboard/dashboarditemcameraorientation.cpp create mode 100644 modules/base/dashboard/dashboarditemcameraorientation.h diff --git a/data/assets/examples/dashboarditem/dashboarditemcameraorientation/cameraorientation.asset b/data/assets/examples/dashboarditem/dashboarditemcameraorientation/cameraorientation.asset new file mode 100644 index 0000000000..80476c7649 --- /dev/null +++ b/data/assets/examples/dashboarditem/dashboarditemcameraorientation/cameraorientation.asset @@ -0,0 +1,16 @@ +-- Basic +-- This example adds a dashboard item to the main dashboard that shows the current camera +-- orientation. + +local Item = { + Identifier = "DashboardItemCameraOrientation_Example", + Type = "DashboardItemCameraOrientation" +} + +asset.onInitialize(function() + openspace.dashboard.addDashboardItem(Item) +end) + +asset.onDeinitialize(function() + openspace.dashboard.removeDashboardItem(Item) +end) diff --git a/modules/base/CMakeLists.txt b/modules/base/CMakeLists.txt index a8e9f0dfba..534680dbef 100644 --- a/modules/base/CMakeLists.txt +++ b/modules/base/CMakeLists.txt @@ -26,6 +26,7 @@ include(${PROJECT_SOURCE_DIR}/support/cmake/module_definition.cmake) set(HEADER_FILES dashboard/dashboarditemangle.h + dashboard/dashboarditemcameraorientation.h dashboard/dashboarditemdate.h dashboard/dashboarditemdistance.h dashboard/dashboarditemelapsedtime.h @@ -93,6 +94,7 @@ source_group("Header Files" FILES ${HEADER_FILES}) set(SOURCE_FILES dashboard/dashboarditemangle.cpp + dashboard/dashboarditemcameraorientation.cpp dashboard/dashboarditemdate.cpp dashboard/dashboarditemdistance.cpp dashboard/dashboarditemelapsedtime.cpp diff --git a/modules/base/basemodule.cpp b/modules/base/basemodule.cpp index 2dc6053972..b31b24e588 100644 --- a/modules/base/basemodule.cpp +++ b/modules/base/basemodule.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -115,6 +116,9 @@ void BaseModule::internalInitialize(const ghoul::Dictionary&) { ghoul_assert(fDashboard, "Dashboard factory was not created"); fDashboard->registerClass("DashboardItemAngle"); + fDashboard->registerClass( + "DashboardItemCameraOrientation" + ); fDashboard->registerClass("DashboardItemDate"); fDashboard->registerClass("DashboardItemDistance"); fDashboard->registerClass("DashboardItemElapsedTime"); @@ -228,6 +232,7 @@ void BaseModule::internalDeinitializeGL() { std::vector BaseModule::documentations() const { return { DashboardItemAngle::Documentation(), + DashboardItemCameraOrientation::Documentation(), DashboardItemDate::Documentation(), DashboardItemDistance::Documentation(), DashboardItemElapsedTime::Documentation(), diff --git a/modules/base/dashboard/dashboarditemcameraorientation.cpp b/modules/base/dashboard/dashboarditemcameraorientation.cpp new file mode 100644 index 0000000000..7b4a841558 --- /dev/null +++ b/modules/base/dashboard/dashboarditemcameraorientation.cpp @@ -0,0 +1,77 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2025 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include + +namespace { + // This `DashboardItem` shows the current camera orientation in the yaw, pitch, and + // roll directions in degrees. Note that the camera's orientation is relative to the + // global coordinate system used in the system. + struct [[codegen::Dictionary(DashboardItemCameraOrientation)]] Parameters { + }; +#include "dashboarditemcameraorientation_codegen.cpp" +} // namespace + +namespace openspace { + +documentation::Documentation DashboardItemCameraOrientation::Documentation() { + return codegen::doc( + "base_dashboarditem_cameraorientation", + DashboardTextItem::Documentation() + ); +} + +DashboardItemCameraOrientation::DashboardItemCameraOrientation( + const ghoul::Dictionary& dictionary) + : DashboardTextItem(dictionary) +{} + +void DashboardItemCameraOrientation::update() { + ZoneScoped; + + const Camera* camera = global::renderEngine->scene()->camera(); + const glm::dquat orientation = camera->rotationQuaternion(); + const glm::dvec3 pitchYawRoll = glm::eulerAngles(orientation); + const glm::dvec3 pitchYawRollDeg = glm::degrees(pitchYawRoll); + + _buffer = std::format( + "Yaw: {:.2f}\nPitch: {:.2f}\nRoll: {:.2f}", + pitchYawRollDeg.y, pitchYawRollDeg.x, pitchYawRollDeg.z + ); +} + +glm::vec2 DashboardItemCameraOrientation::size() const { + ZoneScoped; + + return _font->boundingBox("Yaw: 0.00\nPitch: 0.00\nRoll: 0.00"); +} + +} // namespace openspace diff --git a/modules/base/dashboard/dashboarditemcameraorientation.h b/modules/base/dashboard/dashboarditemcameraorientation.h new file mode 100644 index 0000000000..657275c9a7 --- /dev/null +++ b/modules/base/dashboard/dashboarditemcameraorientation.h @@ -0,0 +1,46 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2025 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#ifndef __OPENSPACE_MODULE_BASE___DASHBOARDITEMCAMERAORIENTATION___H__ +#define __OPENSPACE_MODULE_BASE___DASHBOARDITEMCAMERAORIENTATION___H__ + +#include + +namespace openspace { + +class DashboardItemCameraOrientation : public DashboardTextItem { +public: + explicit DashboardItemCameraOrientation(const ghoul::Dictionary& dictionary); + ~DashboardItemCameraOrientation() override = default; + + void update() override; + + glm::vec2 size() const override; + + static documentation::Documentation Documentation(); +}; + +} // namespace openspace + +#endif // __OPENSPACE_MODULE_BASE___DASHBOARDITEMCAMERAORIENTATION___H__