game_object

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GameObject

type GameObject interface {
	common.Delegate[GameObject]

	// ID returns the object's unique identifier.
	//
	// Returns:
	//   - uint64: the object ID
	ID() uint64

	// Enabled returns whether this object is enabled for rendering.
	//
	// Returns:
	//   - bool: true if enabled
	Enabled() bool

	// Ephemeral returns whether this object is ephemeral.
	// Ephemeral objects are not persisted in the scene's registry when added.
	//
	// Returns:
	//   - bool: true if ephemeral
	Ephemeral() bool

	// Model returns the Model associated with this object, or nil if not set.
	//
	// Returns:
	//   - model.Model: the associated model or nil
	Model() model.Model

	// Animator returns the Animator associated with this object.
	//
	// Returns:
	//   - animator.Animator: the associated Animator, or nil
	Animator() animator.Animator

	// AnimatorInstanceID returns the instance index within the Animator.
	//
	// Returns:
	//   - int: the instance index, or -1 if unset
	AnimatorInstanceID() int

	// Position derives the instance's current position from the Animator.
	// Returns zeros if no Animator is set.
	//
	// Returns:
	//   - x, y, z: position components
	Position() (x, y, z float32)

	// Rotation derives the instance's current rotation from the Animator.
	// Returns zeros if no Animator is set or on skeletal backends.
	//
	// Returns:
	//   - rx, ry, rz: rotation angles
	Rotation() (rx, ry, rz float32)

	// RotationSpeed derives the instance's current rotation speed from the Animator.
	// Returns zeros if no Animator is set or on skeletal backends.
	//
	// Returns:
	//   - rx, ry, rz: rotation speed values
	RotationSpeed() (rx, ry, rz float32)

	// Scale derives the instance's current scale from the Animator.
	// Returns zeros if no Animator is set.
	//
	// Returns:
	//   - sx, sy, sz: scale components
	Scale() (sx, sy, sz float32)

	// TransformData reads all transform data from the Animator in a single pair of calls.
	// Returns zeros if no Animator is set.
	//
	// Returns:
	//   - pos: position as [3]float32 (x, y, z)
	//   - scale: scale as [3]float32 (x, y, z)
	//   - rot: rotation as [3]float32 (rx, ry, rz)
	//   - rotSpeed: rotation speed as [3]float32 (rx, ry, rz)
	TransformData() (pos, scale, rot, rotSpeed [3]float32)

	// SetID sets the object's unique identifier.
	//
	// Parameters:
	//   - id: the ID to assign
	SetID(id uint64)

	// SetEnabled sets whether the object is enabled for rendering.
	//
	// Parameters:
	//   - enabled: true to enable
	SetEnabled(enabled bool)

	// SetModel assigns a Model to this object.
	//
	// Parameters:
	//   - m: the Model to associate
	SetModel(m model.Model)

	// SetAnimator sets the Animator associated with this object.
	//
	// Parameters:
	//   - anim: the Animator to associate
	SetAnimator(anim animator.Animator)

	// SetAnimatorInstanceID sets the instance index within the Animator.
	//
	// Parameters:
	//   - instanceID: the instance index
	SetAnimatorInstanceID(instanceID int)

	// SetPosition updates the instance's position via the Animator, preserving current scale.
	//
	// Parameters:
	//   - x, y, z: new position components
	SetPosition(x, y, z float32)

	// SetRotation updates the instance's rotation via the Animator, preserving current rotation speed.
	//
	// Parameters:
	//   - rx, ry, rz: new rotation angles
	SetRotation(rx, ry, rz float32)

	// SetRotationSpeed updates the instance's rotation speed via the Animator, preserving current rotation.
	//
	// Parameters:
	//   - rx, ry, rz: new rotation speed values
	SetRotationSpeed(rx, ry, rz float32)

	// SetScale updates the instance's scale via the Animator, preserving current position.
	//
	// Parameters:
	//   - sx, sy, sz: new scale factors
	SetScale(sx, sy, sz float32)

	// Light returns the Light attached to this object, or nil if none is set.
	//
	// Returns:
	//   - light.Light: the attached light or nil
	Light() light.Light

	// SetLight attaches a Light to this object. When the object is added to a
	// scene, the scene will automatically sync the light's position from the
	// object's transform each frame. Pass nil to detach.
	//
	// Parameters:
	//   - l: the Light to attach, or nil to detach
	SetLight(l light.Light)

	// RigidBody returns the physics.RigidBody associated with this object, or nil if none is set.
	//
	// Returns:
	//   - physics.RigidBody: the associated rigid body or nil
	RigidBody() physics.RigidBody

	// SetRigidBody sets the RigidBody instance for this GameObject.
	//
	// Parameters:
	//   - rb: the RigidBody to associate with this GameObject
	SetRigidBody(rb physics.RigidBody)
}

