From f6a9bd187090049e807c8ff51e32d3d5647ea276 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Thu, 26 Feb 2015 17:26:41 -0800 Subject: [PATCH] REfining the naming and introducing an orientation offset --- examples/example/misc/sunLightExample.js | 10 ++++++---- libraries/model/src/model/Stage.cpp | 15 ++++++++++++++ libraries/model/src/model/Stage.h | 12 +++++++++++ .../src/SceneScriptingInterface.cpp | 20 +++++++++++-------- .../src/SceneScriptingInterface.h | 8 ++++---- 5 files changed, 49 insertions(+), 16 deletions(-) diff --git a/examples/example/misc/sunLightExample.js b/examples/example/misc/sunLightExample.js index 47fbb9761e..9c58d0bac3 100644 --- a/examples/example/misc/sunLightExample.js +++ b/examples/example/misc/sunLightExample.js @@ -13,9 +13,11 @@ var day = 0.0; var hour = 12.0; var longitude = -115.0; var latitude = -31.0; +var stageOrientation = Quat.fromPitchYawRollDegrees(0.0, 180.0, 0.0); -Scene.setDayTime(hour); -//Scene.setOriginLocation(longitude, latitude, 0.0); +Scene.setStageDayTime(hour); +Scene.setStageOrientation(stageOrientation); +Scene.setStageLocation(longitude, latitude, 0.0); function ticktack() { hour += 0.1; @@ -23,9 +25,9 @@ function ticktack() { if (hour > 24.0) { hour = 0.0; day++; - Scene.setYearTime(day); + Scene.setStageYearTime(day); } - Scene.setDayTime(hour); + Scene.setStageDayTime(hour); } Script.setInterval(ticktack, 41); diff --git a/libraries/model/src/model/Stage.cpp b/libraries/model/src/model/Stage.cpp index 8befec2ed3..d867056e8a 100644 --- a/libraries/model/src/model/Stage.cpp +++ b/libraries/model/src/model/Stage.cpp @@ -73,9 +73,19 @@ void EarthSunModel::updateSun() const { // sun direction is looking up toward Y axis at the specified sun lat, long Vec3d lssd = Vec3d(_worldToSurfaceMat * Vec4d(_sunDir.x, _sunDir.y, _sunDir.z, 0.0)); + + // apply surface rotation offset + glm::dquat dSurfOrient(_surfaceOrientation); + lssd = glm::rotate(dSurfOrient, lssd); + _surfaceSunDir = glm::normalize(Vec3(lssd.x, lssd.y, lssd.z)); } +void EarthSunModel::setSurfaceOrientation(const Quat& orientation) { + _surfaceOrientation = orientation; + invalidate(); +} + double moduloRange(double val, double minVal, double maxVal) { double range = maxVal - minVal; double rval = (val - minVal) / range; @@ -155,6 +165,11 @@ void SunSkyStage::setYearTime(unsigned int day) { invalidate(); } +void SunSkyStage::setOriginOrientation(const Quat& orientation) { + _earthSunModel.setSurfaceOrientation(orientation); + invalidate(); +} + void SunSkyStage::setOriginLocation(float longitude, float latitude, float altitude) { _earthSunModel.setLongitude(longitude); _earthSunModel.setLatitude(latitude); diff --git a/libraries/model/src/model/Stage.h b/libraries/model/src/model/Stage.h index f99d2c1648..762e2d9717 100644 --- a/libraries/model/src/model/Stage.h +++ b/libraries/model/src/model/Stage.h @@ -33,6 +33,10 @@ public: void setAltitude(float altitude); float getAltitude() const { return _altitude; } + + void setSurfaceOrientation(const Quat& orientation); + const Quat& getSurfaceOrientation() const { valid(); return _surfaceOrientation; } + const Vec3d& getSurfacePos() const { valid(); return _surfacePos; } const Mat4d& getSurfaceToWorldMat() const { valid(); return _surfaceToWorldMat; } @@ -67,6 +71,8 @@ protected: double _scale = 1000.0; //Km double _earthRadius = 6360.0; + Quat _surfaceOrientation; + double _longitude = 0.0; double _latitude = 0.0; double _altitude = 0.01; @@ -114,6 +120,12 @@ public: void setYearTime(unsigned int day); unsigned int getYearTime() const { return _yearTime; } + // Origin orientation used to modify the cardinal axis alignement used. + // THe default is north along +Z axis and west along +X axis. this orientation gets added + // to the transform stack producing the sun light direction. + void setOriginOrientation(const Quat& orientation); + const Quat& getOriginOrientation() const { return _earthSunModel.getSurfaceOrientation(); } + // Location used to define the sun & sky is a longitude and latitude [rad] and a earth surface altitude [km] void setOriginLocation(float longitude, float latitude, float surfaceAltitude); float getOriginLatitude() const { return _earthSunModel.getLatitude(); } diff --git a/libraries/script-engine/src/SceneScriptingInterface.cpp b/libraries/script-engine/src/SceneScriptingInterface.cpp index ff255a3e5e..9cac521225 100644 --- a/libraries/script-engine/src/SceneScriptingInterface.cpp +++ b/libraries/script-engine/src/SceneScriptingInterface.cpp @@ -13,10 +13,20 @@ #include "SceneScriptingInterface.h" - Q_INVOKABLE void setOriginGeoLocation(float longitude, float latitude, float altitude); -void SceneScriptingInterface::setOriginLocation(float longitude, float latitude, float altitude) { +void SceneScriptingInterface::setStageOrientation(const glm::quat& orientation) { + _skyStage->setOriginOrientation(orientation); +} +void SceneScriptingInterface::setStageLocation(float longitude, float latitude, float altitude) { _skyStage->setOriginLocation(longitude, latitude, altitude); } + +void SceneScriptingInterface::setStageDayTime(float hour) { + _skyStage->setDayTime(hour); +} +void SceneScriptingInterface::setStageYearTime(int day) { + _skyStage->setYearTime(day); +} + void SceneScriptingInterface::setSunColor(const glm::vec3& color) { _skyStage->setSunColor(color); } @@ -24,12 +34,6 @@ void SceneScriptingInterface::setSunIntensity(float intensity) { _skyStage->setSunIntensity(intensity); } -void SceneScriptingInterface::setDayTime(float hour) { - _skyStage->setDayTime(hour); -} -void SceneScriptingInterface::setYearTime(int day) { - _skyStage->setYearTime(day); -} model::SunSkyStagePointer SceneScriptingInterface::getSkyStage() const { return _skyStage; diff --git a/libraries/script-engine/src/SceneScriptingInterface.h b/libraries/script-engine/src/SceneScriptingInterface.h index 3fc909f9a0..8ae9424c95 100644 --- a/libraries/script-engine/src/SceneScriptingInterface.h +++ b/libraries/script-engine/src/SceneScriptingInterface.h @@ -23,14 +23,14 @@ class SceneScriptingInterface : public QObject, public Dependency { SINGLETON_DEPENDENCY public: - Q_INVOKABLE void setOriginLocation(float longitude, float latitude, float altitude); + Q_INVOKABLE void setStageOrientation(const glm::quat& orientation); + Q_INVOKABLE void setStageLocation(float longitude, float latitude, float altitude); + Q_INVOKABLE void setStageDayTime(float hour); + Q_INVOKABLE void setStageYearTime(int day); Q_INVOKABLE void setSunColor(const glm::vec3& color); Q_INVOKABLE void setSunIntensity(float intensity); - Q_INVOKABLE void setDayTime(float hour); - Q_INVOKABLE void setYearTime(int day); - model::SunSkyStagePointer getSkyStage() const; protected: