SpotLight

Package: Libraries.Game.Graphics · Inherits from: Libraries.Game.Graphics.Light, Libraries.Interface.Item3D, Libraries.Interface.Item, Libraries.Language.Object

A SpotLight lights a 3D scene from one point, in a cone, the way a torch, a car's headlight or a stage light does. Inside its inner angle the light is at full strength; between the inner and outer angles it fades; outside the outer angle it gives no light. Like a point light, it gets dimmer the farther it travels, and it gives no light past its range. A spotlight is an Item3D, so it can be placed with SetPosition, and added to another item, such as a car, so that it moves and turns with it. Its direction is given in its own space: when the item it belongs to turns, the cone turns with it. Under Vulkan, spotlights cast shadows, as point lights do. Under OpenGL they are not drawn yet.

Example Code

use Libraries.Game.Game
use Libraries.Game.Graphics.SpotLight
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color

class Main is Game
action Main
    StartGame()
end

action CreateGame
    Color color

    Model floor
    floor:LoadBox(20, 0.2, 20, color:White())
    Add(floor)

    // A lamp above the floor, shining straight down.
    SpotLight lamp
    lamp:SetPosition(0, 6, 0)
    lamp:SetDirection(0, -1, 0)
    lamp:SetConeAngles(20, 30)
    lamp:SetIntensity(40)
    lamp:SetRange(15)
    Add(lamp)
end
end

Actions

Copy()

This action makes a copy of this light: color, position, offsets, direction, cone angles, intensity and range.

Returns

Libraries.Game.Graphics.SpotLight: The copy.

GetDirection()

This action returns the direction the cone points, in the light's own space. Change it with SetDirection, not by changing the vector.

Returns

Libraries.Compute.Vector3: The direction, of length 1.

GetInnerAngle()

This action returns the angle of full strength, in degrees.

Returns

number: The inner half-angle.

GetIntensity()

This action returns how bright the light is.

Returns

number: The light's intensity.

GetOuterAngle()

This action returns the angle where the light ends, in degrees.

Returns

number: The outer half-angle.

GetRange()

This action returns how far the light reaches: the range set with SetRange, or, if none was set, the distance at which its brightest color, at its intensity, falls below MINIMUM_ILLUMINATION_THRESHOLD.

Returns

number: How far the light reaches, in world units.

GetRangeSetting()

This action returns the range as set with SetRange: 0 if the range is worked out from the intensity and color. A scene saves this, so a light whose range was never set keeps working it out.

Returns

number: The range set, in world units, or 0.

Hide()

This action turns the light off without changing its intensity or color, so Show turns it back on as it was. A hidden light lights nothing and draws no shadows.

Example

use Libraries.Game.Game
use Libraries.Game.Graphics.SpotLight

class Main is Game
    SpotLight lamp

    action Main
        StartGame()
    end

    action CreateGame
        lamp:SetIntensity(5)
        Add(lamp)
        lamp:Hide()
    end
end

SetConeAngles(number inner, number outer)

This action sets the cone's half-angles, in degrees, measured from the direction the light points. Inside the inner angle the light is at full strength; it fades between the two, and gives no light past the outer angle. The outer angle is kept between 1 and 89 degrees, and the inner angle between 0 and the outer angle.

Parameters

  • inner number: The angle of full strength, in degrees.
  • outer number: The angle where the light ends, in degrees.

SetDirection(number x, number y, number z)

This action sets the direction the cone points, in the light's own space. It is made length 1. A direction of zero length is ignored.

Parameters

  • x number: The direction along x.
  • y number: The direction along y.
  • z number: The direction along z.

SetDirection(Libraries.Compute.Vector3 newDirection)

This action sets the direction the cone points, in the light's own space. It is made length 1.

Parameters

SetIntensity(number newIntensity)

This action sets how bright the light is.

Parameters

  • newIntensity number: The light's intensity.

SetLight(Libraries.Game.Graphics.Color newColor, Libraries.Compute.Vector3 newPosition, Libraries.Compute.Vector3 newDirection, number newIntensity, number newOuterAngle)

This action sets the color, position, direction, intensity and outer angle of the light at once. The inner angle becomes two thirds of the outer one.

Parameters

SetRange(number newRange)

This action sets how far the light reaches. It fades smoothly to nothing at this distance. A range of 0 works the range out from the intensity and color instead (see GetRange).

Parameters

  • newRange number: How far the light reaches, in world units, or 0.

Show()

This action turns a hidden light back on, as bright as it was.

Inherited Actions

9 actions from Libraries.Game.Graphics.Light
62 actions from Libraries.Interface.Item
216 actions from Libraries.Interface.Item3D
3 actions from Libraries.Language.Object