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:
Emil Axelsson
2019-02-19 18:46:58 +01:00
committed by GitHub
parent df9fbf8195
commit 2e71eaa4cb
45 changed files with 972 additions and 490 deletions

1
Jenkinsfile vendored
View File

@@ -11,6 +11,7 @@ def modules = [
"multiresvolume",
"spacecraftinstruments",
"space",
"touch",
"toyvolume",
"volume"
];

View File

@@ -39,7 +39,7 @@ asset.onInitialize(function ()
)
openspace.navigation.setCameraState({
Focus = DawnAsset.Dawn.Identifier,
Anchor = DawnAsset.Dawn.Identifier,
Position = { 526781518487.171326, 257168309890.072144, -1381125204152.817383 },
Rotation = { -0.106166, 0.981574, -0.084545, 0.134513 },
})

View File

@@ -96,7 +96,7 @@ asset.onInitialize(function ()
)
openspace.navigation.setCameraState({
Focus = earthAsset.Earth.Identifier,
Anchor = earthAsset.Earth.Identifier,
Position = { 0, 0, 0 },
Rotation = { 0.758797, 0.221490, -0.605693, -0.091135 },
})

View File

@@ -33,7 +33,7 @@ asset.onInitialize(function ()
openspace.setPropertyValueSingle('Scene.Stars.Renderable.Enabled', false);
openspace.navigation.setCameraState({
Focus = "Gaia",
Anchor = "Gaia",
Position = { 1000000000000.0, 1000000000000.0, 1000000000000.0 },
Rotation = { 0.683224, -0.765934, -0.601234, -0.418073 },
})

View File

@@ -43,7 +43,7 @@ asset.onInitialize(function ()
)
openspace.navigation.setCameraState({
Focus = junoAsset.Juno.Identifier,
Anchor = junoAsset.Juno.Identifier,
Position = { 1837386367.601345, -389860693812.834839, 714830404470.398926 },
Rotation = { -0.336540, 0.711402, -0.099212, 0.608937 },
})

View File

@@ -63,7 +63,7 @@ asset.onInitialize(function ()
)
openspace.navigation.setCameraState({
Focus = "Mercury",
Anchor = "Mercury",
Position = { 526781518487.171326, 257168309890.072144, -1381125204152.817383 },
Rotation = {0.180662, 0.021334, 0.979084, 0.091111},
})

View File

@@ -212,7 +212,7 @@ asset.onInitialize(function ()
2160, 4320, 8640
})
openspace.setPropertyValueSingle('NavigationHandler.OrbitalNavigator.FollowFocusNodeRotationDistance', 20.000000);
openspace.setPropertyValueSingle('NavigationHandler.OrbitalNavigator.FollowAnchorNodeRotationDistance', 20.000000);
openspace.addVirtualProperty(
"BoolProperty",
@@ -225,7 +225,7 @@ asset.onInitialize(function ()
)
openspace.navigation.setCameraState({
Focus = NewHorizonsAsset.NewHorizons.Identifier,
Anchor = NewHorizonsAsset.NewHorizons.Identifier,
Position = { 4662120063743.592773, 1263245003503.724854, -955413856565.788086 },
Rotation = { 0.683224, -0.165934, 0.701234, 0.118073 },
})

View File

@@ -133,7 +133,7 @@ asset.onInitialize(function ()
)
openspace.navigation.setCameraState({
Focus = OsirisRexAsset.OsirisRex.Identifier,
Anchor = OsirisRexAsset.OsirisRex.Identifier,
Position = { 26974590199.661884, 76314608558.908020, -127086452897.101791 },
Rotation = { 0.729548, -0.126024, 0.416827, 0.527382 },
})

View File

@@ -137,7 +137,7 @@ asset.onInitialize(function ()
)
openspace.navigation.setCameraState({
Focus = Comet67PAsset.Comet67P.Identifier,
Anchor = Comet67PAsset.Comet67P.Identifier,
Position = { 526781518487.171326, 257168309890.072144, -1381125204152.817383 },
Rotation = { -0.106166, 0.981574, -0.084545, 0.134513 },
})

View File

@@ -1,7 +1,7 @@
local guiCustomization = asset.require('customization/gui')
-- Select which commit hashes to use for the frontend and backend
local frontendHash = "abf5fe23ef29af408d6c071057f1cc706c9b09a3"
local frontendHash = "6a34f2b0c6cfde64b890f12aa5bfaa42ac61a40f"
local backendHash = "6e773425b3e90ba93f0090e44427e474fe5c633f"
local dataProvider = "data.openspaceproject.com/files/webgui"

View File

@@ -71,7 +71,7 @@ asset.onInitialize(function ()
)
openspace.navigation.setCameraState({
Focus = VoyagerAsset.Voyager_1.Identifier,
Anchor = VoyagerAsset.Voyager_1.Identifier,
Position = { 526781518487.171326, 257168309890.072144, -1381125204152.817383 },
Rotation = { -0.106166, 0.981574, -0.084545, 0.134513 },
})

View File

@@ -55,9 +55,7 @@ public:
void deinitialize();
// Mutators
void setFocusNode(SceneGraphNode* node);
void setCamera(Camera* camera);
void resetCameraDirection();
void setInterpolationTime(float durationInSeconds);
void setCameraStateFromDictionary(const ghoul::Dictionary& cameraDict);
@@ -69,12 +67,10 @@ public:
// Accessors
ghoul::Dictionary cameraStateDictionary();
SceneGraphNode* focusNode() const;
glm::dvec3 focusNodeToCameraVector() const;
glm::quat focusNodeToCameraRotation() const;
Camera* camera() const;
const InputState& inputState() const;
const OrbitalNavigator& orbitalNavigator() const;
OrbitalNavigator& orbitalNavigator();
KeyframeNavigator& keyframeNavigator() const;
bool isKeyFrameInteractionEnabled() const;
float interpolationTime() const;
@@ -126,7 +122,6 @@ private:
std::unique_ptr<OrbitalNavigator> _orbitalNavigator;
std::unique_ptr<KeyframeNavigator> _keyframeNavigator;
properties::StringProperty _origin;
properties::BoolProperty _useKeyFrameInteraction;
};

View File

@@ -31,8 +31,10 @@
#include <openspace/interaction/interpolator.h>
#include <openspace/interaction/joystickcamerastates.h>
#include <openspace/interaction/mousecamerastates.h>
#include <openspace/properties/stringproperty.h>
#include <openspace/properties/scalar/boolproperty.h>
#include <openspace/properties/scalar/floatproperty.h>
#include <openspace/properties/triggerproperty.h>
#include <ghoul/glm.h>
#include <glm/gtx/quaternion.hpp>
@@ -51,28 +53,46 @@ public:
OrbitalNavigator();
void updateStatesFromInput(const InputState& inputState, double deltaTime);
void updateCameraStateFromStates(Camera& camera, double deltaTime);
void updateCameraStateFromStates(double deltaTime);
void setFocusNode(SceneGraphNode* focusNode);
void startInterpolateCameraDirection(const Camera& camera);
float rotateToFocusInterpolationTime() const;
void setRotateToFocusInterpolationTime(float durationInSeconds);
Camera* camera() const;
void setCamera(Camera* camera);
void setFocusNode(const std::string& focusNode);
void setAnchorNode(const std::string& anchorNode);
void setAimNode(const std::string& aimNode);
void startRetargetAnchor();
void startRetargetAim();
float retargetInterpolationTime() const;
void setRetargetInterpolationTime(float durationInSeconds);
JoystickCameraStates& joystickStates();
bool followingNodeRotation() const;
SceneGraphNode* focusNode() const;
const SceneGraphNode* anchorNode() const;
const SceneGraphNode* aimNode() const;
bool hasRotationalFriction() const;
bool hasZoomFriction() const;
bool hasRollFriction() const;
glm::dvec3 anchorNodeToCameraVector() const;
glm::quat anchorNodeToCameraRotation() const;
private:
struct CameraRotationDecomposition {
glm::dquat localRotation;
glm::dquat globalRotation;
};
struct CameraPose {
glm::dvec3 position;
glm::dquat rotation;
};
using Displacement = std::pair<glm::dvec3, glm::dvec3>;
struct Friction : public properties::PropertyOwner {
Friction();
@@ -83,9 +103,28 @@ private:
properties::FloatProperty friction;
};
void setFocusNode(const SceneGraphNode* focusNode);
void setAnchorNode(const SceneGraphNode* anchorNode);
void setAimNode(const SceneGraphNode* aimNode);
Camera* _camera;
Friction _friction;
properties::FloatProperty _followFocusNodeRotationDistance;
// Anchor: Node to follow and orbit.
properties::StringProperty _anchor;
// Aim: Node to look at (when camera direction is reset),
// Empty string means same as anchor.
// If these are the same node we call it the `focus` node.
properties::StringProperty _aim;
// Reset camera direction to the anchor node.
properties::TriggerProperty _retargetAnchor;
// Reset camera direction to the aim node.
properties::TriggerProperty _retargetAim;
properties::FloatProperty _followAnchorNodeRotationDistance;
properties::FloatProperty _minimumAllowedDistance;
properties::FloatProperty _mouseSensitivity;
@@ -95,33 +134,64 @@ private:
properties::FloatProperty _stereoscopicDepthOfFocusSurface;
properties::FloatProperty _staticViewScaleExponent;
properties::FloatProperty _rotateToFocusInterpolationTime;
properties::FloatProperty _retargetInterpolationTime;
properties::FloatProperty _stereoInterpolationTime;
properties::FloatProperty _followRotationInterpolationTime;
MouseCameraStates _mouseStates;
JoystickCameraStates _joystickStates;
SceneGraphNode* _focusNode = nullptr;
glm::dvec3 _previousFocusNodePosition;
glm::dquat _previousFocusNodeRotation;
const SceneGraphNode* _anchorNode = nullptr;
const SceneGraphNode* _aimNode = nullptr;
glm::dvec3 _previousAnchorNodePosition;
glm::dquat _previousAnchorNodeRotation;
glm::dvec3 _previousAimNodePosition;
glm::dquat _previousAimNodeRotation;
double _currentCameraToSurfaceDistance = 0.0;
bool _directlySetStereoDistance = false;
Interpolator<double> _rotateToFocusNodeInterpolator;
Interpolator<double> _retargetAimInterpolator;
Interpolator<double> _retargetAnchorInterpolator;
Interpolator<double> _cameraToSurfaceDistanceInterpolator;
Interpolator<double> _followRotationInterpolator;
/**
* Decomposes the cameras rotation in to a global and a local rotation defined by
* Decomposes the camera's rotation in to a global and a local rotation defined by
* CameraRotationDecomposition. The global rotation defines the rotation so that the
* camera points towards the focus node in the direction opposite to the direction
* camera points towards the reference node in the direction opposite to the direction
* out from the surface of the object. The local rotation defines the differential
* from the global to the current total rotation so that
* <code>cameraRotation = globalRotation * localRotation</code>.
*/
CameraRotationDecomposition decomposeCameraRotation(const glm::dvec3& cameraPosition,
const glm::dquat& cameraRotation, const glm::dvec3& cameraLookUp,
const glm::dvec3& cameraViewDirection);
CameraRotationDecomposition decomposeCameraRotationSurface(const CameraPose pose,
const SceneGraphNode& reference);
/**
* Decomposes the camera's rotation in to a global and a local rotation defined by
* CameraRotationDecomposition. The global rotation defines the rotation so that the
* camera points towards the reference node's origin.
* The local rotation defines the differential from the global to the current total
* rotation so that <code>cameraRotation = globalRotation * localRotation</code>.
*/
CameraRotationDecomposition decomposeCameraRotation(const CameraPose pose,
glm::dvec3 reference);
/**
* Composes a pair of global and local rotations into a quaternion that can be used
* as the world rotation for a camera.
*/
glm::dquat composeCameraRotation(const CameraRotationDecomposition& composition);
/*
* Moves and rotates the camera around the anchor node in order to maintain the
* screen space position of the aim node. Also interpolates to the aim node, when
* retargeting the aim.
*/
CameraPose followAim(CameraPose pose, glm::dvec3 cameraToAnchor,
Displacement anchorToAim);
/*
* Perform a camera roll on the local camera rotation
@@ -137,47 +207,47 @@ private:
const glm::dquat& localCameraRotation) const;
/**
* Interpolates the local rotation towards a 0 rotation.
* \returns a modified local rotation interpolated towards 0.
* Interpolates the camera rotation based on active interpolators.
* \returns a new rotation quaternion
*/
glm::dquat interpolateLocalRotation(double deltaTime,
const glm::dquat& localCameraRotation);
double interpolateCameraToSurfaceDistance(double deltaTime,
double currentDistance,
double targetDistance);
Displacement interpolateRetargetAim(double deltaTime, CameraPose pose,
glm::dvec3 cameraToAnchor, Displacement anchorToAim);
double interpolateCameraToSurfaceDistance(double deltaTime, double currentDistance,
double targetDistance);
/**
* Translates the horizontal direction. If far from the focus object, this will
* Translates the horizontal direction. If far from the anchor object, this will
* result in an orbital rotation around the object. This function does not affect the
* rotation but only the position.
* \returns a position vector adjusted in the horizontal direction.
*/
glm::dvec3 translateHorizontally(double deltaTime, const glm::dvec3& cameraPosition,
const glm::dvec3& objectPosition, const glm::dquat& focusNodeRotationDiff,
const glm::dquat& globalCameraRotation,
const glm::dvec3& objectPosition, const glm::dquat& globalCameraRotation,
const SurfacePositionHandle& positionHandle) const;
/*
* Adds rotation to the camera position so that it follows the rotation of the focus
* node defined by the differential focusNodeRotationDiff.
* \returns a position updated with the rotation defined by focusNodeRotationDiff
* Adds rotation to the camera position so that it follows the rotation of the anchor
* node defined by the differential anchorNodeRotationDiff.
* \returns a position updated with the rotation defined by anchorNodeRotationDiff
*/
glm::dvec3 followFocusNodeRotation(const glm::dvec3& cameraPosition,
const glm::dvec3& objectPosition, const glm::dquat& focusNodeRotationDiff) const;
glm::dvec3 followAnchorNodeRotation(const glm::dvec3& cameraPosition,
const glm::dvec3& objectPosition, const glm::dquat& anchorNodeRotationDiff) const;
/**
* Updates the global rotation so that it points towards the focus node.
* \returns a global rotation quaternion defining a rotation towards the focus node.
* Updates the global rotation so that it points towards the anchor node.
* \returns a global rotation quaternion defining a rotation towards the anchor node.
*/
glm::dquat rotateGlobally(const glm::dquat& globalCameraRotation,
const glm::dvec3& objectPosition, const glm::dquat& focusNodeRotationDiff,
const glm::dvec3& cameraPosition,
const glm::dquat& aimNodeRotationDiff,
const SurfacePositionHandle& positionHandle) const;
/**
* Translates the camera position towards or away from the focus node.
* Translates the camera position towards or away from the anchor node.
* \returns a position vector adjusted in the vertical direction.
*/
glm::dvec3 translateVertically(double deltaTime, const glm::dvec3& cameraPosition,
@@ -189,7 +259,7 @@ private:
* \returns a quaternion adjusted to rotate around the out vector of the surface.
*/
glm::dquat rotateHorizontally(double deltaTime,
const glm::dquat& globalCameraRotation, const glm::dvec3& cameraPosition,
const glm::dquat& globalCameraRotation,
const SurfacePositionHandle& positionHandle) const;
/**
@@ -210,17 +280,15 @@ private:
const SurfacePositionHandle& positionHandle);
/**
* Get the vector from the camera to the surface of the focus object in world space.
* Get the vector from the camera to the surface of the anchor object in world space.
*/
glm::dvec3 cameraToSurfaceVector(
const glm::dvec3& cameraPos,
const glm::dvec3& centerPos,
const SurfacePositionHandle& posHandle);
glm::dvec3 cameraToSurfaceVector(const glm::dvec3& cameraPos,
const glm::dvec3& centerPos, const SurfacePositionHandle& posHandle);
/**
* Calculates a SurfacePositionHandle given a camera position in world space.
*/
SurfacePositionHandle calculateSurfacePositionHandle(
SurfacePositionHandle calculateSurfacePositionHandle(const SceneGraphNode& node,
const glm::dvec3 cameraPositionWorldSpace);
};

View File

@@ -96,7 +96,6 @@ public:
void traversePostOrder(const std::function<void(SceneGraphNode*)>& fn);
void update(const UpdateData& data);
void render(const RenderData& data, RendererTasks& tasks);
void updateCamera(Camera* camera) const;
void attachChild(std::unique_ptr<SceneGraphNode> child);
std::unique_ptr<SceneGraphNode> detachChild(SceneGraphNode& child);
@@ -109,7 +108,7 @@ public:
void setDependencies(const std::vector<SceneGraphNode*>& dependencies);
SurfacePositionHandle calculateSurfacePositionHandle(
const glm::dvec3& targetModelSpace);
const glm::dvec3& targetModelSpace) const;
const std::vector<SceneGraphNode*>& dependencies() const;
const std::vector<SceneGraphNode*>& dependentNodes() const;

