LuaTranslation

Inherits Translation

Members

Name

Documentation

Type

Description

Optional

Script

This value is the path to the Lua script that will be executed to compute the translation for this transformation. The script needs to define a function ‘translation’ that takes the current simulation time in seconds past the J2000 epoch as the first argument, the simulation time in seconds past the J2000 epoch of the last frame as the second argument, and the current wall time as milliseconds past the J2000 epoch the third argument and computes the three translation values returned as a table.

File

Value of type ‘File’

No

Inherited members from Translation

Name

Documentation

Type

Description

Optional

Type

The type of translation that is described in this element. The available types of translations depend on the configuration of the application and can be written to disk on application startup into the FactoryDocumentation

String

Must name a valid Translation type

No

Asset Examples

Basic

This asset creates a SceneGraphNode that only displays coordinate axes. The coordinate axes are translated by a value determined by executing a Lua file that returns the translation parameters to be used as a table. In order to see the translation, we need to also have a node that does not move so that we can see the relative movement.

The script file that is used in this example
-- The `translation` function takes exactly three arguments and returns the three
-- translation values (one for each axis) as a single table.
-- The three parameters are all provided as the number of seconds past the J2000 epoch
-- (2000-01-01 12:00:00), which can be both fractional numbers as well as negative numbers
-- for dates earlier than the epoch.
--  1. `simulationTime` is the value of the in-game clock for the current frame
--  2. `prevSimulationTime` is the value of the in-game clock for the previous frame
--  3. `wallTime` is the value of the computer clock as seconds past the epoch
function translation(simulationTime, prevSimulationTime, wallTime)
  -- Make the object rotate around the z axis in a circular pattern
  return { math.sin(simulationTime), math.cos(simulationTime), 0 }
end
 1local NodeFocus = {
 2  Identifier = "LuaTranslation_Example_Focus",
 3  GUI = {
 4    Name = "Basic (Focus)",
 5    Path = "/Examples/LuaTranslation"
 6  }
 7}
 8
 9local Node = {
10  Identifier = "LuaTranslation_Example",
11  Parent = NodeFocus.Identifier,
12  Transform = {
13    Translation = {
14      Type = "LuaTranslation",
15      Script = asset.resource("example.lua")
16    }
17  },
18  Renderable = {
19    Type = "RenderableCartesianAxes"
20  },
21  GUI = {
22    Name = "LuaTranslation - Basic",
23    Path = "/Examples"
24  }
25}
26
27asset.onInitialize(function()
28  openspace.addSceneGraphNode(NodeFocus)
29  openspace.addSceneGraphNode(Node)
30end)
31
32asset.onDeinitialize(function()
33  openspace.removeSceneGraphNode(Node)
34  openspace.removeSceneGraphNode(NodeFocus)
35end)