Jump to content

OBD:PLEA: Difference between revisions

1,417 bytes added ,  24 January 2022
filling in after reading up on BNVs
m (changing link from http->https)
(filling in after reading up on BNVs)
Line 20: Line 20:


;Plane equation
;Plane equation
:The canonical equation for a [https://mathworld.wolfram.com/Plane.html plane] in 3D is :
:The canonical equation for a [https://mathworld.wolfram.com/Plane.html plane] in 3D is
::a * x + b * y + c * z + d = 0
::'''a * x + b * y + c * z + d = 0,'''
:where (a, b, c, d) are 4 real numbers. The plane is the set of points (x, y, z) verifying that equation.
:with (a, b, c, d) being 4 real numbers and (a, b, c) forming a nonzero vector (the plane's "normal").
:The four floats in one of a PLEA's packages are exactly the (a, b, c, d) of the above definition.
:*The set of points (x, y, z) verifying '''a * x + b * y + c * z + d = 0''' are said to be in the plane or at the plane.
::In that case, the first package of the above example defines the plane (0 * x + 0 * y + 1 * z + 612 = 0), i.e., the vertical plane z = -612.
:*The set of points (x, y, z) verifying '''a * x + b * y + c * z + d > 0''' are said to be in front of the plane.
Planes are used for environment culling, collision detection and [[wikipedia:Binary_space_partitioning|BSP]].
:*The set of points (x, y, z) verifying '''a * x + b * y + c * z + d < 0''' are said to be behind the plane.
:'''N.B.''' If a=b=c=0, then the equation is degenerate and applies either to the whole space (if d=0) or to no points at all (if d is non-zero).


:As a further convention, if (a,b,c) is normalized at unit length (i.e., '''a*a + b*b + c*c = 1''') then d is the distance from the plane to the world's origin, along the normal vector.
:The four floats in each element of a PLEA are exactly the (a, b, c, d) of the above definition.
:In the above example, the first element defines the plane (0 * x + 0 * y + 1 * z + 612 = 0), i.e., the vertical plane z = -612.


;Note on plane references
;What planes are for and how they are referenced
:Planes are referenced by index from various other places. The high bit of a plane index is always used to indicate the direction of the plane's normal (or "which face of the plane is up"). That means that if the high bit is set all 4 float values need to be negated to get the referenced plane.
:Planes are used for environment culling, collision detection and [[wikipedia:Binary_space_partitioning|BSP]].
:The plane equations stored in PLEA are referenced from such data as [[ABNA]], [[AKBP]], [[AKBA]] and [[AGQC]] by means of a 32-bit array index.
:However, the high bit of those 32-bit references is not part of the array index, instead it indicates whether the facing of the plane should be flipped.
:*If the high bit is not set, then the 4 values (a, b, c, d) are used as described above.<br />(If referencing the above example without a high bit, then any points with z > - 612 will be in front of the plane, whereas points with z < -612 will be behind the plane.)
:*If the high bit is set, then the plane equation coefficients become (-a, -b, -c, -d).<br />(If referencing the above example with a high bit, then any point with z > - 612 will be behind the plane, whereas points with z < -612 will be in front of the plane.)
:This means that the actual array index is a 31-bit value (i.e., there can only be up to 32768 distinct planes in a level), but the same array element can be used for two different facing directions.