mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-24 04:58:59 -05:00
Refactor
This commit is contained in:
@@ -58,8 +58,6 @@ LookAtInterpolator::LookAtInterpolator(glm::dquat start, glm::dquat end,
|
||||
_path(path)
|
||||
{}
|
||||
|
||||
// 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!!
|
||||
glm::dquat LookAtInterpolator::interpolate(double u) {
|
||||
double tStart = 0.15;
|
||||
double tEnd = 0.7;
|
||||
@@ -72,60 +70,4 @@ glm::dquat LookAtInterpolator::interpolate(double u) {
|
||||
return helpers::getLookAtQuaternion(_path->positionAt(u), lookAtPos, startUpVec);
|
||||
}
|
||||
|
||||
PiecewiseLookAtInterpolator::PiecewiseLookAtInterpolator(glm::dquat start, glm::dquat end,
|
||||
glm::dvec3 startTargetPos,
|
||||
glm::dvec3 endTargetPos,
|
||||
PathCurve* path)
|
||||
: RotationInterpolator(start, end),
|
||||
_startTargetPos(startTargetPos),
|
||||
_endTargetPos(endTargetPos),
|
||||
_path(path)
|
||||
{}
|
||||
|
||||
// Interpolate between a number of keyframes for orientation using SLERP
|
||||
glm::dquat PiecewiseLookAtInterpolator::interpolate(double u) {
|
||||
ghoul_assert(_curve, "Rotation interpolation requires access to curve positions.");
|
||||
|
||||
// breakpoints for subintervals
|
||||
const double u1 = 0.3;
|
||||
const double u2 = 0.8; // TODO: these should probably be based on distance
|
||||
|
||||
glm::dvec3 startUpVec = _start * glm::dvec3(0.0, 1.0, 0.0);
|
||||
glm::dvec3 endUpVec = _end * glm::dvec3(0.0, 1.0, 0.0);
|
||||
|
||||
glm::dquat lookAtStartQ = helpers::getLookAtQuaternion(
|
||||
_path->positionAt(u1),
|
||||
_startTargetPos,
|
||||
startUpVec
|
||||
);
|
||||
|
||||
glm::dquat lookAtEndQ = helpers::getLookAtQuaternion(
|
||||
_path->positionAt(u2),
|
||||
_endTargetPos,
|
||||
endUpVec
|
||||
);
|
||||
|
||||
std::vector<std::pair<glm::dquat, double>> keyframes{
|
||||
{_start, 0.0},
|
||||
{lookAtStartQ, u1},
|
||||
{lookAtEndQ, u2},
|
||||
{_end, 1.0}
|
||||
};
|
||||
|
||||
// Find the current segment and compute interpolation
|
||||
glm::dquat result;
|
||||
for (int i = 0; i < keyframes.size() - 1; ++i) {
|
||||
double ui = keyframes[i].second;
|
||||
double uNext = keyframes[i + 1].second;
|
||||
if (u <= uNext) {
|
||||
double uScaled = (u - ui) / (uNext - ui);
|
||||
uScaled = ghoul::quadraticEaseInOut(uScaled);
|
||||
result = glm::slerp(keyframes[i].first, keyframes[i + 1].first, uScaled);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace openspace::autonavigation
|
||||
|
||||
Reference in New Issue
Block a user