View File

@@ -72,7 +72,6 @@ public:
// Mutators
void setPositionVec3(glm::dvec3 pos);
void setFocusPositionVec3(glm::dvec3 pos);
void setRotation(glm::dquat rotation);
void setScaling(float scaling);
void setMaxFov(float fov);
@@ -86,7 +85,6 @@ public:
const glm::dvec3& positionVec3() const;
glm::dvec3 eyePositionVec3() const;
const glm::dvec3& unsynchedPositionVec3() const;
const glm::dvec3& focusPositionVec3() const;
const glm::dvec3& viewDirectionWorldSpace() const;
const glm::dvec3& lookUpVectorCameraSpace() const;
const glm::dvec3& lookUpVectorWorldSpace() const;
@@ -138,18 +136,6 @@ public:
mutable std::mutex _mutex;
} sgctInternal;
// Deprecated
// [[deprecated("Replaced by Camera::setPositionVec3()")]]
void setPosition(psc pos);
// [[deprecated("Replaced by Camera::setFocusPositionVec3()")]]
void setFocusPosition(psc pos);
// [[deprecated("Replaced by Camera::positionVec3()")]]
psc position() const;
// [[deprecated("Replaced by Camera::unsynchedPositionVec3()")]]
psc unsynchedPosition() const;
// [[deprecated("Replaced by Camera::focusPositionVec3()")]]
psc focusPosition() const;
const glm::mat4& sceneMatrix() const;
// @TODO use Camera::SgctInternal interface instead
// [[deprecated("Replaced by Camera::SgctInternal::viewMatrix()")]]
const glm::mat4& viewMatrix() const;
@@ -160,10 +146,11 @@ public:
std::vector<Syncable*> getSyncables();
private:
// Static constants
static const glm::dvec3 ViewDirectionCameraSpace;
static const glm::dvec3 LookupVectorCameraSpace;
static const glm::dvec3 UpDirectionCameraSpace;
private:
SyncData<glm::dvec3> _position = glm::dvec3(1.0, 1.0, 1.0);
SyncData<glm::dquat> _rotation = glm::dquat(glm::dvec3(1.0, 1.0, 1.0));

View File

