mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-03-11 07:48:37 -05:00
Add a propery for nr simulation steps
This commit is contained in:
@@ -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");
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user