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

    Class Collision

    Static class for collision detection and resolution.

    Index
    • Resolves collision between two bounding volumes, computing the minimum translation vector (MTV) stored in result pointing in the direction to push volume a out of volume b.

      Parameters

      Returns boolean

      True if the volumes are intersecting and MTV was computed, false otherwise.

    • Resolves collision between two axis-aligned boxes, returning a correction vector.

      Parameters

      • b1: BoundingBox

        The first box.

      • b2: BoundingBox

        The second box.

      • result: Vector3D

        Vector to store the correction (points from b2 to b1, along the axis of least penetration).

      Returns boolean

      True if collision was resolved.

    • Resolves collision between an axis-aligned box and an oriented bounding box, returning a correction vector.

      Parameters

      • b: BoundingBox

        The box.

      • o: OBB

        The OBB.

      • result: Vector3D

        Vector to store the correction (points from o to b).

      Returns boolean

      True if collision was resolved.

    • Resolves collision between two convex hulls via the Separating Axis Theorem, returning the minimum-translation-vector correction.

      Parameters

      • a: ConvexHull

        The first hull.

      • b: ConvexHull

        The second hull.

      • result: Vector3D

        Vector to store the correction (points from b to a, along the axis of least penetration).

      Returns boolean

      True if collision was resolved.

    • Resolves collision between two OBBs via the Separating Axis Theorem, returning the minimum-translation-vector correction.

      Parameters

      • a: OBB

        The first OBB.

      • b: OBB

        The second OBB.

      • result: Vector3D

        Vector to store the correction (points from b to a, along the axis of least penetration).

      Returns boolean

      True if collision was resolved.

    • Resolves collision between a sphere and an OBB, returning a correction vector.

      Parameters

      • s: BoundingSphere

        The sphere.

      • o: OBB

        The OBB.

      • result: Vector3D

        Vector to store the correction (points from the OBB towards the sphere).

      Returns boolean

      True if collision was resolved.

    • Universal sweep dispatcher: sweeps any moving bounding volume from origin with displacement delta against any static volume. Supports both 3-arg (moving, delta, target) and 4-arg (moving, origin, delta, target) forms.

      Parameters

      Returns number

      Time of impact in [0, 1] or -1 if no impact.

    • Universal sweep dispatcher: sweeps any moving bounding volume from origin with displacement delta against any static volume. Supports both 3-arg (moving, delta, target) and 4-arg (moving, origin, delta, target) forms.

      Parameters

      Returns number

      Time of impact in [0, 1] or -1 if no impact.

    • Sweeps a moving AABB against a static AABB for CCD.

      Parameters

      • origin: Vector3D

        Center of moving box at the start of the step.

      • delta: Vector3D

        Displacement vector of the moving box.

      • halfExtents: Vector3D

        Half-extents of the moving box.

      • b: BoundingBox

        The static box to sweep against.

      Returns number

      Time of impact in [0, 1] or -1 if no impact.

    • Sweeps a moving AABB against a static OBB for CCD.

      Parameters

      • origin: Vector3D

        Center of moving box at the start of the step.

      • delta: Vector3D

        Displacement vector of the moving box.

      • halfExtents: Vector3D

        Half-extents of the moving box.

      • o: OBB

        The static OBB to sweep against.

      Returns number

      Time of impact in [0, 1] or -1 if no impact.

    • Sweeps a moving AABB against a static sphere for CCD.

      Parameters

      • origin: Vector3D

        Center of moving box at the start of the step.

      • delta: Vector3D

        Displacement vector of the moving box.

      • halfExtents: Vector3D

        Half-extents of the moving box.

      • s: BoundingSphere

        The static sphere to sweep against.

      Returns number

      Time of impact in [0, 1] or -1 if no impact.

    • Sweeps a moving sphere against a static AABB for CCD. Approximates the swept volume as the box expanded by the sphere's radius on every axis (a cheap, standard approximation -- the true Minkowski sum would round the box's edges/corners, which this cheap version doesn't).

      Parameters

      • origin: Vector3D

        The moving sphere's center at the start of this step.

      • delta: Vector3D

        The moving sphere's displacement over this step (not normalized).

      • radius: number

        The moving sphere's radius.

      • b: BoundingBox

        The static box to sweep against.

      Returns number

      The time-of-impact as a fraction of delta in [0, 1], or -1 if no impact.

    • Sweeps a moving sphere against a static OBB for CCD, by transforming the sweep into the OBB's local space (where it becomes an axis-aligned sphere-vs-box sweep, same approach as sweepSphereBox).

      Parameters

      • origin: Vector3D

        The moving sphere's center at the start of this step.

      • delta: Vector3D

        The moving sphere's displacement over this step (not normalized).

      • radius: number

        The moving sphere's radius.

      • o: OBB

        The static OBB to sweep against.

      Returns number

      The time-of-impact as a fraction of delta in [0, 1], or -1 if no impact.

    • Sweeps a moving sphere against a static sphere, used for Continuous Collision Detection (CCD) of fast-moving bodies that could otherwise tunnel through thin/small geometry in a single discrete step.

      Parameters

      • origin: Vector3D

        The moving sphere's center at the start of this step.

      • delta: Vector3D

        The moving sphere's displacement over this step (NOT normalized -- its length matters, since the returned time-of-impact is a fraction of this vector).

      • radius: number

        The moving sphere's radius.

      • s: BoundingSphere

        The static sphere to sweep against.

      Returns number

      The time-of-impact as a fraction of delta in [0, 1], or -1 if no impact occurs during this sweep (including if the two spheres already overlap at origin, since that's a pre-existing overlap the discrete resolver already handles, not a new tunneling event).