Files
OpenSpace/scripts/common.lua
Kalle Bladin 2e4f31ded8 Interaction Updates (#353)
* Interaction speed is not dependent on framerate

* Split up interaction code in files and perform smooth interpolation when changing focus

* Abstract interaction code in to functions.

* Interpolation time is dependent on angle to focus node.

* Use correct delta time when interpolating

* Fix bug regarding decomposition of camera rotation.

* Make orbital interaction mode behave as globe browsing and no longer use interactiondepth below ellipsoid.

* Do not always rotate with object. Depending on distance

* Remove interaction depth below ellipsoid. Now able to interact without renderable

* Remove specification of interactionDepthBelowEllipsoid and cameraMinHeight

* Remove GlobeBrowsingInteractionMode

* Rename OrbitalInteractionMode to OrbitalNavigator and no longer extend interactionmode.

* Move properties from interaction handler to orbital navigator

* Use smooth step for follow rotation interpolator

* Rename KeyframeInteractionMode to KeyframeNavigator

* Rename files

* Clean up.

* Separate mousestate from orbitalnavigator

* Clean up

* Split keybindingmanager from interactionhandler interactionhandler

* Rename interactionhandler to navigationhandler

* Rename files

* Clean up

* Take back usage of gotochunk and gotogeo

* Rename lua library navigation

* Move functionality from navigationhandler to keyframenavigator

* Update scripts for navigation

* Comment code

* Clean up

* Solve but that caused NaN values for camera position when being in center of globe and setting focus to the globe.

* Update jenkins file to remove build folder before building.

* Fix error in jenkins script

* Update jenkins file

* Update jenkins file

* Revert jenkins file

* I hope this makes Jenkins happy.

* Line endings God damnit

* Line endings

* Clean up

* Fix compilation issue

* Take back default scene.

* Fix indentation

* Move functions goToGeo and goToChunk to GlobeBrowsingModule.

* Include algorithm for std::find

* Remove auto and other clean up
2017-07-14 17:17:17 +02:00

145 lines
5.5 KiB
Lua

--[[ Commonly used OpenSpace configuration functions ]]--
helper = {}
helper.renderable = {}
helper.property = {}
-- These helpers are for scheduling lua scripts
-- See class ScriptScheduler and ScheduledScript for reference
helper.scheduledScript = {}
helper.scheduledScript.reversible = {}
-- Function that sets the most common key bindings that are common to most (all?)
-- scenes
helper.setCommonKeys = function()
openspace.bindKeyLocal(
"F1",
helper.property.invert('Global Properties.OnScreenGUI.Main.enabled'),
"Toggles the visibility of the on-screen GUI."
)
openspace.bindKeyLocal(
"F2",
helper.property.invert("RenderEngine.performanceMeasurements"),
"Toogles performance measurements that shows rendering time informations."
)
openspace.bindKeyLocal(
"ESC",
"openspace.toggleShutdown()",
"Toggles the shutdown that will stop OpenSpace after a grace period. Press again to cancel the shutdown during this period."
)
openspace.bindKeyLocal(
"PRINT_SCREEN",
"openspace.setPropertyValueSingle('RenderEngine.takeScreenshot', nil)",
"Saves the contents of the screen to a file in the working directory."
)
openspace.bindKey(
"SPACE",
"openspace.time.togglePause()",
"Starts and stops the simulation time."
)
openspace.bindKey(
"COMMA",
"openspace.setRenderer('Framebuffer');",
"Changes the currently used renderer to use the 'Framebuffer' implementation."
)
openspace.bindKey(
"PERIOD",
"openspace.setRenderer('ABuffer');",
"Changes the currently used renderer to use the 'ABuffer' implementation."
)
openspace.bindKey(
"f",
helper.property.invert('NavigationHandler.OrbitalNavigator.horizontalFriction'),
"Toggles the horizontal friction of the camera. If it is disabled, the camera rotates around the focus object indefinitely."
)
openspace.bindKey(
"Shift+f",
helper.property.invert('NavigationHandler.OrbitalNavigator.verticalFriction'),
"Toggles the vertical friction of the camera. If it is disabled, the camera rises up from or closes in towards the focus object indefinitely."
)
openspace.bindKey(
"Ctrl+f",
helper.property.invert('NavigationHandler.OrbitalNavigator.rotationalFriction'),
"Toggles the rotational friction of the camera. If it is disabled, the camera rotates around its own axis indefinitely."
)
openspace.bindKey(
"w",
"openspace.toggleFade(3)",
"Toggles the fade to black within 3 seconds or shows the rendering after 3 seconds."
)
end
helper.setDeltaTimeKeys = function(t)
local Keys = {
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
'Shift+1', 'Shift+2', 'Shift+3', 'Shift+4', 'Shift+5', 'Shift+6', 'Shift+7', 'Shift+8', 'Shift+9', 'Shift+0',
'Ctrl+1', 'Ctrl+2', 'Ctrl+3', 'Ctrl+4', 'Ctrl+5', 'Ctrl+6', 'Ctrl+7', 'Ctrl+8', 'Ctrl+9', 'Ctrl+0',
'Alt+1', 'Alt+2', 'Alt+3', 'Alt+4', 'Alt+5', 'Alt+6', 'Alt+7', 'Alt+8', 'Alt+9', 'Alt+0'
}
if #t > #Keys then
openspace.printError("Error settings delta time keys: Too many delta times (" .. #t .. ")")
return
end
for i, v in ipairs(t) do
openspace.bindKey(
Keys[i],
'openspace.time.setDeltaTime(' .. v .. ")",
'Setting the simulation speed to ' .. v .. ' seconds per realtime second'
)
end
end
-- Function that returns the string that inverts the fully qualified boolean property 'property'
helper.property.invert = function(property)
local escaped_property = "'" .. property .. "'"
return "openspace.setPropertyValue(" .. escaped_property .. ", not openspace.getPropertyValue(" .. escaped_property .. "));"
end
-- Function that returns the string that increments the 'property' by the 'value'
helper.property.increment = function(property, value)
local v = value or 1
local escaped_property = "'" .. property .. "'"
return "openspace.setPropertyValue(" .. escaped_property .. ", openspace.getPropertyValue(" .. escaped_property .. ") + " .. v .. ");"
end
-- Function that returns the string that decrements the 'property' by the 'value'
helper.property.decrement = function(property, value)
return helper.property.increment(property, -value)
end
-- Function that returns the string that enables/disables the renderable 'renderable'
helper.renderable.toggle = function(renderable)
return helper.property.invert(renderable .. ".renderable.enabled")
end
-- Function that returns the string that sets the enabled property of <renderable> to <enabled>
helper.renderable.setEnabled = function(renderable, enabled)
return "openspace.setPropertyValue('" .. renderable .. ".renderable.enabled', " .. (enabled and "true" or "false") .. ");";
end
-- Function that returns a lua table specifying a reversible ScheduledScript for
-- setting the enabled property of <renderable> to <enabled> at time <time>.
helper.scheduledScript.reversible.setEnabled = function(time, renderable, enabled)
return
{
Time = time,
ForwardScript = helper.renderable.setEnabled(renderable, enabled),
BackwardScript = helper.renderable.setEnabled(renderable, not enabled)
}
end
helper.scheduledScript.setEnabled = function(time, renderable, enabled)
return
{
Time = time,
ForwardScript = helper.renderable.setEnabled(renderable, enabled)
}
end