TriangleCollider3D

Package: Libraries.Game.Collision.Narrowphase · Inherits from: Libraries.Language.Object

TriangleCollider3D is the parent of the colliders that test a shape against a single triangle, such as a sphere, box or cylinder against one triangle of a terrain. It holds what they all share: the triangle in world space, a clipper for building contact polygons, and the one place where a contact is turned into the form CollisionPointsResult3D expects. A collision between two items has an item A and an item B, and CollisionPointsResult3D:AddCollisionPoint expects a normal pointing from B toward A, a point on B, and a depth that is negative when the two overlap. The triangle can be either item. Terrain makes the triangle item A, so that is the usual case, but a collider may be called the other way around. Rather than each collider working this out, they all describe a contact the same way, by a normal pointing from the triangle toward the shape, a point on the shape, and the separation, and AddContact converts it. The triangle colliders never call RefreshCollisionPoints. A concave shape such as terrain tests many triangles against the same collision, and refreshes the points once when it has tested them all. A collider is used in three steps: Begin, to say where contacts go and which item the triangle is; LoadTriangle, to load the triangle; and then the collider's own collision action, which calls AddContact for each contact.

Actions

AddContact(Libraries.Compute.Vector3 normalTowardShape, Libraries.Compute.Vector3 pointOnShape, number separation)

This action reports one contact. The contact is described the same way by every triangle collider, and is converted here to the form that CollisionPointsResult3D expects, based on which item the triangle is. When the triangle is item A, the normal from B toward A points from the shape toward the triangle, and the point on B is the point on the shape. When the shape is item A, the normal points from the triangle toward the shape, and the point on B is the matching point on the triangle, found by moving back across the gap. Either way, the point on A that CollisionPointsResult3D works out, the point on B plus the normal times the depth, is the other side of the same contact.

Parameters

  • normalTowardShape Libraries.Compute.Vector3: The unit normal pointing from the triangle toward the shape.
  • pointOnShape Libraries.Compute.Vector3: The contact point on the shape's surface, in world space.
  • separation number: How far apart the shape and the triangle are along the normal, negative when they overlap.

Begin(Libraries.Game.Collision.LocalCollisionPoints3D collisionPoints, Libraries.Game.Collision.CollisionPointsResult3D result, boolean shapeIsItemA)

This action gets the collider ready to report contacts for one collision.

Parameters

GetClipper()

This action returns the clipper the collider uses to build contact polygons.

Returns

Libraries.Game.Collision.Narrowphase.ContactClipper3D

GetContactThreshold()

This action returns how far apart two shapes may be and still have a contact recorded. Contacts farther apart than this are not kept.

Returns

number

GetGeometry()

This action returns the loaded triangle.

Returns

Libraries.Game.Collision.Narrowphase.TriangleGeometry3D

GetTriangleMargin()

This action returns how thick a shell is added around the triangle. The triangle is treated as if it were this much thicker on both sides and this much wider past every edge, which is what the general collision test does with a triangle's margin.

Returns

number

IsSwapped()

This action returns true when the other shape, not the triangle, is item A.

Returns

boolean

LoadTriangle(Libraries.Compute.Vector3 a, Libraries.Compute.Vector3 b, Libraries.Compute.Vector3 c, number margin)

This action loads a triangle whose corners are already in world space, with the given margin.

Parameters

LoadTriangle(Libraries.Game.Collision.Shapes.Triangle triangle, Libraries.Game.Collision.PhysicsPosition3D transform)

This action loads a triangle, moving its corners into the world using the given transform, and takes its margin from the triangle.

Parameters

Inherited Actions

3 actions from Libraries.Language.Object