Libraries.Game.Graphics.Camera Documentation

Inherits from: Libraries.Language.Object

Actions Documentation

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)

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)

GetCombinedMatrix()

This action returns a matrix containing the combined values of the camera's projection and view matrices. This is primarily used internally by the engine for calculations.

Return

Libraries.Compute.Matrix4: The combined projection and view Matrix of the Camera.

Example

use Libraries.Game.Game
use Libraries.Game.Graphics.Camera
use Libraries.Compute.Matrix4

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame

        Camera cam = GetCamera3D()
        Matrix4 combined = cam:GetCombinedMatrix()
    end

    action Update(number seconds)
    end

end

GetDirection()

This action will return the current direction of the Camera. The direction is returned as a Vector3 object. This is a reference to the actual Vector3 used by the Camera, so changes to the vector will effect the Camera.

Return

Libraries.Compute.Vector3: The Vector3 used by this Camera to store its direction.

Example

use Libraries.Game.Game
use Libraries.Game.Graphics.Camera
use Libraries.Compute.Vector3

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame

        Camera cam = GetCamera3D()
        Vector3 direction = cam:GetDirection()

        output "The default 3D camera direction is " + direction:GetX()
             + ", " + direction:GetY() + ", " + direction:GetZ()
    end

    action Update(number seconds)
    end

end

GetFar()

This action will return the distance to the far clipping plane of the camera. Objects that are farther than the distance to the far clipping plane will not be seen by the camera.

Return

number: The distance to the far clipping plane of the Camera.

Example

use Libraries.Game.Game
use Libraries.Game.Graphics.Camera
use Libraries.Compute.Vector3

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Camera cam = GetCamera3D()
        
        output "The default distance to the far clipping plane of the 3D camera is " + cam:GetFar()
    end

    action Update(number seconds)
    end

end

GetFrustum()

This action returns a frustum containing the area visible to the camera.

Return

Libraries.Compute.Frustum: The frustum that contains the Camera's visible area.

Example

use Libraries.Game.Game
use Libraries.Game.Graphics.Camera
use Libraries.Compute.Frustum

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame

        Camera cam = GetCamera3D()
        Frustum frustum = cam:GetFrustum()
    end

    action Update(number seconds)
    end

end

GetHashCode()

This action gets the hash code for an object.

Return

integer: The integer hash code of the object.

Example

Object o
integer hash = o:GetHashCode()

GetHeight()

This action will return the effective height of the camera lens.

Return

number: The height of the Camera lens.

Example

use Libraries.Game.Game
use Libraries.Game.Graphics.Camera
use Libraries.Compute.Vector3

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame

        Camera cam = GetCamera3D()
        
        output "The default height of the 3D camera is " + cam:GetHeight()
    end

    action Update(number seconds)
    end

end

GetInverseCombinedMatrix()

This action returns a matrix containing the inversed combined projection and view matrices. This is primarily used internally by the engine for calculations.

Return

Libraries.Compute.Matrix4: The inverse of the combined projection and view Matrices of the Camera.

Example

use Libraries.Game.Game
use Libraries.Game.Graphics.Camera
use Libraries.Compute.Matrix4

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame

        Camera cam = GetCamera3D()
        Matrix4 inverse = cam:GetInverseCombinedMatrix()
    end

    action Update(number seconds)
    end

end

GetNear()

This action will return the distance to the near clipping plane of the camera. Objects that are closer than the distance to the near clipping plane will not be seen by the camera.

Return

number: The distance to the near clipping plane of the Camera.

Example

use Libraries.Game.Game
use Libraries.Game.Graphics.Camera
use Libraries.Compute.Vector3

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Camera cam = GetCamera3D()
        
        output "The default distance to the near clipping plane of the 3D camera is " + cam:GetNear()
    end

    action Update(number seconds)
    end

end

GetPickRay(number screenX, number screenY)

GetPickRay will return a ray that begins at the given screen coordinates and points in the direction that the camera is viewing. The Ray's position will be in world coordinates.

Parameters

  • number screenX
  • number screenY

Return

Libraries.Compute.Ray:

