Libraries.Game.Layer3D Documentation

The Layer3D class is used to manage a number of 3D objects, as well as manage input. The Layer2D effectively consists of a 3D "world", where all objects added to it exist in the same space and can interact with each other.

Example Code

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color

class Main is Game

action Main
    StartGame()
end

action CreateGame
    Color color

    Model box
    box:LoadBox(2, 2, 2, color:Maroon())
    box:SetPosition(-2, 0, 2)

    Model sphere
    sphere:LoadSphere(2, 2, 2, color:Teal())
    sphere:SetPosition(2, 0, 2)

    Layer3D layer
    layer:Add(box)
    layer:Add(sphere)
    AddLayer(layer)
end

action Update(number seconds)
end
end

Inherits from: Libraries.Language.Object, Libraries.Game.Layer

Actions Documentation

Add(Libraries.Game.Graphics.DirectionalLight light)

This action will add the given light to the Layer3D. It will be used during lighting of all objects on the layer.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.DirectionalLight
use Libraries.Game.Graphics.AmbientLight

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color
        Model box
        box:LoadBox(2, 2, 2, color:Green())
        box:SetPosition(4, 0, 2)

        DirectionalLight light
        light:SetColor(0.8, 0.8, 0.8, 1)
        light:SetDirection(-1, -0.5, 1)

        AmbientLight ambient
        ambient:SetColor(0.4, 0.4, 0.4, 1)

        Layer3D layer
        layer:Add(box)
        layer:Add(light)
        layer:SetAmbientLight(ambient)
        AddLayer(layer)
    end

    action Update(number seconds)
    end
end

Add(Libraries.Game.Graphics.PointLight light)

This action will add a PointLight to the Layer3D. The Layer3D will treat it as an Item3D (respecting its position and updating it each frame) as well as using it to light up the scene.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.PointLight
use Libraries.Game.Graphics.AmbientLight

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color
        Model box
        box:LoadBox(2, 2, 2, color:Green())
        box:SetPosition(4, 0, 2)

        PointLight light
        light:SetColor(0.8, 0.8, 0.8, 1)
        light:SetPosition(6, 3, 0)
        light:SetIntensity(8)

        AmbientLight ambient
        ambient:SetColor(0.4, 0.4, 0.4, 1)

        Layer3D layer
        layer:Add(box)
        layer:Add(light)
        layer:SetAmbientLight(ambient)
        AddLayer(layer)
    end

    action Update(number seconds)
    end
end

Add(Libraries.Interface.Item3D item)

This action will add an Item3D to this Layer. It will be updated along with the rest of the layer, and will be drawn on the screen (if it is visible and possible to draw the given Item3D). The Item3D will be added to the back of the layer's internal array of items.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Interface.Item3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        // Item3D objects aren't visible, but can still be used for game logic.
        Item3D area
        area:SetWidth(5)
        area:SetHeight(5)
        area:SetDepth(5)
        area:SetPosition(0, 10, 0)

        // Models inherit from Item3D, so they can be added too.
        Model cylinder
        Color color
        cylinder:LoadCylinder(2, 4, 2, color:Orange())
        cylinder:SetPosition(0, 0, 3)

        Layer3D layer
        layer:Add(area)
        layer:Add(cylinder)
        AddLayer(layer)
    end

    action Update(number seconds)
    end
end

Add(integer index, Libraries.Interface.Item3D item)

This action will add an Item3D to this Layer's array of items at the index location. It will be updated along with the rest of the layer, and will be drawn on the screen (if it is visible and possible to draw the given Item3D).

Parameters

  • integer index: The index to store the item at in the layer's array of items.
  • Libraries.Interface.Item3D: The Item3D to be added to this layer.

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Interface.Item3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        // Item3D objects aren't visible, but can still be used for game logic.
        Item3D area
        area:SetDimensions(5, 5, 5)
        area:SetPosition(0, 10, 10)

        // Models inherit from Item2D, so they can be added too.
        Model box
        Color color
        box:LoadBox(3, 3, 3, color:Green())
        box:SetPosition(0, 0, 2)

        Layer3D layer
        layer:Add(0, area)
        layer:Add(1, box)
        AddLayer(layer)
    end

    action Update(number seconds)
    end
end

AddCollisionListener(Libraries.Interface.Events.CollisionListener3D listener)

AddCollisionListener will add a collision listener to this layer. The collision listener will be notified of collisions occuring on this layer, and is responsible for managing the collision events.

Parameters

AddGestureListener(Libraries.Interface.Events.GestureListener listener)

This action will add a GestureListener to the layer. When the layer receives a gesture event, it will first try to find the topmost item which can handle the event. If the event is not handled, then all GestureListeners in the layer will receive the event.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Interface.Events.GestureListener

class Main is Game

    // For most programs, this should be replaced with 
    // a custom class inheriting from GestureListener.
    GestureListener myListener

    action Main
        StartGame()
    end

    action CreateGame
        Layer3D layer
        layer:AddGestureListener(myListener)
        AddLayer(layer)
    end

    action Update(number seconds)
    end

end

AddJoint(Libraries.Game.Physics.Joints.Joint3D joint)

