Some more cleanup

This commit is contained in:
Emma Broman
2021-06-07 11:31:26 +02:00
parent 39c8f8283f
commit 50397cdafe
9 changed files with 57 additions and 101 deletions

View File

@@ -37,8 +37,6 @@
namespace {
constexpr const char* _loggerCat = "AtNodeNavigator";
const double Epsilon = 1E-7;
constexpr const openspace::properties::Property::PropertyInfo OrbitSpeedFactorInfo = {
"OrbitSpeedFactor",
"Orbit Speed Factor",
@@ -58,7 +56,7 @@ AtNodeNavigator::AtNodeNavigator()
AtNodeNavigator::~AtNodeNavigator() {} // NOLINT
const AtNodeNavigator::Behavior AtNodeNavigator::behavior() const {
AtNodeNavigator::Behavior AtNodeNavigator::behavior() const {
return _behavior;
}

View File

@@ -45,7 +45,7 @@ public:
AtNodeNavigator();
~AtNodeNavigator();
const Behavior behavior() const;
Behavior behavior() const;
void setBehavior(Behavior behavior);
void updateCamera(double deltaTime);

View File

@@ -45,6 +45,10 @@ namespace openspace::autonavigation::helpers {
return glm::normalize(glm::inverse(glm::quat_cast(lookAtMat)));
}
glm::dvec3 viewDirection(const glm::dquat& q) {
return glm::normalize(q * glm::dvec3(0.0, 0.0, -1.0));
};
/*
* Calculate the intersection of a line and a sphere
* The line segment is defined from p1 to p2

View File

@@ -40,6 +40,8 @@ namespace openspace::autonavigation::helpers {
glm::dquat lookAtQuaternion(glm::dvec3 eye, glm::dvec3 center, glm::dvec3 up);
glm::dvec3 viewDirection(const glm::dquat& q);
bool lineSphereIntersection(glm::dvec3 linePoint1, glm::dvec3 linePoint2,
glm::dvec3 sphereCenter, double spehereRadius, glm::dvec3& intersectionPoint);

View File

@@ -38,7 +38,6 @@
namespace {
constexpr const char* _loggerCat = "Path";
const double Epsilon = 1E-7;
} // namespace
namespace openspace::autonavigation {
@@ -47,7 +46,36 @@ Path::Path(Waypoint start, Waypoint end, CurveType type,
std::optional<double> duration)
: _start(start), _end(end), _curveType(type)
{
initializePath();
switch (_curveType) {
case CurveType::AvoidCollision:
_curve = std::make_unique<AvoidCollisionCurve>(_start, _end);
_rotationInterpolator = std::make_unique<EasedSlerpInterpolator>(
_start.rotation(),
_end.rotation()
);
break;
case CurveType::Linear:
_curve = std::make_unique<LinearCurve>(_start, _end);
_rotationInterpolator = std::make_unique<EasedSlerpInterpolator>(
_start.rotation(),
_end.rotation()
);
break;
case CurveType::ZoomOutOverview:
_curve = std::make_unique<ZoomOutOverviewCurve>(_start, _end);
_rotationInterpolator = std::make_unique<LookAtInterpolator>(
_start.rotation(),
_end.rotation(),
_start.node()->worldPosition(),
_end.node()->worldPosition(),
_curve.get()
);
break;
default:
LERROR("Could not create curve. Type does not exist!");
throw ghoul::MissingCaseException();
return;
}
_speedFunction = SpeedFunction(SpeedFunction::Type::DampenedQuintic);
@@ -118,39 +146,4 @@ CameraPose Path::interpolatedPose(double distance) const {
return cs;
}
void Path::initializePath() {
_curve.reset();
switch (_curveType) {
case CurveType::AvoidCollision:
_curve = std::make_unique<AvoidCollisionCurve>(_start, _end);
_rotationInterpolator = std::make_unique<EasedSlerpInterpolator>(
_start.rotation(),
_end.rotation()
);
break;
case CurveType::Linear:
_curve = std::make_unique<LinearCurve>(_start, _end);
_rotationInterpolator = std::make_unique<EasedSlerpInterpolator>(
_start.rotation(),
_end.rotation()
);
break;
case CurveType::ZoomOutOverview:
_curve = std::make_unique<ZoomOutOverviewCurve>(_start, _end);
_rotationInterpolator = std::make_unique<LookAtInterpolator>(
_start.rotation(),
_end.rotation(),
_start.node()->worldPosition(),
_end.node()->worldPosition(),
_curve.get()
);
break;
default:
LERROR("Could not create curve. Type does not exist!");
throw ghoul::MissingCaseException();
return;
}
}
} // namespace openspace::autonavigation

View File

@@ -56,7 +56,6 @@ public:
private:
double speedAtTime(double time) const;
void initializePath();
Waypoint _start;
Waypoint _end;

View File

@@ -50,28 +50,6 @@ glm::dquat EasedSlerpInterpolator::interpolate(double u) {
return glm::slerp(_start, _end, uScaled);
}
LookAtRotator::LookAtRotator(glm::dquat start, glm::dquat end,
glm::dvec3 startLookAtPos,
glm::dvec3 endLookAtPos,
PathCurve* path)
: RotationInterpolator(start, end),
_startLookAtPos(startLookAtPos),
_endLookAtPos(endLookAtPos),
_path(path)
{}
glm::dquat LookAtRotator::interpolate(double u) {
double tStart = 0.15;
double tEnd = 0.7;
double uNew = helpers::shiftAndScale(u, tStart, tEnd);
uNew = ghoul::cubicEaseInOut(uNew);
glm::dvec3 lookAtPos = interpolation::linear(uNew, _startLookAtPos, _endLookAtPos);
glm::dvec3 startUpVec = _start * glm::dvec3(0.0, 1.0, 0.0);
return helpers::lookAtQuaternion(_path->positionAt(u), lookAtPos, startUpVec);
}
LookAtInterpolator::LookAtInterpolator(glm::dquat start, glm::dquat end,
glm::dvec3 startLookAtPos,
glm::dvec3 endLookAtPos,
@@ -85,42 +63,39 @@ LookAtInterpolator::LookAtInterpolator(glm::dquat start, glm::dquat end,
// Turn towards start node, turn towards end node, then turn to end view
glm::dquat LookAtInterpolator::interpolate(double u) {
//TODO: base on curve position?
double u1 = 0.2;
double u2 = 0.8;
glm::dvec3 startPosition = _path->positionAt(0.0);
glm::dvec3 endPosition = _path->positionAt(1.0);
const double u1 = 0.2;
const double u2 = 0.8;
const glm::dvec3 startPosition = _path->positionAt(0.0);
const glm::dvec3 endPosition = _path->positionAt(1.0);
glm::dvec3 lookAtPos;
if (u < u1) {
// Create aim positions not too close to camera based on view direction
glm::dvec3 startViewDir = glm::normalize(_start * glm::dvec3(0.0, 0.0, -1.0));
double startViewDist = glm::length(startPosition - _startLookAtPos);
glm::dvec3 startViewPos = startPosition + startViewDist * startViewDir;
double uNew = u / u1;
uNew = ghoul::cubicEaseInOut(uNew);
const glm::dvec3 startViewDir = helpers::viewDirection(_start);
const double startViewDist = glm::length(startPosition - _startLookAtPos);
const glm::dvec3 startViewPos = startPosition + startViewDist * startViewDir;
double uNew = ghoul::cubicEaseInOut(u / u1);
lookAtPos = ghoul::interpolateLinear(uNew, startViewPos, _startLookAtPos);
}
else if (u <= u2) {
double uNew = (u - u1) / (u2 - u1);
uNew = ghoul::cubicEaseInOut(uNew);
double uNew = ghoul::cubicEaseInOut((u - u1) / (u2 - u1));
lookAtPos = ghoul::interpolateLinear(uNew, _startLookAtPos, _endLookAtPos);
}
else if (u2 < u) {
glm::dvec3 endViewDir = glm::normalize(_end * glm::dvec3(0.0, 0.0, -1.0));
double endViewDist = glm::length(endPosition - _endLookAtPos);
glm::dvec3 endViewPos = endPosition + endViewDist * endViewDir;
double uNew = (u - u2) / (1.0 - u2);
uNew = ghoul::cubicEaseInOut(uNew);
const glm::dvec3 endViewDir = helpers::viewDirection(_end);
const double endViewDist = glm::length(endPosition - _endLookAtPos);
const glm::dvec3 endViewPos = endPosition + endViewDist * endViewDir;
double uNew = ghoul::cubicEaseInOut((u - u2) / (1.0 - u2));
lookAtPos = ghoul::interpolateLinear(uNew, _endLookAtPos, endViewPos);
}
// Handle up vector
// Handle up vector separately
glm::dvec3 startUp = _start * glm::dvec3(0.0, 1.0, 0.0);
glm::dvec3 endUp = _end * glm::dvec3(0.0, 1.0, 0.0);
double uInInterval = helpers::shiftAndScale(u, u1, u2);
double uUp = ghoul::sineEaseInOut(uInInterval);
double uUp = helpers::shiftAndScale(u, u1, u2);
uUp = ghoul::sineEaseInOut(uUp);
glm::dvec3 up = ghoul::interpolateLinear(uUp, startUp, endUp);
return helpers::lookAtQuaternion(_path->positionAt(u), lookAtPos, up);

View File

@@ -49,20 +49,6 @@ public:
glm::dquat interpolate(double u);
};
// Look at start node until tStart, then turn to look at end node from tEnd.
// OBS! Does not care about actual end and start value!! I.e. Not an interpolation!
class LookAtRotator : public RotationInterpolator {
public:
LookAtRotator(glm::dquat start, glm::dquat end, glm::dvec3 startLookAtPos,
glm::dvec3 endLookAtPos, PathCurve* path);
glm::dquat interpolate(double u);
private:
glm::dvec3 _startLookAtPos;
glm::dvec3 _endLookAtPos;
PathCurve* _path = nullptr;
};
// Interpolates a look at position for the camera, and takes the start and end rotation
// into account
class LookAtInterpolator : public RotationInterpolator {

View File

@@ -43,10 +43,9 @@ public:
virtual double value(double t) const;
protected:
// must be called by each subclass after initialization
void initializeIntegratedSum();
// store the sum of the function over the duration of the segment,
// Store the sum of the function over the duration of the segment,
// so we don't need to recompue it every time we access the speed
double _integratedSum = 0.0;