Triangle

Package: Libraries.Game.Collision.Shapes · Inherits from: Libraries.Language.Object, Libraries.Game.Collision.Shapes.CollisionShape3D

This class describes a single triangle in 3D. It is the convex shape used for the narrowphase collision check against the individual triangles of a concave shape, such as the triangles that make up a HeightmapTerrainShape. Unlike the other convex shapes, a triangle has no volume, so it cannot be used as the shape of a dynamic Item3D on its own.

Actions

BatchedUnitVectorGetSupportingVertexWithoutMargin(Libraries.Containers.Array<Libraries.Compute.Vector3> vectors, Libraries.Containers.Array<Libraries.Compute.Vector3> supportVerticesOut, integer numberVectors)

This action fills "Array supportVerticesOut" with the corner that is furthest away for each of the directions in "Array vectors."

Parameters

CalculateLocalInertia(number mass, Libraries.Compute.Vector3 inertia)

A triangle has no volume, so there is no meaningful moment of inertia to calculate and the result is always zero. Bullet asserts here, because a triangle is only ever used as part of a larger concave shape and never as the shape of a body that moves on its own.

Parameters

CalculateNormal(Libraries.Compute.Vector3 normal)

This action calculates the unit normal of the plane that the triangle lies in, following the winding of the three corners, and stores it in the passed vector.

Parameters

ComputeBoundingBox(Libraries.Game.BoundingBox boundingBox, Libraries.Game.Collision.PhysicsPosition3D transform)

This action finds the bounding box that would bound the triangle in its current position. Because a triangle has no fixed extents to work from, the box is found by asking the triangle for its furthest corner along each of the six world axes, which is what Bullet calls the slow path.

Parameters

Copy()

This action stores one of the preferred penetration directions in the passed vector. Index zero is the front face of the triangle and index one is the back face.

Returns

Libraries.Game.Collision.Shapes.CollisionShape3D

GetChildCount()

This action returns how many directions the penetration depth solver should prefer to search along. For a triangle these are the two faces of its plane.

Returns

integer

GetEdge(integer index, Libraries.Compute.Vector3 pointA, Libraries.Compute.Vector3 pointB)

This action copies the two corners that make up the edge at the given index into the passed vectors.

Parameters

GetNumberEdges()

This action returns the number of edges in the triangle, which is always three.

Returns

integer

GetNumberPlanes()

This action returns the number of planes that bound the triangle, which is always one.

Returns

integer

GetNumberPreferredPenetrationDirections()

This action returns how many directions the penetration depth solver should prefer to search along. For a triangle these are the two faces of its plane.

Returns

integer

GetNumberVertices()

This action returns the number of corners in the triangle, which is always three.

Returns

integer

GetPlane(Libraries.Compute.Vector3 planeNormal, Libraries.Compute.Vector3 planeSupport, integer index)

This action stores the normal of the triangle's plane, along with a point that lies on that plane, in the passed vectors. A triangle only has one plane, so the index is ignored.

Parameters

GetPlaneEquation(integer index, Libraries.Compute.Vector3 planeNormal, Libraries.Compute.Vector3 planeSupport)

This action stores the normal of the triangle's plane, along with a point that lies on that plane, in the passed vectors. A triangle only has one plane, so the index is ignored.

Parameters

GetPreferredPenetrationDirection(integer index, Libraries.Compute.Vector3 penetrationVector)

This action stores one of the preferred penetration directions in the passed vector. Index zero is the front face of the triangle and index one is the back face.

Parameters

GetVertex(integer index)

This action returns the corner of the triangle at the given index. This is the vector stored by the triangle, not a copy of it, so changing it changes the triangle.

Parameters

  • index integer

Returns

Libraries.Compute.Vector3

GetVertex(integer index, Libraries.Compute.Vector3 out)

This action copies the corner of the triangle at the given index into the passed vector.

Parameters

IsInside(Libraries.Compute.Vector3 point, number tolerance)

This action tests whether a point lies on the triangle, within the given tolerance. The point must be close enough to the triangle's plane and must also be on the inner side of all three of its edges.

Parameters

Returns

boolean

LocalGetSupportingVertexWithoutMargin(Libraries.Compute.Vector3 vector)

This action finds the corner of the triangle that is furthest away in the direction specified by "Vector3 vector", without an offset (margin). The returned vector is not one of the triangle's corners, so the caller is allowed to change it, but it is reused by the next call, so copy it to keep it.

Parameters

Returns

Libraries.Compute.Vector3

RayCast(Libraries.Compute.Vector3 from, Libraries.Compute.Vector3 to, Libraries.Game.Collision.PhysicsPosition3D transform, Libraries.Game.Collision.RayCastResult3D result)

This action checks whether a straight line segment, called a ray, touches this triangle. The ray starts at "from" and ends at "to," both in world space. The triangle's corners are described relative to "transform," which places them in the world. For a triangle that belongs to a concave shape, such as a HeightmapTerrainShape, this is normally the collision transform of the item that owns that shape. A triangle is flat, so the ray hits it only if it crosses the triangle's plane at a point that lies inside its three edges. Either side of the triangle can be hit. The hit normal is always turned to face the side the ray came from, whichever way the corners wind. A ray that only touches the plane at its start or end point, or that lies flat in the plane, does not count as a hit. The collision margin is not used, which matches Bullet. The result works as both an input and an output. Its fraction is the farthest point along the ray that still counts as a hit, where 0 is "from" and 1 is "to." This action only reports a hit that is closer than the result's current fraction. When it finds one, it sets the result's hit flag to true, and sets its fraction, its hit point in world space, and its surface normal in world space. When there is no closer hit, the result is left unchanged. Call SetToDefault on the result before the first shape so that any hit along the whole ray counts. This action does not set the result's hit body, because a shape does not know which item it belongs to. The caller should set the hit body when this action returns true.

Parameters

Returns

boolean: true if this triangle was hit closer than the result's previous fraction, and false otherwise.

Example

use Libraries.Game.Collision.RayCastResult3D
use Libraries.Game.Collision.PhysicsPosition3D
use Libraries.Game.Collision.Shapes.Triangle
use Libraries.Compute.Vector3
// A flat triangle lying on the ground (y = 0).
Vector3 corner0
corner0:Set(0, 0, 0)
Vector3 corner1
corner1:Set(4, 0, 0)
Vector3 corner2
corner2:Set(0, 0, 4)
Triangle triangle
triangle:Set(corner0, corner1, corner2)
PhysicsPosition3D transform
transform:SetToIdentity()
// A ray straight down through the triangle.
Vector3 from
from:Set(1, 10, 1)
Vector3 to
to:Set(1, -10, 1)
RayCastResult3D result
result:SetToDefault()
if triangle:RayCast(from, to, transform, result)
    // The ray crosses y = 0 halfway along, so this outputs a fraction
    // of 0.5. The corners wind so that the triangle's own normal
    // points down, but the reported normal is (0, 1, 0), facing the
    // ray.
    output "Hit at fraction " + result:GetFraction()
end

Set(Libraries.Compute.Vector3 point0, Libraries.Compute.Vector3 point1, Libraries.Compute.Vector3 point2)

This action sets the three corners of the triangle. The values of the passed vectors are copied, so the vectors may be safely reused by the caller.

Parameters

SetVertex(integer index, Libraries.Compute.Vector3 point)

This action sets a single corner of the triangle. The value of the passed vector is copied.

Parameters

Inherited Actions

11 actions from Libraries.Game.Collision.Shapes.CollisionShape3D
3 actions from Libraries.Language.Object