This action will add a MouseWheelListener to the layer. When the layer receives a mouse event, it will first try to find the topmost item which can handle the event. If the event is not handled, then all MouseWheelListeners in the layer will receive the event.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Interface.Events.MouseWheelListener

class Main is Game

    // For most programs, this should be replaced with 
    // a custom class inheriting from MouseWheelListener.
    MouseWheelListener myListener

    action Main
        StartGame()
    end

    action CreateGame
        Layer3D layer
        layer:AddMouseWheelListener(myListener)
        AddLayer(layer)
    end

    action Update(number seconds)
    end

end

AddMouseListener(Libraries.Interface.Events.MouseListener listener)

This action will add a MouseListener to the layer. When the layer receives a mouse event, it will first try to find the topmost item which can handle the event. If the event is not handled, then all MouseListeners in the layer will receive the event.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Interface.Events.MouseListener

class Main is Game

    // For most programs, this should be replaced with 
    // a custom class inheriting from MouseListener.
    MouseListener myListener

    action Main
        StartGame()
    end

    action CreateGame
        Layer3D layer
        layer:AddMouseListener(myListener)
        AddLayer(layer)
    end

    action Update(number seconds)
    end

end

AddMouseMovementListener(Libraries.Interface.Events.MouseMovementListener listener)

This action will add a MouseMovementListener to the layer. When the layer receives a mouse event, it will first try to find the topmost item which can handle the event. If the event is not handled, then all MouseMovementListeners in the layer will receive the event.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Interface.Events.MouseMovementListener

class Main is Game

    // For most programs, this should be replaced with 
    // a custom class inheriting from MouseMovementListener.
    MouseMovementListener myListener

    action Main
        StartGame()
    end

    action CreateGame
        Layer3D layer
        layer:AddMouseMovementListener(myListener)
        AddLayer(layer)
    end

    action Update(number seconds)
    end

end

AddMouseWheelListener(Libraries.Interface.Events.MouseWheelListener listener)

This action will add a MouseWheelListener to the layer. When the layer receives a mouse event, it will first try to find the topmost item which can handle the event. If the event is not handled, then all MouseWheelListeners in the layer will receive the event.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Interface.Events.MouseWheelListener

class Main is Game

    // For most programs, this should be replaced with 
    // a custom class inheriting from MouseWheelListener.
    MouseWheelListener myListener

    action Main
        StartGame()
    end

    action CreateGame
        Layer3D layer
        layer:AddMouseWheelListener(myListener)
        AddLayer(layer)
    end

    action Update(number seconds)
    end

end

AddToFront(Libraries.Interface.Item3D item)

This action will add an Item3D to this layer's array of items at index 0. It will be updated along with the rest of the layer, and will be drawn on the screen (if it is visible and possible to draw the given Item3D). Adding an item to the front will cause it to be drawn and updated before other items in the layer, and other drawn items will appear to be on top of it.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Interface.Item3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        // Item3D objects aren't visible, but can still be used for game logic.
        Item3D area
        area:SetDimensions(5, 5, 5)
        area:SetPosition(0, 0, 5)

        // Models inherit from Item3D, so they can be added too.
        Model cylinder
        Color color
        cylinder:LoadCylinder(3, 3, 3, color:Teal())
        cylinder:SetPosition(1, 0, 1)

        Layer3D layer
        layer:AddToFront(area)
        layer:AddToFront(cylinder)
        AddLayer(layer)
    end

    action Update(number seconds)
    end
end

AddTouchListener(Libraries.Interface.Events.TouchListener listener)

This action will add a TouchListener to the layer. When the layer receives a touch event, it will first try to find the topmost item which can handle the event. If the event is not handled, then all TouchListeners in the layer will receive the event.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Interface.Events.TouchListener

class Main is Game

    // For most programs, this should be replaced with 
    // a custom class inheriting from TouchListener.
    TouchListener myListener

    action Main
        StartGame()
    end

    action CreateGame
        Layer3D layer
        layer:AddTouchListener(myListener)
        AddLayer(layer)
    end

    action Update(number seconds)
    end

end

ApplyGravity()

This action will remove a MouseWheelListener from the layer. The listener will no longer receive events from the layer. If the given MouseWheelListener is not on the layer before calling this action, then this action will have no effect.

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Interface.Events.MouseWheelListener

class Main is Game

    // For most programs, this should be replaced with 
    // a custom class inheriting from MouseWheelListener.
    MouseWheelListener myListener

    action Main
        StartGame()
    end

    action CreateGame
        Layer3D layer
        layer:AddMouseWheelListener(myListener)
        AddLayer(layer)

        layer:RemoveMouseWheelListener(listener)
    end

    action Update(number seconds)
    end

end

AutomaticallyClearForces()

RemoveCollisionListener removes a collision listener to this layer. The collision listener will no longer be notified of collision events occurring on this layer. If the given listener is not a part of this layer, then this action will have no effect.

Return

boolean:

ClearForces()

