From 628f8b479f1576a1e48dcbf4aa0bd96ee0cc7526 Mon Sep 17 00:00:00 2001 From: Kalle Bladin Date: Thu, 18 Aug 2016 16:59:51 -0400 Subject: [PATCH] Update updatestructures to have transform with translation, rotation and scale. --- data/scene/lodearth/lodearth.mod | 26 +++++-------------- include/openspace/util/updatestructures.h | 16 +++++++----- modules/base/rendering/renderablemodel.cpp | 8 +++--- modules/base/rendering/renderablepath.cpp | 2 +- modules/base/rendering/renderabletrail.cpp | 2 +- .../globebrowsing/chunk/chunkedlodglobe.cpp | 7 ++--- .../newhorizons/rendering/renderablefov.cpp | 5 ++-- .../rendering/renderablemodelprojection.cpp | 7 ++--- .../rendering/renderableplaneprojection.cpp | 2 +- src/scene/scenegraphnode.cpp | 6 ++--- 10 files changed, 37 insertions(+), 44 deletions(-) diff --git a/data/scene/lodearth/lodearth.mod b/data/scene/lodearth/lodearth.mod index 4df2ff724a..9e2fe6fa64 100644 --- a/data/scene/lodearth/lodearth.mod +++ b/data/scene/lodearth/lodearth.mod @@ -5,16 +5,13 @@ return { Parent = "SolarSystemBarycenter", Transform = { Translation = { - Type = "StaticEphemeris", - Position = {0,0,0}, - }, - Rotation = { - Type = "StaticRotation", - EulerAngles = {0,0,0}, - }, - Scale = { - Type = "StaticScale", - Scale = 1, + Type = "SpiceEphemeris", + Body = "EARTH", + Reference = "ECLIPJ2000", + Observer = "SUN", + Kernels = { + "${OPENSPACE_DATA}/spice/de430_1850-2150.bsp" + } }, }, }, @@ -39,15 +36,6 @@ return { Name = "LodEarth", Parent = "EarthBarycenter", Transform = { - Translation = { - Type = "SpiceEphemeris", - Body = "EARTH", - Reference = "ECLIPJ2000", - Observer = "SUN", - Kernels = { - "${OPENSPACE_DATA}/spice/de430_1850-2150.bsp" - } - }, Rotation = { Type = "SpiceRotation", SourceFrame = "IAU_EARTH", diff --git a/include/openspace/util/updatestructures.h b/include/openspace/util/updatestructures.h index 991841cdd8..44e8ff25e3 100644 --- a/include/openspace/util/updatestructures.h +++ b/include/openspace/util/updatestructures.h @@ -36,10 +36,14 @@ struct InitializeData { }; -struct UpdateData { - glm::dvec3 position; +struct TransformData { + glm::dvec3 translation; glm::dmat3 rotation; double scale; +}; + +struct UpdateData { + TransformData modelTransform; double time; bool isTimeJump; double delta; @@ -48,13 +52,11 @@ struct UpdateData { struct RenderData { const Camera& camera; - // psc position to be removed in favor of the double precision position - // Now both are here due to dependencies of the psc position + // psc position to be removed in favor of the double precision position defined in + // the translation in transform. psc position; bool doPerformanceMeasurement; - glm::dvec3 positionVec3; - glm::dmat3 rotation; - double scale; + TransformData modelTransform; }; struct RaycasterTask { diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index d0bfe8d734..376fe8cf81 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -209,13 +209,13 @@ void RenderableModel::render(const RenderData& data) { // Model transform and view transform needs to be in double precision glm::dmat4 modelTransform = - glm::translate(glm::dmat4(1.0), data.positionVec3) * // Translation - glm::dmat4(data.rotation) * // Spice rotation - glm::dmat4(glm::scale(glm::dmat4(1.0), glm::dvec3(data.scale))); + glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * // Translation + glm::dmat4(data.modelTransform.rotation) * // Spice rotation + glm::dmat4(glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale))); debugModelRotation; // debug model rotation controlled from GUI glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform; - glm::vec3 directionToSun = glm::normalize(_sunPos - data.positionVec3); + glm::vec3 directionToSun = glm::normalize(_sunPos - data.modelTransform.translation); glm::vec3 directionToSunViewSpace = glm::mat3(data.camera.combinedViewMatrix()) * directionToSun; _programObject->setUniform("transparency", _alpha); diff --git a/modules/base/rendering/renderablepath.cpp b/modules/base/rendering/renderablepath.cpp index d800facd73..29ced4620b 100644 --- a/modules/base/rendering/renderablepath.cpp +++ b/modules/base/rendering/renderablepath.cpp @@ -151,7 +151,7 @@ void RenderablePath::render(const RenderData& data) { _programObject->activate(); // Calculate variables to be used as uniform variables in shader - glm::dvec3 bodyPosition = data.positionVec3; + glm::dvec3 bodyPosition = data.modelTransform.translation; // Model transform and view transform needs to be in double precision glm::dmat4 modelTransform = diff --git a/modules/base/rendering/renderabletrail.cpp b/modules/base/rendering/renderabletrail.cpp index f93f3e2a0d..b6eac3f78a 100644 --- a/modules/base/rendering/renderabletrail.cpp +++ b/modules/base/rendering/renderabletrail.cpp @@ -162,7 +162,7 @@ void RenderableTrail::render(const RenderData& data) { //setPscUniforms(*_programObject.get(), data.camera, data.position); // Calculate variables to be used as uniform variables in shader - glm::dvec3 bodyPosition = data.positionVec3; + glm::dvec3 bodyPosition = data.modelTransform.translation; // Model transform and view transform needs to be in double precision glm::dmat4 modelTransform = diff --git a/modules/globebrowsing/chunk/chunkedlodglobe.cpp b/modules/globebrowsing/chunk/chunkedlodglobe.cpp index e0c8c3c6b5..611ef67444 100644 --- a/modules/globebrowsing/chunk/chunkedlodglobe.cpp +++ b/modules/globebrowsing/chunk/chunkedlodglobe.cpp @@ -231,9 +231,10 @@ namespace openspace { } void ChunkedLodGlobe::update(const UpdateData& data) { - 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)); + glm::dmat4 translation = glm::translate(glm::dmat4(1.0), data.modelTransform.translation); + glm::dmat4 rotation = glm::dmat4(data.modelTransform.rotation); + glm::dmat4 scaling = glm::scale(glm::dmat4(1.0), + glm::dvec3(data.modelTransform.scale, data.modelTransform.scale, data.modelTransform.scale)); _modelTransform = translation * rotation * scaling; _inverseModelTransform = glm::inverse(_modelTransform); diff --git a/modules/newhorizons/rendering/renderablefov.cpp b/modules/newhorizons/rendering/renderablefov.cpp index 67b8318ca4..cb11fcc4d5 100644 --- a/modules/newhorizons/rendering/renderablefov.cpp +++ b/modules/newhorizons/rendering/renderablefov.cpp @@ -559,8 +559,9 @@ void RenderableFov::render(const RenderData& data) { // setup the data to the shader // Model transform and view transform needs to be in double precision glm::dmat4 modelTransform = - glm::translate(glm::dmat4(1.0), data.positionVec3) * // Translation - glm::dmat4(data.rotation); + glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * // Translation + glm::dmat4(data.modelTransform.rotation) * + glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale)); glm::mat4 modelViewProjectionTransform = data.camera.projectionMatrix() * glm::mat4(data.camera.combinedViewMatrix() * diff --git a/modules/newhorizons/rendering/renderablemodelprojection.cpp b/modules/newhorizons/rendering/renderablemodelprojection.cpp index b203ee5f4a..09a8331dc3 100644 --- a/modules/newhorizons/rendering/renderablemodelprojection.cpp +++ b/modules/newhorizons/rendering/renderablemodelprojection.cpp @@ -176,12 +176,13 @@ void RenderableModelProjection::render(const RenderData& data) { _imageTimes.clear(); // Calculate variables to be used as uniform variables in shader - glm::dvec3 bodyPosition = data.positionVec3; + glm::dvec3 bodyPosition = data.modelTransform.translation; // Model transform and view transform needs to be in double precision glm::dmat4 modelTransform = - glm::translate(glm::dmat4(1.0), bodyPosition) * // Translation - glm::dmat4(_stateMatrix); // Rotation + glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * // Translation + glm::dmat4(data.modelTransform.rotation) * // Rotation + glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale)); // Scale glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform; glm::vec3 directionToSun = glm::normalize(_sunPosition.vec3() - glm::vec3(bodyPosition)); glm::vec3 directionToSunViewSpace = glm::mat3(data.camera.combinedViewMatrix()) * directionToSun; diff --git a/modules/newhorizons/rendering/renderableplaneprojection.cpp b/modules/newhorizons/rendering/renderableplaneprojection.cpp index 36a9669ea3..ff03f4e98d 100644 --- a/modules/newhorizons/rendering/renderableplaneprojection.cpp +++ b/modules/newhorizons/rendering/renderableplaneprojection.cpp @@ -135,7 +135,7 @@ void RenderablePlaneProjection::render(const RenderData& data) { _shader->activate(); glm::dmat4 modelTransform = - glm::translate(glm::dmat4(1.0), data.positionVec3) * // Translation + glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * // Translation glm::dmat4(_stateMatrix); glm::mat4 modelViewProjectionTransform = data.camera.projectionMatrix() * diff --git a/src/scene/scenegraphnode.cpp b/src/scene/scenegraphnode.cpp index 3120bd739d..5482dbddaa 100644 --- a/src/scene/scenegraphnode.cpp +++ b/src/scene/scenegraphnode.cpp @@ -276,9 +276,9 @@ void SceneGraphNode::update(const UpdateData& data) { // Assumes _worldRotationCached and _worldScaleCached have been calculated for parent _worldPositionCached = calculateWorldPosition(); - newUpdateData.position = worldPosition(); - newUpdateData.rotation = worldRotationMatrix(); - newUpdateData.scale = worldScale(); + newUpdateData.modelTransform.translation = worldPosition(); + newUpdateData.modelTransform.rotation = worldRotationMatrix(); + newUpdateData.modelTransform .scale = worldScale(); if (_renderable && _renderable->isReady()) { if (data.doPerformanceMeasurement) {