TrinityCore
|
#include <CollisionDetection.h>
Private Member Functions | |
CollisionDetection () | |
virtual | ~CollisionDetection () |
Static Private Attributes | |
static Vector3 | ignore |
static bool | ignoreBool |
static Array< Vector3 > | ignoreArray |
Collision detection primitives and tools for building higher order collision detection schemes.
These routines provide moving and static collision detection. Moving collision detection allows the calculation of collisions that occur during a period of time – as opposed to the intersection of two static bodies.
Moving collision detection routines detect collisions between only static primitives and moving spheres or points. Since the reference frame can be user defined, these functions can be used to detect the collision between two moving bodies by subtracting the velocity vector of one object from the velocity vector of the sphere or point the detection is to occur with. This unified velocity vector will act as if both objects are moving simultaneously.
Collisions are detected for single-sided objects only. That is, no collision is detected when leaving a primitive or passing through a plane or triangle opposite the normal... except for the point-sphere calculation or when otherwise noted.
For a sphere, the collision location returned is the point in world space where the surface of the sphere and the fixed object meet. It is not the position of the center of the sphere at the time of the collision.
The collision normal returned is the surface normal to the fixed object at the collision location.
Static Collision Detection: (Neither object is moving)
Moving Collision Detection:
* Note: Moving collision detection against certain primitives is equivalent to static collision detection against a bigger primitive. Ray, Line Segment == moving Point''; Capsule ==
moving Sphere''; Plane == ``moving Line''
|
static |
Finds the direction of bounce that a sphere would have when it intersects an object with the given time of collision, the collision location and the collision normal.
sphere | Moving sphere. |
velocity | Sphere's velocity. |
collisionTime | Time of collision. |
collisionLocation | Collision location. |
collisionNormal | Surface collision normal. |
|
static |
Finds the closest point on a line segment to a given point.
v0 | line vertex 1. |
v1 | line vertex 2. |
point | External point. |
point
on the line segment.
|
static |
Finds the closest point on a line segment to a given point.
v0 | line vertex 0. |
v1 | line vertex 1. |
edgeDirection | The direction of the segment (unit length). |
edgeLength | The length of the segment. |
point | External point. |
point
on the line segment.
|
static |
Finds the closest point on the perimeter of the triangle to an external point; given a triangle defined by three points v0, v1, & v2, and the external point.
point
on the perimeter of the triangle.
|
static |
Finds the closest point on the perimeter of the triangle to an external point; given a triangle defined by the array of points v, its edge directions and their lengths, as well as the external point.
v | Triangle vertices. |
point | External point. |
edgeIndex | The point lies on the edge between v[edgeIndex] and v[(edgeIndex + 1) % 3] |
point
on the perimeter of the triangle.
|
static |
Calculates the closest points on two lines with each other. If the lines are parallel then using the starting point, else calculate the closest point on each line to the other.
[variables] and algorithm based on derivation at the following website: http://softsurfer.com/Archive/algorithm_0106/algorithm_0106.htm
line1 | Line 1. |
line2 | Line 2. |
closest1 | Closest point on line 1. |
closest2 | Closest point on line 2. |
|
static |
Finds the closest point in the rectangle to an external point; Given a rectangle defined by four points v0, v1, v2, & v3, and the external point.
v0 | Rectangle vertex 1. |
v1 | Rectangle vertex 2. |
v2 | Rectangle vertex 3 |
v3 | Rectangle vertex 4. |
point | External point. |
|
static |
Finds the closest point on the perimeter of the rectangle to an external point; given a rectangle defined by four points v0, v1, v2, & v3, and the external point.
v0 | Rectangle vertex 1. |
v1 | Rectangle vertex 2. |
v2 | Rectangle vertex 3. |
v3 | Rectangle vertex 4. |
point | External point. |
point
on the perimeter of the rectangle.
|
static |
Calculates time between the intersection of a moving point and a fixed Axis-Aligned Box (AABox).
point | Moving point. |
velocity | Sphere's velocity. |
box | Fixed AAbox. |
outLocation | Location of collision. [Post Condition] |
inside | Does the ray originate inside the box? [Post Condition] |
normal | Box's surface normal to collision [Post Condition] |
|
static |
If the ray origin is inside the box, returns inf() but inside is set to true. Beta API
[Andrew] Woo, from "Graphics Gems", Academic Press, 1990 [Optimized] code by Pierre Terdiman, 2000 (~20-30% faster on Celeron 500) [Epsilon] value added by Klaus Hartmann [http://www.codercorner.com/RayAABB.cpp]
|
static |
Calculates time between the intersection of a moving point and a fixed box.
point | Moving point. |
velocity | Sphere's velocity. |
box | Fixed box. |
outLocation | Position of collision. [Post Condition] |
outNormal | Box's surface normal to collision [Post Condition] |
|
static |
Calculates time between the intersection of a moving point and a fixed capsule.
point | Moving point. |
velocity | Point's velocity. |
capsule | Fixed capsule. |
outLocation | Location of collision. [Post Condition] |
outNormal | Capsule's surface normal to collision [Post Condition] |
|
static |
Calculates time between the intersection of a moving point and a fixed plane.
point | Moving point. |
velocity | Point's velocity. |
plane | Fixed plane. |
outLocation | Location of collision. [Post Condition] (Infinite vector on no collision) |
outNormal | Plane's surface normal. [Post Condition] |
|
static |
Calculates time between the intersection of a moving point and a fixed rectangle defined by the points v0, v1, v2, & v3.
point | Moving point. |
velocity | Sphere's velocity. |
v0 | Rectangle vertex 1. |
v1 | Rectangle vertex 2. |
v2 | Rectangle vertex 3 |
v3 | Rectangle vertex 4. |
outLocation | Location of collision [Post Condition] |
outNormal | Rectangle's surface normal. [Post Condition] |
|
static |
Calculates time between the intersection of a moving point and a fixed sphere.
point | Moving point. |
velocity | Point's velocity. |
sphere | Fixed Sphere. |
outLocation | Location of collision. [Post Condition] |
outNormal | Sphere's surface normal to collision [Post Condition] |
solid | If true, rays inside the sphere immediately intersect (good for collision detection). If false, they hit the opposite side of the sphere (good for ray tracing). |
|
inlinestatic |
Calculates time between the intersection of a moving point and a fixed triangle.
orig | Moving point. |
dir | Point's velocity. |
v0 | Triangle vertex 1. |
v1 | Triangle vertex 2. |
v2 | Triangle vertex 3 |
|
inlinestatic |
Calculates time between the intersection of a moving point and a fixed triangle.
orig | Moving point. |
dir | Point's velocity. |
v0 | Triangle vertex 1. |
v1 | Triangle vertex 2. |
v2 | Triangle vertex 3 |
location | Location of collision. [Post Condition] (Infinite vector on no collision) |
|
inlinestatic |
Calculates time between the intersection of a moving point and a fixed triangle.
orig | Moving point. |
dir | Point's velocity. |
tri | Fixed triangle. |
location | Location of collision. [Post Condition] (Infinite vector on no collision) |
normal | Triangle's surface normal. [Post Condition] |
|
inlinestatic |
Calculates time between the intersection of a moving point and a fixed triangle.
orig | Moving point. |
dir | Point's velocity. |
v0 | Triangle vertex 1. |
v1 | Triangle vertex 2. |
v2 | Triangle vertex 3 |
location | Location of collision. [Post Condition] (Infinite vector on no collision) |
normal | Triangle's surface normal. [Post Condition] |
|
static |
Calculates time between the intersection of a moving sphere and a fixed box.
sphere | Moving sphere. |
velocity | Sphere's velocity. |
box | Fixed box. |
outLocation | Location of collision – not center position of sphere at the collision time. [Post Condition] |
outNormal | Box's surface normal to collision [Post Condition] |
|
static |
Calculates time between the intersection of a moving sphere and a fixed capsule.
sphere | Moving sphere. |
velocity | Sphere's velocity. |
capsule | Fixed capsule. |
outLocation | Location of collision – not center position of sphere at the collision time. [Post Condition] |
outNormal | Capsule's surface normal to the collision [Post Condition] |
|
static |
Calculates time between the intersection of a moving sphere and a fixed triangle.
sphere | Moving sphere. |
velocity | Sphere's velocity. |
plane | Fixed Plane. |
outLocation | Location of collision – not center position of sphere at the collision time. [Post Condition] |
outNormal | Box's surface normal to collision [Post Condition] |
|
static |
Calculates time between the intersection of a moving sphere and a fixed rectangle defined by the points v0, v1, v2, & v3.
sphere | Moving sphere. |
velocity | Sphere's velocity. |
v0 | Rectangle vertex 1. |
v1 | Rectangle vertex 2. |
v2 | Rectangle vertex 3 |
v3 | Rectangle vertex 4. |
outLocation | Location of collision – not center position of sphere at the collision time. [Post Condition] |
outNormal | Box's surface normal to collision [Post Condition] |
|
static |
Calculates time between the intersection of a moving sphere and a fixed sphere.
If they are already interpenetrating, returns 0 and location is the closest point on the surface of the fixed sphere to the center of the moving sphere.
sphere | Moving sphere. |
velocity | Sphere's velocity. |
fixedSphere | Fixed Sphere. |
outLocation | Location of collision – not center position of sphere at the collision time. [Post Condition] |
outNormal | Moving sphere's surface normal to collision [Post Condition] |
|
static |
Calculates time between the intersection of a moving sphere and a fixed triangle.
sphere | The moving sphere. |
velocity | The sphere's velocity. |
triangle | Single-sided fixed triangle. |
outLocation | Location of collision, if collision occurs – not center position of sphere at the collision time. If there is interpenetration at the start, this point may be inside the sphere. |
b | Barycentric coordinates. These are not valid unless collision occurs. |
|
static |
Performs a simple bounding sphere check between two boxes to determine whether these boxes could possibly intersect. This is a very cheap operation (three dot products, two sqrts and a few others). If it returns true, an intersection is possible, but not necessarily guaranteed.
a | Vector from box A's center to an outer vertex |
b | Vector from box B's center to an outer vertex |
D | Distance between the centers of the two boxes |
|
static |
Creates a set of standard information about two boxes in order to solve for their collision. This information includes a vector to the radius of the bounding sphere for each box, the vector between each boxes' center and a series of dot products between differing important vectors. These dot products include those between the axes of both boxes (signed and unsigned values), and the dot products between all the axes of box1 and the boxes' center vector and box2 and the boxes' center vector.
[dobted] from David Eberly's papers, variables used in this function correspond to variables used in pages 6 and 7 in the pdf http://www.magic-software.com/Intersection.html http://www.magic-software.com/Documentation/DynamicCollisionDetection.pdf
box1 | Box 1 |
box2 | Box 2 |
a | Box 1's bounding sphere vector |
b | Box 2's bounding sphere vector |
D | Vector between Box 1 and Box 2's center points |
c | Pointer to array of dot products of the axes of Box 1 and Box 2. |
ca | Pointer to array of unsigned dot products of the axes of Box 1 and Box 2. |
ad | Pointer to array of dot products of Box 1 axes and D. |
bd | Pointer to array of dot products of Box 2 axes and D. |
|
static |
Determines whether two fixed solid boxes intersect.
[Adobted] from David Eberly's papers, variables used in this function correspond to variables used in pages 6 and 7 in the pdf http://www.magic-software.com/Intersection.html http://www.magic-software.com/Documentation/DynamicCollisionDetection.pdf
|
static |
|
static |
Tests for the intersection of a fixed sphere and a fixed box.
sphere | Fixed sphere. |
box | Fixed box. |
|
static |
Tests for the intersection of two fixed spheres.
sphere1 | Fixed sphere 1. |
sphere2 | Fixed sphere 2. |
|
static |
|
static |
Tests whether a point is inside a rectangle defined by the vertexes v0, v1, v2, & v3, and the rectangle's plane normal.
v0 | Rectangle vertex 1. |
v1 | Rectangle vertex 2. |
v2 | Rectangle vertex 3. |
v3 | Rectangle vertex 4. |
normal | Normal to rectangle's plane. |
point | The point in question. |
|
static |
Tests whether a point is contained within the triangle defined by v0, v1, and v2 and its plane's normal.
v0 | Triangle vertex 0. |
v1 | Triangle vertex 1. |
v2 | Triangle vertex 2. |
normal | Normal to triangle's plane. |
point | The point in question. |
primaryAxis | Primary axis of triangle. This will be detected if not given. This parameter is provided as an optimization. |
b | Barycentric coordinates; b[i] is the weight on v[i] |
|
inlinestatic |
|
static |
Tests for the intersection of a moving sphere and a fixed box in a given time limit.
sphere | Moving sphere. |
velocity | Velocity of moving sphere. |
box | Fixed box. |
timeLimit | Time limit for intersection test. |
|
static |
Tests for the intersection of a moving sphere and a fixed sphere in a given time limit.
sphere | Moving sphere. |
velocity | Velocity of moving sphere. |
fixedSphere | Fixed sphere. |
timeLimit | Time limit for intersection test. |
|
static |
Tests whether two boxes have axes that are parallel to each other. If they are, axis1 and axis2 are set to be the parallel axes for both box1 and box2 respectively.
ca | Dot products of each of the boxes axes |
epsilon | Fudge factor (small unit by which the dot products may vary and still be considered zero). |
axis1 | Parallel Axis 1. [Post Condition] |
axis2 | Parallel Axis 2. [Post Condition] |
|
static |
Calculates the depth of penetration between two fixed boxes. Contact normal faces away from box1 and into box2. If there is contact, only one contact point is returned. The minimally violated separating plane is computed
[adobted] from David Eberly's papers, variables used in this function correspond to variables used in pages 6 and 7 in the pdf http://www.magic-software.com/Intersection.html http://www.magic-software.com/Documentation/DynamicCollisionDetection.pdf
box1 | Box 1 |
box2 | Box 2 |
contactPoints | Contact point between boxes. [Post Condition] |
contactNormals | Surface normal at contact point. [Post Condition] |
lastSeparatingAxis | Last separating axis. (Used for optimization) |
|
static |
Calculates the depth of penetration between a fixed box and a fixed plane as well as the vertexes of the box that penetrate the plane and the plane normals at those intersections.
box | Fixed Box. |
plane | Fixed Plane. |
contactPoints | Box points that penetrate the plane. [Post Condition] |
contactNormals | Normals at penetration points [Post Condition] |
|
static |
Calculates the depth of penetration between a fixed sphere and a fixed box as well as the deepest point of the sphere that penetrates the box and the normal at that intersection.
The contact point and contact normal vary for each of these situations.
[Adapted] from Jim Arvo's method in Graphics Gems See also http://www.win.tue.nl/~gino/solid/gdc2001depth.pdf
sphere | Fixed Sphere. |
box | Fixed Box. |
contactPoints | Sphere point that penetrates the box. [Post Condition] |
contactNormals | Normal at the penetration point. [Post Condition] |
|
static |
Calculates the depth of penetration between a Fixed Sphere and a Fixed Plane as well as the deepest point of the sphere that penetrates the plane and the plane normal at that intersection.
sphereA | Fixed Sphere. |
planeB | Fixed Plane. |
contactPoints | Sphere point that penetrates the plane. [Post Condition] |
contactNormals | Normal at penetration point. [Post Condition] |
|
static |
Calculates the depth of penetration between two fixed spheres as well as the deepest point of Sphere A that penetrates Sphere B. The normal returned points away from the object A, although it may represent a perpendicular to either the faces of object B or object A depending on their relative orientations.
sphereA | Fixed Sphere A. |
sphereB | Fixed Sphere B. |
contactPoints | Sphere A's deepest point that penetrates Sphere B. [Post Condition] |
contactNormals | Normal at penetration point. [Post Condition] |
|
static |
Calculates the projected distance between the two boxes along the specified separating axis, negative distances correspond to an overlap along that separating axis. The distance is not divided by denominator dot(L, L), see penetrationDepthForFixedSphereFixedBox() for more details
separatingAxisIndex | |
a | Box 1's bounding sphere vector |
b | Box 2's bounding sphere vector |
D | Vector between Box 1 and Box 2's center points |
c | Pointer to array of dot products of the axes of Box 1 and Box 2. |
ca | Pointer to array of unsigned dot products of the axes of Box 1 and Box 2. |
ad | Pointer to array of dot products of Box 1 axes and D. |
bd | Pointer to array of dot products of Box 2 axes and D. |
|
static |
Calculates intersection of a ray and a static Axis-Aligned Box (AABox).
invDir | 1/dir |
location | Location of collision. [Post Condition] |
inside | Does the ray originate inside the box? [Post Condition] |
|
static |
Converts an index [0, 15] to the corresponding separating axis. Does not return normalized vector in the edge-edge case (indices 6 through 15).
|
static |
Finds the direction of slide given a moving sphere, its velocity, the time of collision and the collision location. This function works as if the sphere intersects the surface and continues to hug it.
sphere | Moving sphere. |
velocity | Sphere's velocity. |
collisionTime | Time of collision |
collisionLocation | Collision location. |
|
staticprivate |
Default parameter if value passed to a function as reference is not to be calculated. Must be explicitly supported by function.
Default parameter if value passed to a function as reference is not to be calculated. Must be explicitly supported by function.
|
staticprivate |
Default parameter if value passed to a function as reference is not to be calculated. Must be explicitly supported by function.