LuaRotation

Inherits Rotation

This Rotation type generates the rotation for the attached scene graph node by calling the provided Lua script to create the full matrix used to orient the scene graph node. The returned matrix must be a valid rotation matrix. The script parameter describes in greater detail how the Lua script file should be constructed.

Members

Name

Documentation

Type

Description

Optional

Script

This value is the path to the Lua script that will be executed to compute the rotation for this transformation. The script needs to define a function ‘rotation’ 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 as the third argument. It computes the rotation value factors returned as a table containing the 9 values that make up the resulting rotation matrix.

File

Value of type ‘File’

No

Inherited members from Rotation

Name

Documentation

Type

Description

Optional

Type

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

String

Must name a valid Rotation type

No

TimeFrame

The time frame in which this Rotation is applied. If the in-game time is outside this range, no rotation will be applied.

Table

TimeFrame

Yes

Asset Examples

Basic

This asset creates a scene graph node that only displays coordinate axes. The rotation of coordinate axes are determined by executing a Lua file that returns the rotation matrix to be used.

The script file that is used in this example
-- The `rotation` function takes exactly three arguments and returns the 9 values that
-- make up the final rotation matrix as a 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 rotation(simulationTime, prevSimulationTime, wallTime)
  -- Create a rotation around the x axis
  return {
    1,                        0,                         0,
    0, math.cos(simulationTime), -math.sin(simulationTime),
    0, math.sin(simulationTime),  math.cos(simulationTime)
  }
end
 1local Node = {
 2  Identifier = "LuaRotation_Example",
 3  Transform = {
 4    Rotation = {
 5      Type = "LuaRotation",
 6      Script = asset.resource("example.lua")
 7    }
 8  },
 9  Renderable = {
10    Type = "RenderableCartesianAxes"
11  },
12  GUI = {
13    Name = "LuaRotation - Basic",
14    Path = "/Examples"
15  }
16}
17
18asset.onInitialize(function()
19  openspace.addSceneGraphNode(Node)
20end)
21
22asset.onDeinitialize(function()
23  openspace.removeSceneGraphNode(Node)
24end)