@@ -28,6 +28,7 @@
#include <openspace/documentation/verifier.h>
#include <openspace/engine/globals.h>
#include <openspace/interaction/navigationhandler.h>
#include <openspace/interaction/orbitalnavigator.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/scene/scene.h>
#include <openspace/scene/scenegraphnode.h>
@@ -380,7 +381,14 @@ std::pair<glm::dvec3, std::string> DashboardItemAngle::positionAndLabel(
case Type::Node:
return { comp.node->worldPosition(), comp.node->guiName() };
case Type::Focus:
return { global::navigationHandler.focusNode()->worldPosition(), "focus" };
{
const SceneGraphNode* node =
global::navigationHandler.orbitalNavigator().anchorNode();
return {
node->worldPosition(),
"focus"
};
}
case Type::Camera:
return { global::renderEngine.scene()->camera()->positionVec3(), "camera" };
default:

View File

@@ -28,6 +28,7 @@
#include <openspace/documentation/verifier.h>
#include <openspace/engine/globals.h>
#include <openspace/interaction/navigationhandler.h>
#include <openspace/interaction/orbitalnavigator.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/scene/scene.h>
#include <openspace/scene/scenegraphnode.h>
@@ -402,7 +403,7 @@ std::pair<glm::dvec3, std::string> DashboardItemDistance::positionAndLabel(
}
case Type::Focus:
return {
global::navigationHandler.focusNode()->worldPosition(),
global::navigationHandler.orbitalNavigator().anchorNode()->worldPosition(),
"focus"
};
case Type::Camera:

View File

@@ -29,6 +29,7 @@
#include <openspace/engine/globals.h>
#include <openspace/engine/windowdelegate.h>
#include <openspace/interaction/navigationhandler.h>
#include <openspace/interaction/orbitalnavigator.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/scene/scene.h>
#include <openspace/util/timemanager.h>
@@ -763,8 +764,10 @@ void RenderableFieldlinesSequence::definePropertyCallbackFunctions() {
));
return;
}
global::navigationHandler.setFocusNode(node->parent());
global::navigationHandler.resetCameraDirection();
global::navigationHandler.orbitalNavigator().setFocusNode(
node->parent()->identifier()
);
global::navigationHandler.orbitalNavigator().startRetargetAnchor();
});
_pJumpToStartBtn.onChange([this] {

View File

@@ -116,7 +116,7 @@ void GalaxyRaycaster::postRaycast(const RaycastData&, ghoul::opengl::ProgramObje
bool GalaxyRaycaster::isCameraInside(const RenderData& data, glm::vec3& localPosition) {
// Camera rig position in world coordinates.
const glm::vec4 rigWorldPos = glm::vec4(data.camera.position().vec3(), 1.0);
const glm::vec4 rigWorldPos = glm::vec4(data.camera.positionVec3(), 1.0);
//rigWorldPos /= data.camera.scaling().x * pow(10.0, data.camera.scaling().y);
//glm::mat4 invSgctMatrix = glm::inverse(data.camera.viewMatrix());

View File

@@ -309,7 +309,7 @@ void RenderableGalaxy::update(const UpdateData& data) {
void RenderableGalaxy::render(const RenderData& data, RendererTasks& tasks) {
RaycasterTask task { _raycaster.get(), data };
const glm::vec3 position = data.camera.position().vec3();
const glm::vec3 position = data.camera.positionVec3();
const float length = safeLength(position);
const glm::vec3 galaxySize = _volumeSize;

View File

@@ -31,6 +31,8 @@
#include <modules/globebrowsing/src/globetranslation.h>
#include <modules/globebrowsing/src/memoryawaretilecache.h>
#include <modules/globebrowsing/src/tileprovider.h>
#include <openspace/interaction/navigationhandler.h>
#include <openspace/interaction/orbitalnavigator.h>
#include <openspace/engine/globalscallbacks.h>
#include <openspace/scripting/lualibrary.h>
#include <openspace/util/factorymanager.h>
@@ -474,7 +476,7 @@ void GlobeBrowsingModule::goToGeodetic2(Camera& camera, globebrowsing::Geodetic2
const glm::dvec3 cameraPosition = global::navigationHandler.camera()->positionVec3();
const glm::dmat4 inverseModelTransform =
global::navigationHandler.focusNode()->inverseModelTransform();
global::navigationHandler.orbitalNavigator().anchorNode()->inverseModelTransform();
const glm::dvec3 cameraPositionModelSpace =
glm::dvec3(inverseModelTransform * glm::dvec4(cameraPosition, 1.0));
const SurfacePositionHandle posHandle = globe->calculateSurfacePositionHandle(
@@ -557,7 +559,9 @@ GlobeBrowsingModule::castFocusNodeRenderableToGlobe()
{
using namespace globebrowsing;
const Renderable* renderable = global::navigationHandler.focusNode()->renderable();
const Renderable* renderable =
global::navigationHandler.orbitalNavigator().anchorNode()->renderable();
if (!renderable) {
return nullptr;
}

View File

@@ -208,7 +208,7 @@ int getGeoPositionForCamera(lua_State* L) {
const glm::dvec3 cameraPosition = global::navigationHandler.camera()->positionVec3();
const glm::dmat4 inverseModelTransform =
global::navigationHandler.focusNode()->inverseModelTransform();
global::navigationHandler.orbitalNavigator().anchorNode()->inverseModelTransform();
const glm::dvec3 cameraPositionModelSpace =
glm::dvec3(inverseModelTransform * glm::dvec4(cameraPosition, 1.0));
const SurfacePositionHandle posHandle = globe->calculateSurfacePositionHandle(

View File

@@ -82,10 +82,11 @@ openspace.globebrowsing.documentation = {
},
{
Name = "addFocusNodeFromLatLong",
Arguments = "string, number, number, string",
Arguments = "string, string, number, number, number",
Documentation =
"Creates a new SceneGraphNode that can be used as focus node. " ..
"Usage: openspace.globebrowsing.addFocusNodeFromLatLong(\"Olympus Mons\", -18.65, 226.2, \"Mars\")"
"Usage: openspace.globebrowsing.addFocusNodeFromLatLong(" ..
"\"Olympus Mons\", \"Mars\", -18.65, 226.2, optionalAltitude)"
},
{
Name = "loadWMSServersFromFile",
@@ -289,10 +290,10 @@ openspace.globebrowsing.addFocusNodesFromDirectory = function (dir, node_name)
end
end
openspace.globebrowsing.addFocusNodeFromLatLong = function (name, lat, long, globe_identifier)
openspace.printInfo("Creating focus node for '" .. name .. "'")
openspace.globebrowsing.addFocusNodeFromLatLong = function (name, globe_identifier, lat, long, altitude)
altitude = altitude or 0;
local a, b, c = openspace.globebrowsing.getGeoPosition(globe_identifier, lat, long, 0.0)
local a, b, c = openspace.globebrowsing.getGeoPosition(globe_identifier, lat, long, altitude)
local p = { a, b, c }
local identifier = globe_identifier .. "-" .. name
@@ -301,8 +302,11 @@ openspace.globebrowsing.addFocusNodeFromLatLong = function (name, lat, long, glo
Parent = globe_identifier,
Transform = {
Translation = {
Type = "StaticTranslation",
Position = { p[1], p[2], p[3] }
Type = "GlobeTranslation",
Globe = globe_identifier,
Latitude = lat,
Longitude = long,
FixedAltitude = altitude
}
},
GUI = {

View File

@@ -30,6 +30,7 @@
#include <openspace/documentation/verifier.h>
#include <openspace/engine/globals.h>
#include <openspace/interaction/navigationhandler.h>
#include <openspace/interaction/orbitalnavigator.h>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/util/distanceconversion.h>
#include <openspace/util/updatestructures.h>
@@ -142,7 +143,7 @@ DashboardItemGlobeLocation::DashboardItemGlobeLocation(
void DashboardItemGlobeLocation::render(glm::vec2& penPosition) {
using namespace globebrowsing;
SceneGraphNode* n = global::navigationHandler.focusNode();
const SceneGraphNode* n = global::navigationHandler.orbitalNavigator().anchorNode();
const RenderableGlobe* globe = dynamic_cast<const RenderableGlobe*>(n->renderable());
if (!globe) {
return;

View File

@@ -29,6 +29,7 @@
#include <openspace/engine/globals.h>
#include <openspace/engine/moduleengine.h>
#include <openspace/interaction/navigationhandler.h>
#include <openspace/interaction/orbitalnavigator.h>
#include <openspace/rendering/renderable.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/scene/scene.h>
@@ -122,7 +123,9 @@ void GuiGlobeBrowsingComponent::render() {
// node
// Check if the focus node is a RenderableGlobe
const SceneGraphNode* const focus = global::navigationHandler.focusNode();
const SceneGraphNode* const focus =
global::navigationHandler.orbitalNavigator().anchorNode();
const auto it = std::find(nodes.cbegin(), nodes.cend(), focus);
if (it != nodes.end()) {
_currentNode = focus->identifier();
@@ -145,7 +148,9 @@ void GuiGlobeBrowsingComponent::render() {
ImGui::SameLine();
bool selectFocusNode = ImGui::Button("From Focus");
if (selectFocusNode) {
const SceneGraphNode* const focus = global::navigationHandler.focusNode();
const SceneGraphNode* const focus =
global::navigationHandler.orbitalNavigator().anchorNode();
const auto it = std::find(nodes.cbegin(), nodes.cend(), focus);
if (it != nodes.end()) {
_currentNode = focus->identifier();

View File

@@ -29,6 +29,7 @@
#include <openspace/engine/globals.h>
#include <openspace/engine/windowdelegate.h>
#include <openspace/interaction/navigationhandler.h>
#include <openspace/interaction/orbitalnavigator.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/scene/scene.h>
@@ -113,7 +114,8 @@ void GuiSpaceTimeComponent::render() {
ImGui::NewLine();
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 10.f);
SceneGraphNode* currentFocus = global::navigationHandler.focusNode();
const SceneGraphNode* currentFocus =
global::navigationHandler.orbitalNavigator().anchorNode();
std::string nodeNames;
for (SceneGraphNode* n : nodes) {

View File

@@ -133,7 +133,7 @@ bool MultiresVolumeRaycaster::isCameraInside(const RenderData& data,
glm::vec3& localPosition)
{
// Camera rig position in world coordinates.
glm::vec4 rigWorldPos = glm::vec4(data.camera.position().vec3(), 1.0);
glm::vec4 rigWorldPos = glm::vec4(data.camera.positionVec3(), 1.0);
//rigWorldPos /= data.camera.scaling().x * pow(10.0, data.camera.scaling().y);
//glm::mat4 invSgctMatrix = glm::inverse(data.camera.viewMatrix());

View File

@@ -28,6 +28,8 @@
#include <openspace/properties/property.h>
#include <openspace/query/query.h>
#include <ghoul/logging/logmanager.h>
#include <openspace/engine/globals.h>
#include <openspace/scripting/scriptengine.h>
namespace {
constexpr const char* PropertyKey = "property";
@@ -40,22 +42,19 @@ namespace openspace {
void TriggerPropertyTopic::handleJson(const nlohmann::json& json) {
try {
const std::string& propertyKey = json.at(PropertyKey).get<std::string>();
properties::Property* prop = property(propertyKey);
if (prop) {
LDEBUG("Triggering " + propertyKey);
prop->set("poke");
}
else {
LWARNING("Could not find property " + propertyKey);
}
global::scriptEngine.queueScript(
fmt::format(
"openspace.setPropertyValueSingle(\"{}\", nil)", propertyKey
),
scripting::ScriptEngine::RemoteScripting::Yes
);
}
catch (const std::out_of_range& e) {
LERROR("Could not poke property -- key or value is missing in payload");
LERROR("Could not trigger property -- key or value is missing in payload");
LERROR(e.what());
}
catch (const ghoul::RuntimeError& e) {
LERROR("Could not poke property -- runtime error:");
LERROR("Could not trigger property -- runtime error:");
LERROR(e.what());
}
}

View File

@@ -75,4 +75,9 @@ add_library(libTUIO11
target_include_directories(libTUIO11 PUBLIC
${PROJECT_SOURCE_DIR}/libTUIO11/
${PROJECT_SOURCE_DIR}/libTUIO11/oscpack
${PROJECT_SOURCE_DIR}/libTUIO11/TUIO)
${PROJECT_SOURCE_DIR}/libTUIO11/TUIO)
if (WIN32)
# Tuio dependencies
target_link_libraries(libTUIO11 PRIVATE winmm.lib wininet.lib ws2_32.lib)
endif()

View File

@@ -133,8 +133,8 @@ public:
// Get & Setters
Camera* getCamera();
SceneGraphNode* getFocusNode();
void setFocusNode(SceneGraphNode* focusNode);
const SceneGraphNode* getFocusNode();
void setFocusNode(const SceneGraphNode* focusNode);
void setCamera(Camera* camera);
private:
@@ -185,7 +185,6 @@ private:
void resetToDefault();
Camera* _camera = nullptr;
SceneGraphNode* _focusNode = nullptr;
// Property variables
properties::StringProperty _origin;

View File

@@ -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) {

View File

@@ -28,6 +28,7 @@
#include <openspace/engine/globalscallbacks.h>
#include <openspace/engine/windowdelegate.h>
#include <openspace/interaction/navigationhandler.h>
#include <openspace/interaction/orbitalnavigator.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/rendering/screenspacerenderable.h>
#include <ghoul/logging/logmanager.h>
@@ -119,7 +120,7 @@ TouchModule::TouchModule() : OpenSpaceModule("Touch") {
global::callback::preSync.push_back([&]() {
touch.setCamera(global::navigationHandler.camera());
touch.setFocusNode(global::navigationHandler.focusNode());
touch.setFocusNode(global::navigationHandler.orbitalNavigator().anchorNode());
if (hasNewInput() && global::windowDelegate.isMaster()) {
touch.updateStateFromInput(listOfContactPoints, lastProcessed);

View File

@@ -215,6 +215,7 @@ bool EventHandler::mouseWheelCallback(glm::ivec2 delta) {
bool EventHandler::charCallback(unsigned int charCode, KeyModifier modifier) {
CefKeyEvent keyEvent;
keyEvent.windows_key_code = charCode;
keyEvent.character = charCode;
keyEvent.modifiers = static_cast<uint32>(modifier);
keyEvent.type = KEYEVENT_CHAR;
// TODO(klas): figure out when to block

View File

@@ -39,6 +39,7 @@
#include <openspace/interaction/keybindingmanager.h>
#include <openspace/interaction/sessionrecording.h>
#include <openspace/interaction/navigationhandler.h>
#include <openspace/interaction/orbitalnavigator.h>
#include <openspace/network/networkengine.h>
#include <openspace/network/parallelpeer.h>
#include <openspace/performance/performancemeasurement.h>
@@ -651,7 +652,14 @@ void OpenSpaceEngine::loadSingleAsset(const std::string& assetPath) {
global::renderEngine.setCamera(camera);
global::navigationHandler.setCamera(camera);
global::navigationHandler.setFocusNode(camera->parent());
const SceneGraphNode* parent = camera->parent();
if (parent) {
global::navigationHandler.orbitalNavigator().setFocusNode(parent->identifier());
} else {
global::navigationHandler.orbitalNavigator().setFocusNode(
_scene->root()->identifier()
);
}
global::renderEngine.setScene(_scene.get());

View File

@@ -106,19 +106,22 @@ void ExternInteraction::scriptInteraction(datamessagestructures::ScriptMessage s
datamessagestructures::CameraKeyframe ExternInteraction::generateCameraKeyframe() {
datamessagestructures::CameraKeyframe kf;
SceneGraphNode* focusNode = global::navigationHandler.focusNode();
const SceneGraphNode* focusNode =
global::navigationHandler.orbitalNavigator().anchorNode();
if (!focusNode) {
return kf;
}
//kf._position = global::navigationHandler.camera()->positionVec3();
kf._position = global::navigationHandler.focusNodeToCameraVector();
kf._position = global::navigationHandler.orbitalNavigator().anchorNodeToCameraVector();
kf._followNodeRotation =
global::navigationHandler.orbitalNavigator().followingNodeRotation();
if (kf._followNodeRotation) {
kf._position = glm::inverse(focusNode->worldRotationMatrix()) * kf._position;
kf._rotation = global::navigationHandler.focusNodeToCameraRotation();
kf._rotation =
global::navigationHandler.orbitalNavigator().anchorNodeToCameraVector();
}
else {
kf._rotation = global::navigationHandler.camera()->rotationQuaternion();

View File

@@ -25,7 +25,6 @@
#include <openspace/interaction/navigationhandler.h>
#include <openspace/engine/globals.h>
#include <openspace/query/query.h>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/scripting/lualibrary.h>
#include <openspace/interaction/orbitalnavigator.h>
@@ -41,18 +40,11 @@
namespace {
constexpr const char* _loggerCat = "NavigationHandler";
constexpr const char* KeyFocus = "Focus";
constexpr const char* KeyAnchor = "Anchor";
constexpr const char* KeyAim = "Aim";
constexpr const char* KeyPosition = "Position";
constexpr const char* KeyRotation = "Rotation";
constexpr const openspace::properties::Property::PropertyInfo OriginInfo = {
"Origin",
"Origin",
"The name of the scene graph node that is the origin of the camera interaction. "
"The camera is always focussed on this object and every interaction is relative "
"towards this object. Any scene graph node can be the origin node."
};
constexpr const openspace::properties::Property::PropertyInfo KeyFrameInfo = {
"UseKeyFrameInteraction",
"Use keyframe interaction",
@@ -67,31 +59,14 @@ namespace openspace::interaction {
NavigationHandler::NavigationHandler()
: properties::PropertyOwner({ "NavigationHandler" })
, _origin(OriginInfo)
, _useKeyFrameInteraction(KeyFrameInfo, false)
{
_origin.onChange([this]() {
if (_origin.value().empty()) {
return;
}
SceneGraphNode* node = sceneGraphNode(_origin.value());
if (!node) {
LWARNING(fmt::format(
"Could not find a node in scenegraph called '{}'", _origin.value()
));
return;
}
setFocusNode(node);
resetCameraDirection();
});
_inputState = std::make_unique<InputState>();
_orbitalNavigator = std::make_unique<OrbitalNavigator>();
_keyframeNavigator = std::make_unique<KeyframeNavigator>();
// Add the properties
addProperty(_origin);
addProperty(_useKeyFrameInteraction);
addPropertySubOwner(*_orbitalNavigator);
}
@@ -113,23 +88,19 @@ void NavigationHandler::deinitialize() {
global::parallelPeer.connectionEvent().unsubscribe("NavigationHandler");
}
void NavigationHandler::setFocusNode(SceneGraphNode* node) {
_orbitalNavigator->setFocusNode(node);
_camera->setFocusPositionVec3(focusNode()->worldPosition());
}
void NavigationHandler::setCamera(Camera* camera) {
_camera = camera;
}
void NavigationHandler::resetCameraDirection() {
_orbitalNavigator->startInterpolateCameraDirection(*_camera);
_orbitalNavigator->setCamera(camera);
}
const OrbitalNavigator& NavigationHandler::orbitalNavigator() const {
return *_orbitalNavigator;
}
OrbitalNavigator& NavigationHandler::orbitalNavigator() {
return *_orbitalNavigator;
}
KeyframeNavigator& NavigationHandler::keyframeNavigator() const {
return *_keyframeNavigator;
}
@@ -139,11 +110,11 @@ bool NavigationHandler::isKeyFrameInteractionEnabled() const {
}
float NavigationHandler::interpolationTime() const {
return _orbitalNavigator->rotateToFocusInterpolationTime();
return _orbitalNavigator->retargetInterpolationTime();
}
void NavigationHandler::setInterpolationTime(float durationInSeconds) {
_orbitalNavigator->setRotateToFocusInterpolationTime(durationInSeconds);
_orbitalNavigator->setRetargetInterpolationTime(durationInSeconds);
}
void NavigationHandler::updateCamera(double deltaTime) {
@@ -154,14 +125,13 @@ void NavigationHandler::updateCamera(double deltaTime) {
_cameraUpdatedFromScript = false;
}
else if ( ! _playbackModeEnabled ) {
if (_camera && focusNode()) {
if (_camera) {
if (_useKeyFrameInteraction) {
_keyframeNavigator->updateCamera(*_camera, _playbackModeEnabled);
}
else {
_orbitalNavigator->updateStatesFromInput(*_inputState, deltaTime);
_orbitalNavigator->updateCameraStateFromStates(*_camera, deltaTime);
_camera->setFocusPositionVec3(focusNode()->worldPosition());
_orbitalNavigator->updateCameraStateFromStates(deltaTime);
}
}
}
@@ -183,21 +153,6 @@ void NavigationHandler::stopPlayback() {
_playbackModeEnabled = false;
}
SceneGraphNode* NavigationHandler::focusNode() const {
return _orbitalNavigator->focusNode();
}
glm::dvec3 NavigationHandler::focusNodeToCameraVector() const {
return _camera->positionVec3() - focusNode()->worldPosition();
}
glm::quat NavigationHandler::focusNodeToCameraRotation() const {
glm::dmat4 invWorldRotation = glm::dmat4(
glm::inverse(focusNode()->worldRotationMatrix())
);
return glm::quat(invWorldRotation) * glm::quat(_camera->rotationQuaternion());
}
Camera* NavigationHandler::camera() const {
return _camera;
}
@@ -227,13 +182,15 @@ void NavigationHandler::setCameraStateFromDictionary(const ghoul::Dictionary& ca
{
bool readSuccessful = true;
std::string focus;
std::string anchor;
std::string aim;
glm::dvec3 cameraPosition;
glm::dvec4 cameraRotation; // Need to read the quaternion as a vector first.
readSuccessful &= cameraDict.getValue(KeyFocus, focus);
readSuccessful &= cameraDict.getValue(KeyAnchor, anchor);
readSuccessful &= cameraDict.getValue(KeyPosition, cameraPosition);
readSuccessful &= cameraDict.getValue(KeyRotation, cameraRotation);
cameraDict.getValue(KeyAim, aim); // Aim is not required
if (!readSuccessful) {
throw ghoul::RuntimeError(
@@ -242,7 +199,9 @@ void NavigationHandler::setCameraStateFromDictionary(const ghoul::Dictionary& ca
}
// Set state
_origin = focus;
_orbitalNavigator->setAnchorNode(anchor);
_orbitalNavigator->setAimNode(aim);
_camera->setPositionVec3(cameraPosition);
_camera->setRotation(glm::dquat(
cameraRotation.x, cameraRotation.y, cameraRotation.z, cameraRotation.w));
@@ -260,7 +219,10 @@ ghoul::Dictionary NavigationHandler::cameraStateDictionary() {
ghoul::Dictionary cameraDict;
cameraDict.setValue(KeyPosition, cameraPosition);
cameraDict.setValue(KeyRotation, cameraRotation);
cameraDict.setValue(KeyFocus, focusNode()->identifier());
cameraDict.setValue(KeyAnchor, _orbitalNavigator->anchorNode()->identifier());
if (_orbitalNavigator->aimNode()) {
cameraDict.setValue(KeyAim, _orbitalNavigator->aimNode()->identifier());
}
return cameraDict;
}
@@ -281,8 +243,16 @@ void NavigationHandler::saveCameraStateToFile(const std::string& filepath) {
glm::dquat q = _camera->rotationQuaternion();
ofs << "return {" << std::endl;
ofs << " " << KeyFocus << " = " << "\"" << focusNode()->identifier() << "\""
ofs << " " << KeyAnchor << " = " << "\"" <<
_orbitalNavigator->anchorNode()->identifier() << "\""
<< "," << std::endl;
if (_orbitalNavigator->aimNode()) {
ofs << " " << KeyAim << " = " << "\"" <<
_orbitalNavigator->aimNode()->identifier() << "\""
<< "," << std::endl;
}
ofs << " " << KeyPosition << " = {"
<< std::to_string(p.x) << ", "
<< std::to_string(p.y) << ", "
@@ -391,11 +361,18 @@ scripting::LuaLibrary NavigationHandler::luaLibrary() {
"Restore the camera state from file"
},
{
"resetCameraDirection",
&luascriptfunctions::resetCameraDirection,
"retargetAnchor",
&luascriptfunctions::retargetAnchor,
{},
"void",
"Reset the camera direction to point at the focus node"
"Reset the camera direction to point at the anchor node"
},
{
"retargetAim",
&luascriptfunctions::retargetAim,
{},
"void",
"Reset the camera direction to point at the aim node"
},
{
"bindJoystickAxis",

View File

@@ -86,10 +86,19 @@ int saveCameraStateToFile(lua_State* L) {
return 0;
}
int resetCameraDirection(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::resetCameraDirection");
int retargetAnchor(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::retargetAnchor");
global::navigationHandler.resetCameraDirection();
global::navigationHandler.orbitalNavigator().startRetargetAnchor();
ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
return 0;
}
int retargetAim(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::retargetAim");
global::navigationHandler.orbitalNavigator().startRetargetAim();
ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
return 0;

File diff suppressed because it is too large Load Diff

View File

@@ -291,9 +291,11 @@ void SessionRecording::cleanUpPlayback() {
Scene* scene = camera->parent()->scene();
if (!_timeline.empty()) {
unsigned int p = _timeline[_idxTimeline_cameraPtrPrev].idxIntoKeyframeTypeArray;
global::navigationHandler.setFocusNode(
scene->sceneGraphNode(_keyframesCamera[p].focusNode)
);
const SceneGraphNode* node = scene->sceneGraphNode(_keyframesCamera[p].focusNode);
if (node) {
global::navigationHandler.orbitalNavigator().setFocusNode(node->identifier());
}
}
global::scriptScheduler.stopPlayback();
@@ -428,8 +430,9 @@ void SessionRecording::saveCameraKeyframe() {
return;
}
SceneGraphNode* focusNode = global::navigationHandler.focusNode();
if (!focusNode) {
const SceneGraphNode* anchorNode =
global::navigationHandler.orbitalNavigator().anchorNode();
if (!anchorNode) {
return;
}
@@ -1150,9 +1153,13 @@ bool SessionRecording::processCameraKeyframe(double now) {
// the rendered objects will be unstable and actually incorrect
Camera* camera = global::navigationHandler.camera();
Scene* scene = camera->parent()->scene();
global::navigationHandler.setFocusNode(scene->sceneGraphNode(
_keyframesCamera[prevIdx].focusNode
));
const SceneGraphNode* node =
scene->sceneGraphNode(_keyframesCamera[prevIdx].focusNode);
if (node) {
global::navigationHandler.orbitalNavigator().setFocusNode(node->identifier());
}
return interaction::KeyframeNavigator::updateCamera(
global::navigationHandler.camera(),

View File

@@ -585,20 +585,22 @@ const std::string& ParallelPeer::hostName() {
}
void ParallelPeer::sendCameraKeyframe() {
SceneGraphNode* focusNode = global::navigationHandler.focusNode();
const SceneGraphNode* focusNode =
global::navigationHandler.orbitalNavigator().anchorNode();
if (!focusNode) {
return;
}
// Create a keyframe with current position and orientation of camera
datamessagestructures::CameraKeyframe kf;
kf._position = global::navigationHandler.focusNodeToCameraVector();
kf._position = global::navigationHandler.orbitalNavigator().anchorNodeToCameraVector();
kf._followNodeRotation =
global::navigationHandler.orbitalNavigator().followingNodeRotation();
if (kf._followNodeRotation) {
kf._position = glm::inverse(focusNode->worldRotationMatrix()) * kf._position;
kf._rotation = global::navigationHandler.focusNodeToCameraRotation();
kf._rotation =
global::navigationHandler.orbitalNavigator().anchorNodeToCameraRotation();
}
else {
kf._rotation = global::navigationHandler.camera()->rotationQuaternion();

View File

@@ -364,22 +364,22 @@ std::string PropertyOwner::generateJson() const {
std::function<std::string(properties::PropertyOwner*)> createJson =
[&createJson](properties::PropertyOwner* owner) -> std::string
{
constexpr const char* replStr = R"("{}": "{}",)";
constexpr const char* replStr = R"("{}": "{}")";
std::stringstream json;
json << "{";
json << fmt::format(replStr, "name", owner->identifier());
json << fmt::format(replStr, "name", owner->identifier()) << ",";
json << "\"properties\": [";
const std::vector<properties::Property*>& properties = owner->properties();
for (properties::Property* p : properties) {
json << "{";
json << fmt::format(replStr, "id", p->identifier());
json << fmt::format(replStr, "type", p->className());
json << fmt::format(replStr, "id", p->identifier()) << ",";
json << fmt::format(replStr, "type", p->className()) << ",";
json << fmt::format(
replStr, "fullyQualifiedId", p->fullyQualifiedIdentifier()
);
json << fmt::format(replStr, "guiName", p->guiName());
) << ",";
json << fmt::format(replStr, "guiName", p->guiName()) << ",";
json << fmt::format(replStr, "description", escapedJson(p->description()));
json << "}";
if (p != properties.back()) {

View File

@@ -37,6 +37,9 @@ Scene* sceneGraph() {
SceneGraphNode* sceneGraphNode(const std::string& name) {
const Scene* graph = sceneGraph();
if (!graph) {
return nullptr;
}
return graph->sceneGraphNode(name);
}

View File

@@ -165,7 +165,7 @@ void Renderable::setPscUniforms(ghoul::opengl::ProgramObject& program,
const Camera& camera,
const PowerScaledCoordinate& position)
{
program.setUniform("campos", camera.position().vec4());
program.setUniform("campos", glm::vec4(camera.positionVec3(), 1.f));
program.setUniform("objpos", position.vec4());
program.setUniform("camrot", glm::mat4(camera.viewRotationMatrix()));
program.setUniform("scaling", glm::vec2(1.f, 0.f));

View File

@@ -588,7 +588,7 @@ void SceneGraphNode::setDependencies(const std::vector<SceneGraphNode*>& depende
}
SurfacePositionHandle SceneGraphNode::calculateSurfacePositionHandle(
const glm::dvec3& targetModelSpace)
const glm::dvec3& targetModelSpace) const
{
if (_renderable) {
return _renderable->calculateSurfacePositionHandle(targetModelSpace);
@@ -809,19 +809,4 @@ const SceneGraphNode::PerformanceRecord& SceneGraphNode::performanceRecord() con
return _performanceRecord;
}
void SceneGraphNode::updateCamera(Camera* camera) const {
psc origin(worldPosition());
//int i = 0;
// the camera position
psc relative = camera->position();
psc focus = camera->focusPosition();
psc relative_focus = relative - focus;
psc target = origin + relative_focus;
camera->setPosition(target);
camera->setFocusPosition(origin);
}
} // namespace openspace

View File

@@ -28,15 +28,14 @@
namespace openspace {
const glm::dvec3 Camera::ViewDirectionCameraSpace = glm::dvec3(0, 0, -1);
const glm::dvec3 Camera::LookupVectorCameraSpace = glm::dvec3(0, 1, 0);
const glm::dvec3 Camera::ViewDirectionCameraSpace = glm::dvec3(0.0, 0.0, -1.0);
const glm::dvec3 Camera::UpDirectionCameraSpace = glm::dvec3(0.0, 1.0, 0.0);
Camera::Camera(const Camera& o)
: sgctInternal(o.sgctInternal)
, _position(o._position)
, _rotation(o._rotation)
, _scaling(o._scaling)
, _focusPosition(o._focusPosition)
, _maxFov(o._maxFov)
, _cachedViewDirection(o._cachedViewDirection)
, _cachedLookupVector(o._cachedLookupVector)
@@ -49,11 +48,6 @@ void Camera::setPositionVec3(glm::dvec3 pos) {
_cachedCombinedViewMatrix.isDirty = true;
}
void Camera::setFocusPositionVec3(glm::dvec3 pos) {
std::lock_guard<std::mutex> _lock(_mutex);
_focusPosition = std::move(pos);
}
void Camera::setRotation(glm::dquat rotation) {
std::lock_guard<std::mutex> _lock(_mutex);
_rotation = std::move(rotation);
@@ -116,30 +110,26 @@ const glm::dvec3& Camera::unsynchedPositionVec3() const {
return _position;
}
const glm::dvec3& Camera::focusPositionVec3() const {
return _focusPosition;
}
const glm::dvec3& Camera::viewDirectionWorldSpace() const {
if (_cachedViewDirection.isDirty) {
_cachedViewDirection.datum = glm::normalize(
static_cast<glm::dquat>(_rotation) * ViewDirectionCameraSpace
);
_cachedViewDirection.isDirty = true;
_cachedViewDirection.isDirty = false;
}
return _cachedViewDirection.datum;
}
const glm::dvec3& Camera::lookUpVectorCameraSpace() const {
return LookupVectorCameraSpace;
return UpDirectionCameraSpace;
}
const glm::dvec3& Camera::lookUpVectorWorldSpace() const {
if (_cachedLookupVector.isDirty) {
_cachedLookupVector.datum = glm::normalize(
static_cast<glm::dquat>(_rotation) * LookupVectorCameraSpace
static_cast<glm::dquat>(_rotation) * UpDirectionCameraSpace
);
_cachedLookupVector.isDirty = true;
_cachedLookupVector.isDirty = false;
}
return _cachedLookupVector.datum;
@@ -170,6 +160,7 @@ const glm::dmat4& Camera::viewRotationMatrix() const {
_cachedViewRotationMatrix.datum = glm::mat4_cast(
glm::inverse(static_cast<glm::dquat>(_rotation))
);
_cachedViewRotationMatrix.isDirty = false;
}
return _cachedViewRotationMatrix.datum;
}
@@ -177,6 +168,7 @@ const glm::dmat4& Camera::viewRotationMatrix() const {
const glm::dmat4& Camera::viewScaleMatrix() const {
if (_cachedViewScaleMatrix.isDirty) {
_cachedViewScaleMatrix.datum = glm::scale(glm::mat4(1.f), glm::vec3(_scaling));
_cachedViewScaleMatrix.isDirty = false;
}
return _cachedViewScaleMatrix.datum;
}
@@ -195,7 +187,7 @@ const glm::dmat4& Camera::combinedViewMatrix() const {
glm::dmat4(viewScaleMatrix()) *
glm::dmat4(viewRotationMatrix()) *
cameraTranslation;
_cachedCombinedViewMatrix.isDirty = true;
_cachedCombinedViewMatrix.isDirty = false;
}
return _cachedCombinedViewMatrix.datum;
}
@@ -205,6 +197,8 @@ void Camera::invalidateCache() {
_cachedLookupVector.isDirty = true;
_cachedViewRotationMatrix.isDirty = true;
_cachedCombinedViewMatrix.isDirty = true;
_cachedViewScaleMatrix.isDirty = true;
_cachedSinMaxFov.isDirty = true;
}
void Camera::serialize(std::ostream& os) const {
@@ -270,29 +264,6 @@ const glm::mat4& Camera::SgctInternal::viewProjectionMatrix() const {
return _cachedViewProjectionMatrix.datum;
}
// Deprecated
void Camera::setPosition(psc pos) {
std::lock_guard<std::mutex> _lock(_mutex);
_position = pos.dvec3();
}
void Camera::setFocusPosition(psc pos) {
std::lock_guard<std::mutex> _lock(_mutex);
_focusPosition = pos.dvec3();
}
psc Camera::position() const {
return psc(static_cast<glm::dvec3>(_position));
}
psc Camera::unsynchedPosition() const {
return psc(static_cast<glm::dvec3>(_position));
}
psc Camera::focusPosition() const {
return psc(_focusPosition);
}
const glm::mat4& Camera::viewMatrix() const {
return sgctInternal.viewMatrix();
}