mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-05 10:59:47 -05:00
Make target work with RAE coordinates so it can be used in a dome setup
This commit is contained in:
@@ -80,7 +80,7 @@ public:
|
||||
glm::vec2 lowerLeftCornerScreenSpace();
|
||||
bool intersection(glm::vec2 coord);
|
||||
void translate(glm::vec2 translation, glm::vec2 position);
|
||||
void setCartesianPosition(const glm::vec3& position);
|
||||
void setPosition(const glm::vec3& position);
|
||||
|
||||
// End of addition by skybrowser team
|
||||
|
||||
@@ -95,6 +95,9 @@ protected:
|
||||
glm::mat4 translationMatrix();
|
||||
glm::mat4 localRotationMatrix();
|
||||
|
||||
glm::vec3 raeToCartesian(const glm::vec3& rae) const;
|
||||
glm::vec3 cartesianToRae(const glm::vec3& cartesian) const;
|
||||
|
||||
void draw(glm::mat4 modelTransform);
|
||||
|
||||
virtual void bindTexture() = 0;
|
||||
|
||||
@@ -41,6 +41,7 @@ namespace openspace {
|
||||
void setColor(glm::ivec3 color);
|
||||
void setOpacity(float opacity);
|
||||
void setLock(bool isLocked);
|
||||
void setEquatorialAim(const glm::dvec2& aim);
|
||||
|
||||
// Set callbacks
|
||||
void setSkyBrowser(ScreenSpaceSkyBrowser* browser);
|
||||
|
||||
@@ -30,10 +30,11 @@ namespace openspace {
|
||||
|
||||
// Conversion to screen space from J2000 equatorial / galactic / pixels
|
||||
glm::dvec3 equatorialToScreenSpace3d(const glm::dvec3& coords);
|
||||
glm::dvec3 galacticToScreenSpace3d(const glm::dvec3& coords);
|
||||
glm::dvec3 localCameraToScreenSpace3d(const glm::dvec3& coords);
|
||||
glm::vec2 pixelToScreenSpace2d(const glm::vec2& mouseCoordinate);
|
||||
|
||||
// Conversion local camera space <-> galactic / equatorial
|
||||
glm::dvec3 equatorialToLocalCamera(const glm::dvec3& coords);
|
||||
glm::dvec3 galacticToLocalCamera(const glm::dvec3& coords);
|
||||
glm::dvec3 localCameraToGalactic(const glm::dvec3& coords);
|
||||
glm::dvec3 localCameraToEquatorial(const glm::dvec3& coords);
|
||||
|
||||
@@ -496,7 +496,7 @@ void SkyBrowserModule::moveHoverCircle(int i)
|
||||
glm::vec3 coordsScreen = skybrowser::equatorialToScreenSpace3d(
|
||||
image.equatorialCartesian
|
||||
);
|
||||
_hoverCircle->setCartesianPosition(coordsScreen);
|
||||
_hoverCircle->setPosition(coordsScreen);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,17 +45,13 @@ namespace openspace {
|
||||
|
||||
// Set browser callback functions
|
||||
// Set callback functions so that the target and the browser update each other
|
||||
/*
|
||||
_browser->setCallbackEquatorialAim(
|
||||
[&](const glm::dvec2& equatorialAim) {
|
||||
glm::dvec3 cartesian = skybrowser::sphericalToCartesian(
|
||||
equatorialAim
|
||||
);
|
||||
_target->setCartesianPosition(
|
||||
skybrowser::equatorialToScreenSpace3d(cartesian)
|
||||
);
|
||||
|
||||
_target->setEquatorialAim(equatorialAim);
|
||||
}
|
||||
);
|
||||
*/
|
||||
_browser->setCallbackBorderColor(
|
||||
[&](const glm::ivec3& color) {
|
||||
_target->setColor(color);
|
||||
|
||||
@@ -209,9 +209,21 @@ namespace openspace {
|
||||
void ScreenSpaceSkyTarget::update()
|
||||
{
|
||||
if (_isLocked) {
|
||||
_cartesianPosition = skybrowser::equatorialToScreenSpace3d(
|
||||
glm::dvec3 localCamera = skybrowser::equatorialToLocalCamera(
|
||||
_lockedCoordinates
|
||||
);
|
||||
|
||||
if (_useRadiusAzimuthElevation) {
|
||||
// Keep the set radius
|
||||
glm::vec3 position = _raePosition.value().x * glm::vec3(localCamera);
|
||||
_raePosition = cartesianToRae(position);
|
||||
}
|
||||
else {
|
||||
_cartesianPosition = skybrowser::localCameraToScreenSpace3d(
|
||||
localCamera
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
// Optimization: Only pass messages to the browser when the target is not moving
|
||||
if (_browser && !_isAnimated) {
|
||||
@@ -238,10 +250,18 @@ namespace openspace {
|
||||
|
||||
glm::dvec3 ScreenSpaceSkyTarget::directionGalactic() const {
|
||||
|
||||
|
||||
glm::vec3 localCamera = _cartesianPosition.value();
|
||||
|
||||
if (_useRadiusAzimuthElevation) {
|
||||
|
||||
localCamera = raeToCartesian(_raePosition.value());
|
||||
}
|
||||
|
||||
glm::dmat4 rotation = glm::inverse(
|
||||
global::navigationHandler->camera()->viewRotationMatrix()
|
||||
);
|
||||
glm::dvec4 position = glm::dvec4(_cartesianPosition.value(), 1.0);
|
||||
glm::dvec4 position = glm::dvec4(localCamera, 1.0);
|
||||
|
||||
return glm::normalize(rotation * position);
|
||||
}
|
||||
@@ -305,19 +325,34 @@ namespace openspace {
|
||||
);
|
||||
|
||||
// Rotate target direction
|
||||
glm::dvec3 newDir = rotMat * glm::dvec4(_animationStart, 1.0);
|
||||
|
||||
glm::dvec3 equatorial = glm::dvec3(rotMat * glm::dvec4(_animationStart, 1.0));
|
||||
glm::dvec3 localCamera = skybrowser::equatorialToLocalCamera(equatorial);
|
||||
// Convert to screen space
|
||||
_cartesianPosition = skybrowser::equatorialToScreenSpace3d(newDir);
|
||||
if (_useRadiusAzimuthElevation) {
|
||||
// Keep the radius
|
||||
glm::vec3 position = _raePosition.value().x * glm::vec3(localCamera);
|
||||
_raePosition = cartesianToRae(position);
|
||||
}
|
||||
else {
|
||||
_cartesianPosition = skybrowser::localCameraToScreenSpace3d(localCamera);
|
||||
}
|
||||
|
||||
// Update position
|
||||
glm::dvec3 cartesian = skybrowser::sphericalToCartesian(equatorialAim());
|
||||
_animationStart = glm::normalize(cartesian);
|
||||
}
|
||||
else {
|
||||
glm::dvec3 screenSpace = skybrowser::equatorialToScreenSpace3d(_animationEnd);
|
||||
// Set the exact target position
|
||||
_cartesianPosition = glm::vec3(screenSpace);
|
||||
glm::dvec3 localCamera = skybrowser::equatorialToLocalCamera(_animationEnd);
|
||||
|
||||
if (_useRadiusAzimuthElevation) {
|
||||
glm::vec3 position = _raePosition.value().x * glm::vec3(localCamera);
|
||||
_raePosition = cartesianToRae(position);
|
||||
}
|
||||
else {
|
||||
_cartesianPosition = skybrowser::localCameraToScreenSpace3d(localCamera);
|
||||
}
|
||||
|
||||
_isAnimated = false;
|
||||
// Lock target when it first arrives to the position
|
||||
setLock(_shouldLockAfterAnimation);
|
||||
@@ -325,12 +360,18 @@ namespace openspace {
|
||||
}
|
||||
|
||||
glm::dvec2 ScreenSpaceSkyTarget::equatorialAim() const {
|
||||
// Calculate the galactic coordinate of the target direction
|
||||
// projected onto the celestial sphere
|
||||
glm::dvec3 cartesian = skybrowser::localCameraToEquatorial(
|
||||
_cartesianPosition.value()
|
||||
);
|
||||
return skybrowser::cartesianToSpherical(cartesian);
|
||||
|
||||
// Get the local camera coordinates of the target
|
||||
if (_useRadiusAzimuthElevation) {
|
||||
glm::vec3 cartesian = raeToCartesian(_raePosition.value());
|
||||
glm::dvec3 equatorial = skybrowser::localCameraToEquatorial(cartesian);
|
||||
return skybrowser::cartesianToSpherical(equatorial);
|
||||
|
||||
}
|
||||
else {
|
||||
glm::dvec3 cartesian = skybrowser::localCameraToEquatorial(_cartesianPosition.value());
|
||||
return skybrowser::cartesianToSpherical(cartesian);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -358,15 +399,29 @@ namespace openspace {
|
||||
_lockedCoordinates = skybrowser::sphericalToCartesian(equatorialAim());
|
||||
}
|
||||
}
|
||||
void ScreenSpaceSkyTarget::setEquatorialAim(const glm::dvec2& aim)
|
||||
{
|
||||
glm::dvec3 cartesianAim = skybrowser::sphericalToCartesian(aim);
|
||||
glm::dvec3 localCamera = skybrowser::equatorialToLocalCamera(cartesianAim);
|
||||
if (_useRadiusAzimuthElevation) {
|
||||
// Keep the set radius
|
||||
glm::vec3 position = _raePosition.value().x * glm::vec3(localCamera);
|
||||
_raePosition = cartesianToRae(position);
|
||||
}
|
||||
else {
|
||||
_cartesianPosition = skybrowser::localCameraToScreenSpace3d(localCamera);
|
||||
}
|
||||
}
|
||||
void ScreenSpaceSkyTarget::setSkyBrowser(ScreenSpaceSkyBrowser* browser)
|
||||
{
|
||||
_browser = browser;
|
||||
_enabled.onChange([this]() {
|
||||
_browser->setEnabled(_enabled);
|
||||
});
|
||||
_scale.onChange([&]() {
|
||||
/* _scale.onChange([&]() {
|
||||
|
||||
setFovFromScale();
|
||||
_browser->setVerticalFov(_verticalFov);
|
||||
});
|
||||
}); */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,10 @@
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h> // For M_PI
|
||||
|
||||
|
||||
namespace openspace::skybrowser {
|
||||
|
||||
// Converts from spherical coordinates in the unit of degrees to cartesian coordianates
|
||||
glm::dvec3 sphericalToCartesian(const glm::dvec2& coords) {
|
||||
|
||||
glm::dvec2 coordsRadians = glm::radians(coords);
|
||||
@@ -24,7 +26,8 @@ namespace openspace::skybrowser {
|
||||
return cartesian;
|
||||
}
|
||||
|
||||
glm::dvec2 cartesianToSpherical(const glm::dvec3& coord) {
|
||||
// Converts from cartesian coordianates to spherical in the unit of degrees
|
||||
glm::dvec2 cartesianToSpherical(const glm::dvec3& coord) {
|
||||
// Equatorial coordinates RA = right ascension, Dec = declination
|
||||
double ra = atan2(coord.y, coord.x);
|
||||
double dec = atan2(coord.z, glm::sqrt((coord.x * coord.x) + (coord.y * coord.y)));
|
||||
@@ -36,26 +39,25 @@ namespace openspace::skybrowser {
|
||||
return glm::degrees(celestialCoords);
|
||||
}
|
||||
|
||||
glm::dvec3 galacticToEquatorial(const glm::dvec3& coords) {
|
||||
glm::dvec3 galacticToEquatorial(const glm::dvec3& coords) {
|
||||
return glm::transpose(conversionMatrix) * glm::normalize(coords);
|
||||
}
|
||||
|
||||
glm::dvec3 equatorialToGalactic(const glm::dvec3& coords) {
|
||||
glm::dvec3 equatorialToGalactic(const glm::dvec3& coords) {
|
||||
// On the unit sphere
|
||||
glm::dvec3 rGalactic = conversionMatrix * glm::normalize(coords);
|
||||
return rGalactic * CelestialSphereRadius;
|
||||
}
|
||||
|
||||
glm::dvec3 galacticToScreenSpace3d(const glm::dvec3& coords) {
|
||||
glm::dvec3 localCameraToScreenSpace3d(const glm::dvec3& coords) {
|
||||
|
||||
glm::dvec3 localCameraSpace = galacticToLocalCamera(coords);
|
||||
// Ensure that if the coord is behind the camera,
|
||||
// the converted coordinate will be there too
|
||||
double zCoord = localCameraSpace.z > 0 ? -ScreenSpaceZ : ScreenSpaceZ;
|
||||
double zCoord = coords.z > 0 ? -ScreenSpaceZ : ScreenSpaceZ;
|
||||
|
||||
// Calculate screen space coords x and y
|
||||
double tan_x = localCameraSpace.x / localCameraSpace.z;
|
||||
double tan_y = localCameraSpace.y / localCameraSpace.z;
|
||||
double tan_x = coords.x / coords.z;
|
||||
double tan_y = coords.y / coords.z;
|
||||
|
||||
glm::dvec3 screenSpace = glm::dvec3(zCoord * tan_x, zCoord * tan_y, zCoord);
|
||||
|
||||
@@ -79,6 +81,14 @@ namespace openspace::skybrowser {
|
||||
return skybrowser::galacticToEquatorial(galactic);
|
||||
}
|
||||
|
||||
glm::dvec3 equatorialToLocalCamera(const glm::dvec3& coords)
|
||||
{
|
||||
// Transform equatorial J2000 to galactic coord with infinite radius
|
||||
glm::dvec3 galactic = equatorialToGalactic(coords);
|
||||
glm::dvec3 localCamera = galacticToLocalCamera(galactic);
|
||||
return localCamera;
|
||||
}
|
||||
|
||||
glm::dvec3 galacticToLocalCamera(const glm::dvec3& coords) {
|
||||
// Transform vector to camera's local coordinate system
|
||||
glm::dvec3 camPos = global::navigationHandler->camera()->positionVec3();
|
||||
@@ -89,11 +99,12 @@ namespace openspace::skybrowser {
|
||||
return glm::normalize(viewDirectionLocal);
|
||||
}
|
||||
|
||||
glm::dvec3 equatorialToScreenSpace3d(const glm::dvec3& coords) {
|
||||
glm::dvec3 equatorialToScreenSpace3d(const glm::dvec3& coords) {
|
||||
// Transform equatorial J2000 to galactic coord with infinite radius
|
||||
glm::dvec3 galactic = equatorialToGalactic(coords);
|
||||
glm::dvec3 localCameraSpace = galacticToLocalCamera(coords);
|
||||
// Transform galactic coord to screen space
|
||||
return galacticToScreenSpace3d(galactic);
|
||||
return localCameraToScreenSpace3d(localCameraSpace);
|
||||
}
|
||||
|
||||
double cameraRoll() {
|
||||
@@ -186,6 +197,6 @@ namespace openspace::skybrowser {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -550,7 +550,7 @@ void ScreenSpaceRenderable::translate(glm::vec2 translation, glm::vec2 position)
|
||||
_cartesianPosition = translationMatrix * origin;
|
||||
}
|
||||
|
||||
void ScreenSpaceRenderable::setCartesianPosition(const glm::vec3& position)
|
||||
void ScreenSpaceRenderable::setPosition(const glm::vec3& position)
|
||||
{
|
||||
_cartesianPosition = position;
|
||||
}
|
||||
@@ -589,6 +589,16 @@ glm::mat4 ScreenSpaceRenderable::localRotationMatrix() {
|
||||
return rotation * glm::mat4(glm::quat(glm::vec3(pitch, yaw, roll)));
|
||||
}
|
||||
|
||||
glm::vec3 ScreenSpaceRenderable::raeToCartesian(const glm::vec3& rae) const
|
||||
{
|
||||
return sphericalToCartesian(raeToSpherical(rae));
|
||||
}
|
||||
|
||||
glm::vec3 ScreenSpaceRenderable::cartesianToRae(const glm::vec3& cartesian) const
|
||||
{
|
||||
return sphericalToRae(cartesianToSpherical(cartesian));
|
||||
}
|
||||
|
||||
glm::mat4 ScreenSpaceRenderable::translationMatrix() {
|
||||
glm::vec3 translation = _useRadiusAzimuthElevation ?
|
||||
sphericalToCartesian(raeToSpherical(_raePosition)) :
|
||||
|
||||
Reference in New Issue
Block a user