Skip to content

Game.Rendering.Legacy.Plane

Assembly:
Assembly-CSharp (typical for game code / modding assemblies)

Namespace:
Game.Rendering.Legacy

Type:
struct

Base:
System.ValueType

Summary:
Represents a 3D plane using a normalized surface normal and a signed distance value that satisfies the plane equation: dot(normal, X) + distance = 0. The struct automatically normalizes provided normals in most constructors and setters. Provides utilities to construct a plane from a normal + point or from three points, flip or translate the plane, compute the closest point on the plane, and test point-sidedness.


Fields

  • private Unity.Mathematics.float3 m_Normal
    Stores the plane normal. The code normalizes inputs in most setters/constructors so this field should hold a unit-length vector in normal usage.

  • private System.Single m_Distance
    Signed distance term in the plane equation dot(normal, X) + distance = 0. Positive/negative depends on normal direction. Adjusted by translation operations.

Properties

  • public Unity.Mathematics.float3 normal { get; set; }
    Gets or sets the plane normal. The getter returns m_Normal. The setter assigns the provided value directly to m_Normal (the code shows assignment without re-normalizing in the property setter itself; normalization happens in constructors and specific setters like SetNormalAndPosition).

  • public System.Single distance { get; set; }
    Gets or sets the plane distance term (m_Distance).

  • public Game.Rendering.Legacy.Plane flipped { get; }
    Read-only property that returns a new Plane with the normal and distance negated (i.e., reversed plane orientation). Equivalent to flipping the plane.

Constructors

  • public Plane(Unity.Mathematics.float3 inNormal, Unity.Mathematics.float3 inPoint)
    Constructs a plane using a normal and a point on the plane. The constructor normalizes inNormal to store as m_Normal, and computes m_Distance = -dot(m_Normal, inPoint).

  • public Plane(Unity.Mathematics.float3 inNormal, System.Single d)
    Constructs a plane from a normal and an explicit distance. The normal is normalized before storing; the provided d is used as the distance value (no adjustment made for normalization of the normal).

  • public Plane(Unity.Mathematics.float3 a, Unity.Mathematics.float3 b, Unity.Mathematics.float3 c)
    Constructs a plane from three points (a, b, c). The normal is computed as normalize(cross(b - a, c - a)) and m_Distance = -dot(m_Normal, a).

Methods

  • public void SetNormalAndPosition(Unity.Mathematics.float3 inNormal, Unity.Mathematics.float3 inPoint)
    Sets the plane by a given normal and a point. The implementation normalizes the provided normal for m_Normal, then sets m_Distance = -dot(inNormal, inPoint). Note: the distance calculation uses the original inNormal (not the normalized m_Normal), which can produce incorrect distance if inNormal is not unit-length—this is an implementation detail to be aware of.

  • public void Set3Points(Unity.Mathematics.float3 a, Unity.Mathematics.float3 b, Unity.Mathematics.float3 c)
    Sets the plane from three points. Computes the normal as normalize(cross(b - a, c - a)) and m_Distance = -dot(m_Normal, a).

  • public void Flip()
    Negates the normal and distance in-place (m_Normal = -m_Normal; m_Distance = -m_Distance), reversing the plane's orientation.

  • public void Translate(Unity.Mathematics.float3 translation)
    Translates the plane in-place by adjusting m_Distance += dot(m_Normal, translation). Translation along normal moves the plane accordingly.

  • public static Game.Rendering.Legacy.Plane Translate(Game.Rendering.Legacy.Plane plane, Unity.Mathematics.float3 translation)
    Returns a new Plane which is the given plane translated by translation. Implementation returns a new Plane using the same normal and adjusted distance. (Note: the source uses an assignment expression on plane.m_Distance inside the constructor argument, which mutates the local copy before constructing the returned Plane.)

  • public Unity.Mathematics.float3 ClosestPointOnPlane(Unity.Mathematics.float3 point)
    Returns the closest point on the plane to the given point by projecting the point onto the plane: point - m_Normal * (dot(m_Normal, point) + m_Distance).

  • public System.Single GetDistanceToPoint(Unity.Mathematics.float3 point)
    Returns the signed distance from the point to the plane: dot(m_Normal, point) + m_Distance.

  • public System.Boolean GetSide(Unity.Mathematics.float3 point)
    Returns true when the point is on the side of the plane in the direction of the normal (i.e., signed distance > 0), false otherwise.

  • public System.Boolean SameSide(Unity.Mathematics.float3 inPt0, Unity.Mathematics.float3 inPt1)
    Returns true if both points are on the same side of the plane (both positive distances or both non-positive). The implementation compares GetDistanceToPoint for both points and includes explicit branch logic; result effectively indicates if both are > 0 or both <= 0.

  • public override System.String ToString()
    Returns a formatted string representing the plane: "(normal:(x, y, z), distance:d)" where components are formatted to one decimal place.

Usage Example

using Unity.Mathematics;
using Game.Rendering.Legacy;

void Example()
{
    // Create from normal and point
    float3 normal = new float3(0, 1, 0);
    float3 pointOnPlane = new float3(0, 5, 0);
    Plane p1 = new Plane(normal, pointOnPlane); // horizontal plane at y = 5

    // Create from three points
    Plane p2 = new Plane(new float3(0,0,0), new float3(1,0,0), new float3(0,0,1));

    // Flip plane orientation
    Plane flipped = p1.flipped;

    // Translate plane up by 2 units
    p1.Translate(new float3(0, 2, 0)); // modifies p1
    Plane moved = Plane.Translate(p2, new float3(0, 3, 0)); // returns new plane

    // Query distance and closest point
    float distance = p1.GetDistanceToPoint(new float3(0, 10, 0));
    float3 closest = p1.ClosestPointOnPlane(new float3(2, 10, -1));

    // Side tests
    bool onPositiveSide = p1.GetSide(new float3(0, 6, 0));
    bool sameSide = p1.SameSide(new float3(0, 6, 0), new float3(0, 7, 0));

    // Debug print
    UnityEngine.Debug.Log(p1.ToString());
}

Notes and gotchas: - Constructors and Set3Points normalize the input normals; however SetNormalAndPosition uses the original (non-normalized) inNormal when computing m_Distance—this can lead to inconsistent distances if passing a non-unit inNormal. Prefer passing a unit normal or using constructor overloads that compute distance from a point. - The struct is value-type: operations like Translate(Plane, translation) work on copies; the static Translate returns a new Plane rather than modifying the original passed-in plane instance.