Turn the scaling transformation into providing three scaling factors (x, y, z)

Add NonUniformStaticScale class to provide independent scaling factors (closes #1151)
This commit is contained in:
Alexander Bock
2020-05-12 15:27:24 +02:00
parent 3b427bfd15
commit f7170a9506
17 changed files with 172 additions and 40 deletions
+2
View File
@@ -62,6 +62,7 @@ set(HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/rotation/luarotation.h
${CMAKE_CURRENT_SOURCE_DIR}/rotation/staticrotation.h
${CMAKE_CURRENT_SOURCE_DIR}/scale/luascale.h
${CMAKE_CURRENT_SOURCE_DIR}/scale/nonuniformstaticscale.h
${CMAKE_CURRENT_SOURCE_DIR}/scale/staticscale.h
${CMAKE_CURRENT_SOURCE_DIR}/scale/timedependentscale.h
${CMAKE_CURRENT_SOURCE_DIR}/timeframe/timeframeinterval.h
@@ -111,6 +112,7 @@ set(SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/rotation/luarotation.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rotation/staticrotation.cpp
${CMAKE_CURRENT_SOURCE_DIR}/scale/luascale.cpp
${CMAKE_CURRENT_SOURCE_DIR}/scale/nonuniformstaticscale.cpp
${CMAKE_CURRENT_SOURCE_DIR}/scale/staticscale.cpp
${CMAKE_CURRENT_SOURCE_DIR}/scale/timedependentscale.cpp
${CMAKE_CURRENT_SOURCE_DIR}/timeframe/timeframeinterval.cpp
+2
View File
@@ -59,6 +59,7 @@
#include <modules/base/rotation/staticrotation.h>
#include <modules/base/rotation/timelinerotation.h>
#include <modules/base/scale/luascale.h>
#include <modules/base/scale/nonuniformstaticscale.h>
#include <modules/base/scale/staticscale.h>
#include <modules/base/scale/timedependentscale.h>
#include <modules/base/translation/timelinetranslation.h>
@@ -155,6 +156,7 @@ void BaseModule::internalInitialize(const ghoul::Dictionary&) {
ghoul_assert(fScale, "Scale factory was not created");
fScale->registerClass<LuaScale>("LuaScale");
fScale->registerClass<NonUniformStaticScale>("NonUniformStaticScale");
fScale->registerClass<StaticScale>("StaticScale");
fScale->registerClass<TimeDependentScale>("TimeDependentScale");
+8 -4
View File
@@ -43,7 +43,7 @@ namespace {
"scaling factor for this transformation. The script needs to define a function "
"'scale' that takes the current simulation time in seconds past the J2000 epoch "
"as the first argument, the current wall time as milliseconds past the J2000 "
"epoch the second argument and computes the scaling factor."
"epoch the second argument and computes the three scaling factors."
};
} // namespace
@@ -86,7 +86,7 @@ LuaScale::LuaScale(const ghoul::Dictionary& dictionary) : LuaScale() {
_luaScriptFile = absPath(dictionary.value<std::string>(ScriptInfo.identifier));
}
double LuaScale::scaleValue(const UpdateData& data) const {
glm::dvec3 LuaScale::scaleValue(const UpdateData& data) const {
ghoul::lua::runScriptFile(_state, _luaScriptFile);
// Get the scaling function
@@ -97,7 +97,7 @@ double LuaScale::scaleValue(const UpdateData& data) const {
"LuaScale",
fmt::format("Script '{}' does not have a function 'scale'", _luaScriptFile)
);
return 0.0;
return glm::dvec3(1.0);
}
// First argument is the number of seconds past the J2000 epoch in ingame time
@@ -120,7 +120,11 @@ double LuaScale::scaleValue(const UpdateData& data) const {
);
}
return luaL_checknumber(_state, -1);
const double x = luaL_checknumber(_state, -1);
const double y = luaL_checknumber(_state, -2);
const double z = luaL_checknumber(_state, -3);
lua_settop(_state, 0);
return glm::dvec3(x, y, z);
}
} // namespace openspace
+1 -1
View File
@@ -41,7 +41,7 @@ public:
LuaScale();
LuaScale(const ghoul::Dictionary& dictionary);
double scaleValue(const UpdateData& data) const override;
glm::dvec3 scaleValue(const UpdateData& data) const override;
static documentation::Documentation Documentation();
@@ -0,0 +1,79 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2020 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <modules/base/scale/nonuniformstaticscale.h>
#include <openspace/documentation/documentation.h>
#include <openspace/documentation/verifier.h>
namespace {
constexpr openspace::properties::Property::PropertyInfo ScaleInfo = {
"Scale",
"Scale",
"These values are used as scaling factors for the scene graph node that this "
"transformation is attached to relative to its parent."
};
} // namespace
namespace openspace {
documentation::Documentation NonUniformStaticScale::Documentation() {
using namespace openspace::documentation;
return {
"Static Scaling",
"base_scale_static",
{
{
ScaleInfo.identifier,
new DoubleVector3Verifier,
Optional::No,
ScaleInfo.description
}
}
};
}
glm::dvec3 NonUniformStaticScale::scaleValue(const UpdateData&) const {
return _scaleValue;
}
NonUniformStaticScale::NonUniformStaticScale()
: _scaleValue(ScaleInfo, glm::dvec3(1.0), glm::dvec3(0.1), glm::dvec3(100.0))
{
addProperty(_scaleValue);
_scaleValue.onChange([this]() {
requireUpdate();
});
}
NonUniformStaticScale::NonUniformStaticScale(const ghoul::Dictionary& dictionary)
: NonUniformStaticScale()
{
documentation::testSpecificationAndThrow(Documentation(), dictionary, "StaticScale");
_scaleValue = dictionary.value<glm::dvec3>(ScaleInfo.identifier);
}
} // namespace openspace
@@ -0,0 +1,50 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2020 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_MODULE_BASE___NONUNIFORMSTATICSCALE___H__
#define __OPENSPACE_MODULE_BASE___NONUNIFORMSTATICSCALE___H__
#include <openspace/scene/scale.h>
#include <openspace/properties/vector/dvec3property.h>
namespace openspace {
namespace documentation { struct Documentation; }
class NonUniformStaticScale : public Scale {
public:
NonUniformStaticScale();
NonUniformStaticScale(const ghoul::Dictionary& dictionary);
glm::dvec3 scaleValue(const UpdateData& data) const override;
static documentation::Documentation Documentation();
private:
properties::DVec3Property _scaleValue;
};
} // namespace openspace
#endif // __OPENSPACE_MODULE_BASE___NONUNIFORMSTATICSCALE___H__
+2 -2
View File
@@ -54,8 +54,8 @@ documentation::Documentation StaticScale::Documentation() {
};
}
double StaticScale::scaleValue(const UpdateData&) const {
return _scaleValue;
glm::dvec3 StaticScale::scaleValue(const UpdateData&) const {
return glm::dvec3(_scaleValue);
}
StaticScale::StaticScale() : _scaleValue(ScaleInfo, 1.f, 0.1f, 100.f) {
+1 -1
View File
@@ -37,7 +37,7 @@ class StaticScale : public Scale {
public:
StaticScale();
StaticScale(const ghoul::Dictionary& dictionary);
double scaleValue(const UpdateData& data) const override;
glm::dvec3 scaleValue(const UpdateData& data) const override;
static documentation::Documentation Documentation();
+3 -3
View File
@@ -108,7 +108,7 @@ TimeDependentScale::TimeDependentScale(const ghoul::Dictionary& dictionary)
addProperty(_clampToPositive);
}
double TimeDependentScale::scaleValue(const UpdateData& data) const {
glm::dvec3 TimeDependentScale::scaleValue(const UpdateData& data) const {
if (_cachedReferenceDirty) {
_cachedReference = Time::convertTime(_referenceDate);
_cachedReferenceDirty = false;
@@ -118,10 +118,10 @@ double TimeDependentScale::scaleValue(const UpdateData& data) const {
const double dt = now - _cachedReference;
if (_clampToPositive) {
return std::max(0.0, dt) * _speed;
return glm::dvec3(std::max(0.0, dt) * _speed);
}
else {
return dt * _speed;
return glm::dvec3(dt * _speed);
}
}
+1 -1
View File
@@ -38,7 +38,7 @@ namespace documentation { struct Documentation; }
class TimeDependentScale : public Scale {
public:
TimeDependentScale(const ghoul::Dictionary& dictionary);
double scaleValue(const UpdateData& data) const override;
glm::dvec3 scaleValue(const UpdateData& data) const override;
static documentation::Documentation Documentation();
@@ -897,15 +897,13 @@ void RenderableGlobe::update(const UpdateData& data) {
}
setBoundingSphere(static_cast<float>(
_ellipsoid.maximumRadius() * data.modelTransform.scale
_ellipsoid.maximumRadius() * glm::compMax(data.modelTransform.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));
glm::dmat4 scaling = glm::scale(glm::dmat4(1.0), data.modelTransform.scale);
_cachedModelTransform = translation * rotation * scaling;
_cachedInverseModelTransform = glm::inverse(_cachedModelTransform);
@@ -1118,7 +1116,9 @@ void RenderableGlobe::renderChunks(const RenderData& data, RendererTasks&,
// Apply an extra scaling to the height if the object is scaled
_globalRenderer.program->setUniform(
"heightScale",
static_cast<float>(data.modelTransform.scale * data.camera.scaling())
static_cast<float>(
glm::compMax(data.modelTransform.scale) * data.camera.scaling()
)
);
}
@@ -1461,7 +1461,9 @@ void RenderableGlobe::renderChunkLocally(const Chunk& chunk, const RenderData& d
// Apply an extra scaling to the height if the object is scaled
program.setUniform(
"heightScale",
static_cast<float>(data.modelTransform.scale * data.camera.scaling())
static_cast<float>(
glm::compMax(data.modelTransform.scale) * data.camera.scaling()
)
);
}