Small World Engine API Reference - v0.46.1
    Preparing search index...

    Class Vector3D

    A class representing a 3D vector. Data is stored as individual properties for fast access in JS engines.

    Implements

    Index

    Constructors

    • Creates a new Vector3D.

      Parameters

      • x: number = 0

        The x component. Defaults to 0.

      • y: number = 0

        The y component. Defaults to 0.

      • z: number = 0

        The z component. Defaults to 0.

      Returns Vector3D

    Properties

    x: number = 0

    The x component. Defaults to 0.

    y: number = 0

    The y component. Defaults to 0.

    z: number = 0

    The z component. Defaults to 0.

    ZERO: Vector3D = ...

    Static zero vector to avoid unnecessary allocations. Should be treated as read-only.

    Methods

    • Adds a scalar value to all components.

      Parameters

      • s: number

        The scalar to add.

      Returns this

      this

    • Calculates the Euclidean distance to another vector.

      Parameters

      Returns number

      The distance.

    • Calculates the squared distance to another vector.

      Parameters

      Returns number

      The squared distance.

    • Divides the vector by a scalar.

      Parameters

      • s: number

        The scalar to divide by.

      Returns this

      this

    • Calculates the dot product of this vector and another.

      Parameters

      Returns number

      The dot product.

    • Sets this vector's components to the maximum of its own and the given vector's.

      Parameters

      Returns this

      this

    • Sets this vector's components to the minimum of its own and the given vector's.

      Parameters

      Returns this

      this

    • Multiplies the vector components by another vector (component-wise).

      Parameters

      Returns this

      this

    • Scales the vector by a scalar value.

      Parameters

      • s: number

        The scalar factor.

      Returns this

      this

    • Sets the components of the vector.

      Parameters

      • x: number

        The x component.

      • y: number = x

        The y component. Defaults to x.

      • z: number = y

        The z component. Defaults to y.

      Returns this

      this

    • Transforms the direction of this vector with a matrix. This ignores the translation component of the matrix.

      Parameters

      • m: Matrix4

        The transformation matrix.

      Returns this

      this