mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-03-13 17:09:05 -05:00
Move conversion function to target and add some utility functions to target and browser
This commit is contained in:
@@ -27,8 +27,8 @@ namespace openspace {
|
||||
bool sendMessageToWWT(const ghoul::Dictionary& msg);
|
||||
void sendMouseEvent(CefStructBase<CefMouseEventTraits> event, int x, int y) const;
|
||||
void WWTfollowCamera();
|
||||
glm::dvec2 convertGalacticToCelestial(glm::dvec3 coords) const;
|
||||
float fieldOfView() const;
|
||||
void setFieldOfView(float fov);
|
||||
void scrollZoom(float scroll);
|
||||
ScreenSpaceSkyTarget* getSkyTarget();
|
||||
|
||||
|
||||
@@ -33,11 +33,15 @@ namespace openspace {
|
||||
void setDimensions(glm::vec2 currentBrowserDimensions);
|
||||
void updateFOV(float browserFOV);
|
||||
|
||||
glm::dvec2 convertGalacticToCelestial(glm::dvec3 rGal) const;
|
||||
glm::vec2 getCelestialCoords();
|
||||
glm::vec2 getScreenSpacePosition();
|
||||
glm::vec2 getAnglePosition();
|
||||
void setConnectedBrowser();
|
||||
void setBorderColor(glm::ivec3 color);
|
||||
glm::ivec3 getColor();
|
||||
|
||||
void setPosition(glm::vec3 pos);
|
||||
|
||||
void translate(glm::vec2 translation, glm::vec2 position);
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <openspace/engine/globals.h>
|
||||
#include <openspace/engine/globalscallbacks.h>
|
||||
#include <openspace/engine/windowdelegate.h>
|
||||
#include <openspace/interaction/navigationhandler.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/engine/moduleengine.h>
|
||||
#include <openspace/util/camera.h>
|
||||
@@ -20,9 +19,9 @@
|
||||
#include <glm/gtx/rotate_vector.hpp >
|
||||
#include <thread>
|
||||
#include <chrono> // Milliseconds
|
||||
|
||||
#include <optional>
|
||||
#include <openspace/util/coordinateconversion.h> // to adjust camera angle
|
||||
#include <glm/gtx/vector_angle.hpp>
|
||||
|
||||
namespace {
|
||||
constexpr const char* _loggerCat = "ScreenSpaceSkyBrowser";
|
||||
|
||||
@@ -158,6 +157,10 @@ namespace openspace {
|
||||
return _fieldOfView;
|
||||
}
|
||||
|
||||
void ScreenSpaceSkyBrowser::setFieldOfView(float fov) {
|
||||
_fieldOfView = fov;
|
||||
}
|
||||
|
||||
void ScreenSpaceSkyBrowser::scrollZoom(float scroll) {
|
||||
|
||||
float zoomFactor = log(_fieldOfView + 1.1f);
|
||||
@@ -260,19 +263,8 @@ namespace openspace {
|
||||
_threadWWTMessages = std::thread([&] {
|
||||
while (_camIsSyncedWWT) {
|
||||
|
||||
// Get camera view direction and orthogonal coordinate system of camera view direction
|
||||
glm::vec3 viewDirection = global::navigationHandler->camera()->viewDirectionWorldSpace();
|
||||
glm::vec3 upDirection = global::navigationHandler->camera()->lookUpVectorWorldSpace();
|
||||
glm::vec3 sideDirection = glm::cross(upDirection, viewDirection);
|
||||
|
||||
glm::vec2 angleOffset = _skyTarget ? _skyTarget->getAnglePosition() : glm::vec2(0);
|
||||
// Change view if target is moved
|
||||
glm::vec3 targetDirection = glm::rotate(viewDirection, angleOffset.x, upDirection);
|
||||
targetDirection = glm::rotate(targetDirection, angleOffset.y, sideDirection);
|
||||
|
||||
// Convert to celestial coordinates
|
||||
glm::dvec2 celestCoords = convertGalacticToCelestial(targetDirection);
|
||||
ghoul::Dictionary message = createMessageForMovingWWTCamera(celestCoords, _fieldOfView);
|
||||
glm::vec2 celestCoordsTarget = _skyTarget ? _skyTarget->getCelestialCoords() : glm::vec2(0.f);
|
||||
ghoul::Dictionary message = createMessageForMovingWWTCamera(celestCoordsTarget, _fieldOfView);
|
||||
|
||||
// Sleep so we don't bombard WWT with too many messages
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
@@ -282,24 +274,7 @@ namespace openspace {
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
glm::dvec2 ScreenSpaceSkyBrowser::convertGalacticToCelestial(glm::dvec3 rGal) const {
|
||||
// Used the math from this website: https://gea.esac.esa.int/archive/documentation/GD -->
|
||||
// R2/Data_processing/chap_cu3ast/sec_cu3ast_intro/ssec_cu3ast_intro_tansforms.html#SSS1
|
||||
const glm::dmat3 conversionMatrix = glm::dmat3({
|
||||
-0.0548755604162154, 0.4941094278755837, -0.8676661490190047, // col 0
|
||||
-0.8734370902348850, -0.4448296299600112, -0.1980763734312015, // col 1
|
||||
-0.4838350155487132, 0.7469822444972189, 0.4559837761750669 // col 2
|
||||
});
|
||||
|
||||
glm::dvec3 rICRS = glm::transpose(conversionMatrix) * rGal;
|
||||
float ra = atan2(rICRS[1], rICRS[0]);
|
||||
float dec = atan2(rICRS[2], glm::sqrt((rICRS[0] * rICRS[0]) + (rICRS[1] * rICRS[1])));
|
||||
|
||||
ra = ra > 0 ? ra : ra + (2 * glm::pi<float>());
|
||||
|
||||
return glm::dvec2(glm::degrees(ra), glm::degrees(dec));
|
||||
}
|
||||
|
||||
/*
|
||||
void ScreenSpaceSkyBrowser::translate(glm::vec2 translation) {
|
||||
glm::vec3 position = _cartesianPosition;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <modules/skybrowser/include/screenspaceskybrowser.h>
|
||||
#include <modules/skybrowser/skybrowsermodule.h>
|
||||
#include <openspace/engine/globals.h>
|
||||
#include <openspace/interaction/navigationhandler.h>
|
||||
#include <openspace/engine/windowdelegate.h>
|
||||
#include <openspace/engine/moduleengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
@@ -21,6 +22,7 @@
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#include <glm/gtx/string_cast.hpp>
|
||||
#include <glm/gtx/matrix_decompose.hpp>
|
||||
#include <glm/gtx/vector_angle.hpp>
|
||||
#include <optional>
|
||||
|
||||
namespace {
|
||||
@@ -241,6 +243,9 @@ namespace openspace {
|
||||
void ScreenSpaceSkyTarget::translate(glm::vec2 translation, glm::vec2 position) {
|
||||
_cartesianPosition = glm::translate(glm::mat4(1.f), glm::vec3(translation, 0.0f)) * glm::vec4(position, _cartesianPosition.value().z, 1.0f);
|
||||
}
|
||||
void ScreenSpaceSkyTarget::setPosition(glm::vec3 pos) {
|
||||
_cartesianPosition = pos;
|
||||
}
|
||||
|
||||
glm::vec2 ScreenSpaceSkyTarget::getAnglePosition() {
|
||||
glm::vec3 pos = _cartesianPosition.value();
|
||||
@@ -275,6 +280,39 @@ namespace openspace {
|
||||
|
||||
}
|
||||
|
||||
glm::vec2 ScreenSpaceSkyTarget::getCelestialCoords() {
|
||||
// Get camera view direction and orthogonal coordinate system of camera view direction
|
||||
glm::vec3 viewDirection = global::navigationHandler->camera()->viewDirectionWorldSpace();
|
||||
glm::vec3 upDirection = global::navigationHandler->camera()->lookUpVectorWorldSpace();
|
||||
glm::vec3 sideDirection = glm::cross(upDirection, viewDirection);
|
||||
|
||||
glm::vec2 angleOffset = getAnglePosition();
|
||||
// Change view if target is moved
|
||||
glm::vec3 targetDirection = glm::rotate(viewDirection, angleOffset.x, upDirection);
|
||||
targetDirection = glm::rotate(targetDirection, angleOffset.y, sideDirection);
|
||||
|
||||
// Convert to celestial coordinates
|
||||
return convertGalacticToCelestial(targetDirection);
|
||||
}
|
||||
|
||||
glm::dvec2 ScreenSpaceSkyTarget::convertGalacticToCelestial(glm::dvec3 rGal) const {
|
||||
// Used the math from this website: https://gea.esac.esa.int/archive/documentation/GD -->
|
||||
// R2/Data_processing/chap_cu3ast/sec_cu3ast_intro/ssec_cu3ast_intro_tansforms.html#SSS1
|
||||
const glm::dmat3 conversionMatrix = glm::dmat3({
|
||||
-0.0548755604162154, 0.4941094278755837, -0.8676661490190047, // col 0
|
||||
-0.8734370902348850, -0.4448296299600112, -0.1980763734312015, // col 1
|
||||
-0.4838350155487132, 0.7469822444972189, 0.4559837761750669 // col 2
|
||||
});
|
||||
|
||||
glm::dvec3 rICRS = glm::transpose(conversionMatrix) * rGal;
|
||||
float ra = atan2(rICRS[1], rICRS[0]);
|
||||
float dec = atan2(rICRS[2], glm::sqrt((rICRS[0] * rICRS[0]) + (rICRS[1] * rICRS[1])));
|
||||
|
||||
ra = ra > 0 ? ra : ra + (2 * glm::pi<float>());
|
||||
|
||||
return glm::dvec2(glm::degrees(ra), glm::degrees(dec));
|
||||
}
|
||||
|
||||
void ScreenSpaceSkyTarget::updateFOV(float browserFOV) {
|
||||
float horizFOV = global::windowDelegate->getHorizFieldOfView();
|
||||
_scale = std::max((browserFOV/horizFOV),(_showCrosshairThreshold.value()/horizFOV));
|
||||
|
||||
Reference in New Issue
Block a user