mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-06 19:50:03 -06:00
Merge pull request #2189 from OpenSpace/feature/getting-started-tour
Feature/getting started tour
This commit is contained in:
@@ -421,6 +421,46 @@ glm::vec3 GlobeBrowsingModule::cartesianCoordinatesFromGeo(
|
||||
return glm::vec3(globe.ellipsoid().cartesianPosition(pos));
|
||||
}
|
||||
|
||||
glm::dvec3 GlobeBrowsingModule::geoPosition() const {
|
||||
using namespace globebrowsing;
|
||||
|
||||
const SceneGraphNode* n = global::navigationHandler->orbitalNavigator().anchorNode();
|
||||
if (!n) {
|
||||
return glm::dvec3(0.0);
|
||||
}
|
||||
const RenderableGlobe* globe = dynamic_cast<const RenderableGlobe*>(n->renderable());
|
||||
if (!globe) {
|
||||
return glm::dvec3(0.0);
|
||||
}
|
||||
|
||||
const glm::dvec3 cameraPosition = global::navigationHandler->camera()->positionVec3();
|
||||
const glm::dmat4 inverseModelTransform = glm::inverse(n->modelTransform());
|
||||
const glm::dvec3 cameraPositionModelSpace =
|
||||
glm::dvec3(inverseModelTransform * glm::dvec4(cameraPosition, 1.0));
|
||||
const SurfacePositionHandle posHandle = globe->calculateSurfacePositionHandle(
|
||||
cameraPositionModelSpace
|
||||
);
|
||||
|
||||
const Geodetic2 geo2 = globe->ellipsoid().cartesianToGeodetic2(
|
||||
posHandle.centerToReferenceSurface
|
||||
);
|
||||
|
||||
double lat = glm::degrees(geo2.lat);
|
||||
double lon = glm::degrees(geo2.lon);
|
||||
|
||||
double altitude = glm::length(
|
||||
cameraPositionModelSpace - posHandle.centerToReferenceSurface
|
||||
);
|
||||
|
||||
if (glm::length(cameraPositionModelSpace) <
|
||||
glm::length(posHandle.centerToReferenceSurface))
|
||||
{
|
||||
altitude = -altitude;
|
||||
}
|
||||
|
||||
return glm::dvec3(lat, lon, altitude);
|
||||
}
|
||||
|
||||
void GlobeBrowsingModule::goToChunk(const globebrowsing::RenderableGlobe& globe,
|
||||
const globebrowsing::TileIndex& ti,
|
||||
glm::vec2 uv, bool doResetCameraDirection)
|
||||
|
||||
@@ -63,6 +63,8 @@ public:
|
||||
glm::vec3 cartesianCoordinatesFromGeo(const globebrowsing::RenderableGlobe& globe,
|
||||
double latitude, double longitude, double altitude);
|
||||
|
||||
glm::dvec3 geoPosition() const;
|
||||
|
||||
globebrowsing::cache::MemoryAwareTileCache* tileCache();
|
||||
scripting::LuaLibrary luaLibrary() const override;
|
||||
std::vector<documentation::Documentation> documentations() const override;
|
||||
|
||||
@@ -24,11 +24,13 @@
|
||||
|
||||
#include <modules/globebrowsing/src/dashboarditemglobelocation.h>
|
||||
|
||||
#include <modules/globebrowsing/globebrowsingmodule.h>
|
||||
#include <modules/globebrowsing/src/basictypes.h>
|
||||
#include <modules/globebrowsing/src/renderableglobe.h>
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/engine/globals.h>
|
||||
#include <openspace/engine/moduleengine.h>
|
||||
#include <openspace/navigation/navigationhandler.h>
|
||||
#include <openspace/navigation/orbitalnavigator.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
@@ -171,42 +173,13 @@ DashboardItemGlobeLocation::DashboardItemGlobeLocation(
|
||||
|
||||
void DashboardItemGlobeLocation::render(glm::vec2& penPosition) {
|
||||
ZoneScoped
|
||||
|
||||
GlobeBrowsingModule* module = global::moduleEngine->module<GlobeBrowsingModule>();
|
||||
|
||||
using namespace globebrowsing;
|
||||
|
||||
const SceneGraphNode* n = global::navigationHandler->orbitalNavigator().anchorNode();
|
||||
if (!n) {
|
||||
return;
|
||||
}
|
||||
const RenderableGlobe* globe = dynamic_cast<const RenderableGlobe*>(n->renderable());
|
||||
if (!globe) {
|
||||
return;
|
||||
}
|
||||
|
||||
const glm::dvec3 cameraPosition = global::navigationHandler->camera()->positionVec3();
|
||||
const glm::dmat4 inverseModelTransform = glm::inverse(n->modelTransform());
|
||||
const glm::dvec3 cameraPositionModelSpace =
|
||||
glm::dvec3(inverseModelTransform * glm::dvec4(cameraPosition, 1.0));
|
||||
const SurfacePositionHandle posHandle = globe->calculateSurfacePositionHandle(
|
||||
cameraPositionModelSpace
|
||||
);
|
||||
|
||||
const Geodetic2 geo2 = globe->ellipsoid().cartesianToGeodetic2(
|
||||
posHandle.centerToReferenceSurface
|
||||
);
|
||||
|
||||
double lat = glm::degrees(geo2.lat);
|
||||
double lon = glm::degrees(geo2.lon);
|
||||
|
||||
double altitude = glm::length(
|
||||
cameraPositionModelSpace - posHandle.centerToReferenceSurface
|
||||
);
|
||||
|
||||
if (glm::length(cameraPositionModelSpace) <
|
||||
glm::length(posHandle.centerToReferenceSurface))
|
||||
{
|
||||
altitude = -altitude;
|
||||
}
|
||||
glm::dvec3 position = module->geoPosition();
|
||||
double lat = position.x;
|
||||
double lon = position.y;
|
||||
double altitude = position.z;
|
||||
|
||||
std::pair<double, std::string> dist = simplifyDistance(altitude);
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ set(HEADER_FILES
|
||||
include/serverinterface.h
|
||||
include/topics/authorizationtopic.h
|
||||
include/topics/bouncetopic.h
|
||||
include/topics/cameratopic.h
|
||||
include/topics/documentationtopic.h
|
||||
include/topics/enginemodetopic.h
|
||||
include/topics/flightcontrollertopic.h
|
||||
@@ -58,6 +59,7 @@ set(SOURCE_FILES
|
||||
src/serverinterface.cpp
|
||||
src/topics/authorizationtopic.cpp
|
||||
src/topics/bouncetopic.cpp
|
||||
src/topics/cameratopic.cpp
|
||||
src/topics/documentationtopic.cpp
|
||||
src/topics/enginemodetopic.cpp
|
||||
src/topics/flightcontrollertopic.cpp
|
||||
|
||||
56
modules/server/include/topics/cameratopic.h
Normal file
56
modules/server/include/topics/cameratopic.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2022 *
|
||||
* *
|
||||
* 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_SERVER___CAMERATOPIC___H__
|
||||
#define __OPENSPACE_MODULE_SERVER___CAMERATOPIC___H__
|
||||
|
||||
#include <modules/server/include/topics/topic.h>
|
||||
#include <chrono>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class CameraTopic : public Topic {
|
||||
public:
|
||||
CameraTopic();
|
||||
virtual ~CameraTopic();
|
||||
|
||||
void handleJson(const nlohmann::json& json) override;
|
||||
bool isDone() const override;
|
||||
|
||||
private:
|
||||
const int UnsetOnChangeHandle = -1;
|
||||
|
||||
void sendCameraData();
|
||||
|
||||
int _dataCallbackHandle = UnsetOnChangeHandle;
|
||||
bool _isDone = false;
|
||||
std::chrono::system_clock::time_point _lastUpdateTime;
|
||||
glm::dvec3 _lastPosition = glm::dvec3(0);
|
||||
|
||||
std::chrono::milliseconds _cameraPositionUpdateTime = std::chrono::milliseconds(100);
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_SERVER___CAMERATOPIC___H__
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <modules/server/servermodule.h>
|
||||
|
||||
#include <modules/globebrowsing/globebrowsingmodule.h>
|
||||
#include <modules/server/include/serverinterface.h>
|
||||
#include <modules/server/include/connection.h>
|
||||
#include <modules/server/include/topics/topic.h>
|
||||
@@ -50,6 +51,15 @@ ServerModule::ServerModule()
|
||||
, _interfaceOwner({"Interfaces", "Interfaces", "Server Interfaces"})
|
||||
{
|
||||
addPropertySubOwner(_interfaceOwner);
|
||||
|
||||
global::callback::preSync->emplace_back([this]() {
|
||||
// Trigger callbacks
|
||||
using K = CallbackHandle;
|
||||
using V = CallbackFunction;
|
||||
for (const std::pair<const K, V>& it : _preSyncCallbacks) {
|
||||
it.second(); // call function
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ServerModule::~ServerModule() {
|
||||
@@ -233,4 +243,28 @@ void ServerModule::consumeMessages() {
|
||||
}
|
||||
}
|
||||
|
||||
ServerModule::CallbackHandle ServerModule::addPreSyncCallback(CallbackFunction cb)
|
||||
{
|
||||
CallbackHandle handle = _nextCallbackHandle++;
|
||||
_preSyncCallbacks.emplace_back(handle, std::move(cb));
|
||||
return handle;
|
||||
}
|
||||
|
||||
void ServerModule::removePreSyncCallback(CallbackHandle handle) {
|
||||
const auto it = std::find_if(
|
||||
_preSyncCallbacks.begin(),
|
||||
_preSyncCallbacks.end(),
|
||||
[handle](const std::pair<CallbackHandle, CallbackFunction>& cb) {
|
||||
return cb.first == handle;
|
||||
}
|
||||
);
|
||||
|
||||
ghoul_assert(
|
||||
it != _preSyncCallbacks.end(),
|
||||
"handle must be a valid callback handle"
|
||||
);
|
||||
|
||||
_preSyncCallbacks.erase(it);
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -49,6 +49,8 @@ struct Message {
|
||||
class ServerModule : public OpenSpaceModule {
|
||||
public:
|
||||
static constexpr const char* Name = "Server";
|
||||
using CallbackHandle = int;
|
||||
using CallbackFunction = std::function<void()>;
|
||||
|
||||
ServerModule();
|
||||
virtual ~ServerModule() override;
|
||||
@@ -57,6 +59,9 @@ public:
|
||||
|
||||
int skyBrowserUpdateTime() const;
|
||||
|
||||
CallbackHandle addPreSyncCallback(CallbackFunction cb);
|
||||
void removePreSyncCallback(CallbackHandle handle);
|
||||
|
||||
protected:
|
||||
void internalInitialize(const ghoul::Dictionary& configuration) override;
|
||||
|
||||
@@ -79,6 +84,10 @@ private:
|
||||
std::vector<std::unique_ptr<ServerInterface>> _interfaces;
|
||||
properties::PropertyOwner _interfaceOwner;
|
||||
int _skyBrowserUpdateTime = 100;
|
||||
|
||||
// Callbacks for tiggering topic
|
||||
int _nextCallbackHandle = 0;
|
||||
std::vector<std::pair<CallbackHandle, CallbackFunction>> _preSyncCallbacks;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include <modules/server/include/topics/authorizationtopic.h>
|
||||
#include <modules/server/include/topics/bouncetopic.h>
|
||||
#include <modules/server/include/topics/cameratopic.h>
|
||||
#include <modules/server/include/topics/documentationtopic.h>
|
||||
#include <modules/server/include/topics/enginemodetopic.h>
|
||||
#include <modules/server/include/topics/flightcontrollertopic.h>
|
||||
@@ -71,6 +72,7 @@ namespace {
|
||||
constexpr const char* BounceTopicKey = "bounce";
|
||||
constexpr const char* FlightControllerTopicKey = "flightcontroller";
|
||||
constexpr const char* SkyBrowserKey = "skybrowser";
|
||||
constexpr const char* CameraKey = "camera";
|
||||
} // namespace
|
||||
|
||||
namespace openspace {
|
||||
@@ -110,6 +112,7 @@ Connection::Connection(std::unique_ptr<ghoul::io::Socket> s, std::string address
|
||||
_topicFactory.registerClass<FlightControllerTopic>(FlightControllerTopicKey);
|
||||
_topicFactory.registerClass<VersionTopic>(VersionTopicKey);
|
||||
_topicFactory.registerClass<SkyBrowserTopic>(SkyBrowserKey);
|
||||
_topicFactory.registerClass<CameraTopic>(CameraKey);
|
||||
}
|
||||
|
||||
void Connection::handleMessage(const std::string& message) {
|
||||
|
||||
102
modules/server/src/topics/cameratopic.cpp
Normal file
102
modules/server/src/topics/cameratopic.cpp
Normal file
@@ -0,0 +1,102 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2022 *
|
||||
* *
|
||||
* 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 "modules/server/include/topics/cameratopic.h"
|
||||
|
||||
#include <modules/server/include/connection.h>
|
||||
#include <modules/server/servermodule.h>
|
||||
#include <modules/globebrowsing/globebrowsingmodule.h>
|
||||
#include <modules/globebrowsing/src/dashboarditemglobelocation.h>
|
||||
#include <openspace/engine/moduleengine.h>
|
||||
#include <openspace/engine/globals.h>
|
||||
#include <openspace/properties/property.h>
|
||||
#include <openspace/query/query.h>
|
||||
#include <openspace/util/distanceconversion.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
|
||||
namespace {
|
||||
constexpr const char* EventKey = "event";
|
||||
constexpr const char* SubscribeEvent = "start_subscription";
|
||||
constexpr const char* UnsubscribeEvent = "stop_subscription";
|
||||
} // namespace
|
||||
|
||||
using nlohmann::json;
|
||||
|
||||
namespace openspace {
|
||||
|
||||
CameraTopic::CameraTopic()
|
||||
: _lastUpdateTime(std::chrono::system_clock::now())
|
||||
{}
|
||||
|
||||
CameraTopic::~CameraTopic() {
|
||||
if (_dataCallbackHandle != UnsetOnChangeHandle) {
|
||||
ServerModule* module = global::moduleEngine->module<ServerModule>();
|
||||
if (module) {
|
||||
module->removePreSyncCallback(_dataCallbackHandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool CameraTopic::isDone() const {
|
||||
return _isDone;
|
||||
}
|
||||
|
||||
void CameraTopic::handleJson(const nlohmann::json& json) {
|
||||
std::string event = json.at(EventKey).get<std::string>();
|
||||
|
||||
if (event != SubscribeEvent) {
|
||||
_isDone = true;
|
||||
return;
|
||||
}
|
||||
|
||||
ServerModule* module = global::moduleEngine->module<ServerModule>();
|
||||
_dataCallbackHandle = module->addPreSyncCallback(
|
||||
[this]() {
|
||||
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
|
||||
if (now - _lastUpdateTime > _cameraPositionUpdateTime) {
|
||||
sendCameraData();
|
||||
_lastUpdateTime = std::chrono::system_clock::now();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void CameraTopic::sendCameraData() {
|
||||
using namespace openspace;
|
||||
|
||||
GlobeBrowsingModule* module = global::moduleEngine->module<GlobeBrowsingModule>();
|
||||
glm::dvec3 position = module->geoPosition();
|
||||
std::pair<double, std::string> altSimplified = simplifyDistance(position.z);
|
||||
|
||||
nlohmann::json jsonData = {
|
||||
{ "latitude", position.x },
|
||||
{ "longitude", position.y },
|
||||
{ "altitude", altSimplified.first },
|
||||
{ "altitudeUnit", altSimplified.second }
|
||||
};
|
||||
|
||||
_connection->sendJson(wrappedPayload(jsonData));
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
@@ -55,7 +55,7 @@ SkyBrowserTopic::SkyBrowserTopic()
|
||||
|
||||
SkyBrowserTopic::~SkyBrowserTopic() {
|
||||
if (_targetDataCallbackHandle != UnsetOnChangeHandle) {
|
||||
SkyBrowserModule* module = global::moduleEngine->module<SkyBrowserModule>();
|
||||
ServerModule* module = global::moduleEngine->module<ServerModule>();
|
||||
if (module) {
|
||||
module->removePreSyncCallback(_targetDataCallbackHandle);
|
||||
}
|
||||
@@ -78,7 +78,7 @@ void SkyBrowserTopic::handleJson(const nlohmann::json& json) {
|
||||
return;
|
||||
}
|
||||
|
||||
SkyBrowserModule* module = global::moduleEngine->module<SkyBrowserModule>();
|
||||
ServerModule* module = global::moduleEngine->module<ServerModule>();
|
||||
_targetDataCallbackHandle = module->addPreSyncCallback(
|
||||
[this]() {
|
||||
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
|
||||
|
||||
@@ -214,13 +214,6 @@ SkyBrowserModule::SkyBrowserModule()
|
||||
if (_cameraRotation.isAnimating() && _allowCameraRotation) {
|
||||
incrementallyRotateCamera();
|
||||
}
|
||||
|
||||
// Trigger callbacks (should maybe have a check to see if update is needed)
|
||||
using K = CallbackHandle;
|
||||
using V = CallbackFunction;
|
||||
for (const std::pair<K, V>& it : _preSyncCallbacks) {
|
||||
it.second(); // call function
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -487,31 +480,6 @@ bool SkyBrowserModule::isSelectedPairFacingCamera() const {
|
||||
return found ? found->isFacingCamera() : false;
|
||||
}
|
||||
|
||||
SkyBrowserModule::CallbackHandle SkyBrowserModule::addPreSyncCallback(
|
||||
CallbackFunction cb)
|
||||
{
|
||||
CallbackHandle handle = _nextCallbackHandle++;
|
||||
_preSyncCallbacks.emplace_back(handle, std::move(cb));
|
||||
return handle;
|
||||
}
|
||||
|
||||
void SkyBrowserModule::removePreSyncCallback(CallbackHandle handle) {
|
||||
const auto it = std::find_if(
|
||||
_preSyncCallbacks.begin(),
|
||||
_preSyncCallbacks.end(),
|
||||
[handle](const std::pair<CallbackHandle, CallbackFunction>& cb) {
|
||||
return cb.first == handle;
|
||||
}
|
||||
);
|
||||
|
||||
ghoul_assert(
|
||||
it != _preSyncCallbacks.end(),
|
||||
"handle must be a valid callback handle"
|
||||
);
|
||||
|
||||
_preSyncCallbacks.erase(it);
|
||||
}
|
||||
|
||||
std::vector<documentation::Documentation> SkyBrowserModule::documentations() const {
|
||||
return {
|
||||
RenderableSkyTarget::Documentation(),
|
||||
|
||||
@@ -47,8 +47,6 @@ struct ImageData;
|
||||
class SkyBrowserModule : public OpenSpaceModule {
|
||||
public:
|
||||
constexpr static const char* Name = "SkyBrowser";
|
||||
using CallbackHandle = int;
|
||||
using CallbackFunction = std::function<void()>;
|
||||
|
||||
SkyBrowserModule();
|
||||
|
||||
@@ -89,9 +87,6 @@ public:
|
||||
void loadImages(const std::string& root, const std::filesystem::path& directory);
|
||||
int nLoadedImages() const;
|
||||
|
||||
CallbackHandle addPreSyncCallback(CallbackFunction cb);
|
||||
void removePreSyncCallback(CallbackHandle handle);
|
||||
|
||||
scripting::LuaLibrary luaLibrary() const override;
|
||||
std::vector<documentation::Documentation> documentations() const override;
|
||||
|
||||
@@ -125,10 +120,6 @@ private:
|
||||
|
||||
// Data handler for the image collections
|
||||
std::unique_ptr<WwtDataHandler> _dataHandler;
|
||||
|
||||
// Callbacks for tiggering topic
|
||||
int _nextCallbackHandle = 0;
|
||||
std::vector<std::pair<CallbackHandle, CallbackFunction>> _preSyncCallbacks;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
Reference in New Issue
Block a user