Enable Translation classes to signal when settings have changed substantially

RenderableTrail listens to those changes and recomputes the trail if Translation settings have changed
Minor GUI improvements
Remove try/catch block from SpiceRotation
Update Ghoul reference
This commit is contained in:
Alexander Bock
2016-11-26 14:45:09 +01:00
parent c199d38aac
commit d4145ede0c
10 changed files with 47 additions and 21 deletions

View File

@@ -46,7 +46,16 @@ public:
glm::dvec3 position(double time);
// Registers a callback that gets called when a significant change has been made that
// invalidates potentially stored points, for example in trails
void onParameterChange(std::function<void()> callback);
static openspace::Documentation Documentation();
protected:
void notifyObservers();
std::function<void()> _onParameterChangeCallback;
};
} // namespace openspace

View File

@@ -349,7 +349,7 @@ void RenderablePlanet::render(const RenderData& data) {
glm::dmat4 rot = glm::rotate(glm::dmat4(1.0), M_PI_2, glm::dvec3(1, 0, 0));
glm::dmat4 roty = glm::rotate(glm::dmat4(1.0), M_PI_2, glm::dvec3(0, -1, 0));
//glm::dmat4 rotProp = glm::rotate(glm::dmat4(1.0), glm::radians(static_cast<double>(_rotation)), glm::dvec3(0, 1, 0));
modelTransform = modelTransform * rot /** roty*/ /** rotProp*/;
modelTransform = modelTransform * rot * roty /** rotProp*/;
glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform;

View File

@@ -143,6 +143,7 @@ RenderableTrail::RenderableTrail(const ghoul::Dictionary& dictionary)
_translation = std::unique_ptr<Translation>(Translation::createFromDictionary(
dictionary.value<ghoul::Dictionary>(KeyTranslation)
));
addPropertySubOwner(_translation.get());
_lineColor = dictionary.value<glm::vec3>(KeyColor);
addProperty(_lineColor);

View File

@@ -131,7 +131,7 @@ openspace::Documentation RenderableTrailOrbit::Documentation() {
RenderableTrailOrbit::RenderableTrailOrbit(const ghoul::Dictionary& dictionary)
: RenderableTrail(dictionary)
, _period("period", "Period in days", 0.0, 0.0, 1e9)
, _resolution("resoluion", "Number of Samples along Orbit", 10000, 1, 1e6)
, _resolution("resolution", "Number of Samples along Orbit", 10000, 1, 1e6)
, _needsFullSweep(true)
, _indexBufferDirty(true)
{
@@ -141,6 +141,10 @@ RenderableTrailOrbit::RenderableTrailOrbit(const ghoul::Dictionary& dictionary)
"RenderableTrailOrbit"
);
_translation->onParameterChange([this](){
_needsFullSweep = true;
});
// Period is in days
using namespace std::chrono;
int factor = duration_cast<seconds>(hours(24)).count();
@@ -180,12 +184,6 @@ void RenderableTrailOrbit::update(const UpdateData& data) {
// 2. Update floating position
// 3. Determine which parts of the array to upload and upload the data
// Early bailout when we don't move in time
if (data.timePaused || data.delta == 0.0) {
return;
}
// 1
// Update the trails; the report contains whether any of the other values has been
// touched and if so, how many

View File

@@ -140,6 +140,10 @@ RenderableTrailTrajectory::RenderableTrailTrajectory(const ghoul::Dictionary& di
"RenderableTrailTrajectory"
);
_translation->onParameterChange([this]() {
_needsFullSweep = true;
});
_startTime = dictionary.value<std::string>(KeyStartTime);
_startTime.onChange([this] { _needsFullSweep = true; });
addProperty(_startTime);

View File

@@ -116,17 +116,11 @@ SpiceRotation::SpiceRotation(const ghoul::Dictionary& dictionary)
}
void SpiceRotation::update(const UpdateData& data) {
try {
_matrix = SpiceManager::ref().positionTransformMatrix(
_sourceFrame,
_destinationFrame,
data.time
);
}
catch (const ghoul::RuntimeError&) {
// In case of missing coverage
_matrix = glm::dmat3(1);
}
_matrix = SpiceManager::ref().positionTransformMatrix(
_sourceFrame,
_destinationFrame,
data.time
);
}
} // namespace openspace

View File

@@ -144,8 +144,18 @@ SpiceTranslation::SpiceTranslation(const ghoul::Dictionary& dictionary)
}
}
auto update = [this](){
notifyObservers();
};
_target.onChange(update);
addProperty(_target);
_origin.onChange(update);
addProperty(_origin);
_frame.onChange(update);
addProperty(_frame);
}
glm::dvec3 SpiceTranslation::position() const {

View File

@@ -74,6 +74,7 @@ void GuiPropertyComponent::renderPropertyOwner(properties::PropertyOwner* owner)
return;
}
int nThisProperty = nVisibleProperties(owner->properties(), _visibility);
ImGui::PushID(owner->name().c_str());
const auto& subOwners = owner->propertySubOwners();
for (properties::PropertyOwner* subOwner : subOwners) {
@@ -82,7 +83,7 @@ void GuiPropertyComponent::renderPropertyOwner(properties::PropertyOwner* owner)
if (count == 0) {
continue;
}
if (subOwners.size() == 1) {
if (subOwners.size() == 1 && (nThisProperty == 0)) {
renderPropertyOwner(subOwner);
}
else {

View File

@@ -97,5 +97,14 @@ glm::dvec3 Translation::position(double time) {
return position();
}
void Translation::notifyObservers() {
if (_onParameterChangeCallback) {
_onParameterChangeCallback();
}
}
void Translation::onParameterChange(std::function<void()> callback) {
_onParameterChangeCallback = std::move(callback);
}
} // namespace openspace