Item3DBackToFrontComparison
Package: Libraries.Game · Inherits from: Libraries.Containers.Support.Comparison, Libraries.Language.Object
Item3DBackToFrontComparison sorts 3D items from farthest to nearest from a point, such as the camera. Layer3D uses it to draw transparent models after everything else, farthest first, so each blends over what is behind it. Distances are measured to each item's position, and compared squared, so no square roots are needed.
Example Code
use Libraries.Game.Item3DBackToFrontComparison
use Libraries.Interface.Item3D
use Libraries.Containers.Array
Item3D near
near:SetPosition(0, 0, 2)
Item3D far
far:SetPosition(0, 0, 10)
Array<Item3D> items
items:Add(near)
items:Add(far)
Item3DBackToFrontComparison backToFront
backToFront:SetOrigin(0, 0, 0)
items:Sort(backToFront)
output items:Get(0):GetZ()
Actions
Compare(Libraries.Language.Object a, Libraries.Language.Object b)
This action compares two items by their distance from the origin. The farther item comes first.
Parameters
aLibraries.Language.Object: The first item.bLibraries.Language.Object: The second item.
Returns
integer: -1 if a is farther, 1 if b is farther, or 0 if they
are the same distance.
SetOrigin(number x, number y, number z)
This action sets the point distances are measured from.
Parameters
xnumber: The point's x coordinate.ynumber: The point's y coordinate.znumber: The point's z coordinate.