@box2d/debug-draw
Version:
Debug drawing helper for @box2d
251 lines • 8.37 kB
TypeScript
import { b2Vec2, b2Transform, XY } from "../common/b2_math";
import type { b2Shape } from "./b2_shape";
import { b2Readonly } from "../common/b2_readonly";
export declare enum b2ContactFeatureType {
e_vertex = 0,
e_face = 1
}
/**
* The features that intersect to form the contact point
* This must be 4 bytes or less.
*/
export declare class b2ContactFeature {
private m_key;
private m_key_invalid;
/** Feature index on shapeA */
private m_indexA;
/** Feature index on shapeB */
private m_indexB;
/** The feature type on shapeA */
private m_typeA;
/** The feature type on shapeB */
private m_typeB;
get key(): number;
set key(value: number);
get indexA(): number;
set indexA(value: number);
get indexB(): number;
set indexB(value: number);
get typeA(): number;
set typeA(value: number);
get typeB(): number;
set typeB(value: number);
}
/**
* Contact ids to facilitate warm starting.
*/
export declare class b2ContactID {
readonly cf: b2ContactFeature;
Copy(o: b2ContactID): b2ContactID;
Clone(): b2ContactID;
get key(): number;
set key(value: number);
}
/**
* A manifold point is a contact point belonging to a contact
* manifold. It holds details related to the geometry and dynamics
* of the contact points.
* The local point usage depends on the manifold type:
* -e_circles: the local center of circleB
* -e_faceA: the local center of cirlceB or the clip point of polygonB
* -e_faceB: the clip point of polygonA
* This structure is stored across time steps, so we keep it small.
* Note: the impulses are used for internal caching and may not
* provide reliable contact forces, especially for high speed collisions.
*/
export declare class b2ManifoldPoint {
/** Usage depends on manifold type */
readonly localPoint: b2Vec2;
/** The non-penetration impulse */
normalImpulse: number;
/** The friction impulse */
tangentImpulse: number;
/** Uniquely identifies a contact point between two shapes */
readonly id: b2ContactID;
Reset(): void;
Copy(o: b2ManifoldPoint): b2ManifoldPoint;
}
export declare enum b2ManifoldType {
e_circles = 0,
e_faceA = 1,
e_faceB = 2
}
/**
* A manifold for two touching convex shapes.
* Box2D supports multiple types of contact:
* - clip point versus plane with radius
* - point versus point with radius (circles)
* The local point usage depends on the manifold type:
* -e_circles: the local center of circleA
* -e_faceA: the center of faceA
* -e_faceB: the center of faceB
* Similarly the local normal usage:
* -e_circles: not used
* -e_faceA: the normal on polygonA
* -e_faceB: the normal on polygonB
* We store contacts in this way so that position correction can
* account for movement, which is critical for continuous physics.
* All contact scenarios must be expressed in one of these types.
* This structure is stored across time steps, so we keep it small.
*/
export declare class b2Manifold {
/** The points of contact */
readonly points: b2ManifoldPoint[];
/** Not use for Type::e_points */
readonly localNormal: b2Vec2;
/** Usage depends on manifold type */
readonly localPoint: b2Vec2;
type: b2ManifoldType;
/** The number of manifold points */
pointCount: number;
Reset(): void;
Copy(o: b2Manifold): b2Manifold;
Clone(): b2Manifold;
}
/**
* This is used to compute the current state of a contact manifold.
*/
export declare class b2WorldManifold {
/** World vector pointing from A to B */
readonly normal: b2Vec2;
/** World contact point (point of intersection) */
readonly points: b2Vec2[];
/** A negative value indicates overlap, in meters */
readonly separations: number[];
private static Initialize_s_pointA;
private static Initialize_s_pointB;
private static Initialize_s_cA;
private static Initialize_s_cB;
private static Initialize_s_planePoint;
private static Initialize_s_clipPoint;
/**
* Evaluate the manifold with supplied transforms. This assumes
* modest motion from the original state. This does not change the
* point count, impulses, etc. The radii must come from the shapes
* that generated the manifold.
*/
Initialize(manifold: b2Manifold, xfA: b2Readonly<b2Transform>, radiusA: number, xfB: b2Readonly<b2Transform>, radiusB: number): void;
}
/**
* This is used for determining the state of contact points.
*/
export declare enum b2PointState {
/** Point does not exist */
b2_nullState = 0,
/** Point was added in the update */
b2_addState = 1,
/** Point persisted across the update */
b2_persistState = 2,
/** Point was removed in the update */
b2_removeState = 3
}
/**
* Compute the point states given two manifolds. The states pertain to the transition from manifold1
* to manifold2. So state1 is either persist or remove while state2 is either add or persist.
*/
export declare function b2GetPointStates(state1: b2PointState[], state2: b2PointState[], manifold1: b2Manifold, manifold2: b2Manifold): void;
/**
* Used for computing contact manifolds.
*/
export declare class b2ClipVertex {
readonly v: b2Vec2;
readonly id: b2ContactID;
Copy(other: b2ClipVertex): b2ClipVertex;
}
/**
* Ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).
*/
export declare class b2RayCastInput {
readonly p1: b2Vec2;
readonly p2: b2Vec2;
maxFraction: number;
Copy(o: b2RayCastInput): b2RayCastInput;
}
/**
* Ray-cast output data. The ray hits at p1 + fraction * (p2 - p1), where p1 and p2
* come from b2RayCastInput.
*/
export declare class b2RayCastOutput {
readonly normal: b2Vec2;
fraction: number;
Copy(o: b2RayCastOutput): b2RayCastOutput;
}
/**
* An axis aligned bounding box.
*/
export declare class b2AABB {
/** The lower vertex */
readonly lowerBound: b2Vec2;
/** The upper vertex */
readonly upperBound: b2Vec2;
Copy(o: b2AABB): b2AABB;
/**
* Verify that the bounds are sorted.
*/
IsValid(): boolean;
/**
* Get the center of the AABB.
*/
GetCenter(out: XY): XY;
/**
* Get the extents of the AABB (half-widths).
*/
GetExtents(out: XY): XY;
/**
* Get the perimeter length
*/
GetPerimeter(): number;
/**
* Combine an AABB into this one.
*/
Combine1(aabb: b2AABB): b2AABB;
/**
* Combine two AABBs into this one.
*/
Combine2(aabb1: b2AABB, aabb2: b2AABB): b2AABB;
static Combine(aabb1: b2AABB, aabb2: b2AABB, out: b2AABB): b2AABB;
/**
* Does this aabb contain the provided AABB.
*/
Contains(aabb: b2AABB): boolean;
RayCast(output: b2RayCastOutput, input: b2RayCastInput): boolean;
TestContain(point: XY): boolean;
TestOverlap(other: b2AABB): boolean;
}
/**
* Clipping for contact manifolds.
* Sutherland-Hodgman clipping.
*/
export declare function b2ClipSegmentToLine(vOut: readonly [b2ClipVertex, b2ClipVertex], [vIn0, vIn1]: readonly [b2ClipVertex, b2ClipVertex], normal: b2Readonly<b2Vec2>, offset: number, vertexIndexA: number): number;
/**
* Determine if two generic shapes overlap.
*/
export declare function b2TestOverlap(shapeA: b2Shape, indexA: number, shapeB: b2Shape, indexB: number, xfA: b2Readonly<b2Transform>, xfB: b2Readonly<b2Transform>): boolean;
/** Convex hull used for polygon collision */
export type b2Hull = Array<Readonly<XY>>;
/**
* Compute the convex hull of a set of points.
* quickhull algorithm
* - merges vertices based on b2_linearSlop
* - removes collinear points using b2_linearSlop
* - returns an empty hull if it fails
*
* Some failure cases:
* - all points very close together
* - all points on a line
* - less than 3 points
* - more than b2_maxPolygonVertices points
*
* This welds close points and removes collinear points.
*
* @returns an empty hull if it fails.
*/
export declare function b2ComputeHull(points: ReadonlyArray<Readonly<XY>>, count: number): Readonly<b2Hull>;
/**
* This determines if a hull is valid. Checks for:
* - convexity
* - collinear points
* This is expensive and should not be called at runtime.
*/
export declare function b2ValidateHull(hull: Readonly<b2Hull>, count: number): boolean;
//# sourceMappingURL=b2_collision.d.ts.map