Just a little more

This commit is contained in:
Emma Broman
2021-06-08 11:14:06 +02:00
parent d96bbda721
commit 97e184a978
12 changed files with 32 additions and 46 deletions

View File

@@ -45,6 +45,7 @@ namespace {
"DefaultCurveOption",
"Default Curve Option",
"The defualt curve type chosen when generating a path, if none is specified"
// TODO: right now there is no way to specify a type for a single path
};
constexpr openspace::properties::Property::PropertyInfo IncludeRollInfo = {
@@ -64,7 +65,7 @@ namespace {
{
"ApplyStopBehaviorWhenIdle",
"Apply Stop Behavior When Idle",
"If enabled, the camera is controlled using the set stop behavior when"
"If enabled, the camera is controlled using the set stop behavior when "
"no path is playing"
};
@@ -99,9 +100,9 @@ AutoNavigationHandler::AutoNavigationHandler()
, _orbitSpeedFactor(OrbitSpeedFactorInfo, 0.5, 0.0, 20.0)
{
_defaultCurveOption.addOptions({
{ CurveType::AvoidCollision, "AvoidCollision" },
{ CurveType::Linear, "Linear" },
{ CurveType::ZoomOutOverview, "ZoomOutOverview"}
{ Path::CurveType::AvoidCollision, "AvoidCollision" },
{ Path::CurveType::Linear, "Linear" },
{ Path::CurveType::ZoomOutOverview, "ZoomOutOverview"}
});
addProperty(_defaultCurveOption);
@@ -196,9 +197,6 @@ void AutoNavigationHandler::updateCamera(double deltaTime) {
void AutoNavigationHandler::createPath(PathInstruction& instruction) {
clearPath();
// TODO: Improve how curve types are handled
const int curveType = _defaultCurveOption;
std::vector<Waypoint> waypoints = instruction.waypoints();
Waypoint waypointToAdd;
@@ -211,10 +209,13 @@ void AutoNavigationHandler::createPath(PathInstruction& instruction) {
waypointToAdd = waypoints[0];
}
// TODO: Improve how curve types are handled
const int curveType = _defaultCurveOption;
_currentPath = std::make_unique<Path>(
instruction.startPoint(),
waypointToAdd,
CurveType(curveType),
Path::CurveType(curveType),
instruction.duration()
);

View File

@@ -37,8 +37,7 @@ namespace openspace {
namespace openspace::autonavigation {
//struct Waypoint;
struct PathInstruction;
class PathInstruction;
class AutoNavigationHandler : public properties::PropertyOwner {
public:
@@ -87,8 +86,6 @@ private:
properties::FloatProperty _speedScale;
properties::FloatProperty _orbitSpeedFactor;
// for testing pause behaviors.
// TODO: remove later, if it causes problems with regular navigation
properties::BoolProperty _applyStopBehaviorWhenIdle;
properties::OptionProperty _stopBehavior;
};

View File

@@ -55,12 +55,10 @@ AutoNavigationModule::AutoNavigationModule()
: OpenSpaceModule(Name)
, _minValidBoundingSphere(MinBoundingSphereInfo, 10.0, 1.0, 3e10)
, _relevantNodeTags(RelevantNodeTagsInfo)
{
addPropertySubOwner(_autoNavigationHandler);
addProperty(_minValidBoundingSphere);
// Add the relevant tags
_relevantNodeTags = std::vector<std::string>{
"planet_solarSystem",
"moon_solarSystem"

View File

@@ -40,12 +40,11 @@
namespace {
constexpr const char* _loggerCat = "AutoNavigation";
constexpr const double Epsilon = 1e-12;
} // namespace
namespace openspace::autonavigation::luascriptfunctions {
const double Epsilon = 1e-12;
int isFlying(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::isFlying");

View File

@@ -39,11 +39,10 @@
namespace {
constexpr const char* _loggerCat = "AvoidCollisionCurve";
const double CloseToNodeThresholdFactor = 5.0;
const double AvoidCollisionDistanceFactor = 3.0;
const double CollisionBufferSizeFactor = 1.0;
const int MaxAvoidCollisionSteps = 10;
constexpr const double CloseToNodeThresholdFactor = 5.0;
constexpr const double AvoidCollisionDistanceFactor = 3.0;
constexpr const double CollisionBufferSizeFactor = 1.0;
constexpr const int MaxAvoidCollisionSteps = 10;
} // namespace
namespace openspace::autonavigation {

View File

@@ -33,6 +33,12 @@ namespace openspace::autonavigation {
class Path {
public:
enum CurveType {
AvoidCollision,
Linear,
ZoomOutOverview
};
Path(Waypoint start, Waypoint end, CurveType type,
std::optional<double> duration = std::nullopt);

View File

@@ -34,7 +34,6 @@
namespace {
constexpr const char* _loggerCat = "PathCurve";
const double Epsilon = 1E-7;
} // namespace
namespace openspace::autonavigation {
@@ -56,7 +55,7 @@ glm::dvec3 PathCurve::positionAt(double relativeLength) {
// Input s is a length value, in the range [0, _length]
// Returns curve parameter in range [0, 1]
double PathCurve::curveParameter(double s) {
if (s <= Epsilon) return 0.0;
if (s <= 0.0) return 0.0;
if (s >= _totalLength) return 1.0;
unsigned int segmentIndex;

View File

@@ -31,12 +31,6 @@
namespace openspace::autonavigation {
enum CurveType {
AvoidCollision,
Linear,
ZoomOutOverview
};
class PathCurve {
public:
virtual ~PathCurve() = 0;

View File

@@ -77,6 +77,8 @@ namespace {
namespace openspace::autonavigation {
using NavigationState = interaction::NavigationHandler::NavigationState;
documentation::Documentation PathInstruction::Documentation() {
return codegen::doc<Parameters>("autonavigation_pathinstruction");
}

View File

@@ -26,15 +26,12 @@
#define __OPENSPACE_MODULE___PATHINSTRUCTION___H__
#include <modules/autonavigation/waypoint.h>
#include <openspace/interaction/navigationhandler.h>
#include <optional>
namespace openspace::autonavigation {
class PathInstruction {
public:
using NavigationState = interaction::NavigationHandler::NavigationState;
PathInstruction(const ghoul::Dictionary& dictionary);
Waypoint startPoint() const;

View File

@@ -27,7 +27,7 @@
namespace openspace::autonavigation {
// The speed function describing the shape of the speed curve. Values in [0,1].
// The speed function describing the shape of the speed curve. Values in [0,1]
class SpeedFunction {
public:
enum class Type {

View File

@@ -45,24 +45,27 @@ Waypoint::Waypoint(const glm::dvec3& pos, const glm::dquat& rot, const std::stri
const SceneGraphNode* node = sceneGraphNode(nodeIdentifier);
if (!node) {
LERROR(fmt::format("Could not find node '{}'.", nodeIdentifier));
LERROR(fmt::format("Could not find node '{}'", nodeIdentifier));
return;
}
validBoundingSphere = findValidBoundingSphere(node);
}
Waypoint::Waypoint(const NavigationState& ns) {
// OBS! The following code is exactly the same as used in
// OBS! The following code to get the position and rotation is exactly the same as in
// NavigationHandler::applyNavigationState. Should probably be made into a function.
// TODO: make that function
const SceneGraphNode* referenceFrame = sceneGraphNode(ns.referenceFrame);
const SceneGraphNode* anchorNode = sceneGraphNode(ns.anchor); // The anchor is also the target
const SceneGraphNode* anchorNode = sceneGraphNode(ns.anchor);
if (!anchorNode) {
LERROR(fmt::format("Could not find node '{}' to target.", ns.anchor));
LERROR(fmt::format("Could not find node '{}' to target", ns.anchor));
return;
}
nodeIdentifier = ns.anchor;
validBoundingSphere = findValidBoundingSphere(anchorNode);
const glm::dvec3 anchorWorldPosition = anchorNode->worldPosition();
const glm::dmat3 referenceFrameTransform = referenceFrame->worldRotationMatrix();
@@ -87,15 +90,6 @@ Waypoint::Waypoint(const NavigationState& ns) {
glm::dquat yawRotation = glm::angleAxis(ns.yaw, glm::dvec3(0.f, -1.f, 0.f));
pose.rotation = neutralCameraRotation * yawRotation * pitchRotation;
nodeIdentifier = ns.anchor;
const SceneGraphNode* node = sceneGraphNode(nodeIdentifier);
if (!node) {
LERROR(fmt::format("Could not find node '{}'.", nodeIdentifier));
return;
}
validBoundingSphere = findValidBoundingSphere(node);
}
glm::dvec3 Waypoint::position() const {