Add a propery for nr simulation steps

This commit is contained in:
Emma Broman
2020-06-08 09:40:01 +02:00
parent 7d9455e4a8
commit 33dd0ff3a0
3 changed files with 23 additions and 3 deletions

View File

@@ -90,6 +90,13 @@ namespace {
"the direction of the camera position at the start of the path."
};
constexpr const openspace::properties::Property::PropertyInfo NumberSimulationStepsInfo = {
"NumberSimulationSteps",
"Number Simulation Steps",
"The number of steps used to simulate the camera motion, per frame. A larger number "
"increases the precision, at the cost of reduced efficiency."
};
} // namespace
namespace openspace::autonavigation {
@@ -103,6 +110,7 @@ AutoNavigationHandler::AutoNavigationHandler()
, _applyStopBehaviorWhenIdle(ApplyStopBehaviorWhenIdleInfo, false)
, _relevantNodeTags(RelevantNodeTagsInfo)
, _defaultPositionOffsetAngle(DefaultPositionOffsetAngleInfo, 30.0f, -90.0f, 90.0f)
, _nrSimulationSteps(NumberSimulationStepsInfo, 5, 2 , 10)
{
addPropertySubOwner(_atNodeNavigator);
@@ -134,6 +142,7 @@ AutoNavigationHandler::AutoNavigationHandler()
addProperty(_relevantNodeTags);
addProperty(_defaultPositionOffsetAngle);
addProperty(_nrSimulationSteps);
}
AutoNavigationHandler::~AutoNavigationHandler() {} // NOLINT
@@ -155,6 +164,10 @@ const std::vector<SceneGraphNode*>& AutoNavigationHandler::relevantNodes() const
return _relevantNodes;
}
int AutoNavigationHandler::nrSimulationStepsPerFrame() const {
return _nrSimulationSteps;
}
void AutoNavigationHandler::updateCamera(double deltaTime) {
ghoul_assert(camera() != nullptr, "Camera must not be nullptr");

View File

@@ -53,6 +53,7 @@ public:
const SceneGraphNode* anchor() const;
bool hasFinished() const;
const std::vector<SceneGraphNode*>& relevantNodes() const;
int nrSimulationStepsPerFrame() const;
void updateCamera(double deltaTime);
void createPath(PathSpecification& spec);
@@ -115,6 +116,7 @@ private:
properties::StringListProperty _relevantNodeTags;
properties::FloatProperty _defaultPositionOffsetAngle;
properties::IntProperty _nrSimulationSteps;
};
} // namespace openspace::autonavigation

View File

@@ -24,11 +24,13 @@
#include <modules/autonavigation/pathsegment.h>
#include <modules/autonavigation/autonavigationmodule.h>
#include <modules/autonavigation/avoidcollisioncurve.h>
#include <modules/autonavigation/pathcurves.h>
#include <modules/autonavigation/rotationinterpolator.h>
#include <modules/autonavigation/speedfunction.h>
#include <openspace/engine/globals.h>
#include <openspace/engine/moduleengine.h>
#include <openspace/scene/scenegraphnode.h>
#include <ghoul/logging/logmanager.h>
@@ -81,11 +83,14 @@ CameraPose PathSegment::traversePath(double dt) {
return _start.pose;
}
AutoNavigationModule* module = global::moduleEngine.module<AutoNavigationModule>();
AutoNavigationHandler& handler = module->AutoNavigationHandler();
const int nrSteps = handler.nrSimulationStepsPerFrame();
// compute displacement along the path during this frame
double displacement = 0.0;
int steps = 5; // TODO: make a property (larger value increases precision)
double h = dt / steps;
for (int i = 0; i < steps; ++i) {
double h = dt / nrSteps;
for (int i = 0; i < nrSteps; ++i) {
double t = _progressedTime + i * h;
double speed = 0.5 * (speedAtTime(t - 0.01*h) + speedAtTime(t + 0.01*h)); // average
displacement += h * speed;