GetPickRay(number screenX, number screenY, number viewportX, number viewportY, number viewportWidth, number viewportHeight)

GetPickRay will return a ray that begins at the given screen coordinates and points in the direction that the camera is viewing. The Ray's position will be in world coordinates. This action will calculate the point using the given position and dimensions of the viewport.

Parameters

  • number screenX
  • number screenY
  • number viewportX
  • number viewportY
  • number viewportWidth
  • number viewportHeight

Return

Libraries.Compute.Ray:

GetPosition()

This action will return the current position of the Camera. The position is returned as a Vector3 object containing the current x, y, and z coordinates. This is a reference to the actual Vector3 used by the Camera, so changes to the vector will effect the Camera.

Return

Libraries.Compute.Vector3: The Vector3 used by the Camera to store its position.

Example

use Libraries.Game.Game
use Libraries.Game.Graphics.Camera
use Libraries.Compute.Vector3

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame

        Camera cam = GetCamera3D()
        Vector3 position = cam:GetPosition()

        output "The default 3D camera position is " + position:GetX()
             + ", " + position:GetY() + ", " + position:GetZ()
    end

    action Update(number seconds)
    end

end

GetProjectionMatrix()

This action returns the calculated projection matrix of the Camera. This is primarily used internally by the engine for calculations.

Return

Libraries.Compute.Matrix4: The projection Matrix of the Camera.

Example

use Libraries.Game.Game
use Libraries.Game.Graphics.Camera
use Libraries.Compute.Matrix4

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Camera cam = GetCamera3D()
        Matrix4 projection = cam:GetProjectionMatrix()
    end

    action Update(number seconds)
    end

end

GetUp()

This action will return the direction that the camera considers to be up. The returned Vector3 indicates the direction that the top of the camera faces out towards. This is a reference to the actual Vector3 used by the Camera, so changes to the vector will effect the Camera.

Return

Libraries.Compute.Vector3: The Vector3 used by the Camera to store the "up" direction.

Example

use Libraries.Game.Game
use Libraries.Game.Graphics.Camera
use Libraries.Compute.Vector3

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Camera cam = GetCamera3D()
        Vector3 up = cam:GetUp()

        output "The default 3D camera up direction is " + up:GetX()
             + ", " + up:GetY() + ", " + up:GetZ()
    end

    action Update(number seconds)
    end

end

GetViewMatrix()

This action returns the calculated view matrix of the camera. This is primarily used internally by the engine for calculations.

Return

Libraries.Compute.Matrix4: The view Matrix of the Camera.

Example

use Libraries.Game.Game
use Libraries.Game.Graphics.Camera
use Libraries.Compute.Matrix4

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame

        Camera cam = GetCamera3D()
        Matrix4 view = cam:GetViewMatrix()
    end

    action Update(number seconds)
    end

end

GetWidth()

This action will return the effective width of the camera lens.

Return

number: The width of the Camera lens.

Example

use Libraries.Game.Game
use Libraries.Game.Graphics.Camera
use Libraries.Compute.Vector3

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Camera cam = GetCamera3D()
        
        output "The default width of the 3D camera is " + cam:GetWidth()
    end

    action Update(number seconds)
    end

end

GetZoom()

The GetZoom action returns the current level of zoom used by the camera. The default value is 1.

Return

number: The current zoom level.

Example

use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.Drawable
use Libraries.Game.Graphics.Camera

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color

        Drawable box
        box:LoadFilledRectangle(200, 200, color:Teal())
        box:SetPosition(300, 200)
        Add(box)
    end

    action Update(number seconds)
        Camera cam = GetCamera2D()

        if cam:GetZoom() < 2
            number newZoom = cam:GetZoom() + seconds / 4
            cam:SetZoom(newZoom)
        end
    end
end

LookAt(Libraries.Compute.Vector3 target)

This action will angle the camera to look at the given point in 3D space.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Camera
use Libraries.Game.Graphics.AmbientLight
use Libraries.Game.Graphics.DirectionalLight
use Libraries.Compute.Vector3

