CylinderTriangleCollider
Package: Libraries.Game.Collision.Narrowphase · Inherits from: Libraries.Language.Object, Libraries.Game.Collision.Narrowphase.TriangleCollider3D
CylinderTriangleCollider finds the contacts between a cylinder and one triangle. It handles the two ways a cylinder usually rests on a surface itself, and hands every other case to the general collision test, ConvexConvexPairSolver. It works in the cylinder's own space, where the cylinder is centered on the origin and its height runs along its up axis. First it checks a set of directions that can separate the two: the triangle's normal, the cylinder's axis, the axis crossed with each triangle edge, and the direction from the axis out to each triangle corner. If any shows a gap wider than the contact threshold, there is no contact. These directions are not every direction that could separate a cylinder from a triangle, so passing this check does not prove the two touch, but failing it always proves they do not. Then it looks at how the cylinder's axis lines up with the triangle's normal: Standing on a cap, when the axis is within 10 degrees of the normal: the cap facing the triangle is treated as an eight sided shape around its rim, cut down to the area over the triangle, and each remaining point that reaches the triangle becomes a contact. This gives up to four. Lying on its side, when the axis is within 10 degrees of the triangle's plane: the line along the cylinder's side nearest the triangle is cut down to the area over the triangle, and its ends become up to two contacts. Anything else, such as a tilted cylinder touching on its rim, or a standing or lying cylinder whose contact does not fall over the triangle, uses the general collision test, which gives one contact. So does a triangle with no area. The triangle is thickened by its margin, as with the general collision test. The cylinder is its full size, its half extents plus its margin, with sharp rims, while the general test rounds its rims by its margin.
Example Code
use Libraries.Compute.Vector3
use Libraries.Interface.Item3D
use Libraries.Game.Collision.PhysicsPosition3D
use Libraries.Game.Collision.LocalCollisionPoints3D
use Libraries.Game.Collision.CollisionPointsResult3D
use Libraries.Game.Collision.Shapes.Cylinder
use Libraries.Game.Collision.Shapes.Triangle
Item3D ground
Item3D barrel
LocalCollisionPoints3D points
points:Set(ground, barrel)
CollisionPointsResult3D result
result:Initialize(ground, barrel)
Triangle triangle
Vector3 a
a:Set(-5, 0, 5)
Vector3 b
b:Set(5, 0, 5)
Vector3 c
c:Set(0, 0, -5)
triangle:Set(a, b, c)
PhysicsPosition3D triangleTransform
Cylinder cylinder
cylinder:Set(0.6, 1, 0.6)
PhysicsPosition3D cylinderTransform
cylinderTransform:GetOrigin():Set(0, 0.53, 0)
CylinderTriangleCollider collider
collider:Collide(points, triangle, triangleTransform, cylinder, cylinderTransform, result, false)
// The cylinder stands on its bottom cap, so points holds four contacts
// around the rim.
Actions
Collide(Libraries.Game.Collision.LocalCollisionPoints3D collisionPoints, Libraries.Game.Collision.Shapes.Triangle triangle, Libraries.Game.Collision.PhysicsPosition3D triangleTransform, Libraries.Game.Collision.Shapes.Cylinder cylinder, Libraries.Game.Collision.PhysicsPosition3D transform, Libraries.Game.Collision.CollisionPointsResult3D result, boolean cylinderIsItemA)
This action tests a cylinder against a triangle, and reports contacts if they are within the collision's contact threshold. It does not refresh the collision's points, so it can be called for many triangles in a row.
Parameters
collisionPointsLibraries.Game.Collision.LocalCollisionPoints3D: The collision's stored contact points.triangleLibraries.Game.Collision.Shapes.Triangle: The triangle, with its corners in its own space.triangleTransformLibraries.Game.Collision.PhysicsPosition3D: Where the triangle is in the world.cylinderLibraries.Game.Collision.Shapes.Cylinder: The cylinder.transformLibraries.Game.Collision.PhysicsPosition3D: Where the cylinder is in the world. Its origin is the cylinder's center.resultLibraries.Game.Collision.CollisionPointsResult3D: Where contacts are reported. It must already be initialized with the collision's two items.cylinderIsItemAboolean: False when the triangle is item A, as terrain calls it, and true when the cylinder is item A.
UsedGeneralTest()
This action returns true if the last call to Collide handed the work to the general collision test.
Returns
boolean
Inherited Actions
9 actions from Libraries.Game.Collision.Narrowphase.TriangleCollider3D
- AddContact(Libraries.Compute.Vector3 normalTowardShape, Libraries.Compute.Vector3 pointOnShape, number separation)
- Begin(Libraries.Game.Collision.LocalCollisionPoints3D collisionPoints, Libraries.Game.Collision.CollisionPointsResult3D result, boolean shapeIsItemA)
- GetClipper()
- GetContactThreshold()
- GetGeometry()
- GetTriangleMargin()
- IsSwapped()
- LoadTriangle(Libraries.Game.Collision.Shapes.Triangle triangle, Libraries.Game.Collision.PhysicsPosition3D transform)
- LoadTriangle(Libraries.Compute.Vector3 a, Libraries.Compute.Vector3 b, Libraries.Compute.Vector3 c, number margin)