Replace unused system rotation computation with the one that is actually used

This commit is contained in:
Emma Broman
2020-10-15 16:03:38 +02:00
parent 6b25489819
commit 11425dfdb7
3 changed files with 34 additions and 70 deletions

View File

@@ -24,6 +24,7 @@
#include <modules/exoplanets/exoplanetshelper.h>
#include <openspace/util/spicemanager.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/fmt.h>
#include <ghoul/logging/logmanager.h>
@@ -137,44 +138,41 @@ glm::dmat4 computeOrbitPlaneRotationMatrix(float i, float bigom, float omega) {
return orbitPlaneRotation;
}
// Rotate the original coordinate system (where x is pointing to First Point of Aries)
// so that x is pointing from star to the sun.
// Modified from "http://www.opengl-tutorial.org/intermediate-tutorials/
// tutorial-17-quaternions/ #how-do-i-find-the-rotation-between-2-vectors"
glm::dmat3 exoplanetSystemRotation(glm::dvec3 start, glm::dvec3 end) {
glm::quat rotationQuat;
glm::dvec3 rotationAxis;
const float cosTheta = static_cast<float>(glm::dot(start, end));
constexpr float Epsilon = 1E-3f;
glm::dmat3 computeSystemRotation(glm::dvec3 starPosition) {
const glm::dvec3 sunPosition = glm::dvec3(0.0, 0.0, 0.0);
const glm::dvec3 starToSunVec = glm::normalize(sunPosition - starPosition);
const glm::dvec3 galacticNorth = glm::dvec3(0.0, 0.0, 1.0);
if (cosTheta < -1.f + Epsilon) {
// special case when vectors in opposite directions:
// there is no "ideal" rotation axis
// So guess one; any will do as long as it's perpendicular to start vector
rotationAxis = glm::cross(glm::dvec3(0.0, 0.0, 1.0), start);
if (glm::length2(rotationAxis) < 0.01f) {
// bad luck, they were parallel, try again!
rotationAxis = glm::cross(glm::dvec3(1.0, 0.0, 0.0), start);
}
const glm::dmat3 galacticToCelestialMatrix =
SpiceManager::ref().positionTransformMatrix("GALACTIC", "J2000", 0.0);
rotationAxis = glm::normalize(rotationAxis);
rotationQuat = glm::quat(glm::radians(180.f), rotationAxis);
return glm::dmat3(glm::toMat4(rotationQuat));
}
rotationAxis = glm::cross(start, end);
const float s = sqrt((1.f + cosTheta) * 2.f);
const float invs = 1.f / s;
rotationQuat = glm::quat(
s * 0.5f,
static_cast<float>(rotationAxis.x * invs),
static_cast<float>(rotationAxis.y * invs),
static_cast<float>(rotationAxis.z * invs)
const glm::dvec3 celestialNorth = glm::normalize(
galacticToCelestialMatrix * galacticNorth
);
return glm::dmat3(glm::toMat4(rotationQuat));
// Earth's north vector projected onto the skyplane, the plane perpendicular to the
// viewing vector (starToSunVec)
const float celestialAngle = static_cast<float>(glm::dot(
celestialNorth,
starToSunVec
));
glm::dvec3 northProjected = glm::normalize(
celestialNorth - (celestialAngle / glm::length(starToSunVec)) * starToSunVec
);
const glm::dvec3 beta = glm::normalize(glm::cross(starToSunVec, northProjected));
return glm::dmat3(
northProjected.x,
northProjected.y,
northProjected.z,
beta.x,
beta.y,
beta.z,
starToSunVec.x,
starToSunVec.y,
starToSunVec.z
);
}
std::string createIdentifier(std::string name) {

View File

@@ -82,7 +82,7 @@ glm::dmat4 computeOrbitPlaneRotationMatrix(float i, float bigom, float omega);
// Rotate the original coordinate system (where x is pointing to First Point of Aries)
// so that x is pointing from star to the sun.
glm::dmat3 exoplanetSystemRotation(glm::dvec3 start, glm::dvec3 end);
glm::dmat3 computeSystemRotation(glm::dvec3 starPosition);
// Create an identifier without whitespaces
std::string createIdentifier(std::string name);

View File

@@ -29,7 +29,6 @@
#include <openspace/scene/scenegraphnode.h>
#include <openspace/scripting/scriptengine.h>
#include <openspace/util/distanceconstants.h>
#include <openspace/util/spicemanager.h>
#include <openspace/util/timeconversion.h>
#include <openspace/util/timemanager.h>
#include <ghoul/filesystem/filesystem.h>
@@ -146,40 +145,7 @@ void createExoplanetSystem(std::string_view starName) {
p.positionZ * distanceconstants::Parsec
);
const glm::dvec3 sunPosition = glm::dvec3(0.0, 0.0, 0.0);
const glm::dvec3 starToSunVec = glm::normalize(sunPosition - starPosition);
const glm::dvec3 galacticNorth = glm::dvec3(0.0, 0.0, 1.0);
const glm::dmat3 galaxticToCelestialMatrix =
SpiceManager::ref().positionTransformMatrix("GALACTIC", "J2000", 0.0);
const glm::dvec3 celestialNorth = glm::normalize(
galaxticToCelestialMatrix * galacticNorth
);
// Earth's north vector projected onto the skyplane, the plane perpendicular to the
// viewing vector (starToSunVec)
const float celestialAngle = static_cast<float>(glm::dot(
celestialNorth,
starToSunVec
));
glm::dvec3 northProjected = glm::normalize(
celestialNorth - (celestialAngle / glm::length(starToSunVec)) * starToSunVec
);
const glm::dvec3 beta = glm::normalize(glm::cross(starToSunVec, northProjected));
const glm::dmat3 exoplanetSystemRotation = glm::dmat3(
northProjected.x,
northProjected.y,
northProjected.z,
beta.x,
beta.y,
beta.z,
starToSunVec.x,
starToSunVec.y,
starToSunVec.z
);
const glm::dmat3 exoplanetSystemRotation = computeSystemRotation(starPosition);
// Star renderable globe, if we have a radius and bv color index
std::string starGlobeRenderableString;