class Main is Game

    Vector3 target

    action Main
        StartGame()
    end

    action CreateGame
        Color color

        Model box
        box:LoadBox(2, 2, 2, color:Purple())
        box:SetPosition(10, 0, 0)
        Add(box)

        Camera cam = GetCamera3D()
        cam:SetPosition(0, 2, -7)

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

        DirectionalLight light
        light:SetColor(0.8, 0.8, 0.8, 1)
        light:SetDirection(-1, -1, 2)
        Add(light)
    end

    action Update(number seconds)
        Camera cam = GetCamera3D()

        if target:GetX() < 10
            target:SetX(target:GetX() + seconds)
            cam:LookAt(target)
        end
    end
end

LookAt(number x, number y, number z)

This action will angle the camera to look at the given point in 3D space.

Parameters

  • number x: The x-coordinate of the point to look at.
  • number y: The y-coordinate of the point to look at.
  • number z: The z-coordinate of the point to look at.

Example

use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Camera
use Libraries.Game.Graphics.AmbientLight
use Libraries.Game.Graphics.DirectionalLight

class Main is Game

    number targetX = 0

    action Main
        StartGame()
    end

    action CreateGame
        Color color

        Model box
        box:LoadBox(2, 2, 2, color:Purple())
        box:SetPosition(10, 0, 0)
        Add(box)

        Camera cam = GetCamera3D()
        cam:SetPosition(0, 2, -7)

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

        DirectionalLight light
        light:SetColor(0.8, 0.8, 0.8, 1)
        light:SetDirection(-1, -1, 2)
        Add(light)
    end

    action Update(number seconds)
        Camera cam = GetCamera3D()

        if targetX < 10
            targetX = targetX + seconds
            cam:LookAt(targetX, 0, 0)
        end
    end
end

Move(Libraries.Compute.Vector3 vector)

This action moves the camera on the x, y, and z planes by the amounts stored in the given Vector3.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Camera
use Libraries.Game.Graphics.AmbientLight
use Libraries.Game.Graphics.DirectionalLight
use Libraries.Compute.Vector3

class Main is Game

    Vector3 moveVector

    action Main
        StartGame()
    end

    action CreateGame
        Color color

        Model cube
        cube:LoadBox(2, 2, 2, color:Orange())
        Add(cube)

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

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

        Camera cam = GetCamera3D()
        cam:SetPosition(-8, 2, 0)
    end

    action Update(number seconds)
        Camera cam = GetCamera3D()
        Vector3 position = cam:GetPosition()

        if position:GetX() < 0
            moveVector:Set(2 * seconds, 0, -1 * seconds)
            cam:Move(moveVector)
        end
    end

end

Move(number x, number y, number z)

This action moves the camera by the given amounts on the x, y, and z planes, respectively.

Parameters

  • number x: How far to move the camera on the x-axis.
  • number y: How far to move the camera on the y-axis.
  • number z: How far to move the camera on the z-axis.

Example

use Libraries.Game.Game
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Camera
use Libraries.Game.Graphics.AmbientLight
use Libraries.Game.Graphics.DirectionalLight
use Libraries.Compute.Vector3

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color

        Model cube
        cube:LoadBox(2, 2, 2, color:Orange())
        Add(cube)

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

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

        Camera cam = GetCamera3D()
        cam:SetPosition(-8, 2, 0)
    end

    action Update(number seconds)
        Camera cam = GetCamera3D()
        Vector3 position = cam:GetPosition()

        if position:GetX() < 0
            cam:Move(2 * seconds, 0, -1 * seconds)
        end
    end

end

Rotate(Libraries.Compute.Quaternion quaternion)

This action rotates the camera the given number of degrees around the axis given as a 3D vector.

Parameters

Rotate(Libraries.Compute.Vector3 axis, number degrees)

This action rotates the camera the given number of degrees around the axis given as a 3D vector. The axis is essentially a ray that starts at the center of the camera and points outward. The camera will then rotate clockwise around that ray.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.Drawable
use Libraries.Game.Graphics.Camera
use Libraries.Compute.Vector3

