📄 collisiondetection.h
字号:
const class Sphere& sphere,
const Vector3& velocity,
const Triangle& triangle,
Vector3& outLocation,
Vector3& outNormal = ignore);
/**
Calculates time between the intersection of a moving sphere and a fixed
rectangle defined by the points v0, v1, v2, & v3.
@param sphere Moving sphere.
@param velocity Sphere's velocity.
@param v0 Rectangle vertex 1.
@param v1 Rectangle vertex 2.
@param v2 Rectangle vertex 3
@param v3 Rectangle vertex 4.
@param location Location of collision -- not center position of sphere
at the collision time. [Post Condition]
@param outNormal Box's surface normal to collision [Post Condition]
@return Time til collision. If there is no collision then the return
value will be inf().
*/
static float collisionTimeForMovingSphereFixedRectangle(
const class Sphere& sphere,
const Vector3& velocity,
const Vector3& v0,
const Vector3& v1,
const Vector3& v2,
const Vector3& v3,
Vector3& outLocation,
Vector3& outNormal = ignore);
/**
Calculates time between the intersection of a moving sphere and a fixed
box.
@note This function will not detect an intersection between a moving object
that is already interpenetrating the fixed object.
@param sphere Moving sphere.
@param velocity Sphere's velocity.
@param box Fixed box.
@param location Location of collision -- not center position of sphere
at the collision time. [Post Condition]
@param outNormal Box's surface normal to collision [Post Condition]
@return Time til collision. If there is no collision then the return
value will be inf().
*/
static float collisionTimeForMovingSphereFixedBox(
const class Sphere& sphere,
const Vector3& velocity,
const class Box& box,
Vector3& outLocation,
Vector3& outNormal = ignore);
/**
Calculates time between the intersection of a moving sphere and a fixed
sphere.
@note This won't detect a collision if the sphere is already interpenetrating
the fixed sphere.
@param movingSphere Moving sphere.
@param velocity Sphere's velocity.
@param fixedSphere Fixed Sphere.
@param location Location of collision -- not center position of sphere
at the collision time. [Post Condition]
@param outNormal Sphere's surface normal to collision [Post Condition]
@return Time til collision. If there is no collision then the return
value will be inf().
*/
static float collisionTimeForMovingSphereFixedSphere(
const class Sphere& sphere,
const Vector3& velocity,
const class Sphere& fixedSphere,
Vector3& outLocation,
Vector3& outNormal = ignore);
/**
Calculates time between the intersection of a moving sphere and a fixed
capsule.
@note This won't detect a collision if the sphere is already
interpenetrating the capsule.
@param sphere Moving sphere.
@param velocity Sphere's velocity.
@param capsule Fixed capsule.
@param location Location of collision -- not center position of sphere
at the collision time. [Post Condition]
@param outNormal Capsule's surface normal to the collision [Post Condition]
@return Time til collision. If there is no collision then the return
value will be inf().
*/
static float collisionTimeForMovingSphereFixedCapsule(
const class Sphere& sphere,
const Vector3& velocity,
const class Capsule& capsule,
Vector3& outLocation,
Vector3& outNormal = ignore);
/**
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.
@note This function works like a pong style ball bounce.
@param sphere Moving sphere.
@param velocity Sphere's velocity.
@param collisionTime Time of collision.
@param collisionLocation Collision location.
@param collisionNormal Surface collision normal.
@return Direction of bounce.
*/
static Vector3 bounceDirection(
const class Sphere& sphere,
const Vector3& velocity,
const float collisionTime,
const Vector3& collisionLocation,
const Vector3& collisionNormal);
/**
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.
@note The result will work well for calculating the movement of a player
who collides with an object and continues moving along the object instead
of just bouncing off it.
@param sphere Moving sphere.
@param velocity Sphere's velocity.
@param collisionTime Time of collision
@param collisionLocation Collision location.
@return Direction of slide.
*/
static Vector3 slideDirection(
const class Sphere& sphere,
const Vector3& velocity,
const float collisionTime,
const Vector3& collisionLocation);
/**
Finds the closest point on a line segment to a given point.
@param v0 line vertex 1.
@param v1 line vertex 2.
@param point External point.
@return Closests point to <code>point</code> on the line segment.
*/
static Vector3 closestPointOnLineSegment(
const Vector3& v0,
const Vector3& v1,
const Vector3& point);
/**
Finds the closest point on a line segment to a given point.
@note This is an optimization to closestPointOnLineSegment. Edge length
and direction can be used in this function if already pre-calculated. This
prevents doing the same work twice.
@param v0 line vertex 1.
@param v1 line vertex 2.
@param edgeDirection The direction of the segment (unit length).
@param edgeLength The length of the segment.
@param point External point.
@return Closests point to <code>point</code> on the line segment.
*/
static Vector3 closestPointOnLineSegment(
const Vector3& v0,
const Vector3& v1,
const Vector3& edgeDirection,
float edgeLength,
const Vector3& point);
/**
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.
@param v0 Triangle vertex 1.
@param v1 Triangle vertex 2.
@param v2 Triangle vertex 3.
@param point External point.
@return Closests point to <code>point</code> on the perimeter of the
triangle.
*/
static Vector3 closestPointToTrianglePerimeter(
const Vector3& v0,
const Vector3& v1,
const Vector3& v2,
const Vector3& point);
/**
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.
@note This is an optimization to closestPointToTrianglePerimeter. Edge length
and direction can be used in this function if already pre-calculated. This
prevents doing the same work twice.
@param v0 Triangle vertex 1.
@param v1 Triangle vertex 2.
@param v2 Triangle vertex 3.
@param point External point.
@return Closests point to <code>point</code> on the perimeter of the
triangle.
*/
static Vector3 closestPointToTrianglePerimeter(
const Vector3 v[3],
const Vector3 edgeDirection[3],
const double edgeLength[3],
const Vector3& point);
/**
Tests whether a point is contained within the triangle defined by
v0, v1, & v2 and its plane's normal.
@param v0 Triangle vertex 1.
@param v1 Triangle vertex 2.
@param v2 Triangle vertex 3.
@param normal Normal to triangle's plane.
@param point The point in question.
@param primaryAxis Primary axis of triangle. This will be detected
if not given. This parameter is provided as an optimization.
@return true - if point is inside the triangle.
@return false - otherwise
*/
static bool isPointInsideTriangle(
const Vector3& v0,
const Vector3& v1,
const Vector3& v2,
const Vector3& normal,
const Vector3& point,
Vector3::Axis primaryAxis = Vector3::DETECT_AXIS);
/**
Tests for the intersection of a moving sphere and a fixed box in a
given time limit.
@note Returns true if any part of the sphere is inside the box
during the time period (inf means "ever"). Useful for
performing bounding-box collision detection.
@param sphere Moving sphere.
@param velocity Velocity of moving sphere.
@param box Fixed box.
@param timeLimit Time limit for intersection test.
@return true - if the two objects will touch.
@return false - if there is no intersection.
*/
static bool movingSpherePassesThroughFixedBox(
const Sphere& sphere,
const Vector3& velocity,
const Box& box,
double timeLimit = inf());
/**
Tests for the intersection of a moving sphere and a fixed sphere in a
given time limit.
@note This function will not detect an intersection between a moving object
that is already interpenetrating the fixed object.
@param sphere Moving sphere.
@param velocity Velocity of moving sphere.
@param fixedSphere Fixed sphere.
@param timeLimit Time limit for intersection test.
@return true - if the two spheres will touch.
@return false - if there is no intersection.
*/
static bool movingSpherePassesThroughFixedSphere(
const Sphere& sphere,
const Vector3& velocity,
const Sphere& fixedSphere,
double timeLimit = inf());
/**
Tests for the intersection of two fixed spheres.
@param sphere1 Fixed sphere 1.
@param sphere2 Fixed sphere 2.
@return true - if the two spheres touch.
@return false - if there is no intersection.
*/
static bool fixedSolidSphereIntersectsFixedSolidSphere(
const Sphere& sphere1,
const Sphere& sphere2);
/**
Tests for the intersection of a fixed sphere and a fixed box.
@param sphere Fixed sphere.
@param box Fixed box.
@return true - if the two objects touch.
@return false - if there is no intersection.
*/
static bool fixedSolidSphereIntersectsFixedSolidBox(
const Sphere& sphere,
const Box& box);
/**
Tests whether a point is inside a rectangle defined by the vertexes
v0, v1, v2, & v3, and the rectangle's plane normal.
@param v0 Rectangle vertex 1.
@param v1 Rectangle vertex 2.
@param v2 Rectangle vertex 3.
@param v3 Rectangle vertex 4.
@param normal Normal to rectangle's plane.
@param point The point in question.
@return true - if point is inside the rectangle.
@return false - otherwise
*/
static bool isPointInsideRectangle(
const Vector3& v0,
const Vector3& v1,
const Vector3& v2,
const Vector3& v3,
const Vector3& normal,
const Vector3& point);
/**
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.
@param v0 Rectangle vertex 1.
@param v1 Rectangle vertex 2.
@param v2 Rectangle vertex 3.
@param v3 Rectangle vertex 4.
@param point External point.
@return Closests point to <code>point</code> on the perimeter of the
rectangle.
*/
static Vector3 closestPointToRectanglePerimeter(
const Vector3& v0,
const Vector3& v1,
const Vector3& v2,
const Vector3& v3,
const Vector3& point);
/**
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.
@param v0 Rectangle vertex 1.
@param v1 Rectangle vertex 2.
@param v2 Rectangle vertex 3
@param v3 Rectangle vertex 4.
@param point External point.
@return Closet point in the rectangle to the external point.
*/
static Vector3 closestPointToRectangle(
const Vector3& v0,
const Vector3& v1,
const Vector3& v2,
const Vector3& v3,
const Vector3& point);
};
} // namespace
#endif // G3D_COLLISIONDETECTION_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -