SphereTriangleCollider

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

SphereTriangleCollider finds the contact between a sphere and one triangle. Because a sphere is round, the contact is always at the point on the triangle closest to the sphere's center, whether that point is on the triangle's face, along an edge or at a corner, so one closest point calculation is all that is needed. This is the same approach Bullet uses for a sphere against a triangle. It reports at most one contact. The triangle is treated as thickened by its margin, the same way the general collision test treats it, so a sphere comes to rest at the same height on either one.

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.Sphere
use Libraries.Game.Collision.Shapes.Triangle

Item3D ground
Item3D ball
LocalCollisionPoints3D points
points:Set(ground, ball)
CollisionPointsResult3D result
result:Initialize(ground, ball)

Triangle triangle
Vector3 a
a:Set(0, 0, 0)
Vector3 b
b:Set(1, 0, 0)
Vector3 c
c:Set(0, 0, -1)
triangle:Set(a, b, c)
PhysicsPosition3D triangleTransform

Sphere sphere
sphere:SetRadius(0.5)
PhysicsPosition3D sphereTransform
sphereTransform:GetOrigin():Set(0.25, 0.5, -0.25)

SphereTriangleCollider collider
collider:Collide(points, triangle, triangleTransform, sphere, sphereTransform, result, false)
// points now holds one contact, with the sphere resting on the triangle.

Actions

Collide(Libraries.Game.Collision.LocalCollisionPoints3D collisionPoints, Libraries.Game.Collision.Shapes.Triangle triangle, Libraries.Game.Collision.PhysicsPosition3D triangleTransform, Libraries.Game.Collision.Shapes.Sphere sphere, Libraries.Game.Collision.PhysicsPosition3D sphereTransform, Libraries.Game.Collision.CollisionPointsResult3D result, boolean sphereIsItemA)

This action tests a sphere against a triangle, and reports a contact 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

CollideLoaded(number radius, Libraries.Compute.Vector3 center)

This action tests a sphere with the given radius and center against the triangle that is already loaded. Begin and LoadTriangle must have been called first.

Parameters

Inherited Actions

9 actions from Libraries.Game.Collision.Narrowphase.TriangleCollider3D
3 actions from Libraries.Language.Object