class Main is Game

    Vector3 axis

    action Main
        StartGame()
    end

    action CreateGame
        Color color

        Drawable box1
        box1:LoadFilledRectangle(200, 200, color:Pink())
        box1:SetPosition(300, 0)
        Add(box1)

        Drawable box2
        box2:LoadFilledRectangle(200, 200, color:Maroon())
        box2:SetPosition(300, 400)
        Add(box2)

        axis:Set(0, 0, 1)
    end

    action Update(number seconds)
        Camera cam = GetCamera2D()
        cam:Rotate(axis, 20 * seconds)
    end
end

Rotate(number axisX, number axisY, number axisZ, number degrees)

This action rotates the camera the given number of degrees clockwise around an axis. The axis is essentially a ray that starts at the center of the camera and points outward. The camera will then rotate clockwise around that ray. The ray is defined using three numbers, representing which way it points on the x, y, and z planes, respectively.

Parameters

  • number axisX: The x-component of the ray to rotate around.
  • number axisY: The y-component of the ray to rotate around.
  • number axisZ: The z-component of the ray to rotate around.
  • number degrees: How many degrees to rotate about the axis.

Example

use Libraries.Game.Game
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.Drawable
use Libraries.Game.Graphics.Camera

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color

        Drawable box1
        box1:LoadFilledRectangle(200, 200, color:Pink())
        box1:SetPosition(300, 0)
        Add(box1)

        Drawable box2
        box2:LoadFilledRectangle(200, 200, color:Maroon())
        box2:SetPosition(300, 400)
        Add(box2)
    end

    action Update(number seconds)
        Camera cam = GetCamera2D()
        cam:Rotate(20 * seconds, 0, 0, 1)
    end
end

Rotate(Libraries.Compute.Matrix4 transform)

This action rotates the camera using the rotational information stored in a Matrix4 object. Typically the Matrix4 is primed using actions such as "SetToRotation" to store the rotational information before calling this action.

Parameters

Example


use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Camera
use Libraries.Compute.Matrix4
use Libraries.Game.Graphics.AmbientLight
use Libraries.Game.Graphics.DirectionalLight

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color

        Model cube
        cube:LoadBox(2, 2, 2, color:Orange())
        Add(cube)

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

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

        Matrix4 matrix
        matrix:SetToRotation(0, 1, 0, 45)

        Camera camera = GetCamera3D()
        camera:SetPosition(-3, 3, -3)
        camera:Rotate(matrix)
    end

    action Update(number seconds)
    end
end

RotateAround(Libraries.Compute.Vector3 point, Libraries.Compute.Vector3 axis, number degrees)

This action will rotate the camera clockwise around the given point, with the camera's rotation being about the given axis. The camera is rotated by the given number of degrees.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Camera
use Libraries.Compute.Vector3
use Libraries.Game.Graphics.AmbientLight
use Libraries.Game.Graphics.DirectionalLight

class Main is Game

    Vector3 point
    Vector3 axis

    action Main
        StartGame()
    end

    action CreateGame
        Color color

        Model cube
        cube:LoadBox(2, 2, 2, color:Orange())
        Add(cube)

        point:Set(0, 0, 0)
        axis:Set(0, 1, 0)

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

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

    action Update(number seconds)
        Camera cam = GetCamera3D()
        cam:RotateAround(point, axis, 30 * seconds)
    end
end

ScreenToWorldCoordinates(Libraries.Compute.Vector3 coords)

This action will translate a point given in screen coordinates to the world space. The z-coordinate of the given coordinates will be used to determine if the world coordinate returned should be on the near or far plane of the camera. A z-coordinate of 0 will get a point on the near plane, and a z-coordinate of 1 will get a point on the far plane. The calculated point will be contained in the Vector3 object that was passed as a parameter.

Parameters

Return

Libraries.Compute.Vector3:

ScreenToWorldCoordinates(Libraries.Compute.Vector3 coords, number viewportX, number viewportY, number viewportWidth, number viewportHeight)

This action will translate a point given in screen coordinates to the world space. The z-coordinate of the given coordinates will be used to determine if the world coordinate returned should be on the ne