mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-23 12:39:24 -05:00
Feature/anchor and aim (#799)
Introduce the ability to navigate using an anchor and aim. Example use: Set spacecraft as anchor and planet as aim to always look down at a planet, while followin the spacecraft in its orbit.
This commit is contained in:
@@ -1021,6 +1021,8 @@ void TouchInteraction::computeVelocities(const std::vector<TuioCursor>& list,
|
||||
{
|
||||
const TuioCursor& cursor = list.at(0);
|
||||
const int action = interpretInteraction(list, lastProcessed);
|
||||
const SceneGraphNode* anchor =
|
||||
global::navigationHandler.orbitalNavigator().anchorNode();
|
||||
|
||||
#ifdef TOUCH_DEBUG_PROPERTIES
|
||||
const std::map<int, std::string> interactionNames = {
|
||||
@@ -1082,11 +1084,11 @@ void TouchInteraction::computeVelocities(const std::vector<TuioCursor>& list,
|
||||
) / lastProcessed.size();
|
||||
|
||||
glm::dvec3 camPos = _camera->positionVec3();
|
||||
glm::dvec3 centerPos = _focusNode->worldPosition();
|
||||
glm::dvec3 centerPos = anchor->worldPosition();
|
||||
glm::dvec3 currDistanceToFocusNode = camPos - centerPos;
|
||||
|
||||
double distanceFromFocusSurface =
|
||||
length(currDistanceToFocusNode) - _focusNode->boundingSphere();
|
||||
length(currDistanceToFocusNode) - anchor->boundingSphere();
|
||||
double zoomFactor = (distance - lastDistance);
|
||||
#ifdef TOUCH_DEBUG_PROPERTIES
|
||||
pinchConsecCt++;
|
||||
@@ -1161,12 +1163,9 @@ void TouchInteraction::computeVelocities(const std::vector<TuioCursor>& list,
|
||||
// pick something in the scene as focus node
|
||||
if (_pickingSelected) {
|
||||
setFocusNode(_pickingSelected);
|
||||
// cant do setFocusNode() since TouchInteraction is not subclass of
|
||||
// InteractionMode
|
||||
global::navigationHandler.setFocusNode(_focusNode);
|
||||
|
||||
// rotate camera to look at new focus, using slerp quat
|
||||
glm::dvec3 camToFocus = _focusNode->worldPosition() -
|
||||
glm::dvec3 camToFocus = _pickingSelected->worldPosition() -
|
||||
_camera->positionVec3();
|
||||
glm::dvec3 forward = glm::normalize(_camera->viewDirectionWorldSpace());
|
||||
double angle = glm::angle(forward, camToFocus);
|
||||
@@ -1206,8 +1205,15 @@ double TouchInteraction::computeConstTimeDecayCoefficient(double velocity) {
|
||||
}
|
||||
|
||||
double TouchInteraction::computeTapZoomDistance(double zoomGain) {
|
||||
double dist = glm::distance(_camera->positionVec3(), _camera->focusPositionVec3());
|
||||
dist -= _focusNode->boundingSphere();
|
||||
const SceneGraphNode* anchor =
|
||||
global::navigationHandler.orbitalNavigator().anchorNode();
|
||||
|
||||
double dist = glm::distance(
|
||||
_camera->positionVec3(),
|
||||
global::navigationHandler.orbitalNavigator().anchorNode()->worldPosition()
|
||||
);
|
||||
|
||||
dist -= anchor->boundingSphere();
|
||||
|
||||
double newVelocity = dist * _tapZoomFactor;
|
||||
newVelocity *= std::max(_touchScreenSize.value() * 0.1, 1.0);
|
||||
@@ -1221,13 +1227,16 @@ double TouchInteraction::computeTapZoomDistance(double zoomGain) {
|
||||
void TouchInteraction::step(double dt) {
|
||||
using namespace glm;
|
||||
|
||||
const SceneGraphNode* anchor =
|
||||
global::navigationHandler.orbitalNavigator().anchorNode();
|
||||
|
||||
// since functions cant be called directly (TouchInteraction not a subclass of
|
||||
// InteractionMode)
|
||||
setFocusNode(global::navigationHandler.focusNode());
|
||||
if (_focusNode && _camera) {
|
||||
setFocusNode(global::navigationHandler.orbitalNavigator().anchorNode());
|
||||
if (anchor && _camera) {
|
||||
// Create variables from current state
|
||||
dvec3 camPos = _camera->positionVec3();
|
||||
dvec3 centerPos = _focusNode->worldPosition();
|
||||
dvec3 centerPos = anchor->worldPosition();
|
||||
|
||||
dvec3 directionToCenter = normalize(centerPos - camPos);
|
||||
dvec3 centerToCamera = camPos - centerPos;
|
||||
@@ -1245,7 +1254,7 @@ void TouchInteraction::step(double dt) {
|
||||
dquat globalCamRot = normalize(quat_cast(inverse(lookAtMat)));
|
||||
dquat localCamRot = inverse(globalCamRot) * _camera->rotationQuaternion();
|
||||
|
||||
double boundingSphere = _focusNode->boundingSphere();
|
||||
double boundingSphere = anchor->boundingSphere();
|
||||
dvec3 centerToBoundingSphere;
|
||||
double distance = std::max(length(centerToCamera) - boundingSphere, 0.0);
|
||||
_currentRadius = boundingSphere /
|
||||
@@ -1399,10 +1408,6 @@ void TouchInteraction::decelerate(double dt) {
|
||||
_vel.roll *= computeDecayCoeffFromFrametime(_constTimeDecayCoeff.roll, times);
|
||||
_vel.pan *= computeDecayCoeffFromFrametime(_constTimeDecayCoeff.pan, times);
|
||||
_vel.zoom *= computeDecayCoeffFromFrametime(_constTimeDecayCoeff.zoom, times);
|
||||
|
||||
glm::dvec3 camPos = _camera->positionVec3();
|
||||
glm::dvec3 centerPos = _focusNode->worldPosition();
|
||||
glm::dvec3 centerToCamera = camPos - centerPos;
|
||||
}
|
||||
|
||||
double TouchInteraction::computeDecayCoeffFromFrametime(double coeff, int times) {
|
||||
@@ -1489,14 +1494,14 @@ Camera* TouchInteraction::getCamera() {
|
||||
return _camera;
|
||||
}
|
||||
|
||||
SceneGraphNode* TouchInteraction::getFocusNode() {
|
||||
return _focusNode;
|
||||
const SceneGraphNode* TouchInteraction::getFocusNode() {
|
||||
return global::navigationHandler.orbitalNavigator().anchorNode();
|
||||
}
|
||||
void TouchInteraction::setCamera(Camera* camera) {
|
||||
_camera = camera;
|
||||
}
|
||||
void TouchInteraction::setFocusNode(SceneGraphNode* focusNode) {
|
||||
_focusNode = focusNode;
|
||||
void TouchInteraction::setFocusNode(const SceneGraphNode* focusNode) {
|
||||
global::navigationHandler.orbitalNavigator().setAnchorNode(focusNode->identifier());
|
||||
}
|
||||
|
||||
void FrameTimeAverage::updateWithNewFrame(double sample) {
|
||||
|
||||
Reference in New Issue
Block a user