Fixed failed merging of master.

This commit is contained in:
Jonathas Costa
2019-07-31 15:05:52 -04:00
61 changed files with 21213 additions and 7434 deletions
+6 -1
View File
@@ -54,11 +54,14 @@ set(OPENSPACE_SOURCE
${OPENSPACE_BASE_DIR}/src/interaction/navigationhandler_lua.inl
${OPENSPACE_BASE_DIR}/src/interaction/mousecamerastates.cpp
${OPENSPACE_BASE_DIR}/src/interaction/orbitalnavigator.cpp
${OPENSPACE_BASE_DIR}/src/interaction/scriptcamerastates.cpp
${OPENSPACE_BASE_DIR}/src/interaction/externinteraction.cpp
${OPENSPACE_BASE_DIR}/src/interaction/sessionrecording.cpp
${OPENSPACE_BASE_DIR}/src/interaction/sessionrecording_lua.inl
${OPENSPACE_BASE_DIR}/src/interaction/shortcutmanager.cpp
${OPENSPACE_BASE_DIR}/src/interaction/shortcutmanager_lua.inl
${OPENSPACE_BASE_DIR}/src/interaction/websocketinputstate.cpp
${OPENSPACE_BASE_DIR}/src/interaction/websocketcamerastates.cpp
${OPENSPACE_BASE_DIR}/src/mission/mission.cpp
${OPENSPACE_BASE_DIR}/src/mission/missionmanager.cpp
${OPENSPACE_BASE_DIR}/src/mission/missionmanager_lua.inl
@@ -202,7 +205,6 @@ if (APPLE)
${OPENSPACE_BASE_DIR}/src/interaction/touchbar.mm
)
endif ()
set(OPENSPACE_HEADER
${OPENSPACE_BASE_DIR}/include/openspace/json.h
${OPENSPACE_BASE_DIR}/include/openspace/documentation/core_registration.h
@@ -236,9 +238,12 @@ set(OPENSPACE_HEADER
${OPENSPACE_BASE_DIR}/include/openspace/interaction/navigationhandler.h
${OPENSPACE_BASE_DIR}/include/openspace/interaction/orbitalnavigator.h
${OPENSPACE_BASE_DIR}/include/openspace/interaction/externinteraction.h
${OPENSPACE_BASE_DIR}/include/openspace/interaction/scriptcamerastates.h
${OPENSPACE_BASE_DIR}/include/openspace/interaction/sessionrecording.h
${OPENSPACE_BASE_DIR}/include/openspace/interaction/sessionrecording.inl
${OPENSPACE_BASE_DIR}/include/openspace/interaction/shortcutmanager.h
${OPENSPACE_BASE_DIR}/include/openspace/interaction/websocketinputstate.h
${OPENSPACE_BASE_DIR}/include/openspace/interaction/websocketcamerastates.h
${OPENSPACE_BASE_DIR}/include/openspace/mission/mission.h
${OPENSPACE_BASE_DIR}/include/openspace/mission/missionmanager.h
${OPENSPACE_BASE_DIR}/include/openspace/network/parallelconnection.h
-2
View File
@@ -94,8 +94,6 @@ template <>
std::string to_string(const openspace::documentation::TestResult::Offense::Reason& value)
{
switch (value) {
case openspace::documentation::TestResult::Offense::Reason::ExtraKey:
return "Extra key";
case openspace::documentation::TestResult::Offense::Reason::MissingKey:
return "Missing key";
case openspace::documentation::TestResult::Offense::Reason::UnknownIdentifier:
+6
View File
@@ -33,6 +33,7 @@
#include <openspace/engine/windowdelegate.h>
#include <openspace/interaction/keybindingmanager.h>
#include <openspace/interaction/joystickinputstate.h>
#include <openspace/interaction/websocketinputstate.h>
#include <openspace/interaction/navigationhandler.h>
#include <openspace/interaction/sessionrecording.h>
#include <openspace/interaction/shortcutmanager.h>
@@ -154,6 +155,11 @@ interaction::JoystickInputStates& gJoystickInputStates() {
return g;
}
interaction::WebsocketInputStates& gWebsocketInputStates() {
static interaction::WebsocketInputStates g;
return g;
}
interaction::KeybindingManager& gKeybindingManager() {
static interaction::KeybindingManager g;
return g;
+22 -3
View File
@@ -708,6 +708,10 @@ void OpenSpaceEngine::loadSingleAsset(const std::string& assetPath) {
bool loading = true;
while (loading) {
if (_shouldAbortLoading) {
global::windowDelegate.terminate();
break;
}
_loadingScreen->render();
_assetManager->update();
@@ -719,10 +723,10 @@ void OpenSpaceEngine::loadSingleAsset(const std::string& assetPath) {
progressInfo.progress = (*it)->progress();
if ((*it)->nTotalBytesIsKnown()) {
progressInfo.currentSize = static_cast<int>(
progressInfo.currentSize = static_cast<uint64_t>(
(*it)->nSynchronizedBytes()
);
progressInfo.totalSize = static_cast<int>(
progressInfo.totalSize = static_cast<uint64_t>(
(*it)->nTotalBytes()
);
}
@@ -750,6 +754,10 @@ void OpenSpaceEngine::loadSingleAsset(const std::string& assetPath) {
}
}
}
if (_shouldAbortLoading) {
_loadingScreen = nullptr;
return;
}
_loadingScreen->setPhase(LoadingScreen::Phase::Initialization);
@@ -992,7 +1000,8 @@ void OpenSpaceEngine::preSynchronization() {
global::syncEngine.preSynchronization(SyncEngine::IsMaster(master));
if (master) {
double dt = global::windowDelegate.averageDeltaTime();
double dt = global::windowDelegate.deltaTime();
if (global::sessionRecording.isSavingFramesDuringPlayback()) {
dt = global::sessionRecording.fixedDeltaTimeDuringFrameOutput();
@@ -1183,6 +1192,16 @@ void OpenSpaceEngine::postDraw() {
}
void OpenSpaceEngine::keyboardCallback(Key key, KeyModifier mod, KeyAction action) {
if (_loadingScreen) {
// If the loading screen object exists, we are currently loading and want key
// presses to behave differently
if (key == Key::Escape) {
_shouldAbortLoading = true;
}
return;
}
using F = std::function<bool (Key, KeyModifier, KeyAction)>;
for (const F& func : global::callback::keyboard) {
const bool isConsumed = func(key, mod, action);
+27 -3
View File
@@ -26,6 +26,7 @@
#include <openspace/engine/globals.h>
#include <openspace/interaction/joystickinputstate.h>
#include <openspace/interaction/websocketinputstate.h>
#include <ghoul/fmt.h>
#include <algorithm>
@@ -91,10 +92,13 @@ bool InputState::isKeyPressed(std::pair<Key, KeyModifier> keyModPair) const {
}
bool InputState::isKeyPressed(Key key) const {
auto it = std::find_if(_keysDown.begin(), _keysDown.end(),
auto it = std::find_if(
_keysDown.begin(),
_keysDown.end(),
[key](const std::pair<Key, KeyModifier>& keyModPair) {
return key == keyModPair.first;
});
return key == keyModPair.first;
}
);
return it != _keysDown.end();
}
@@ -111,4 +115,24 @@ bool InputState::joystickButton(int i) const {
return global::joystickInputStates.button(i, JoystickAction::Press);
}
float InputState::websocketAxis(int i) const {
return global::websocketInputStates.axis(i);
}
bool InputState::websocketButton(int i) const {
return global::websocketInputStates.button(i, WebsocketAction::Press);
}
void InputState::resetWebsockets() {
using K = size_t;
using V = WebsocketInputState*;
for (const std::pair<const K, V>& p : global::websocketInputStates) {
p.second->isConnected = false;
}
}
bool InputState::hasWebsocketStates() const {
return !global::websocketInputStates.empty();
}
} // namespace openspace::interaction
+72 -22
View File
@@ -67,7 +67,7 @@ namespace openspace::interaction {
ghoul::Dictionary
openspace::interaction::NavigationHandler::NavigationState::dictionary() const
openspace::interaction::NavigationHandler::NavigationState::dictionary() const
{
ghoul::Dictionary cameraDict;
cameraDict.setValue(KeyPosition, position);
@@ -94,7 +94,7 @@ openspace::interaction::NavigationHandler::NavigationState::dictionary() const
}
openspace::interaction::NavigationHandler::NavigationState::NavigationState(
const ghoul::Dictionary& dictionary)
const ghoul::Dictionary& dictionary)
{
const bool hasAnchor = dictionary.hasValue<std::string>(KeyAnchor);
const bool hasPosition = dictionary.hasValue<glm::dvec3>(KeyPosition);
@@ -130,13 +130,13 @@ openspace::interaction::NavigationHandler::NavigationState::NavigationState(
}
openspace::interaction::NavigationHandler::NavigationState::NavigationState(
std::string anchor,
std::string aim,
std::string referenceFrame,
glm::dvec3 position,
std::optional<glm::dvec3> up,
double yaw,
double pitch)
std::string anchor,
std::string aim,
std::string referenceFrame,
glm::dvec3 position,
std::optional<glm::dvec3> up,
double yaw,
double pitch)
: anchor(std::move(anchor))
, aim(std::move(aim))
, referenceFrame(std::move(referenceFrame))
@@ -214,7 +214,8 @@ void NavigationHandler::updateCamera(double deltaTime) {
applyNavigationState(_pendingNavigationState.value());
_orbitalNavigator.resetVelocities();
_pendingNavigationState.reset();
} else if (!_playbackModeEnabled && _camera) {
}
else if (!_playbackModeEnabled && _camera) {
if (_useKeyFrameInteraction) {
_keyframeNavigator.updateCamera(*_camera, _playbackModeEnabled);
}
@@ -272,7 +273,7 @@ void NavigationHandler::applyNavigationState(const NavigationHandler::Navigation
// Construct vectors of a "neutral" view, i.e. when the aim is centered in view.
glm::dvec3 neutralView =
glm::normalize(aimNode->worldPosition() - cameraPositionWorld);
glm::dquat neutralCameraRotation = glm::inverse(glm::quat_cast(glm::lookAt(
glm::dvec3(0.0),
neutralView,
@@ -331,7 +332,7 @@ void NavigationHandler::keyboardCallback(Key key, KeyModifier modifier, KeyActio
}
NavigationHandler::NavigationState NavigationHandler::navigationState(
const SceneGraphNode& referenceFrame) const
const SceneGraphNode& referenceFrame) const
{
const SceneGraphNode* anchor = _orbitalNavigator.anchorNode();
const SceneGraphNode* aim = _orbitalNavigator.aimNode();
@@ -355,7 +356,7 @@ NavigationHandler::NavigationState NavigationHandler::navigationState(
// Need to compensate by redisual roll left in local rotation:
const glm::dquat unroll = glm::angleAxis(eulerAngles.z, glm::dvec3(0, 0, 1));
const glm::dvec3 neutralUp =
glm::inverse(invNeutralRotation) * unroll * _camera->lookUpVectorCameraSpace();
glm::inverse(invNeutralRotation) * unroll * _camera->lookUpVectorCameraSpace();
const glm::dmat3 invReferenceFrameTransform =
glm::inverse(referenceFrame.worldRotationMatrix());
@@ -366,7 +367,7 @@ NavigationHandler::NavigationState NavigationHandler::navigationState(
return NavigationState(
_orbitalNavigator.anchorNode()->identifier(),
_orbitalNavigator.aimNode() ?
_orbitalNavigator.aimNode()->identifier() : "",
_orbitalNavigator.aimNode()->identifier() : "",
referenceFrame.identifier(),
position,
invReferenceFrameTransform * neutralUp, yaw, pitch
@@ -374,7 +375,7 @@ NavigationHandler::NavigationState NavigationHandler::navigationState(
}
void NavigationHandler::saveNavigationState(const std::string& filepath,
const std::string& referenceFrameIdentifier)
const std::string& referenceFrameIdentifier)
{
const SceneGraphNode* referenceFrame = _orbitalNavigator.followingNodeRotation() ?
_orbitalNavigator.anchorNode() :
@@ -428,9 +429,9 @@ void NavigationHandler::loadNavigationState(const std::string& filepath) {
}
void NavigationHandler::setJoystickAxisMapping(int axis,
JoystickCameraStates::AxisType mapping,
JoystickCameraStates::AxisInvert shouldInvert,
JoystickCameraStates::AxisNormalize shouldNormalize)
JoystickCameraStates::AxisType mapping,
JoystickCameraStates::AxisInvert shouldInvert,
JoystickCameraStates::AxisNormalize shouldNormalize)
{
_orbitalNavigator.joystickStates().setAxisMapping(
axis,
@@ -440,8 +441,22 @@ void NavigationHandler::setJoystickAxisMapping(int axis,
);
}
void NavigationHandler::setWebsocketAxisMapping(int axis,
WebsocketCameraStates::AxisType mapping,
WebsocketCameraStates::AxisInvert shouldInvert,
WebsocketCameraStates::AxisNormalize shouldNormalize)
{
_orbitalNavigator.websocketStates().setAxisMapping(
axis,
mapping,
shouldInvert,
shouldNormalize
);
}
JoystickCameraStates::AxisInformation
NavigationHandler::joystickAxisMapping(int axis) const
NavigationHandler::joystickAxisMapping(int axis) const
{
return _orbitalNavigator.joystickStates().axisMapping(axis);
}
@@ -455,9 +470,9 @@ float NavigationHandler::joystickAxisDeadzone(int axis) const {
}
void NavigationHandler::bindJoystickButtonCommand(int button, std::string command,
JoystickAction action,
JoystickCameraStates::ButtonCommandRemote remote,
std::string documentation)
JoystickAction action,
JoystickCameraStates::ButtonCommandRemote remote,
std::string documentation)
{
_orbitalNavigator.joystickStates().bindButtonCommand(
button,
@@ -635,6 +650,41 @@ scripting::LuaLibrary NavigationHandler::luaLibrary() {
"int",
"Returns the script that is currently bound to be executed when the "
"provided button is pressed"
},
{
"addGlobalRotation",
&luascriptfunctions::addGlobalRotation,
{},
"double, double",
"Directly adds to the global rotation of the camera"
},
{
"addLocalRotation",
&luascriptfunctions::addLocalRotation,
{},
"double, double",
"Directly adds to the local rotation of the camera"
},
{
"addTruckMovement",
&luascriptfunctions::addTruckMovement,
{},
"double, double",
"Directly adds to the truck movement of the camera"
},
{
"addLocalRoll",
&luascriptfunctions::addLocalRoll,
{},
"double, double",
"Directly adds to the local roll of the camera"
},
{
"addGlobalRoll",
&luascriptfunctions::addGlobalRoll,
{},
"double, double",
"Directly adds to the global roll of the camera"
}
}
};
+73 -5
View File
@@ -23,6 +23,7 @@
****************************************************************************************/
#include <numeric>
#include <openspace/interaction/scriptcamerastates.h>
namespace openspace::luascriptfunctions {
@@ -51,9 +52,7 @@ int setNavigationState(lua_State* L) {
ghoul::Dictionary navigationStateDictionary;
ghoul::lua::luaDictionaryFromState(L, navigationStateDictionary);
using namespace openspace::documentation;
TestResult r = testSpecification(
openspace::documentation::TestResult r = openspace::documentation::testSpecification(
interaction::NavigationHandler::NavigationState::Documentation(),
navigationStateDictionary
);
@@ -61,8 +60,7 @@ int setNavigationState(lua_State* L) {
if (!r.success) {
lua_settop(L, 0);
return ghoul::lua::luaError(
L,
fmt::format("Could not set camera state: {}", ghoul::to_string(r))
L, fmt::format("Could not set camera state: {}", ghoul::to_string(r))
);
}
@@ -250,4 +248,74 @@ int joystickButton(lua_State* L) {
return 1;
}
int addGlobalRotation(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, 2, "lua::addGlobalRotation");
const double v1 = ghoul::lua::value<double>(L, 1, ghoul::lua::PopValue::No);
const double v2 = ghoul::lua::value<double>(L, 2, ghoul::lua::PopValue::No);
global::navigationHandler.orbitalNavigator().scriptStates().addGlobalRotation(
glm::dvec2(v1, v2)
);
lua_settop(L, 0);
return 0;
}
int addLocalRotation(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, 2, "lua::addLocalRotation");
const double v1 = ghoul::lua::value<double>(L, 1, ghoul::lua::PopValue::No);
const double v2 = ghoul::lua::value<double>(L, 2, ghoul::lua::PopValue::No);
global::navigationHandler.orbitalNavigator().scriptStates().addLocalRotation(
glm::dvec2(v1, v2)
);
lua_settop(L, 0);
return 0;
}
int addTruckMovement(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, 2, "lua::addTruckMovement");
const double v1 = ghoul::lua::value<double>(L, 1, ghoul::lua::PopValue::No);
const double v2 = ghoul::lua::value<double>(L, 2, ghoul::lua::PopValue::No);
global::navigationHandler.orbitalNavigator().scriptStates().addTruckMovement(
glm::dvec2(v1, v2)
);
lua_settop(L, 0);
return 0;
}
int addLocalRoll(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, 2, "lua::addLocalRoll");
const double v1 = ghoul::lua::value<double>(L, 1, ghoul::lua::PopValue::No);
const double v2 = ghoul::lua::value<double>(L, 2, ghoul::lua::PopValue::No);
global::navigationHandler.orbitalNavigator().scriptStates().addLocalRoll(
glm::dvec2(v1, v2)
);
lua_settop(L, 0);
return 0;
}
int addGlobalRoll(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, 2, "lua::addGlobalRoll");
const double v1 = ghoul::lua::value<double>(L, 1, ghoul::lua::PopValue::No);
const double v2 = ghoul::lua::value<double>(L, 2, ghoul::lua::PopValue::No);
global::navigationHandler.orbitalNavigator().scriptStates().addGlobalRoll(
glm::dvec2(v1, v2)
);
lua_settop(L, 0);
return 0;
}
} // namespace openspace::luascriptfunctions
+76 -9
View File
@@ -109,6 +109,13 @@ namespace {
"the sensitivity is the less impact a joystick motion will have."
};
constexpr openspace::properties::Property::PropertyInfo WebsocketSensitivityInfo = {
"WebsocketSensitivity",
"Websocket Sensitivity",
"Determines the sensitivity of the camera motion thorugh a websocket. The lower "
"the sensitivity is the less impact a webstick motion will have."
};
constexpr openspace::properties::Property::PropertyInfo FrictionInfo = {
"Friction",
"Friction Factor",
@@ -205,6 +212,7 @@ OrbitalNavigator::OrbitalNavigator()
, _minimumAllowedDistance(MinimumDistanceInfo, 10.0f, 0.0f, 10000.f)
, _mouseSensitivity(MouseSensitivityInfo, 15.0f, 1.0f, 50.f)
, _joystickSensitivity(JoystickSensitivityInfo, 10.0f, 1.0f, 50.f)
, _websocketSensitivity(WebsocketSensitivityInfo, 10.0f, 1.0f, 50.f)
, _useAdaptiveStereoscopicDepth(UseAdaptiveStereoscopicDepthInfo, true)
, _stereoscopicDepthOfFocusSurface(StereoscopicDepthOfFocusSurfaceInfo, 8, 0.25, 100)
, _staticViewScaleExponent(StaticViewScaleExponentInfo, 0.f, -30, 10)
@@ -213,6 +221,7 @@ OrbitalNavigator::OrbitalNavigator()
, _followRotationInterpolationTime(FollowRotationInterpTimeInfo, 1.0, 0.0, 10.0)
, _mouseStates(_mouseSensitivity * 0.0001, 1 / (_friction.friction + 0.0000001))
, _joystickStates(_joystickSensitivity * 0.1, 1 / (_friction.friction + 0.0000001))
, _websocketStates(_websocketSensitivity, 1 / (_friction.friction + 0.0000001))
{
_anchor.onChange([this]() {
@@ -290,26 +299,34 @@ OrbitalNavigator::OrbitalNavigator()
_friction.roll.onChange([&]() {
_mouseStates.setRotationalFriction(_friction.roll);
_joystickStates.setRotationalFriction(_friction.roll);
_websocketStates.setRotationalFriction(_friction.roll);
});
_friction.rotational.onChange([&]() {
_mouseStates.setHorizontalFriction(_friction.rotational);
_joystickStates.setHorizontalFriction(_friction.rotational);
_websocketStates.setHorizontalFriction(_friction.rotational);
});
_friction.zoom.onChange([&]() {
_mouseStates.setVerticalFriction(_friction.zoom);
_joystickStates.setVerticalFriction(_friction.zoom);
_websocketStates.setVerticalFriction(_friction.zoom);
});
_friction.friction.onChange([&]() {
_mouseStates.setVelocityScaleFactor(1 / (_friction.friction + 0.0000001));
_joystickStates.setVelocityScaleFactor(1 / (_friction.friction + 0.0000001));
_websocketStates.setVelocityScaleFactor(1 / (_friction.friction + 0.0000001));
});
_mouseSensitivity.onChange([&]() {
_mouseStates.setSensitivity(_mouseSensitivity * pow(10.0, -4));
});
_joystickSensitivity.onChange([&]() {
_joystickStates.setSensitivity(_joystickSensitivity * pow(10.0, -4));
_joystickStates.setSensitivity(_joystickSensitivity * 0.1);
});
_websocketSensitivity.onChange([&]() {
_websocketStates.setSensitivity(_websocketSensitivity);
});
addPropertySubOwner(_friction);
@@ -331,6 +348,7 @@ OrbitalNavigator::OrbitalNavigator()
addProperty(_mouseSensitivity);
addProperty(_joystickSensitivity);
addProperty(_websocketSensitivity);
}
glm::dvec3 OrbitalNavigator::anchorNodeToCameraVector() const {
@@ -348,6 +366,7 @@ glm::quat OrbitalNavigator::anchorNodeToCameraRotation() const {
void OrbitalNavigator::resetVelocities() {
_mouseStates.resetVelocities();
_joystickStates.resetVelocities();
_scriptStates.resetVelocities();
}
void OrbitalNavigator::updateStatesFromInput(const InputState& inputState,
@@ -355,6 +374,8 @@ void OrbitalNavigator::updateStatesFromInput(const InputState& inputState,
{
_mouseStates.updateStateFromInput(inputState, deltaTime);
_joystickStates.updateStateFromInput(inputState, deltaTime);
_websocketStates.updateStateFromInput(inputState, deltaTime);
_scriptStates.updateStateFromInput(inputState, deltaTime);
}
void OrbitalNavigator::updateCameraStateFromStates(double deltaTime) {
@@ -871,7 +892,9 @@ glm::dquat OrbitalNavigator::roll(double deltaTime,
{
const glm::dquat mouseRollQuat = glm::angleAxis(
_mouseStates.localRollVelocity().x * deltaTime +
_joystickStates.localRollVelocity().x * deltaTime,
_joystickStates.localRollVelocity().x * deltaTime +
_websocketStates.localRollVelocity().x * deltaTime +
_scriptStates.localRollVelocity().x * deltaTime,
glm::dvec3(0.0, 0.0, 1.0)
);
return localCameraRotation * mouseRollQuat;
@@ -892,8 +915,20 @@ glm::dquat OrbitalNavigator::rotateLocally(double deltaTime,
0.0
) * deltaTime);
const glm::dquat websocketRotationDiff = glm::dquat(glm::dvec3(
_websocketStates.localRotationVelocity().y,
_websocketStates.localRotationVelocity().x,
0.0
) * deltaTime);
return localCameraRotation * joystickRotationDiff * mouseRotationDiff;
const glm::dquat scriptRotationDiff = glm::dquat(glm::dvec3(
_scriptStates.localRotationVelocity().y,
_scriptStates.localRotationVelocity().x,
0.0
) * deltaTime);
return localCameraRotation * joystickRotationDiff * mouseRotationDiff *
websocketRotationDiff * scriptRotationDiff;
}
glm::dquat OrbitalNavigator::interpolateLocalRotation(double deltaTime,
const glm::dquat& localCameraRotation)
@@ -1061,19 +1096,31 @@ glm::dvec3 OrbitalNavigator::translateHorizontally(double deltaTime,
const glm::dquat mouseRotationDiffCamSpace = glm::dquat(glm::dvec3(
-_mouseStates.globalRotationVelocity().y * deltaTime,
-_mouseStates.globalRotationVelocity().x * deltaTime,
0) * speedScale);
0.0) * speedScale);
const glm::dquat joystickRotationDiffCamSpace = glm::dquat(glm::dvec3(
-_joystickStates.globalRotationVelocity().y * deltaTime,
-_joystickStates.globalRotationVelocity().x * deltaTime,
0.0) * speedScale
);
const glm::dquat scriptRotationDiffCamSpace = glm::dquat(glm::dvec3(
-_scriptStates.globalRotationVelocity().y * deltaTime,
-_scriptStates.globalRotationVelocity().x * deltaTime,
0.0) * speedScale
);
const glm::dquat websocketRotationDiffCamSpace = glm::dquat(glm::dvec3(
-_websocketStates.globalRotationVelocity().y * deltaTime,
-_websocketStates.globalRotationVelocity().x * deltaTime,
0) * speedScale
);
// Transform to world space
const glm::dquat rotationDiffWorldSpace = globalCameraRotation *
joystickRotationDiffCamSpace *
mouseRotationDiffCamSpace *
glm::inverse(globalCameraRotation);
joystickRotationDiffCamSpace * mouseRotationDiffCamSpace *
websocketRotationDiffCamSpace * scriptRotationDiffCamSpace *
glm::inverse(globalCameraRotation);
// Rotate and find the difference vector
const glm::dvec3 rotationDiffVec3 =
@@ -1134,7 +1181,9 @@ glm::dvec3 OrbitalNavigator::translateVertically(double deltaTime,
const glm::dvec3 actualSurfaceToCamera = posDiff - centerToActualSurface;
const double totalVelocity = _joystickStates.truckMovementVelocity().y +
_mouseStates.truckMovementVelocity().y;
_mouseStates.truckMovementVelocity().y +
_websocketStates.truckMovementVelocity().y +
_scriptStates.truckMovementVelocity().y;
return cameraPosition - actualSurfaceToCamera * totalVelocity * deltaTime;
}
@@ -1153,7 +1202,9 @@ glm::dquat OrbitalNavigator::rotateHorizontally(double deltaTime,
const glm::dquat mouseCameraRollRotation = glm::angleAxis(
_mouseStates.globalRollVelocity().x * deltaTime +
_joystickStates.globalRollVelocity().x * deltaTime,
_joystickStates.globalRollVelocity().x * deltaTime +
_websocketStates.globalRollVelocity().x * deltaTime +
_scriptStates.globalRollVelocity().x * deltaTime,
directionFromSurfaceToCamera
);
return mouseCameraRollRotation * globalCameraRotation;
@@ -1239,4 +1290,20 @@ const JoystickCameraStates& OrbitalNavigator::joystickStates() const {
return _joystickStates;
}
WebsocketCameraStates& OrbitalNavigator::websocketStates() {
return _websocketStates;
}
const WebsocketCameraStates& OrbitalNavigator::websocketStates() const {
return _websocketStates;
}
ScriptCameraStates& OrbitalNavigator::scriptStates() {
return _scriptStates;
}
const ScriptCameraStates& OrbitalNavigator::scriptStates() const {
return _scriptStates;
}
} // namespace openspace::interaction
+118
View File
@@ -0,0 +1,118 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2019 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <openspace/interaction/scriptcamerastates.h>
#include <openspace/interaction/inputstate.h>
namespace {
const double SENSITIVITY_ADJUSTMENT_INCREASE = 8.0;
const double SENSITIVITY_ADJUSTMENT_DECREASE = 0.5;
}
namespace openspace::interaction {
ScriptCameraStates::ScriptCameraStates() : CameraInteractionStates(1.0, 1.0) {}
void ScriptCameraStates::updateStateFromInput(const InputState& inputState,
double deltaTime)
{
if (_localRotation != glm::dvec2(0.0)) {
_localRotationState.velocity.set(
_localRotation * _sensitivity,
deltaTime
);
_localRotation = glm::dvec2(0.0);
}
else {
_localRotationState.velocity.decelerate(deltaTime);
}
if (_globalRotation != glm::dvec2(0.0)) {
_globalRotationState.velocity.set(
_globalRotation * _sensitivity,
deltaTime
);
_globalRotation = glm::dvec2(0.0);
}
else {
_globalRotationState.velocity.decelerate(deltaTime);
}
if (_truckMovement != glm::dvec2(0.0)) {
_truckMovementState.velocity.set(
_truckMovement * _sensitivity,
deltaTime
);
_truckMovement = glm::dvec2(0.0);
}
else {
_truckMovementState.velocity.decelerate(deltaTime);
}
if (_localRoll != glm::dvec2(0.0)) {
_localRollState.velocity.set(
_localRoll * _sensitivity,
deltaTime
);
_localRoll = glm::dvec2(0.0);
}
else {
_localRollState.velocity.decelerate(deltaTime);
}
if (_globalRoll != glm::dvec2(0.0)) {
_globalRollState.velocity.set(
_globalRoll * _sensitivity,
deltaTime
);
_globalRoll = glm::dvec2(0.0);
}
else {
_globalRollState.velocity.decelerate(deltaTime);
}
}
void ScriptCameraStates::addLocalRotation(const glm::dvec2& delta) {
_localRotation += delta;
}
void ScriptCameraStates::addGlobalRotation(const glm::dvec2& delta) {
_globalRotation += delta;
}
void ScriptCameraStates::addTruckMovement(const glm::dvec2& delta) {
_truckMovement += delta;
}
void ScriptCameraStates::addLocalRoll(const glm::dvec2& delta) {
_localRoll += delta;
}
void ScriptCameraStates::addGlobalRoll(const glm::dvec2& delta) {
_globalRoll += delta;
}
} // namespace openspace::interaction
+260
View File
@@ -0,0 +1,260 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2019 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <openspace/interaction/websocketcamerastates.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/interaction/inputstate.h>
#include <openspace/scripting/scriptengine.h>
#include <ghoul/misc/stringconversion.h>
#include <utility>
namespace openspace::interaction {
WebsocketCameraStates::WebsocketCameraStates(double sensitivity, double velocityScaleFactor)
: CameraInteractionStates(sensitivity, velocityScaleFactor)
{}
void WebsocketCameraStates::updateStateFromInput(const InputState& inputState,
double deltaTime)
{
std::pair<bool, glm::dvec2> globalRotation = { false, glm::dvec2(0.0) };
std::pair<bool, double> zoom = { false, 0.0 };
std::pair<bool, glm::dvec2> localRoll = { false, glm::dvec2(0.0) };
std::pair<bool, glm::dvec2> globalRoll = { false, glm::dvec2(0.0) };
std::pair<bool, glm::dvec2> localRotation = { false, glm::dvec2(0.0) };
if (inputState.hasWebsocketStates()) {
for (int i = 0; i < WebsocketInputState::MaxAxes; ++i) {
AxisInformation t = _axisMapping[i];
if (t.type == AxisType::None) {
continue;
}
float value = inputState.websocketAxis(i);
bool hasValue = abs(value) > t.deadzone;
if (!hasValue) {
value = 0.f;
}
if (t.normalize) {
value = (value + 1.f) / 2.f;
}
if (t.invert) {
value *= -1.f;
}
value = static_cast<float>(value * _sensitivity);
switch (t.type) {
case AxisType::None:
break;
case AxisType::OrbitX:
globalRotation.first = hasValue || globalRotation.first;
globalRotation.second.x = value;
break;
case AxisType::OrbitY:
globalRotation.first = hasValue || globalRotation.first;
globalRotation.second.y = value;
break;
case AxisType::ZoomIn:
zoom.first = hasValue || zoom.first;
zoom.second += value;
break;
case AxisType::ZoomOut:
zoom.first = hasValue || zoom.first;
zoom.second -= value;
break;
case AxisType::LocalRollX:
localRoll.first = hasValue || localRoll.first;
localRoll.second.x = value;
break;
case AxisType::LocalRollY:
localRoll.first = hasValue || localRoll.first;
localRoll.second.y = value;
break;
case AxisType::GlobalRollX:
globalRoll.first = hasValue || globalRoll.first;
globalRoll.second.x = value;
break;
case AxisType::GlobalRollY:
globalRoll.first = hasValue || globalRoll.first;
globalRoll.second.y = value;
break;
case AxisType::PanX:
localRotation.first = hasValue || localRotation.first;
localRotation.second.x = value;
break;
case AxisType::PanY:
localRotation.first = hasValue || localRotation.first;
localRotation.second.y = value;
break;
}
}
}
if (globalRotation.first) {
_globalRotationState.velocity.set(globalRotation.second, deltaTime);
}
else {
_globalRotationState.velocity.decelerate(deltaTime);
}
if (zoom.first) {
_truckMovementState.velocity.set(glm::dvec2(zoom.second), deltaTime);
}
else {
_truckMovementState.velocity.decelerate(deltaTime);
}
if (localRoll.first) {
_localRollState.velocity.set(localRoll.second, deltaTime);
}
else {
_localRollState.velocity.decelerate(deltaTime);
}
if (globalRoll.first) {
_globalRollState.velocity.set(globalRoll.second, deltaTime);
}
else {
_globalRollState.velocity.decelerate(deltaTime);
}
if (localRotation.first) {
_localRotationState.velocity.set(localRotation.second, deltaTime);
}
else {
_localRotationState.velocity.decelerate(deltaTime);
}
}
void WebsocketCameraStates::setAxisMapping(int axis, AxisType mapping,
AxisInvert shouldInvert,
AxisNormalize shouldNormalize)
{
ghoul_assert(axis < WebsocketInputState::MaxAxes, "axis must be < MaxAxes");
_axisMapping[axis].type = mapping;
_axisMapping[axis].invert = shouldInvert;
_axisMapping[axis].normalize = shouldNormalize;
}
WebsocketCameraStates::AxisInformation WebsocketCameraStates::axisMapping(int axis) const {
return _axisMapping[axis];
}
void WebsocketCameraStates::setDeadzone(int axis, float deadzone) {
_axisMapping[axis].deadzone = deadzone;
}
float WebsocketCameraStates::deadzone(int axis) const {
return _axisMapping[axis].deadzone;
}
void WebsocketCameraStates::bindButtonCommand(int button, std::string command,
WebsocketAction action,
ButtonCommandRemote remote,
std::string documentation)
{
_buttonMapping.insert({
button,
{ std::move(command), action, remote, std::move(documentation) }
});
}
void WebsocketCameraStates::clearButtonCommand(int button) {
for (auto it = _buttonMapping.begin(); it != _buttonMapping.end();) {
// If the current iterator is the button that we are looking for, delete it
// (std::multimap::erase will return the iterator to the next element for us)
if (it->first == button) {
it = _buttonMapping.erase(it);
}
else {
++it;
}
}
}
std::vector<std::string> WebsocketCameraStates::buttonCommand(int button) const {
std::vector<std::string> result;
auto itRange = _buttonMapping.equal_range(button);
for (auto it = itRange.first; it != itRange.second; ++it) {
result.push_back(it->second.command);
}
return result;
}
} // namespace openspace::interaction
namespace ghoul {
template <>
std::string to_string(const openspace::interaction::WebsocketCameraStates::AxisType& type)
{
using T = openspace::interaction::WebsocketCameraStates::AxisType;
switch (type) {
case T::None: return "None";
case T::OrbitX: return "Orbit X";
case T::OrbitY: return "Orbit Y";
case T::ZoomIn: return "Zoom In";
case T::ZoomOut: return "Zoom Out";
case T::LocalRollX: return "LocalRoll X";
case T::LocalRollY: return "LocalRoll Y";
case T::GlobalRollX: return "GlobalRoll X";
case T::GlobalRollY: return "GlobalRoll Y";
case T::PanX: return "Pan X";
case T::PanY: return "Pan Y";
default: return "";
}
}
template <>
openspace::interaction::WebsocketCameraStates::AxisType from_string(
const std::string& string)
{
using T = openspace::interaction::WebsocketCameraStates::AxisType;
static const std::map<std::string, T> Map = {
{ "None", T::None },
{ "Orbit X", T::OrbitX },
{ "Orbit Y", T::OrbitY },
{ "Zoom In", T::ZoomIn },
{ "Zoom Out", T::ZoomOut },
{ "LocalRoll X", T::LocalRollX },
{ "LocalRoll Y", T::LocalRollY },
{ "GlobalRoll X", T::GlobalRollX },
{ "GlobalRoll Y", T::GlobalRollY },
{ "Pan X", T::PanX },
{ "Pan Y", T::PanY }
};
return Map.at(string);
}
} // namespace ghoul
+97
View File
@@ -0,0 +1,97 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2019 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <openspace/interaction/websocketinputstate.h>
#include <ghoul/misc/invariants.h>
#include <ghoul/misc/stringconversion.h>
#include <map>
#include <numeric>
namespace openspace::interaction {
float WebsocketInputStates::axis(int axis) const {
ghoul_precondition(axis >= 0, "axis must be 0 or positive");
float res = std::accumulate(
begin(),
end(),
0.f,
[axis](float value, const std::pair<const size_t, const WebsocketInputState *> state) {
if (state.second->isConnected) {
value += state.second->axes[axis];
}
return value;
}
);
// If multiple websockets are connected, we might get values outside the -1,1 range by
// summing them up
return std::clamp(res, -1.f, 1.f);
}
bool WebsocketInputStates::button(int button, WebsocketAction action) const {
ghoul_precondition(button >= 0, "button must be 0 or positive");
bool res = std::any_of(
begin(),
end(),
[button, action](const std::pair<const size_t, const WebsocketInputState *> state) {
return state.second->isConnected ?
( state.second->buttons[button] == action )
: false;
}
);
return res;
}
} // namespace openspace::interaction
namespace ghoul {
template <>
std::string to_string(const openspace::interaction::WebsocketAction& action) {
switch (action) {
case openspace::interaction::WebsocketAction::Idle: return "Idle";
case openspace::interaction::WebsocketAction::Press: return "Press";
case openspace::interaction::WebsocketAction::Repeat: return "Repeat";
case openspace::interaction::WebsocketAction::Release: return "Release";
default: return "";
}
}
template <>
openspace::interaction::WebsocketAction from_string(const std::string& string) {
static const std::map<std::string, openspace::interaction::WebsocketAction> Map = {
{ "Idle", openspace::interaction::WebsocketAction::Idle },
{ "Press", openspace::interaction::WebsocketAction::Press },
{ "Repeat", openspace::interaction::WebsocketAction::Repeat },
{ "Release", openspace::interaction::WebsocketAction::Release }
};
return Map.at(string);
}
} // namespace ghoul
+2 -10
View File
@@ -440,11 +440,7 @@ void LoadingScreen::render() {
if (info.totalSize < 1024 * 1024) { // 1MB
text = fmt::format(
"{} ({}%)\n{}/{} {}",
text,
p,
info.currentSize,
info.totalSize,
"bytes"
text, p, info.currentSize, info.totalSize, "bytes"
);
}
else {
@@ -453,11 +449,7 @@ void LoadingScreen::render() {
text = fmt::format(
"{} ({}%)\n{:.3f}/{:.3f} {}",
text,
p,
curr,
total,
"MB"
text, p, curr, total, "MB"
);
}
}