Free camera

This module contains the FreeCamera component, which represents a free camera that can be controlled by the user. The free camera can be enabled or disabled, and its position and rotation can be set. Note that all functions in this module create a new camera if one does not already exist. The free camera can be controlled using the following inputs:

W: move forward

S: move backward

D: move right

A: move left

E: move up

C: move down

Middle mouse button: move the camera by dragging the mouse

Right mouse button: rotate the camera by dragging the mouse

Mouse wheel: move the camera forward or backward

Classes

FreeCamera : Component

Represents the free camera component. The current position of the camera

Fields:
  • position : float3 - The current rotation of the camera

  • rotation : quat4 = quat4() - Whether to use scaled game time for the camera movement

  • useScaledTime : bool = false - The current euler angles of the camera

FreeCamera.set_state(pos: float3; rot: quat4)

Sets the state of the free camera component with the given position and rotation.

Arguments:
  • pos : float3

  • rot : quat4

FreeCamera(pos: float3; rot: quat4): FreeCamera

Initializes the free camera component with the given position and rotation.

Arguments:
  • pos : float3

  • rot : quat4

Functions

create_free_camera(position: float3; rotation: quat4 = quat4()): NodeId

Creates a free camera in the scene with default parameters fov=65, znear=0.01, zfar=10000.

Arguments:
  • position : float3 - the initial position of the camera

  • rotation : quat4 - the initial quaternion rotation of the camera

Returns:
  • NodeId - the ID of the created camera node

Usage example:

let freeCamera = create_free_camera(float3(0))
enable_free_camera(freeCamera: NodeId&; isActive: bool = true)

Changes the active state of the free camera.

Arguments:
  • freeCamera : NodeId & - the ID of the free camera node

  • isActive : bool - the new active state of the camera (true by default)

is_active_free_camera(freeCamera: NodeId): bool

Checks if the free camera is active.

Arguments:
  • freeCamera : NodeId & - the ID of the free camera node

Returns:
  • bool - true if the free camera is active, false otherwise

toggle_free_camera(freeCamera: NodeId&; position: float3; rotation: quat4; isActive: bool = true)

Toggles the state of the free camera and sets its position, rotation and active state (true by default).

Arguments:
  • freeCamera : NodeId & - the ID of the free camera node

  • position : float3 - the new position of the camera

  • rotation : quat4 - the new rotation of the camera

  • isActive : bool - the new active state of the camera