Vector3Interface

Namespace:

namespace Lenga\Engine\Interfaces;

Defines the contract for a three-component vector with typed x, y, and z properties. The concrete Vector3 class implements this interface. Use Vector3Interface when writing utilities that operate on any 3D vector without depending on the specific implementation.

Properties

Property Type Description
$x float X component.
$y float Y component.
$z float Z component.

Example

use Lenga\Engine\Core\Behaviour;
use Lenga\Engine\Interfaces\Vector3Interface;

/**
 * Returns the squared magnitude of any Vector3Interface, useful for
 * distance comparisons without the cost of a square root.
 */
function sqrMagnitude(Vector3Interface $v): float
{
    return $v->x ** 2 + $v->y ** 2 + $v->z ** 2;
}

class ProximityTrigger extends Behaviour
{
    public float $triggerRadius = 5.0;

    public function update(): void
    {
        $delta = $this->transform->getPosition();
        if (sqrMagnitude($delta) < $this->triggerRadius ** 2) {
            // within range
        }
    }
}