mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-03-13 17:09:05 -05:00
Make coordinate conversion functions more modular
This commit is contained in:
@@ -8,11 +8,10 @@
|
||||
|
||||
|
||||
namespace openspace::skybrowser {
|
||||
const bool SPHERICAL = true;
|
||||
const bool CARTESIAN = false;
|
||||
const double SCREENSPACE_Z = -2.1;
|
||||
const double RAD_TO_DEG = 180.0 / M_PI;
|
||||
const double DEG_TO_RAD = M_PI / 180.0;
|
||||
constexpr double infinity = std::numeric_limits<float>::max();
|
||||
|
||||
// Conversion matrix from this paper: https://arxiv.org/abs/1010.3773v1
|
||||
const glm::dmat3 conversionMatrix = glm::dmat3({
|
||||
@@ -25,8 +24,9 @@ namespace openspace::skybrowser {
|
||||
glm::dvec2 cartesianToSpherical(glm::dvec3 cartesianCoords);
|
||||
glm::dvec3 sphericalToCartesian(glm::dvec2 sphericalCoords);
|
||||
glm::dvec2 galacticCartesianToJ2000(glm::dvec3 rGal);
|
||||
glm::dvec3 J2000SphericalToGalacticCartesian(glm::dvec2 coords, double distance);
|
||||
glm::dvec3 J2000CartesianToGalacticCartesian(glm::dvec3 coords, double distance);
|
||||
glm::dvec3 galacticCartesianToCameraLocalCartesian(glm::dvec3 galCoords);
|
||||
glm::dvec3 J2000SphericalToGalacticCartesian(glm::dvec2 coords, double distance = infinity);
|
||||
glm::dvec3 J2000CartesianToGalacticCartesian(glm::dvec3 coords, double distance = infinity);
|
||||
// Convert J2000, spherical or Cartesian, to screen space
|
||||
glm::dvec3 J2000SphericalToScreenSpace(glm::dvec2 coords);
|
||||
glm::dvec3 J2000CartesianToScreenSpace(glm::dvec3 coords);
|
||||
|
||||
@@ -50,12 +50,7 @@ namespace openspace::skybrowser {
|
||||
|
||||
glm::dvec3 galacticToScreenSpace(glm::dvec3 imageCoordsGalacticCartesian) {
|
||||
|
||||
// Transform vector to camera's local coordinate system
|
||||
glm::dvec3 camPos = global::navigationHandler->camera()->positionVec3();
|
||||
glm::dvec3 camToCoordsDir = glm::normalize(imageCoordsGalacticCartesian - camPos);
|
||||
glm::dmat4 camMat = global::navigationHandler->camera()->viewRotationMatrix();
|
||||
glm::dvec3 viewDirectionLocal = camMat * glm::dvec4(camToCoordsDir, 1.0);
|
||||
viewDirectionLocal = glm::normalize(viewDirectionLocal);
|
||||
glm::dvec3 viewDirectionLocal = galacticCartesianToCameraLocalCartesian(imageCoordsGalacticCartesian);
|
||||
// Ensure that if the coord is behind the camera, the converted coord will be there too
|
||||
double zCoord = viewDirectionLocal.z > 0 ? -SCREENSPACE_Z : SCREENSPACE_Z;
|
||||
|
||||
@@ -69,18 +64,25 @@ namespace openspace::skybrowser {
|
||||
return imageCoordsScreenSpace;
|
||||
}
|
||||
|
||||
glm::dvec3 galacticCartesianToCameraLocalCartesian(glm::dvec3 galCoords) {
|
||||
// Transform vector to camera's local coordinate system
|
||||
glm::dvec3 camPos = global::navigationHandler->camera()->positionVec3();
|
||||
glm::dvec3 camToCoordsDir = glm::normalize(galCoords - camPos);
|
||||
glm::dmat4 camMat = global::navigationHandler->camera()->viewRotationMatrix();
|
||||
glm::dvec3 viewDirectionLocal = camMat * glm::dvec4(camToCoordsDir, 1.0);
|
||||
viewDirectionLocal = glm::normalize(viewDirectionLocal);
|
||||
return viewDirectionLocal;
|
||||
}
|
||||
|
||||
glm::dvec3 J2000CartesianToScreenSpace(glm::dvec3 coords) {
|
||||
// Transform equatorial J2000 to galactic coord with infinite radius
|
||||
constexpr double infinity = std::numeric_limits<float>::max();
|
||||
// Transform equatorial J2000 to galactic coord with infinite radius
|
||||
glm::dvec3 imageCoordsGalacticCartesian = J2000CartesianToGalacticCartesian(coords, infinity);
|
||||
// Transform galactic coord to screen space
|
||||
return galacticToScreenSpace(imageCoordsGalacticCartesian);
|
||||
}
|
||||
|
||||
glm::dvec3 J2000SphericalToScreenSpace(glm::dvec2 coords) {
|
||||
|
||||
glm::dvec3 J2000SphericalToScreenSpace(glm::dvec2 coords) {
|
||||
// Transform equatorial J2000 to galactic coord with infinite radius
|
||||
constexpr double infinity = std::numeric_limits<float>::max();
|
||||
glm::dvec3 imageCoordsGalacticCartesian = J2000SphericalToGalacticCartesian(coords, infinity);
|
||||
// Transform galactic coord to screen space
|
||||
return galacticToScreenSpace(imageCoordsGalacticCartesian);
|
||||
|
||||
Reference in New Issue
Block a user