mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-08 20:50:19 -06:00
Update RenderableGlobe to use transformation from SceneGraphnNode and fix bug in SpiceRotation.
This commit is contained in:
@@ -3,6 +3,20 @@ return {
|
||||
{
|
||||
Name = "EarthBarycenter",
|
||||
Parent = "SolarSystemBarycenter",
|
||||
Transform = {
|
||||
Translation = {
|
||||
Type = "StaticEphemeris",
|
||||
Position = {0,0,0},
|
||||
},
|
||||
Rotation = {
|
||||
Type = "StaticRotation",
|
||||
EulerAngles = {0,0,0},
|
||||
},
|
||||
Scale = {
|
||||
Type = "StaticScale",
|
||||
Scale = 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
-- EarthTrail module
|
||||
{
|
||||
@@ -46,8 +60,6 @@ return {
|
||||
},
|
||||
Renderable = {
|
||||
Type = "RenderableGlobe",
|
||||
Frame = "IAU_EARTH",
|
||||
Body = "EARTH",
|
||||
Radii = {6378137.0, 6378137.0, 6356752.314245}, -- Earth's radii
|
||||
CameraMinHeight = 300,
|
||||
InteractionDepthBelowEllipsoid = 0, -- Useful when having negative height map values
|
||||
|
||||
@@ -13,6 +13,7 @@ function preInitialization()
|
||||
dofile(openspace.absPath('${SCRIPTS}/bind_keys.lua'))
|
||||
|
||||
-- Load Spice Kernels
|
||||
openspace.spice.loadKernel("${OPENSPACE_DATA}/spice/de430_1850-2150.bsp")
|
||||
|
||||
-- background
|
||||
-- SCLK kernels needs to be loaded before CK kernels (and generally first)
|
||||
|
||||
@@ -38,6 +38,8 @@ struct InitializeData {
|
||||
|
||||
struct UpdateData {
|
||||
glm::dvec3 position;
|
||||
glm::dmat3 rotation;
|
||||
double scale;
|
||||
double time;
|
||||
bool isTimeJump;
|
||||
double delta;
|
||||
|
||||
@@ -78,31 +78,15 @@ const glm::dmat3& SpiceRotation::matrix() const {
|
||||
void SpiceRotation::update(const UpdateData& data) {
|
||||
if (!_kernelsLoadedSuccessfully)
|
||||
return;
|
||||
|
||||
// TODO : Need to be checking for real if the frame is fixed since fixed frames
|
||||
// do not have CK coverage.
|
||||
bool sourceFrameIsFixed = _sourceFrame == "GALACTIC";
|
||||
bool destinationFrameIsFixed = _destinationFrame == "GALACTIC";
|
||||
|
||||
bool sourceHasCoverage =
|
||||
!_sourceFrame.empty() &&
|
||||
SpiceManager::ref().hasFrameId(_sourceFrame) &&
|
||||
(SpiceManager::ref().hasCkCoverage(_sourceFrame, data.time) ||
|
||||
sourceFrameIsFixed);
|
||||
bool destinationHasCoverage =
|
||||
!_destinationFrame.empty() &&
|
||||
SpiceManager::ref().hasFrameId(_destinationFrame) &&
|
||||
(SpiceManager::ref().hasCkCoverage(_destinationFrame, data.time) ||
|
||||
destinationFrameIsFixed);
|
||||
|
||||
if (sourceHasCoverage && destinationHasCoverage) {
|
||||
try {
|
||||
_rotationMatrix = SpiceManager::ref().positionTransformMatrix(
|
||||
_sourceFrame,
|
||||
_destinationFrame,
|
||||
data.time);
|
||||
}
|
||||
else {
|
||||
_rotationMatrix = glm::dmat3(1.0);
|
||||
catch (const ghoul::RuntimeError&) {
|
||||
// In case of missing coverage
|
||||
_rotationMatrix = glm::dmat3(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -155,15 +155,6 @@ namespace openspace {
|
||||
stats.startNewRecord();
|
||||
|
||||
int j2000s = Time::now().unsyncedJ2000Seconds();
|
||||
/*
|
||||
int lastJ2000s = stats.i.previous("time");
|
||||
if (j2000s == lastJ2000s) {
|
||||
stats.disable();
|
||||
}
|
||||
else {
|
||||
stats.enable();
|
||||
}
|
||||
*/
|
||||
|
||||
auto duration = std::chrono::system_clock::now().time_since_epoch();
|
||||
auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
|
||||
@@ -197,11 +188,9 @@ namespace openspace {
|
||||
_leftRoot->reverseBreadthFirst(renderJob);
|
||||
_rightRoot->reverseBreadthFirst(renderJob);
|
||||
|
||||
|
||||
if (_savedCamera != nullptr) {
|
||||
DebugRenderer::ref().renderCameraFrustum(data, *_savedCamera);
|
||||
}
|
||||
|
||||
|
||||
//LDEBUG("min distnace to camera: " << minDistToCamera);
|
||||
|
||||
@@ -242,24 +231,16 @@ namespace openspace {
|
||||
}
|
||||
|
||||
void ChunkedLodGlobe::update(const UpdateData& data) {
|
||||
_modelTransform =
|
||||
translate(dmat4(1), data.position) * // Translation
|
||||
dmat4(stateMatrix()); // Rotation
|
||||
glm::dmat4 translation = glm::translate(glm::dmat4(1.0), data.position);
|
||||
glm::dmat4 rotation = glm::dmat4(data.rotation);
|
||||
glm::dmat4 scaling = glm::scale(glm::dmat4(1.0), glm::dvec3(data.scale, data.scale, data.scale));
|
||||
|
||||
_modelTransform = translation * rotation * scaling;
|
||||
_inverseModelTransform = glm::inverse(_modelTransform);
|
||||
|
||||
_renderer->update();
|
||||
}
|
||||
|
||||
void ChunkedLodGlobe::setStateMatrix(const glm::dmat3& stateMatrix)
|
||||
{
|
||||
_stateMatrix = stateMatrix;
|
||||
}
|
||||
|
||||
const glm::dmat3& ChunkedLodGlobe::stateMatrix()
|
||||
{
|
||||
return _stateMatrix;
|
||||
}
|
||||
|
||||
const glm::dmat4& ChunkedLodGlobe::modelTransform() {
|
||||
return _modelTransform;
|
||||
}
|
||||
|
||||
@@ -76,16 +76,12 @@ namespace openspace {
|
||||
const ChunkNode& findChunkNode(const Geodetic2 location) const;
|
||||
ChunkNode& findChunkNode(const Geodetic2 location);
|
||||
|
||||
void setStateMatrix(const glm::dmat3& stateMatrix);
|
||||
|
||||
bool testIfCullable(const Chunk& chunk, const RenderData& renderData) const;
|
||||
int getDesiredLevel(const Chunk& chunk, const RenderData& renderData) const;
|
||||
|
||||
double minDistToCamera;
|
||||
|
||||
//Scalar globeRadius;
|
||||
const Ellipsoid& ellipsoid() const;
|
||||
const glm::dmat3& stateMatrix();
|
||||
const glm::dmat4& modelTransform();
|
||||
const glm::dmat4& inverseModelTransform();
|
||||
|
||||
@@ -145,7 +141,6 @@ namespace openspace {
|
||||
std::unique_ptr<ChunkLevelEvaluator> _chunkEvaluatorByDistance;
|
||||
|
||||
const Ellipsoid& _ellipsoid;
|
||||
glm::dmat3 _stateMatrix;
|
||||
glm::dmat4 _modelTransform;
|
||||
glm::dmat4 _inverseModelTransform;
|
||||
|
||||
|
||||
@@ -370,7 +370,6 @@ namespace openspace {
|
||||
Geodetic2 swCorner = chunk.surfacePatch().getCorner(Quad::SOUTH_WEST);
|
||||
auto patchSize = chunk.surfacePatch().size();
|
||||
|
||||
// TODO : Model transform should be fetched as a matrix directly.
|
||||
dmat4 modelTransform = chunk.owner()->modelTransform();
|
||||
dmat4 viewTransform = data.camera.combinedViewMatrix();
|
||||
mat4 modelViewTransform = mat4(viewTransform * modelTransform);
|
||||
|
||||
@@ -178,13 +178,6 @@ namespace openspace {
|
||||
}
|
||||
|
||||
void RenderableGlobe::update(const UpdateData& data) {
|
||||
|
||||
// set spice-orientation in accordance to timestamp
|
||||
_chunkedLodGlobe->setStateMatrix(
|
||||
SpiceManager::ref().positionTransformMatrix(_frame, "GALACTIC", data.time));
|
||||
// We currently do not consider rotation anywhere in the rendering.
|
||||
// @TODO Consider rotation everywhere in the rendering (culling, splitting, camera, etc)
|
||||
//_chunkedLodGlobe->setStateMatrix(glm::dmat3(1.0));
|
||||
_time = data.time;
|
||||
_distanceSwitch.update(data);
|
||||
|
||||
@@ -207,10 +200,6 @@ namespace openspace {
|
||||
return _ellipsoid;
|
||||
}
|
||||
|
||||
const glm::dmat3& RenderableGlobe::stateMatrix() {
|
||||
return _chunkedLodGlobe->stateMatrix();
|
||||
}
|
||||
|
||||
float RenderableGlobe::getHeight(glm::dvec3 position) {
|
||||
// Get the tile provider for the height map
|
||||
const auto& heightMapProviders = _tileProviderManager->getTileProviderGroup(LayeredTextures::HeightMaps).getActiveTileProviders();
|
||||
|
||||
@@ -112,13 +112,11 @@ public:
|
||||
|
||||
glm::dvec3 projectOnEllipsoid(glm::dvec3 position);
|
||||
const Ellipsoid& ellipsoid();
|
||||
const glm::dmat3& stateMatrix();
|
||||
float getHeight(glm::dvec3 position);
|
||||
float cameraMinHeight();
|
||||
double interactionDepthBelowEllipsoid();
|
||||
std::shared_ptr<ChunkedLodGlobe> chunkedLodGlobe();
|
||||
|
||||
|
||||
// Properties
|
||||
properties::BoolProperty _isEnabled;
|
||||
properties::FloatProperty lodScaleFactor;
|
||||
@@ -128,9 +126,6 @@ public:
|
||||
properties::BoolProperty _saveOrThrowCamera;
|
||||
properties::BoolProperty _resetTileProviders;
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
double _interactionDepthBelowEllipsoid;
|
||||
|
||||
@@ -142,7 +137,6 @@ private:
|
||||
std::shared_ptr<TileProviderManager> _tileProviderManager;
|
||||
std::shared_ptr<ChunkedLodGlobe> _chunkedLodGlobe;
|
||||
|
||||
|
||||
DistanceSwitch _distanceSwitch;
|
||||
|
||||
properties::FloatProperty _cameraMinHeight;
|
||||
|
||||
@@ -367,6 +367,8 @@ void RenderEngine::postSynchronizationPreDraw() {
|
||||
// update and evaluate the scene starting from the root node
|
||||
_sceneGraph->update({
|
||||
glm::dvec3(0),
|
||||
glm::dmat3(1),
|
||||
1,
|
||||
Time::ref().currentTime(),
|
||||
Time::ref().timeJumped(),
|
||||
Time::ref().deltaTime(),
|
||||
|
||||
@@ -209,7 +209,11 @@ bool Scene::loadSceneInternal(const std::string& sceneDescriptionFilePath) {
|
||||
// TODO need to check this; unnecessary? (ab)
|
||||
for (SceneGraphNode* node : _graph.nodes()) {
|
||||
try {
|
||||
node->update({glm::dvec3(0), Time::ref().currentTime() });
|
||||
node->update({
|
||||
glm::dvec3(0),
|
||||
glm::dmat3(1),
|
||||
1,
|
||||
Time::ref().currentTime() });
|
||||
}
|
||||
catch (const ghoul::RuntimeError& e) {
|
||||
LERRORC(e.component, e.message);
|
||||
|
||||
@@ -193,6 +193,18 @@ bool SceneGraphNode::deinitialize() {
|
||||
delete _renderable;
|
||||
_renderable = nullptr;
|
||||
}
|
||||
if (_ephemeris) {
|
||||
delete _ephemeris;
|
||||
_ephemeris = nullptr;
|
||||
}
|
||||
if (_rotation) {
|
||||
delete _rotation;
|
||||
_rotation = nullptr;
|
||||
}
|
||||
if (_scale) {
|
||||
delete _scale;
|
||||
_scale = nullptr;
|
||||
}
|
||||
|
||||
//delete _ephemeris;
|
||||
//_ephemeris = nullptr;
|
||||
@@ -213,21 +225,19 @@ bool SceneGraphNode::deinitialize() {
|
||||
}
|
||||
|
||||
void SceneGraphNode::update(const UpdateData& data) {
|
||||
UpdateData newUpdateData = data;
|
||||
|
||||
if (_ephemeris) {
|
||||
if (data.doPerformanceMeasurement) {
|
||||
glFinish();
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
|
||||
_ephemeris->update(newUpdateData);
|
||||
_ephemeris->update(data);
|
||||
|
||||
glFinish();
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
_performanceRecord.updateTimeEphemeris = (end - start).count();
|
||||
}
|
||||
else
|
||||
_ephemeris->update(newUpdateData);
|
||||
_ephemeris->update(data);
|
||||
}
|
||||
|
||||
if (_rotation) {
|
||||
@@ -235,14 +245,14 @@ void SceneGraphNode::update(const UpdateData& data) {
|
||||
glFinish();
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
|
||||
_rotation->update(newUpdateData);
|
||||
_rotation->update(data);
|
||||
|
||||
glFinish();
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
_performanceRecord.updateTimeEphemeris = (end - start).count();
|
||||
}
|
||||
else
|
||||
_rotation->update(newUpdateData);
|
||||
_rotation->update(data);
|
||||
}
|
||||
|
||||
if (_scale) {
|
||||
@@ -250,23 +260,25 @@ void SceneGraphNode::update(const UpdateData& data) {
|
||||
glFinish();
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
|
||||
_scale->update(newUpdateData);
|
||||
_scale->update(data);
|
||||
|
||||
glFinish();
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
_performanceRecord.updateTimeEphemeris = (end - start).count();
|
||||
}
|
||||
else
|
||||
_scale->update(newUpdateData);
|
||||
_scale->update(data);
|
||||
}
|
||||
UpdateData newUpdateData = data;
|
||||
|
||||
_worldRotationCached = calculateWorldRotation();
|
||||
_worldScaleCached = calculateWorldScale();
|
||||
|
||||
// Assumes _worldRotationCached and _worldScaleCached have been calculated for parent
|
||||
_worldPositionCached = calculateWorldPosition();
|
||||
|
||||
newUpdateData.position = worldPosition();
|
||||
newUpdateData.rotation = worldRotationMatrix();
|
||||
newUpdateData.scale = worldScale();
|
||||
|
||||
if (_renderable && _renderable->isReady()) {
|
||||
if (data.doPerformanceMeasurement) {
|
||||
|
||||
Reference in New Issue
Block a user