This action will set the ambient lighting present in this Layer. If the layer already had ambient lighting, it will be overwritten.

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.DirectionalLight
use Libraries.Game.Graphics.AmbientLight

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color
        Model box
        box:LoadBox(2, 2, 2, color:Green())
        box:SetPosition(4, 0, 2)

        DirectionalLight light
        light:SetColor(0.8, 0.8, 0.8, 1)
        light:SetDirection(-1, -0.5, 1)

        AmbientLight ambient
        ambient:SetColor(0.4, 0.4, 0.4, 1)

        Layer3D layer
        layer:Add(box)
        layer:Add(light)
        layer:SetAmbientLight(ambient)
        AddLayer(layer)
    end

    action Update(number seconds)
    end
end

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

Parameters

Return

integer: The Compare result, Smaller, Equal, or Larger.

Example

Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)

DisableItemLighting(Libraries.Interface.Item3D item)

This action will disable lighting for the given Item3D (if it is a light) and any of its children (if they are lights). This action is called automatically by the Layer when adding or removing items. Most users will never need to use this action directly.

Parameters

Draw()

This action will draw all items in this Layer on the screen (if they can be drawn and they aren't hidden). If the Layer is currently hidden, then this action will do nothing. This is automatically called by the Game class as needed. Most users will never need to use this action directly.

Empty()

This action will clear all the items in this layer.

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color

        Model box
        box:LoadBox(2, 2, 2, color:Red())
        box:SetPosition(0, 0, 2)

        Layer3D layer
        layer:Add(box)
        AddLayer(layer)

        layer:Empty()
    end

    action Update(number seconds)
    end
end

EnableItemLighting(Libraries.Interface.Item3D item)

This action will enable lighting for the given Item3D (if it is a light) and any of its children (if they are lights). This action is called automatically by the Layer when adding or removing items. Most users will never need to use this action directly.

Parameters

EnablePhysics(boolean flag)

This action sets the Skybox that should be used by this Layer3D. The given Skybox will be rendered behind all other items in the layer. If the given parameter is undefined, the Layer will not render a skybox. By default, the skybox is undefined.

Parameters

  • boolean flag

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Skybox

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        // Assuming we have 6 image files, "Sky-Right.png", "Sky-Left.png", etc.
        Skybox skybox
        skybox:Load("Sky-Right.png", "Sky-Left.png", "Sky-Up.png", "Sky-Down.png", "Sky-Forward.png", "Sky-Back.png")

        Layer3D layer = GetCurrentLayer3D()
        layer:SetSkybox(skybox)

        Skybox layerBox = layer:GetSkybox()
    end
end

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

Example

use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)

Get(integer index)

This action will get an Item3D stored in the layer at the given index in the layer's internal array of items.

Parameters

  • integer index: The index to retrieve an item from in the layer's array of items.

Return

Libraries.Interface.Item3D: The Item3D stored at the index in the array.

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Interface.Item3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color
        Model sphere
        sphere:LoadSphere(3, 3, 3, color:White())
        sphere:SetPosition(0, 0, 2)

        Layer3D layer
        layer:Add(sphere)
        AddLayer(layer)

        Item3D item = layer:Get(0)
    end

    action Update(number seconds)
    end
end

GetAmbientLight()

This action will return the AmbientLight being used on this Layer3D. If the scene doesn't have any ambient lighting, then this action will return undefined.

Return

Libraries.Game.Graphics.AmbientLight: The AmbientLight used in the Layer.

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.DirectionalLight
use Libraries.Game.Graphics.AmbientLight

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color
        Model box
        box:LoadBox(2, 2, 2, color:Green())
        box:SetPosition(4, 0, 2)

        DirectionalLight light
        light:SetColor(0.8, 0.8, 0.8, 1)
        light:SetDirection(-1, -0.5, 1)

        AmbientLight ambient
        ambient:SetColor(0.4, 0.4, 0.4, 1)

        Layer3D layer
        layer:Add(box)
        layer:Add(light)
        layer:SetAmbientLight(ambient)
        AddLayer(layer)

        AmbientLight returnedLight = layer:GetAmbientLight()
    end

    action Update(number seconds)
    end
end

GetAutomaticResizing()

This action returns whether or not the Layer will automatically respond to ResizeEvents. If this value is true, then the Layer will automatically adjust the camera and resize Items on the Layer when a ResizeEvent occurs.

Return

boolean:

GetCamera()

This action will return the camera being used by this Layer. The camera is used to determine what will be drawn on the screen. Objects will be drawn on the screen as they are seen by the Layer's set camera.

Return

Libraries.Game.Graphics.Camera: The camera currently being used by this layer.

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Camera

class Main is Game

    Camera layerCamera = undefined

    action Main
        StartGame()
    end

    action CreateGame
        Layer3D layer
        layerCamera = layer:GetCamera()
        AddLayer(layer)
    end

    action Update(number seconds)
    end
end

GetCollisionList()

This action gets the list of items on this layer that are colliding and returns it as an array.

Return

Libraries.Interface.Events.CollisionEvent3D:

GetCollisionManager()

This action gets the collision manager for this object which is responsible for managing the collisions between all colliding items on this layer.

Return

Libraries.Game.Collision.CollisionManager3D:

GetDirectionalLight(integer index)

This action will return a direc