From f637a301274df12929105b2cee82b1ad94de1407 Mon Sep 17 00:00:00 2001 From: Erik Broberg Date: Wed, 10 Aug 2016 12:55:44 -0400 Subject: [PATCH] Let RenderableModels have a model rotation property for debugging --- modules/base/rendering/renderablemodel.cpp | 19 ++++++++++++++++--- modules/base/rendering/renderablemodel.h | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index 66de07c2d7..4becb16e01 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -61,10 +61,11 @@ namespace { namespace openspace { -RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary) + RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary) : Renderable(dictionary) , _colorTexturePath("colorTexture", "Color Texture") , _performFade("performFading", "Perform Fading", false) + , _debugModelRotation("modelrotation", "Model Rotation", glm::vec3(0.f), glm::vec3(0.f), glm::vec3(360.f)) , _fading("fading", "Fade", 0) , _programObject(nullptr) , _texture(nullptr) @@ -91,10 +92,11 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary) _colorTexturePath = absPath(texturePath); addPropertySubOwner(_geometry); - addProperty(_colorTexturePath); _colorTexturePath.onChange(std::bind(&RenderableModel::loadTexture, this)); + addProperty(_debugModelRotation); + dictionary.getValue(keySource, _source); dictionary.getValue(keyDestination, _destination); if (dictionary.hasKeyAndValue(keyModelTransform)) @@ -198,13 +200,24 @@ void RenderableModel::render(const RenderData& data) { } + + // Calculate variables to be used as uniform variables in shader glm::dvec3 bodyPosition = data.positionVec3; + // debug rotation controlled from GUI + glm::mat4 unitMat4(1); + glm::vec3 debugEulerRot = glm::radians(_debugModelRotation.value()); + glm::mat4 rotX = glm::rotate(unitMat4, debugEulerRot.x, glm::vec3(1, 0, 0)); + glm::mat4 rotY = glm::rotate(unitMat4, debugEulerRot.y, glm::vec3(0, 1, 0)); + glm::mat4 rotZ = glm::rotate(unitMat4, debugEulerRot.z, glm::vec3(0, 0, 1)); + glm::dmat4 debugModelRotation = rotX * rotY * rotZ; + // 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::dmat4(_stateMatrix) * // Spice rotation + debugModelRotation; // debug model rotation controlled from GUI 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/base/rendering/renderablemodel.h b/modules/base/rendering/renderablemodel.h index 72eb92fd83..bf658aca9d 100644 --- a/modules/base/rendering/renderablemodel.h +++ b/modules/base/rendering/renderablemodel.h @@ -79,6 +79,7 @@ private: psc _sunPosition; properties::BoolProperty _performShading; + properties::Vec3Property _debugModelRotation; }; } // namespace openspace