GameObject defines the interface for a scene entity bound to an Animator instance. Position, rotation, and scale are derived from the Animator's internal arrays via the animatorInstanceID, eliminating per-object data duplication.

func NewGameObject

func NewGameObject(options ...GameObjectBuilderOption) GameObject

NewGameObject creates a new GameObject configured with the given options.

Parameters:

  • options: functional options to configure the object

Returns:

  • GameObject: the newly created object

type GameObjectBuilderOption

type GameObjectBuilderOption func(*gameObject)

GameObjectBuilderOption is a functional option for configuring a GameObject during construction.

func WithEnabled

func WithEnabled(enabled bool) GameObjectBuilderOption

WithEnabled sets whether the GameObject is enabled for rendering.

Parameters:

  • enabled: true to render the object, false to skip it

Returns:

  • GameObjectBuilderOption: functional option to set the Enabled state

func WithEphemeral

func WithEphemeral(ephemeral bool) GameObjectBuilderOption

WithEphemeral marks the GameObject as ephemeral. Ephemeral objects are not persisted in the scene's registry when added via Scene.Add. The scene only ensures the object's animator is registered for rendering.

Parameters:

  • ephemeral: true to mark as ephemeral

Returns:

  • GameObjectBuilderOption: functional option to set the Ephemeral flag

func WithID

WithID sets the ID of the GameObject.

Parameters:

  • id: unique identifier for the GameObject

Returns:

  • GameObjectBuilderOption: functional option to set the ID

func WithLight

func WithLight(l light.Light) GameObjectBuilderOption

WithLight attaches a Light to the GameObject. When added to a scene, the scene will automatically sync the light's position from the object's transform each frame.

Parameters:

  • l: the Light to attach

Returns:

  • GameObjectBuilderOption: functional option to set the attached light

func WithModel

func WithModel(m model.Model) GameObjectBuilderOption

WithModel sets the Model for this GameObject.

Parameters:

  • m: the Model to associate

Returns:

  • GameObjectBuilderOption: functional option to set the Model

func WithPosition

func WithPosition(x, y, z float32) GameObjectBuilderOption

WithPosition sets the initial position of the GameObject before it is added to a Scene.

Parameters:

  • x: the x position
  • y: the y position
  • z: the z position

Returns:

  • GameObjectBuilderOption: functional option to set the initial position

func WithRigidBody added in v0.1.0

func WithRigidBody(rb physics.RigidBody) GameObjectBuilderOption

WithRigidBody attaches a RigidBody to the GameObject. When added to a scene, the scene will automatically sync the rigid body's position and rotation from the object's transform each frame, and apply physics simulation to the rigid body.

Parameters:

  • rb: the RigidBody to attach

Returns:

  • GameObjectBuilderOption: functional option to set the attached rigid body

func WithRotation

func WithRotation(rx, ry, rz float32) GameObjectBuilderOption

WithRotation sets the initial rotation of the GameObject before it is added to a Scene.

Parameters:

  • rx: the x rotation angle
  • ry: the y rotation angle
  • rz: the z rotation angle

Returns:

  • GameObjectBuilderOption: functional option to set the initial rotation

func WithRotationSpeed

func WithRotationSpeed(rx, ry, rz float32) GameObjectBuilderOption

WithRotationSpeed sets the initial rotation speed of the GameObject before it is added to a Scene.

Parameters:

  • rx: the x rotation speed
  • ry: the y rotation speed
  • rz: the z rotation speed

Returns:

  • GameObjectBuilderOption: functional option to set the initial rotation speed

func WithScale

func WithScale(sx, sy, sz float32) GameObjectBuilderOption

WithScale sets the initial scale of the GameObject before it is added to a Scene.

Parameters:

  • sx: the x scale factor
  • sy: the y scale factor
  • sz: the z scale factor

Returns:

  • GameObjectBuilderOption: functional option to set the initial scale

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL