Transform

Namespace:

namespace Lenga\Engine\Core;

class Transform

Transform stores an object's position, rotation, and scale.

When an object has a parent:

  • localPosition is the offset from that parent
  • localRotation is the rotation relative to that parent
  • localScale is the scale relative to that parent

When you want the final world-space values, use:

  • position
  • rotation
  • lossyScale

Rotation in Lenga

Lenga supports two ways to work with 3D rotation:

  • Euler-angle properties such as $localEulerAngles and $eulerAngles
  • quaternion properties such as $localRotation and $rotation

The Inspector is still mainly Euler-facing in this release, but runtime 3D transform composition uses quaternion-backed rotation math. That means you can author readable Euler values in the editor and still use safer quaternion rotation workflows in code.

Common Properties

Property Type What it means
$localPosition Vector3 Position relative to the parent.
$position Vector3 World-space position.
$localEulerAngles Vector3 Local rotation in degrees.
$eulerAngles Vector3 World rotation in degrees.
$localRotation Quaternion Local rotation relative to the parent.
$rotation Quaternion World rotation.
$localScale Vector3 Scale relative to the parent.
$lossyScale Vector3 Final scale after parent scaling is applied.
$right Vector3 World-space right direction.
$up Vector3 World-space up direction.
$forward Vector3 World-space forward direction.

Methods

getChildren

public function getChildren(): array

Returns the direct child transforms.

childCount

public function childCount(): int

Returns the number of direct children.

getChild

public function getChild(int $index): ?Transform

Returns the child at the given index, or null.

find

public function find(string $path): ?Transform

Finds a child by a slash-separated path such as "Weapon/Muzzle".

isChildOf

public function isChildOf(Transform $parent): bool

detachChildren

public function detachChildren(): void

setParent

public function setParent(?Transform $newParent, bool $worldPositionStays = true): void

Changes the parent transform.

When worldPositionStays is true, Lenga keeps the object's world-space position, rotation, and scale, then recalculates the local values under the new parent.

When worldPositionStays is false, Lenga keeps the current local values and lets the final world transform change relative to the new parent.

translate

public function translate(Vector3 $offset, bool $relativeToSelf = true): void

Moves the transform by the given offset.

  • When relativeToSelf is true, the offset is applied in the object's own rotated space.
  • When relativeToSelf is false, the offset is applied in world space.

translate2D

public function translate2D(float $dx, float $dy, bool $relativeToSelf = true): void

rotate

public function rotate(Vector3|float $xOrEuler, ?float $y = null, ?float $z = null, bool $relativeToSelf = true): void

Applies a rotation delta.

  • When relativeToSelf is true, the delta is applied in local space.
  • When relativeToSelf is false, the delta is applied in world space.

For more deliberate 3D rotation control, set $localRotation or $rotation directly with Quaternion.

rotate2D

public function rotate2D(float $degrees, bool $relativeToSelf = true): void

lookAt

public function lookAt(Vector3 $worldPosition): void

Rotates the object so it faces the given world-space point.

getNativeId

public function getNativeId(): ?int

Example

use Lenga\Engine\Core\Behaviour;
use Lenga\Engine\Core\Quaternion;
use Lenga\Engine\Core\Time;
use Lenga\Engine\Core\Vector3;

class ObjectController extends Behaviour
{
    public function update(): void
    {
        $transform = $this->transform;

        $worldPosition = $transform->position;
        $worldRotation = $transform->rotation;
        $worldEuler = $transform->eulerAngles;

        $transform->position = new Vector3(
            $worldPosition->x + (1.0 * Time::deltaTime()),
            $worldPosition->y,
            $worldPosition->z,
        );

        $transform->rotate(0.0, 90.0 * Time::deltaTime(), 0.0);

        $transform->localRotation = Quaternion::fromEulerAngles(
            new Vector3(0.0, 45.0, 0.0)
        );

        $transform->translate(
            new Vector3(0.0, 0.0, -1.0 * Time::deltaTime())
        );

        $forward = $transform->forward;
        $right = $transform->right;
    }
}

Usage Notes

  • Use Euler angles when you want readable degree values.
  • Use quaternions when you want safer 3D rotation composition in code.
  • The scene format and Inspector still use Euler-facing values for authoring, but runtime transform composition is quaternion-backed for 3D workflows.