@@ -0,0 +1,137 @@
/*
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
import { B2_pi, B2_epsilon } from '../../Common/b2Settings';
import { B2Sq, B2Sqrt, B2Asin, B2Pow, B2Vec2, B2Transform } from '../../Common/b2Math';
import { B2Shape } from './b2Shape';
/// A circle shape.
export class B2CircleShape extends B2Shape {
constructor(radius = 0) {
super(0 /* e_circleShape */, radius);
this.m_p = new B2Vec2();
}
/// Implement B2Shape.
Clone() {
return new B2CircleShape().Copy(this);
}
Copy(other) {
super.Copy(other);
/// b2Assert(other instanceof B2CircleShape);
this.m_p.Copy(other.m_p);
return this;
}
/// @see B2Shape::GetChildCount
GetChildCount() {
return 1;
}
TestPoint(transform, p) {
const center = B2Transform.MulXV(transform, this.m_p, B2CircleShape.TestPoint_s_center);
const d = B2Vec2.SubVV(p, center, B2CircleShape.TestPoint_s_d);
return B2Vec2.DotVV(d, d) <= B2Sq(this.m_radius);
}
ComputeDistance(xf, p, normal, childIndex) {
const center = B2Transform.MulXV(xf, this.m_p, B2CircleShape.ComputeDistance_s_center);
B2Vec2.SubVV(p, center, normal);
return normal.Normalize() - this.m_radius;
}
RayCast(output, input, transform, childIndex) {
const position = B2Transform.MulXV(transform, this.m_p, B2CircleShape.RayCast_s_position);
const s = B2Vec2.SubVV(input.p1, position, B2CircleShape.RayCast_s_s);
const b = B2Vec2.DotVV(s, s) - B2Sq(this.m_radius);
// Solve quadratic equation.
const r = B2Vec2.SubVV(input.p2, input.p1, B2CircleShape.RayCast_s_r);
const c = B2Vec2.DotVV(s, r);
const rr = B2Vec2.DotVV(r, r);
const sigma = c * c - rr * b;
// Check for negative discriminant and short segment.
if (sigma < 0 || rr < B2_epsilon) {
return false;
}
// Find the point of intersection of the line with the circle.
let a = (-(c + B2Sqrt(sigma)));
// Is the intersection point on the segment?
if (0 <= a && a <= input.maxFraction * rr) {
a /= rr;
output.fraction = a;
B2Vec2.AddVMulSV(s, a, r, output.normal).SelfNormalize();
return true;
}
return false;
}
ComputeAABB(aabb, transform, childIndex) {
const p = B2Transform.MulXV(transform, this.m_p, B2CircleShape.ComputeAABB_s_p);
aabb.lowerBound.Set(p.x - this.m_radius, p.y - this.m_radius);
aabb.upperBound.Set(p.x + this.m_radius, p.y + this.m_radius);
}
/// @see B2Shape::ComputeMass
ComputeMass(massData, density) {
const radius_sq = B2Sq(this.m_radius);
massData.mass = density * B2_pi * radius_sq;
massData.center.Copy(this.m_p);
// inertia about the local origin
massData.I = massData.mass * (0.5 * radius_sq + B2Vec2.DotVV(this.m_p, this.m_p));
}
SetupDistanceProxy(proxy, index) {
proxy.m_vertices = proxy.m_buffer;
proxy.m_vertices[0].Copy(this.m_p);
proxy.m_count = 1;
proxy.m_radius = this.m_radius;
}
ComputeSubmergedArea(normal, offset, xf, c) {
const p = B2Transform.MulXV(xf, this.m_p, new B2Vec2());
const l = (-(B2Vec2.DotVV(normal, p) - offset));
if (l < (-this.m_radius) + B2_epsilon) {
// Completely dry
return 0;
}
if (l > this.m_radius) {
// Completely wet
c.Copy(p);
return B2_pi * this.m_radius * this.m_radius;
}
// Magic
const r2 = this.m_radius * this.m_radius;
const l2 = l * l;
const area = r2 * (B2Asin(l / this.m_radius) + B2_pi / 2) + l * B2Sqrt(r2 - l2);
const com = (-2 / 3 * B2Pow(r2 - l2, 1.5) / area);
c.x = p.x + normal.x * com;
c.y = p.y + normal.y * com;
return area;
}
Dump(log) {
log(' const shape: B2CircleShape = new B2CircleShape();\n');
log(' shape.m_radius = %.15f;\n', this.m_radius);
log(' shape.m_p.Set(%.15f, %.15f);\n', this.m_p.x, this.m_p.y);
}
}
/// Implement B2Shape.
B2CircleShape.TestPoint_s_center = new B2Vec2();
B2CircleShape.TestPoint_s_d = new B2Vec2();
/// #if B2_ENABLE_PARTICLE
/// @see B2Shape::ComputeDistance
B2CircleShape.ComputeDistance_s_center = new B2Vec2();
/// #endif
/// Implement B2Shape.
// Collision Detection in Interactive 3D Environments by Gino van den Bergen
// From Section 3.1.2
// x = s + a * r
// norm(x) = radius
B2CircleShape.RayCast_s_position = new B2Vec2();
B2CircleShape.RayCast_s_s = new B2Vec2();
B2CircleShape.RayCast_s_r = new B2Vec2();
/// @see B2Shape::ComputeAABB
B2CircleShape.ComputeAABB_s_p = new B2Vec2();
@@ -0,0 +1,38 @@
import { B2Vec2, B2Transform } from '../../Common/b2Math';
import { B2AABB, B2RayCastInput, B2RayCastOutput } from '../b2Collision';
import { B2DistanceProxy } from '../b2Distance';
import { B2MassData } from './b2Shape';
import { B2Shape } from './b2Shape';
export declare class B2EdgeShape extends B2Shape {
m_vertex1: B2Vec2;
m_vertex2: B2Vec2;
m_vertex0: B2Vec2;
m_vertex3: B2Vec2;
m_hasVertex0: boolean;
m_hasVertex3: boolean;
constructor();
Set(v1: B2Vec2, v2: B2Vec2): B2EdgeShape;
Clone(): B2EdgeShape;
Copy(other: B2EdgeShape): B2EdgeShape;
GetChildCount(): number;
TestPoint(xf: B2Transform, p: B2Vec2): boolean;
private static ComputeDistance_s_v1;
private static ComputeDistance_s_v2;
private static ComputeDistance_s_d;
private static ComputeDistance_s_s;
ComputeDistance(xf: B2Transform, p: B2Vec2, normal: B2Vec2, childIndex: number): number;
private static RayCast_s_p1;
private static RayCast_s_p2;
private static RayCast_s_d;
private static RayCast_s_e;
private static RayCast_s_q;
private static RayCast_s_r;
RayCast(output: B2RayCastOutput, input: B2RayCastInput, xf: B2Transform, childIndex: number): boolean;
private static ComputeAABB_s_v1;
private static ComputeAABB_s_v2;
ComputeAABB(aabb: B2AABB, xf: B2Transform, childIndex: number): void;
ComputeMass(massData: B2MassData, density: number): void;
SetupDistanceProxy(proxy: B2DistanceProxy, index: number): void;
ComputeSubmergedArea(normal: B2Vec2, offset: number, xf: B2Transform, c: B2Vec2): number;
Dump(log: (format: string, ...args: any[]) => void): void;
}
@@ -0,0 +1,180 @@
/*
* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
import { B2_polygonRadius } from '../../Common/b2Settings';
import { B2Vec2, B2Rot, B2Transform } from '../../Common/b2Math';
import { B2Shape } from './b2Shape';
/// A line segment (edge) shape. These can be connected in chains or loops
/// to other edge shapes. The connectivity information is used to ensure
/// correct contact normals.
export class B2EdgeShape extends B2Shape {
constructor() {
super(1 /* e_edgeShape */, B2_polygonRadius);
this.m_vertex1 = new B2Vec2();
this.m_vertex2 = new B2Vec2();
this.m_vertex0 = new B2Vec2();
this.m_vertex3 = new B2Vec2();
this.m_hasVertex0 = false;
this.m_hasVertex3 = false;
}
/// Set this as an isolated edge.
Set(v1, v2) {
this.m_vertex1.Copy(v1);
this.m_vertex2.Copy(v2);
this.m_hasVertex0 = false;
this.m_hasVertex3 = false;
return this;
}
/// Implement B2Shape.
Clone() {
return new B2EdgeShape().Copy(this);
}
Copy(other) {
super.Copy(other);
/// b2Assert(other instanceof B2EdgeShape);
this.m_vertex1.Copy(other.m_vertex1);
this.m_vertex2.Copy(other.m_vertex2);
this.m_vertex0.Copy(other.m_vertex0);
this.m_vertex3.Copy(other.m_vertex3);
this.m_hasVertex0 = other.m_hasVertex0;
this.m_hasVertex3 = other.m_hasVertex3;
return this;
}
/// @see B2Shape::GetChildCount
GetChildCount() {
return 1;
}
/// @see B2Shape::TestPoint
TestPoint(xf, p) {
return false;
}
ComputeDistance(xf, p, normal, childIndex) {
const v1 = B2Transform.MulXV(xf, this.m_vertex1, B2EdgeShape.ComputeDistance_s_v1);
const v2 = B2Transform.MulXV(xf, this.m_vertex2, B2EdgeShape.ComputeDistance_s_v2);
const d = B2Vec2.SubVV(p, v1, B2EdgeShape.ComputeDistance_s_d);
const s = B2Vec2.SubVV(v2, v1, B2EdgeShape.ComputeDistance_s_s);
const ds = B2Vec2.DotVV(d, s);
if (ds > 0) {
const s2 = B2Vec2.DotVV(s, s);
if (ds > s2) {
B2Vec2.SubVV(p, v2, d);
}
else {
d.SelfMulSub(ds / s2, s);
}
}
normal.Copy(d);
return normal.Normalize();
}
RayCast(output, input, xf, childIndex) {
// Put the ray into the edge's frame of reference.
const p1 = B2Transform.MulTXV(xf, input.p1, B2EdgeShape.RayCast_s_p1);
const p2 = B2Transform.MulTXV(xf, input.p2, B2EdgeShape.RayCast_s_p2);
const d = B2Vec2.SubVV(p2, p1, B2EdgeShape.RayCast_s_d);
const v1 = this.m_vertex1;
const v2 = this.m_vertex2;
const e = B2Vec2.SubVV(v2, v1, B2EdgeShape.RayCast_s_e);
const normal = output.normal.Set(e.y, -e.x).SelfNormalize();
// q = p1 + t * d
// dot(normal, q - v1) = 0
// dot(normal, p1 - v1) + t * dot(normal, d) = 0
const numerator = B2Vec2.DotVV(normal, B2Vec2.SubVV(v1, p1, B2Vec2.s_t0));
const denominator = B2Vec2.DotVV(normal, d);
if (denominator === 0) {
return false;
}
const t = numerator / denominator;
if (t < 0 || input.maxFraction < t) {
return false;
}
const q = B2Vec2.AddVMulSV(p1, t, d, B2EdgeShape.RayCast_s_q);
// q = v1 + s * r
// s = dot(q - v1, r) / dot(r, r)
const r = B2Vec2.SubVV(v2, v1, B2EdgeShape.RayCast_s_r);
const rr = B2Vec2.DotVV(r, r);
if (rr === 0) {
return false;
}
const s = B2Vec2.DotVV(B2Vec2.SubVV(q, v1, B2Vec2.s_t0), r) / rr;
if (s < 0 || 1 < s) {
return false;
}
output.fraction = t;
B2Rot.MulRV(xf.q, output.normal, output.normal);
if (numerator > 0) {
output.normal.SelfNeg();
}
return true;
}
ComputeAABB(aabb, xf, childIndex) {
const v1 = B2Transform.MulXV(xf, this.m_vertex1, B2EdgeShape.ComputeAABB_s_v1);
const v2 = B2Transform.MulXV(xf, this.m_vertex2, B2EdgeShape.ComputeAABB_s_v2);
B2Vec2.MinV(v1, v2, aabb.lowerBound);
B2Vec2.MaxV(v1, v2, aabb.upperBound);
const r = this.m_radius;
aabb.lowerBound.SelfSubXY(r, r);
aabb.upperBound.SelfAddXY(r, r);
}
/// @see B2Shape::ComputeMass
ComputeMass(massData, density) {
massData.mass = 0;
B2Vec2.MidVV(this.m_vertex1, this.m_vertex2, massData.center);
massData.I = 0;
}
SetupDistanceProxy(proxy, index) {
proxy.m_vertices = proxy.m_buffer;
proxy.m_vertices[0].Copy(this.m_vertex1);
proxy.m_vertices[1].Copy(this.m_vertex2);
proxy.m_count = 2;
proxy.m_radius = this.m_radius;
}
ComputeSubmergedArea(normal, offset, xf, c) {
c.SetZero();
return 0;
}
Dump(log) {
log(' const shape: B2EdgeShape = new B2EdgeShape();\n');
log(' shape.m_radius = %.15f;\n', this.m_radius);
log(' shape.m_vertex0.Set(%.15f, %.15f);\n', this.m_vertex0.x, this.m_vertex0.y);
log(' shape.m_vertex1.Set(%.15f, %.15f);\n', this.m_vertex1.x, this.m_vertex1.y);
log(' shape.m_vertex2.Set(%.15f, %.15f);\n', this.m_vertex2.x, this.m_vertex2.y);
log(' shape.m_vertex3.Set(%.15f, %.15f);\n', this.m_vertex3.x, this.m_vertex3.y);
log(' shape.m_hasVertex0 = %s;\n', this.m_hasVertex0);
log(' shape.m_hasVertex3 = %s;\n', this.m_hasVertex3);
}
}
/// #if B2_ENABLE_PARTICLE
/// @see B2Shape::ComputeDistance
B2EdgeShape.ComputeDistance_s_v1 = new B2Vec2();
B2EdgeShape.ComputeDistance_s_v2 = new B2Vec2();
B2EdgeShape.ComputeDistance_s_d = new B2Vec2();
B2EdgeShape.ComputeDistance_s_s = new B2Vec2();
/// #endif
/// Implement B2Shape.
// p = p1 + t * d
// v = v1 + s * e
// p1 + t * d = v1 + s * e
// s * e - t * d = p1 - v1
B2EdgeShape.RayCast_s_p1 = new B2Vec2();
B2EdgeShape.RayCast_s_p2 = new B2Vec2();
B2EdgeShape.RayCast_s_d = new B2Vec2();
B2EdgeShape.RayCast_s_e = new B2Vec2();
B2EdgeShape.RayCast_s_q = new B2Vec2();
B2EdgeShape.RayCast_s_r = new B2Vec2();
/// @see B2Shape::ComputeAABB
B2EdgeShape.ComputeAABB_s_v1 = new B2Vec2();
B2EdgeShape.ComputeAABB_s_v2 = new B2Vec2();
@@ -0,0 +1,56 @@
import { B2Vec2, B2Transform } from '../../Common/b2Math';
import { B2AABB, B2RayCastInput, B2RayCastOutput } from '../b2Collision';
import { B2DistanceProxy } from '../b2Distance';
import { B2MassData } from './b2Shape';
import { B2Shape } from './b2Shape';
export declare class B2PolygonShape extends B2Shape {
m_centroid: B2Vec2;
m_vertices: B2Vec2[];
m_normals: B2Vec2[];
m_count: number;
constructor();
Clone(): B2PolygonShape;
Copy(other: B2PolygonShape): B2PolygonShape;
GetChildCount(): number;
private static Set_s_ps;
private static Set_s_hull;
private static Set_s_r;
private static Set_s_v;
Set(vertices: B2Vec2[], count?: number, start?: number): B2PolygonShape;
SetAsArray(vertices: B2Vec2[], count?: number): B2PolygonShape;
SetAsBox(hx: number, hy: number, center?: B2Vec2, angle?: number): B2PolygonShape;
private static TestPoint_s_pLocal;
TestPoint(xf: B2Transform, p: B2Vec2): boolean;
private static ComputeDistance_s_pLocal;
private static ComputeDistance_s_normalForMaxDistance;
private static ComputeDistance_s_minDistance;
private static ComputeDistance_s_distance;
ComputeDistance(xf: B2Transform, p: B2Vec2, normal: B2Vec2, childIndex: number): number;
private static RayCast_s_p1;
private static RayCast_s_p2;
private static RayCast_s_d;
RayCast(output: B2RayCastOutput, input: B2RayCastInput, xf: B2Transform, childIndex: number): boolean;
private static ComputeAABB_s_v;
ComputeAABB(aabb: B2AABB, xf: B2Transform, childIndex: number): void;
private static ComputeMass_s_center;
private static ComputeMass_s_s;
private static ComputeMass_s_e1;
private static ComputeMass_s_e2;
ComputeMass(massData: B2MassData, density: number): void;
private static Validate_s_e;
private static Validate_s_v;
Validate(): boolean;
SetupDistanceProxy(proxy: B2DistanceProxy, index: number): void;
private static ComputeSubmergedArea_s_normalL;
private static ComputeSubmergedArea_s_depths;
private static ComputeSubmergedArea_s_md;
private static ComputeSubmergedArea_s_intoVec;
private static ComputeSubmergedArea_s_outoVec;
private static ComputeSubmergedArea_s_center;
ComputeSubmergedArea(normal: B2Vec2, offset: number, xf: B2Transform, c: B2Vec2): number;
Dump(log: (format: string, ...args: any[]) => void): void;
private static ComputeCentroid_s_pRef;
private static ComputeCentroid_s_e1;
private static ComputeCentroid_s_e2;
static ComputeCentroid(vs: B2Vec2[], count: number, out: B2Vec2): B2Vec2;
}

Large diffs are not rendered by default.

@@ -0,0 +1,33 @@
import { B2Vec2, B2Transform } from '../../Common/b2Math';
import { B2AABB, B2RayCastInput, B2RayCastOutput } from '../b2Collision';
import { B2DistanceProxy } from '../b2Distance';
export declare class B2MassData {
mass: number;
center: B2Vec2;
I: number;
}
export declare const enum B2ShapeType {
e_unknown = -1,
e_circleShape = 0,
e_edgeShape = 1,
e_polygonShape = 2,
e_chainShape = 3,
e_shapeTypeCount = 4,
}
export declare abstract class B2Shape {
m_type: B2ShapeType;
m_radius: number;
constructor(type: B2ShapeType, radius: number);
abstract Clone(): B2Shape;
Copy(other: B2Shape): B2Shape;
GetType(): B2ShapeType;
abstract GetChildCount(): number;
abstract TestPoint(xf: B2Transform, p: B2Vec2): boolean;
abstract ComputeDistance(xf: B2Transform, p: B2Vec2, normal: B2Vec2, childIndex: number): number;
abstract RayCast(output: B2RayCastOutput, input: B2RayCastInput, transform: B2Transform, childIndex: number): boolean;
abstract ComputeAABB(aabb: B2AABB, xf: B2Transform, childIndex: number): void;
abstract ComputeMass(massData: B2MassData, density: number): void;
abstract SetupDistanceProxy(proxy: B2DistanceProxy, index: number): void;
abstract ComputeSubmergedArea(normal: B2Vec2, offset: number, xf: B2Transform, c: B2Vec2): number;
abstract Dump(log: (format: string, ...args: any[]) => void): void;
}
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
import { B2Vec2 } from '../../Common/b2Math';
/// This holds the mass data computed for a shape.
export class B2MassData {
constructor() {
/// The mass of the shape, usually in kilograms.
this.mass = 0;
/// The position of the shape's centroid relative to the shape's origin.
this.center = new B2Vec2(0, 0);
/// The rotational inertia of the shape about the local origin.
this.I = 0;
}
}
/// A shape is used for collision detection. You can create a shape however you like.
/// Shapes used for simulation in B2World are created automatically when a B2Fixture
/// is created. Shapes may encapsulate a one or more child shapes.
export class B2Shape {
constructor(type, radius) {
this.m_type = -1 /* e_unknown */;
this.m_radius = 0;
this.m_type = type;
this.m_radius = radius;
}
Copy(other) {
/// b2Assert(this.m_type === other.m_type);
this.m_radius = other.m_radius;
return this;
}
/// Get the type of this shape. You can use this to down cast to the concrete shape.
/// @return the shape type.
GetType() {
return this.m_type;
}
}
@@ -0,0 +1,5 @@
export * from './b2Shape';
export * from './b2CircleShape';
export * from './b2PolygonShape';
export * from './b2EdgeShape';
export * from './b2ChainShape';
@@ -0,0 +1,5 @@
export * from './b2Shape';
export * from './b2CircleShape';
export * from './b2PolygonShape';
export * from './b2EdgeShape';
export * from './b2ChainShape';
@@ -0,0 +1,34 @@
import { B2Vec2 } from '../Common/b2Math';
import { B2AABB, B2RayCastInput } from './b2Collision';
import { B2TreeNode, B2DynamicTree } from './b2DynamicTree';
import { B2ContactManager } from '../Dynamics/b2ContactManager';
export declare class B2Pair {
proxyA: B2TreeNode | null;
proxyB: B2TreeNode | null;
}
export declare class B2BroadPhase {
m_tree: B2DynamicTree;
m_proxyCount: number;
m_moveCount: number;
m_moveBuffer: B2TreeNode[];
m_pairCount: number;
m_pairBuffer: B2Pair[];
CreateProxy(aabb: B2AABB, userData: any): B2TreeNode;
DestroyProxy(proxy: B2TreeNode): void;
MoveProxy(proxy: B2TreeNode, aabb: B2AABB, displacement: B2Vec2): void;
TouchProxy(proxy: B2TreeNode): void;
GetFatAABB(proxy: B2TreeNode): B2AABB;
GetUserData(proxy: B2TreeNode): any;
TestOverlap(proxyA: B2TreeNode, proxyB: B2TreeNode): boolean;
GetProxyCount(): number;
UpdatePairs(contactManager: B2ContactManager): void;
Query(callback: (node: B2TreeNode) => boolean, aabb: B2AABB): void;
RayCast(callback: (input: B2RayCastInput, node: B2TreeNode) => number, input: B2RayCastInput): void;
GetTreeHeight(): number;
GetTreeBalance(): number;
GetTreeQuality(): number;
ShiftOrigin(newOrigin: B2Vec2): void;
BufferMove(proxy: B2TreeNode): void;
UnBufferMove(proxy: B2TreeNode): void;
}
export declare function B2PairLessThan(pair1: B2Pair, pair2: B2Pair): number;
@@ -0,0 +1,197 @@
/*
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
import { B2TestOverlapAABB } from './b2Collision';
import { B2DynamicTree } from './b2DynamicTree';
export class B2Pair {
constructor() {
this.proxyA = null;
this.proxyB = null;
}
}
/// The broad-phase is used for computing pairs and performing volume queries and ray casts.
/// This broad-phase does not persist pairs. Instead, this reports potentially new pairs.
/// It is up to the client to consume the new pairs and to track subsequent overlap.
export class B2BroadPhase {
constructor() {
this.m_tree = new B2DynamicTree();
this.m_proxyCount = 0;
// public m_moveCapacity: number = 16;
this.m_moveCount = 0;
this.m_moveBuffer = [];
// public m_pairCapacity: number = 16;
this.m_pairCount = 0;
this.m_pairBuffer = [];
}
// public m_queryProxyId: number = 0;
/// Create a proxy with an initial AABB. Pairs are not reported until
/// UpdatePairs is called.
CreateProxy(aabb, userData) {
const proxy = this.m_tree.CreateProxy(aabb, userData);
++this.m_proxyCount;
this.BufferMove(proxy);
return proxy;
}
/// Destroy a proxy. It is up to the client to remove any pairs.
DestroyProxy(proxy) {
this.UnBufferMove(proxy);
--this.m_proxyCount;
this.m_tree.DestroyProxy(proxy);
}
/// Call MoveProxy as many times as you like, then when you are done
/// call UpdatePairs to finalized the proxy pairs (for your time step).
MoveProxy(proxy, aabb, displacement) {
const buffer = this.m_tree.MoveProxy(proxy, aabb, displacement);
if (buffer) {
this.BufferMove(proxy);
}
}
/// Call to trigger a re-processing of it's pairs on the next call to UpdatePairs.
TouchProxy(proxy) {
this.BufferMove(proxy);
}
/// Get the fat AABB for a proxy.
GetFatAABB(proxy) {
return this.m_tree.GetFatAABB(proxy);
}
/// Get user data from a proxy. Returns NULL if the id is invalid.
GetUserData(proxy) {
return this.m_tree.GetUserData(proxy);
}
/// Test overlap of fat AABBs.
TestOverlap(proxyA, proxyB) {
const aabbA = this.m_tree.GetFatAABB(proxyA);
const aabbB = this.m_tree.GetFatAABB(proxyB);
return B2TestOverlapAABB(aabbA, aabbB);
}
/// Get the number of proxies.
GetProxyCount() {
return this.m_proxyCount;
}
/// Update the pairs. This results in pair callbacks. This can only add pairs.
UpdatePairs(contactManager) {
// Reset pair buffer
this.m_pairCount = 0;
// Perform tree queries for all moving proxies.
for (let i = 0; i < this.m_moveCount; ++i) {
const queryProxy = this.m_moveBuffer[i];
if (queryProxy === null) {
continue;
}
const that = this;
// We have to query the tree with the fat AABB so that
// we don't fail to create a pair that may touch later.
const fatAABB = this.m_tree.GetFatAABB(queryProxy);
// Query tree, create pairs and add them pair buffer.
this.m_tree.Query((proxy) => {
// A proxy cannot form a pair with itself.
if (proxy.m_id === queryProxy.m_id) {
return true;
}
// Grow the pair buffer as needed.
if (that.m_pairCount === that.m_pairBuffer.length) {
that.m_pairBuffer[that.m_pairCount] = new B2Pair();
}
const pair = that.m_pairBuffer[that.m_pairCount];
// pair.proxyA = proxy < queryProxy ? proxy : queryProxy;
// pair.proxyB = proxy >= queryProxy ? proxy : queryProxy;
if (proxy.m_id < queryProxy.m_id) {
pair.proxyA = proxy;
pair.proxyB = queryProxy;
}
else {
pair.proxyA = queryProxy;
pair.proxyB = proxy;
}
++that.m_pairCount;
return true;
}, fatAABB);
}
// Reset move buffer
this.m_moveCount = 0;
// Sort the pair buffer to expose duplicates.
this.m_pairBuffer.length = this.m_pairCount;
this.m_pairBuffer.sort(B2PairLessThan);
// Send the pairs back to the client.
let i = 0;
while (i < this.m_pairCount) {
const primaryPair = this.m_pairBuffer[i];
const userDataA = this.m_tree.GetUserData(primaryPair.proxyA);
const userDataB = this.m_tree.GetUserData(primaryPair.proxyB);
contactManager.AddPair(userDataA, userDataB);
++i;
// Skip any duplicate pairs.
while (i < this.m_pairCount) {
const pair = this.m_pairBuffer[i];
if (pair.proxyA.m_id !== primaryPair.proxyA.m_id || pair.proxyB.m_id !== primaryPair.proxyB.m_id) {
break;
}
++i;
}
}
// Try to keep the tree balanced.
// this.m_tree.Rebalance(4);
}
/// Query an AABB for overlapping proxies. The callback class
/// is called for each proxy that overlaps the supplied AABB.
Query(callback, aabb) {
this.m_tree.Query(callback, aabb);
}
/// Ray-cast against the proxies in the tree. This relies on the callback
/// to perform a exact ray-cast in the case were the proxy contains a shape.
/// The callback also performs the any collision filtering. This has performance
/// roughly equal to k * log(n), where k is the number of collisions and n is the
/// number of proxies in the tree.
/// @param input the ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).
/// @param callback a callback class that is called for each proxy that is hit by the ray.
RayCast(callback, input) {
this.m_tree.RayCast(callback, input);
}
/// Get the height of the embedded tree.
GetTreeHeight() {
return this.m_tree.GetHeight();
}
/// Get the balance of the embedded tree.
GetTreeBalance() {
return this.m_tree.GetMaxBalance();
}
/// Get the quality metric of the embedded tree.
GetTreeQuality() {
return this.m_tree.GetAreaRatio();
}
/// Shift the world origin. Useful for large worlds.
/// The shift formula is: position -= newOrigin
/// @param newOrigin the new origin with respect to the old origin
ShiftOrigin(newOrigin) {
this.m_tree.ShiftOrigin(newOrigin);
}
BufferMove(proxy) {
this.m_moveBuffer[this.m_moveCount] = proxy;
++this.m_moveCount;
}
UnBufferMove(proxy) {
const i = this.m_moveBuffer.indexOf(proxy);
this.m_moveBuffer[i] = null;
}
}
/// This is used to sort pairs.
export function B2PairLessThan(pair1, pair2) {
if (pair1.proxyA.m_id === pair2.proxyA.m_id) {
return pair1.proxyB.m_id - pair2.proxyB.m_id;
}
return pair1.proxyA.m_id - pair2.proxyA.m_id;
}
@@ -0,0 +1,6 @@
import { B2Transform } from '../Common/b2Math';
import { B2Manifold } from './b2Collision';
import { B2CircleShape } from './Shapes/b2CircleShape';
import { B2PolygonShape } from './Shapes/b2PolygonShape';
export declare function B2CollideCircles(manifold: B2Manifold, circleA: B2CircleShape, xfA: B2Transform, circleB: B2CircleShape, xfB: B2Transform): void;
export declare function B2CollidePolygonAndCircle(manifold: B2Manifold, polygonA: B2PolygonShape, xfA: B2Transform, circleB: B2CircleShape, xfB: B2Transform): void;
@@ -0,0 +1,100 @@
import { B2_maxFloat, B2_epsilon } from '../Common/b2Settings';
import { B2Vec2, B2Transform } from '../Common/b2Math';
const B2CollideCircles_s_pA = new B2Vec2();
const B2CollideCircles_s_pB = new B2Vec2();
export function B2CollideCircles(manifold, circleA, xfA, circleB, xfB) {
manifold.pointCount = 0;
const pA = B2Transform.MulXV(xfA, circleA.m_p, B2CollideCircles_s_pA);
const pB = B2Transform.MulXV(xfB, circleB.m_p, B2CollideCircles_s_pB);
const distSqr = B2Vec2.DistanceSquaredVV(pA, pB);
const radius = circleA.m_radius + circleB.m_radius;
if (distSqr > radius * radius) {
return;
}
manifold.type = 0 /* e_circles */;
manifold.localPoint.Copy(circleA.m_p);
manifold.localNormal.SetZero();
manifold.pointCount = 1;
manifold.points[0].localPoint.Copy(circleB.m_p);
manifold.points[0].id.key = 0;
}
const B2CollidePolygonAndCircle_s_c = new B2Vec2();
const B2CollidePolygonAndCircle_s_cLocal = new B2Vec2();
const B2CollidePolygonAndCircle_s_faceCenter = new B2Vec2();
export function B2CollidePolygonAndCircle(manifold, polygonA, xfA, circleB, xfB) {
manifold.pointCount = 0;
// Compute circle position in the frame of the polygon.
const c = B2Transform.MulXV(xfB, circleB.m_p, B2CollidePolygonAndCircle_s_c);
const cLocal = B2Transform.MulTXV(xfA, c, B2CollidePolygonAndCircle_s_cLocal);
// Find the min separating edge.
let normalIndex = 0;
let separation = (-B2_maxFloat);
const radius = polygonA.m_radius + circleB.m_radius;
const vertexCount = polygonA.m_count;
const vertices = polygonA.m_vertices;
const normals = polygonA.m_normals;
for (let i = 0; i < vertexCount; ++i) {
const s = B2Vec2.DotVV(normals[i], B2Vec2.SubVV(cLocal, vertices[i], B2Vec2.s_t0));
if (s > radius) {
// Early out.
return;
}
if (s > separation) {
separation = s;
normalIndex = i;
}
}
// Vertices that subtend the incident face.
const vertIndex1 = normalIndex;
const vertIndex2 = (vertIndex1 + 1) % vertexCount;
const v1 = vertices[vertIndex1];
const v2 = vertices[vertIndex2];
// If the center is inside the polygon ...
if (separation < B2_epsilon) {
manifold.pointCount = 1;
manifold.type = 1 /* e_faceA */;
manifold.localNormal.Copy(normals[normalIndex]);
B2Vec2.MidVV(v1, v2, manifold.localPoint);
manifold.points[0].localPoint.Copy(circleB.m_p);
manifold.points[0].id.key = 0;
return;
}
// Compute barycentric coordinates
const u1 = B2Vec2.DotVV(B2Vec2.SubVV(cLocal, v1, B2Vec2.s_t0), B2Vec2.SubVV(v2, v1, B2Vec2.s_t1));
const u2 = B2Vec2.DotVV(B2Vec2.SubVV(cLocal, v2, B2Vec2.s_t0), B2Vec2.SubVV(v1, v2, B2Vec2.s_t1));
if (u1 <= 0) {
if (B2Vec2.DistanceSquaredVV(cLocal, v1) > radius * radius) {
return;
}
manifold.pointCount = 1;
manifold.type = 1 /* e_faceA */;
B2Vec2.SubVV(cLocal, v1, manifold.localNormal).SelfNormalize();
manifold.localPoint.Copy(v1);
manifold.points[0].localPoint.Copy(circleB.m_p);
manifold.points[0].id.key = 0;
}
else if (u2 <= 0) {
if (B2Vec2.DistanceSquaredVV(cLocal, v2) > radius * radius) {
return;
}
manifold.pointCount = 1;
manifold.type = 1 /* e_faceA */;
B2Vec2.SubVV(cLocal, v2, manifold.localNormal).SelfNormalize();
manifold.localPoint.Copy(v2);
manifold.points[0].localPoint.Copy(circleB.m_p);
manifold.points[0].id.key = 0;
}
else {
const faceCenter = B2Vec2.MidVV(v1, v2, B2CollidePolygonAndCircle_s_faceCenter);
separation = B2Vec2.DotVV(B2Vec2.SubVV(cLocal, faceCenter, B2Vec2.s_t1), normals[vertIndex1]);
if (separation > radius) {
return;
}
manifold.pointCount = 1;
manifold.type = 1 /* e_faceA */;
manifold.localNormal.Copy(normals[vertIndex1]).SelfNormalize();
manifold.localPoint.Copy(faceCenter);
manifold.points[0].localPoint.Copy(circleB.m_p);
manifold.points[0].id.key = 0;
}
}
@@ -0,0 +1,7 @@
import { B2Transform } from '../Common/b2Math';
import { B2Manifold } from './b2Collision';
import { B2CircleShape } from './Shapes/b2CircleShape';
import { B2PolygonShape } from './Shapes/b2PolygonShape';
import { B2EdgeShape } from './Shapes/b2EdgeShape';
export declare function B2CollideEdgeAndCircle(manifold: B2Manifold, edgeA: B2EdgeShape, xfA: B2Transform, circleB: B2CircleShape, xfB: B2Transform): void;
export declare function B2CollideEdgeAndPolygon(manifold: B2Manifold, edgeA: B2EdgeShape, xfA: B2Transform, polygonB: B2PolygonShape, xfB: B2Transform): void;

Large diffs are not rendered by default.

@@ -0,0 +1,4 @@
import { B2Transform } from '../Common/b2Math';
import { B2Manifold } from './b2Collision';
import { B2PolygonShape } from './Shapes/b2PolygonShape';
export declare function B2CollidePolygons(manifold: B2Manifold, polyA: B2PolygonShape, xfA: B2Transform, polyB: B2PolygonShape, xfB: B2Transform): void;
@@ -0,0 +1,247 @@
import { B2_maxFloat, B2_maxManifoldPoints } from '../Common/b2Settings';
import { B2Vec2, B2Rot, B2Transform } from '../Common/b2Math';
import { B2ClipVertex, B2ClipSegmentToLine } from './b2Collision';
const B2EdgeSeparation_s_normal1World = new B2Vec2();
const B2EdgeSeparation_s_normal1 = new B2Vec2();
const B2EdgeSeparation_s_v1 = new B2Vec2();
const B2EdgeSeparation_s_v2 = new B2Vec2();
function B2EdgeSeparation(poly1, xf1, edge1, poly2, xf2) {
/// const count1: number = poly1.m_count;
const vertices1 = poly1.m_vertices;
const normals1 = poly1.m_normals;
const count2 = poly2.m_count;
const vertices2 = poly2.m_vertices;
/// b2Assert(0 <= edge1 && edge1 < count1);
// Convert normal from poly1's frame into poly2's frame.
const normal1World = B2Rot.MulRV(xf1.q, normals1[edge1], B2EdgeSeparation_s_normal1World);
const normal1 = B2Rot.MulTRV(xf2.q, normal1World, B2EdgeSeparation_s_normal1);
// Find support vertex on poly2 for -normal.
let index = 0;
let minDot = B2_maxFloat;
for (let i = 0; i < count2; ++i) {
const dot = B2Vec2.DotVV(vertices2[i], normal1);
if (dot < minDot) {
minDot = dot;
index = i;
}
}
const v1 = B2Transform.MulXV(xf1, vertices1[edge1], B2EdgeSeparation_s_v1);
const v2 = B2Transform.MulXV(xf2, vertices2[index], B2EdgeSeparation_s_v2);
const separation = B2Vec2.DotVV(B2Vec2.SubVV(v2, v1, B2Vec2.s_t0), normal1World);
return separation;
}
const B2FindMaxSeparation_s_d = new B2Vec2();
const B2FindMaxSeparation_s_dLocal1 = new B2Vec2();
function B2FindMaxSeparation(edgeIndex, poly1, xf1, poly2, xf2) {
const count1 = poly1.m_count;
const normals1 = poly1.m_normals;
// Vector pointing from the centroid of poly1 to the centroid of poly2.
const d = B2Vec2.SubVV(B2Transform.MulXV(xf2, poly2.m_centroid, B2Vec2.s_t0), B2Transform.MulXV(xf1, poly1.m_centroid, B2Vec2.s_t1), B2FindMaxSeparation_s_d);
const dLocal1 = B2Rot.MulTRV(xf1.q, d, B2FindMaxSeparation_s_dLocal1);
// Find edge normal on poly1 that has the largest projection onto d.
let edge = 0;
let maxDot = (-B2_maxFloat);
for (let i = 0; i < count1; ++i) {
const dot = B2Vec2.DotVV(normals1[i], dLocal1);
if (dot > maxDot) {
maxDot = dot;
edge = i;
}
}
// Get the separation for the edge normal.
let s = B2EdgeSeparation(poly1, xf1, edge, poly2, xf2);
// Check the separation for the previous edge normal.
const prevEdge = (edge + count1 - 1) % count1;
const sPrev = B2EdgeSeparation(poly1, xf1, prevEdge, poly2, xf2);
// Check the separation for the next edge normal.
const nextEdge = (edge + 1) % count1;
const sNext = B2EdgeSeparation(poly1, xf1, nextEdge, poly2, xf2);
// Find the best edge and the search direction.
let bestEdge = 0;
let bestSeparation = 0;
let increment = 0;
if (sPrev > s && sPrev > sNext) {
increment = -1;
bestEdge = prevEdge;
bestSeparation = sPrev;
}
else if (sNext > s) {
increment = 1;
bestEdge = nextEdge;
bestSeparation = sNext;
}
else {
edgeIndex[0] = edge;
return s;
}
// Perform a local search for the best edge normal.
while (true) {
if (increment === -1) {
edge = (bestEdge + count1 - 1) % count1;
}
else {
edge = (bestEdge + 1) % count1;
}
s = B2EdgeSeparation(poly1, xf1, edge, poly2, xf2);
if (s > bestSeparation) {
bestEdge = edge;
bestSeparation = s;
}
else {
break;
}
}
edgeIndex[0] = bestEdge;
return bestSeparation;
}
const B2FindIncidentEdge_s_normal1 = new B2Vec2();
function B2FindIncidentEdge(c, poly1, xf1, edge1, poly2, xf2) {
/// const count1: number = poly1.m_count;
const normals1 = poly1.m_normals;
const count2 = poly2.m_count;
const vertices2 = poly2.m_vertices;
const normals2 = poly2.m_normals;
/// b2Assert(0 <= edge1 && edge1 < count1);
// Get the normal of the reference edge in poly2's frame.
const normal1 = B2Rot.MulTRV(xf2.q, B2Rot.MulRV(xf1.q, normals1[edge1], B2Vec2.s_t0), B2FindIncidentEdge_s_normal1);
// Find the incident edge on poly2.
let index = 0;
let minDot = B2_maxFloat;
for (let i = 0; i < count2; ++i) {
const dot = B2Vec2.DotVV(normal1, normals2[i]);
if (dot < minDot) {
minDot = dot;
index = i;
}
}
// Build the clip vertices for the incident edge.
const i1 = index;
const i2 = (i1 + 1) % count2;
const c0 = c[0];
B2Transform.MulXV(xf2, vertices2[i1], c0.v);
const cf0 = c0.id.cf;
cf0.indexA = edge1;
cf0.indexB = i1;
cf0.typeA = 1 /* e_face */;
cf0.typeB = 0 /* e_vertex */;
const c1 = c[1];
B2Transform.MulXV(xf2, vertices2[i2], c1.v);
const cf1 = c1.id.cf;
cf1.indexA = edge1;
cf1.indexB = i2;
cf1.typeA = 1 /* e_face */;
cf1.typeB = 0 /* e_vertex */;
}
const B2CollidePolygons_s_incidentEdge = B2ClipVertex.MakeArray(2);
const B2CollidePolygons_s_clipPoints1 = B2ClipVertex.MakeArray(2);
const B2CollidePolygons_s_clipPoints2 = B2ClipVertex.MakeArray(2);
const B2CollidePolygons_s_edgeA = [0];
const B2CollidePolygons_s_edgeB = [0];
const B2CollidePolygons_s_localTangent = new B2Vec2();
const B2CollidePolygons_s_localNormal = new B2Vec2();
const B2CollidePolygons_s_planePoint = new B2Vec2();
const B2CollidePolygons_s_normal = new B2Vec2();
const B2CollidePolygons_s_tangent = new B2Vec2();
const B2CollidePolygons_s_ntangent = new B2Vec2();
const B2CollidePolygons_s_v11 = new B2Vec2();
const B2CollidePolygons_s_v12 = new B2Vec2();
export function B2CollidePolygons(manifold, polyA, xfA, polyB, xfB) {
manifold.pointCount = 0;
const totalRadius = polyA.m_radius + polyB.m_radius;
const edgeA = B2CollidePolygons_s_edgeA;
edgeA[0] = 0;
const separationA = B2FindMaxSeparation(edgeA, polyA, xfA, polyB, xfB);
if (separationA > totalRadius) {
return;
}
const edgeB = B2CollidePolygons_s_edgeB;
edgeB[0] = 0;
const separationB = B2FindMaxSeparation(edgeB, polyB, xfB, polyA, xfA);
if (separationB > totalRadius) {
return;
}
let poly1; // reference polygon
let poly2; // incident polygon
let xf1, xf2;
let edge1 = 0; // reference edge
let flip = 0;
const k_relativeTol = 0.98;
const k_absoluteTol = 0.001;
if (separationB > k_relativeTol * separationA + k_absoluteTol) {
poly1 = polyB;
poly2 = polyA;
xf1 = xfB;
xf2 = xfA;
edge1 = edgeB[0];
manifold.type = 2 /* e_faceB */;
flip = 1;
}
else {
poly1 = polyA;
poly2 = polyB;
xf1 = xfA;
xf2 = xfB;
edge1 = edgeA[0];
manifold.type = 1 /* e_faceA */;
flip = 0;
}
const incidentEdge = B2CollidePolygons_s_incidentEdge;
B2FindIncidentEdge(incidentEdge, poly1, xf1, edge1, poly2, xf2);
const count1 = poly1.m_count;
const vertices1 = poly1.m_vertices;
const iv1 = edge1;
const iv2 = (edge1 + 1) % count1;
const local_v11 = vertices1[iv1];
const local_v12 = vertices1[iv2];
const localTangent = B2Vec2.SubVV(local_v12, local_v11, B2CollidePolygons_s_localTangent);
localTangent.Normalize();
const localNormal = B2Vec2.CrossVOne(localTangent, B2CollidePolygons_s_localNormal);
const planePoint = B2Vec2.MidVV(local_v11, local_v12, B2CollidePolygons_s_planePoint);
const tangent = B2Rot.MulRV(xf1.q, localTangent, B2CollidePolygons_s_tangent);
const normal = B2Vec2.CrossVOne(tangent, B2CollidePolygons_s_normal);
const v11 = B2Transform.MulXV(xf1, local_v11, B2CollidePolygons_s_v11);
const v12 = B2Transform.MulXV(xf1, local_v12, B2CollidePolygons_s_v12);
// Face offset.
const frontOffset = B2Vec2.DotVV(normal, v11);
// Side offsets, extended by polytope skin thickness.
const sideOffset1 = -B2Vec2.DotVV(tangent, v11) + totalRadius;
const sideOffset2 = B2Vec2.DotVV(tangent, v12) + totalRadius;
// Clip incident edge against extruded edge1 side edges.
const clipPoints1 = B2CollidePolygons_s_clipPoints1;
const clipPoints2 = B2CollidePolygons_s_clipPoints2;
let np;
// Clip to box side 1
const ntangent = B2Vec2.NegV(tangent, B2CollidePolygons_s_ntangent);
np = B2ClipSegmentToLine(clipPoints1, incidentEdge, ntangent, sideOffset1, iv1);
if (np < 2) {
return;
}
// Clip to negative box side 1
np = B2ClipSegmentToLine(clipPoints2, clipPoints1, tangent, sideOffset2, iv2);
if (np < 2) {
return;
}
// Now clipPoints2 contains the clipped points.
manifold.localNormal.Copy(localNormal);
manifold.localPoint.Copy(planePoint);
let pointCount = 0;
for (let i = 0; i < B2_maxManifoldPoints; ++i) {
const cv = clipPoints2[i];
const separation = B2Vec2.DotVV(normal, cv.v) - frontOffset;
if (separation <= totalRadius) {
const cp = manifold.points[pointCount];
B2Transform.MulTXV(xf2, cv.v, cp.localPoint);
cp.id.Copy(cv.id);
if (flip) {
// Swap features
const cf = cp.id.cf;
cp.id.cf.indexA = cf.indexB;
cp.id.cf.indexB = cf.indexA;
cp.id.cf.typeA = cf.typeB;
cp.id.cf.typeB = cf.typeA;
}
++pointCount;
}
}
manifold.pointCount = pointCount;
}
@@ -0,0 +1,107 @@
import { B2Vec2, B2Transform } from '../Common/b2Math';
import { B2Shape } from './Shapes/b2Shape';
export declare const enum B2ContactFeatureType {
e_vertex = 0,
e_face = 1,
}
export declare class B2ContactFeature {
_key: number;
_key_invalid: boolean;
_indexA: number;
_indexB: number;
_typeA: number;
_typeB: number;
constructor();
key: number;
indexA: number;
indexB: number;
typeA: number;
typeB: number;
}
export declare class B2ContactID {
cf: B2ContactFeature;
Copy(o: B2ContactID): B2ContactID;
Clone(): B2ContactID;
key: number;
}
export declare class B2ManifoldPoint {
localPoint: B2Vec2;
normalImpulse: number;
tangentImpulse: number;
id: B2ContactID;
static MakeArray(length: number): B2ManifoldPoint[];
Reset(): void;
Copy(o: B2ManifoldPoint): B2ManifoldPoint;
}
export declare const enum B2ManifoldType {
e_unknown = -1,
e_circles = 0,
e_faceA = 1,
e_faceB = 2,
}
export declare class B2Manifold {
points: B2ManifoldPoint[];
localNormal: B2Vec2;
localPoint: B2Vec2;
type: number;
pointCount: number;
Reset(): void;
Copy(o: B2Manifold): B2Manifold;
Clone(): B2Manifold;
}
export declare class B2WorldManifold {
normal: B2Vec2;
points: B2Vec2[];
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;
Initialize(manifold: B2Manifold, xfA: B2Transform, radiusA: number, xfB: B2Transform, radiusB: number): void;
}
export declare const enum B2PointState {
B2_nullState = 0,
B2_addState = 1,
B2_persistState = 2,
B2_removeState = 3,
}
export declare function B2GetPointStates(state1: B2PointState[], state2: B2PointState[], manifold1: B2Manifold, manifold2: B2Manifold): void;
export declare class B2ClipVertex {
v: B2Vec2;
id: B2ContactID;
static MakeArray(length: number): B2ClipVertex[];
Copy(other: B2ClipVertex): B2ClipVertex;
}
export declare class B2RayCastInput {
p1: B2Vec2;
p2: B2Vec2;
maxFraction: number;
Copy(o: B2RayCastInput): B2RayCastInput;
}
export declare class B2RayCastOutput {
normal: B2Vec2;
fraction: number;
Copy(o: B2RayCastOutput): B2RayCastOutput;
}
export declare class B2AABB {
lowerBound: B2Vec2;
upperBound: B2Vec2;
private m_cache_center;
private m_cache_extent;
Copy(o: B2AABB): B2AABB;
IsValid(): boolean;
GetCenter(): B2Vec2;
GetExtents(): B2Vec2;
GetPerimeter(): number;
Combine1(aabb: B2AABB): B2AABB;
Combine2(aabb1: B2AABB, aabb2: B2AABB): B2AABB;
static Combine(aabb1: B2AABB, aabb2: B2AABB, out: B2AABB): B2AABB;
Contains(aabb: B2AABB): boolean;
RayCast(output: B2RayCastOutput, input: B2RayCastInput): boolean;
TestOverlap(other: B2AABB): boolean;
}
export declare function B2TestOverlapAABB(a: B2AABB, b: B2AABB): boolean;
export declare function B2ClipSegmentToLine(vOut: B2ClipVertex[], vIn: B2ClipVertex[], normal: B2Vec2, offset: number, vertexIndexA: number): number;
export declare function B2TestOverlapShape(shapeA: B2Shape, indexA: number, shapeB: B2Shape, indexB: number, xfA: B2Transform, xfB: B2Transform): boolean;

Large diffs are not rendered by default.

@@ -0,0 +1,68 @@
import { B2Vec2, B2Transform } from '../Common/b2Math';
import { B2Shape } from './Shapes/b2Shape';
export declare class B2DistanceProxy {
m_buffer: B2Vec2[];
m_vertices: B2Vec2[];
m_count: number;
m_radius: number;
Reset(): B2DistanceProxy;
SetShape(shape: B2Shape, index: number): void;
GetSupport(d: B2Vec2): number;
GetSupportVertex(d: B2Vec2): B2Vec2;
GetVertexCount(): number;
GetVertex(index: number): B2Vec2;
}
export declare class B2SimplexCache {
metric: number;
count: number;
indexA: number[];
indexB: number[];
Reset(): B2SimplexCache;
}
export declare class B2DistanceInput {
proxyA: B2DistanceProxy;
proxyB: B2DistanceProxy;
transformA: B2Transform;
transformB: B2Transform;
useRadii: boolean;
Reset(): B2DistanceInput;
}
export declare class B2DistanceOutput {
pointA: B2Vec2;
pointB: B2Vec2;
distance: number;
iterations: number;
Reset(): B2DistanceOutput;
}
export declare let B2_gjkCalls: number;
export declare let B2_gjkIters: number;
export declare let B2_gjkMaxIters: number;
export declare class B2SimplexVertex {
wA: B2Vec2;
wB: B2Vec2;
w: B2Vec2;
a: number;
indexA: number;
indexB: number;
Copy(other: B2SimplexVertex): B2SimplexVertex;
}
export declare class B2Simplex {
m_v1: B2SimplexVertex;
m_v2: B2SimplexVertex;
m_v3: B2SimplexVertex;
m_vertices: B2SimplexVertex[];
m_count: number;
constructor();
ReadCache(cache: B2SimplexCache, proxyA: B2DistanceProxy, transformA: B2Transform, proxyB: B2DistanceProxy, transformB: B2Transform): void;
WriteCache(cache: B2SimplexCache): void;
GetSearchDirection(out: B2Vec2): B2Vec2;
GetClosestPoint(out: B2Vec2): B2Vec2;
GetWitnessPoints(pA: B2Vec2, pB: B2Vec2): void;
GetMetric(): number;
Solve2(): void;
Solve3(): void;
private static s_e12;
private static s_e13;
private static s_e23;
}
export declare function B2Distance(output: B2DistanceOutput, cache: B2SimplexCache, input: B2DistanceInput): void;

Large diffs are not rendered by default.

@@ -0,0 +1,54 @@
import { B2Vec2 } from '../Common/b2Math';
import { B2GrowableStack } from '../Common/b2GrowableStack';
import { B2AABB, B2RayCastInput } from './b2Collision';
export declare class B2TreeNode {
m_id: number;
aabb: B2AABB;
userData: any;
parent: B2TreeNode;
child1: B2TreeNode;
child2: B2TreeNode;
height: number;
constructor(id?: number);
IsLeaf(): boolean;
}
export declare class B2DynamicTree {
m_root: B2TreeNode;
m_freeList: B2TreeNode;
m_path: number;
m_insertionCount: number;
static s_stack: B2GrowableStack;
static s_r: B2Vec2;
static s_v: B2Vec2;
static s_abs_v: B2Vec2;
static s_segmentAABB: B2AABB;
static s_subInput: B2RayCastInput;
static s_combinedAABB: B2AABB;
static s_aabb: B2AABB;
GetUserData(proxy: B2TreeNode): any;
GetFatAABB(proxy: B2TreeNode): B2AABB;
Query(callback: (node: B2TreeNode) => boolean, aabb: B2AABB): void;
RayCast(callback: (input: B2RayCastInput, node: B2TreeNode) => number, input: B2RayCastInput): void;
static s_node_id: number;
AllocateNode(): B2TreeNode;
FreeNode(node: B2TreeNode): void;
CreateProxy(aabb: B2AABB, userData: any): B2TreeNode;
DestroyProxy(proxy: B2TreeNode): void;
MoveProxy(proxy: B2TreeNode, aabb: B2AABB, displacement: B2Vec2): boolean;
InsertLeaf(leaf: B2TreeNode): void;
RemoveLeaf(leaf: B2TreeNode): void;
Balance(A: B2TreeNode): B2TreeNode;
GetHeight(): number;
private static GetAreaNode(node);
GetAreaRatio(): number;
ComputeHeightNode(node: B2TreeNode): number;
ComputeHeight(): number;
ValidateStructure(index: B2TreeNode): void;
ValidateMetrics(index: B2TreeNode): void;
Validate(): void;
private static GetMaxBalanceNode(node, maxBalance);
GetMaxBalance(): number;
RebuildBottomUp(): void;
private static ShiftOriginNode(node, newOrigin);
ShiftOrigin(newOrigin: B2Vec2): void;
}

Large diffs are not rendered by default.

@@ -0,0 +1,46 @@
import { B2Vec2, B2Sweep } from '../Common/b2Math';
import { B2DistanceProxy, B2SimplexCache } from './b2Distance';
export declare let B2_toiTime: number;
export declare let B2_toiMaxTime: number;
export declare let B2_toiCalls: number;
export declare let B2_toiIters: number;
export declare let B2_toiMaxIters: number;
export declare let B2_toiRootIters: number;
export declare let B2_toiMaxRootIters: number;
export declare class B2TOIInput {
proxyA: B2DistanceProxy;
proxyB: B2DistanceProxy;
sweepA: B2Sweep;
sweepB: B2Sweep;
tMax: number;
}
export declare const enum B2TOIOutputState {
e_unknown = 0,
e_failed = 1,
e_overlapped = 2,
e_touching = 3,
e_separated = 4,
}
export declare class B2TOIOutput {
state: B2TOIOutputState;
t: number;
}
export declare const enum B2SeparationFunctionType {
e_unknown = -1,
e_points = 0,
e_faceA = 1,
e_faceB = 2,
}
export declare class B2SeparationFunction {
m_proxyA: B2DistanceProxy;
m_proxyB: B2DistanceProxy;
m_sweepA: B2Sweep;
m_sweepB: B2Sweep;
m_type: B2SeparationFunctionType;
m_localPoint: B2Vec2;
m_axis: B2Vec2;
Initialize(cache: B2SimplexCache, proxyA: B2DistanceProxy, sweepA: B2Sweep, proxyB: B2DistanceProxy, sweepB: B2Sweep, t1: number): number;
FindMinSeparation(indexA: number[], indexB: number[], t: number): number;
Evaluate(indexA: number, indexB: number, t: number): number;
}
export declare function B2TimeOfImpact(output: B2TOIOutput, input: B2TOIInput): void;

Large diffs are not rendered by default.

@@ -0,0 +1,9 @@
export * from './Shapes/index';
export * from './b2Collision';
export * from './b2Distance';
export * from './b2BroadPhase';
export * from './b2DynamicTree';
export * from './b2TimeOfImpact';
export * from './b2CollideCircle';
export * from './b2CollidePolygon';
export * from './b2CollideEdge';
@@ -0,0 +1,9 @@
export * from './Shapes/index';
export * from './b2Collision';
export * from './b2Distance';
export * from './b2BroadPhase';
export * from './b2DynamicTree';
export * from './b2TimeOfImpact';
export * from './b2CollideCircle';
export * from './b2CollidePolygon';
export * from './b2CollideEdge';
@@ -0,0 +1,2 @@
export declare class B2BlockAllocator {
}
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
export class B2BlockAllocator {
}
@@ -0,0 +1,57 @@
import { B2Vec2, B2Transform } from './b2Math';
export declare class B2Color {
static RED: B2Color;
static GREEN: B2Color;
static BLUE: B2Color;
r: number;
g: number;
b: number;
a: number;
constructor(rr?: number, gg?: number, bb?: number, aa?: number);
Clone(): B2Color;
Copy(other: B2Color): B2Color;
IsEqual(color: B2Color): boolean;
IsZero(): boolean;
GetColor(out: B2Color): B2Color;
SetColor(color: B2Color): void;
Set(a0: number | B2Color, a1?: number, a2?: number, a3?: number): void;
SetRGB(rr: number, gg: number, bb: number): B2Color;
SetRGBA(rr: number, gg: number, bb: number, aa: number): B2Color;
SelfAdd(color: B2Color): B2Color;
Add(color: B2Color, out: B2Color): B2Color;
SelfSub(color: B2Color): B2Color;
Sub(color: B2Color, out: B2Color): B2Color;
SelfMul_0_1(s: number): B2Color;
Mul_0_1(s: number, out: B2Color): B2Color;
Mix(mixColor: B2Color, strength: number): void;
static MixColors(colorA: B2Color, colorB: B2Color, strength: number): void;
MakeStyleString(alpha?: number): string;
static MakeStyleString(r: number, g: number, b: number, a?: number): string;
}
export declare const enum B2DrawFlags {
e_none = 0,
e_shapeBit = 1,
e_jointBit = 2,
e_aabbBit = 4,
e_pairBit = 8,
e_centerOfMassBit = 16,
e_particleBit = 32,
e_controllerBit = 64,
e_all = 63,
}
export declare class B2Draw {
m_drawFlags: B2DrawFlags;
SetFlags(flags: B2DrawFlags): void;
GetFlags(): B2DrawFlags;
AppendFlags(flags: B2DrawFlags): void;
ClearFlags(flags: B2DrawFlags): void;
PushTransform(xf: B2Transform): void;
PopTransform(xf: B2Transform): void;
DrawPolygon(vertices: B2Vec2[], vertexCount: number, color: B2Color): void;
DrawSolidPolygon(vertices: B2Vec2[], vertexCount: number, color: B2Color): void;
DrawCircle(center: B2Vec2, radius: number, color: B2Color): void;
DrawSolidCircle(center: B2Vec2, radius: number, axis: B2Vec2, color: B2Color): void;
DrawParticles(centers: B2Vec2[], radius: number, colors: B2Color[], count: number): void;
DrawSegment(p1: B2Vec2, p2: B2Vec2, color: B2Color): void;
DrawTransform(xf: B2Transform): void;
}
@@ -0,0 +1,177 @@
/*
* Copyright (c) 2011 Erin Catto http://box2d.org
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
/// Color for debug drawing. Each value has the range [0,1].
export class B2Color {
constructor(rr = 0.5, gg = 0.5, bb = 0.5, aa = 1.0) {
this.r = rr;
this.g = gg;
this.b = bb;
this.a = aa;
}
Clone() {
return new B2Color().Copy(this);
}
Copy(other) {
this.r = other.r;
this.g = other.g;
this.b = other.b;
this.a = other.a;
return this;
}
IsEqual(color) {
return (this.r === color.r) && (this.g === color.g) && (this.b === color.b) && (this.a === color.a);
}
IsZero() {
return (this.r === 0) && (this.g === 0) && (this.b === 0) && (this.a === 0);
}
GetColor(out) {
out.Copy(this);
return out;
}
SetColor(color) {
this.Copy(color);
}
Set(a0, a1, a2, a3 = 1.0) {
if (a0 instanceof B2Color) {
this.Copy(a0);
}
else {
this.SetRGBA(a0, a1, a2, a3);
}
}
SetRGB(rr, gg, bb) {
this.r = rr;
this.g = gg;
this.b = bb;
return this;
}
SetRGBA(rr, gg, bb, aa) {
this.r = rr;
this.g = gg;
this.b = bb;
this.a = aa;
return this;
}
SelfAdd(color) {
this.r += color.r;
this.g += color.g;
this.b += color.b;
this.a += color.a;
return this;
}
Add(color, out) {
out.r = this.r + color.r;
out.g = this.g + color.g;
out.b = this.b + color.b;
out.a = this.a + color.a;
return out;
}
SelfSub(color) {
this.r -= color.r;
this.g -= color.g;
this.b -= color.b;
this.a -= color.a;
return this;
}
Sub(color, out) {
out.r = this.r - color.r;
out.g = this.g - color.g;
out.b = this.b - color.b;
out.a = this.a - color.a;
return out;
}
SelfMul_0_1(s) {
this.r *= s;
this.g *= s;
this.b *= s;
this.a *= s;
return this;
}
Mul_0_1(s, out) {
out.r = this.r * s;
out.g = this.g * s;
out.b = this.b * s;
out.a = this.a * s;
return this;
}
Mix(mixColor, strength) {
B2Color.MixColors(this, mixColor, strength);
}
static MixColors(colorA, colorB, strength) {
const dr = (strength * (colorB.r - colorA.r));
const dg = (strength * (colorB.g - colorA.g));
const db = (strength * (colorB.b - colorA.b));
const da = (strength * (colorB.a - colorA.a));
colorA.r += dr;
colorA.g += dg;
colorA.b += db;
colorA.a += da;
colorB.r -= dr;
colorB.g -= dg;
colorB.b -= db;
colorB.a -= da;
}
MakeStyleString(alpha = this.a) {
return B2Color.MakeStyleString(this.r, this.g, this.b, alpha);
}
static MakeStyleString(r, g, b, a = 1.0) {
r = Math.round(Math.max(0, Math.min(255, r * 255)));
g = Math.round(Math.max(0, Math.min(255, g * 255)));
b = Math.round(Math.max(0, Math.min(255, b * 255)));
a = Math.max(0, Math.min(1, a));
if (a < 1.0) {
return 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')';
}
else {
return 'rgb(' + r + ',' + g + ',' + b + ')';
}
}
}
B2Color.RED = new B2Color(1, 0, 0);
B2Color.GREEN = new B2Color(0, 1, 0);
B2Color.BLUE = new B2Color(0, 0, 1);
/// Implement and register this class with a B2World to provide debug drawing of physics
/// entities in your game.
export class B2Draw {
constructor() {
this.m_drawFlags = 0;
}
SetFlags(flags) {
this.m_drawFlags = flags;
}
GetFlags() {
return this.m_drawFlags;
}
AppendFlags(flags) {
this.m_drawFlags |= flags;
}
ClearFlags(flags) {
this.m_drawFlags &= ~flags;
}
PushTransform(xf) { }
PopTransform(xf) { }
DrawPolygon(vertices, vertexCount, color) { }
DrawSolidPolygon(vertices, vertexCount, color) { }
DrawCircle(center, radius, color) { }
DrawSolidCircle(center, radius, axis, color) { }
/// #if B2_ENABLE_PARTICLE
DrawParticles(centers, radius, colors, count) { }
/// #endif
DrawSegment(p1, p2, color) { }
DrawTransform(xf) { }
}
@@ -0,0 +1,9 @@
export declare class B2GrowableStack {
m_stack: any[];
m_count: number;
constructor(N: number);
Reset(): B2GrowableStack;
Push(element: any): void;
Pop(): any;
GetCount(): number;
}
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2010 Erin Catto http://www.box2d.org
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
/// This is a growable LIFO stack with an initial capacity of N.
/// If the stack size exceeds the initial capacity, the heap is used
/// to increase the size of the stack.
export class B2GrowableStack {
constructor(N) {
this.m_stack = [];
this.m_count = 0;
this.m_stack = [];
this.m_count = 0;
}
Reset() {
this.m_count = 0;
return this;
}
Push(element) {
this.m_stack[this.m_count] = element;
this.m_count++;
}
Pop() {
/// b2Assert(this.m_count > 0);
this.m_count--;
const element = this.m_stack[this.m_count];
this.m_stack[this.m_count] = null;
return element;
}
GetCount() {
return this.m_count;
}
}
@@ -0,0 +1,208 @@
export declare const B2_pi_over_180: number;
export declare const B2_180_over_pi: number;
export declare const B2_two_pi: number;
export declare function B2Abs(n: number): number;
export declare function B2Min(a: number, b: number): number;
export declare function B2Max(a: number, b: number): number;
export declare function B2Clamp(a: number, lo: number, hi: number): number;
export declare function B2Swap(a: any[], b: any[]): void;
export declare function B2IsValid(n: number): boolean;
export declare function B2Sq(n: number): number;
export declare function B2InvSqrt(n: number): number;
export declare function B2Sqrt(n: number): number;
export declare function B2Pow(x: number, y: number): number;
export declare function B2DegToRad(degrees: number): number;
export declare function B2RadToDeg(radians: number): number;
export declare function B2Cos(radians: number): number;
export declare function B2Sin(radians: number): number;
export declare function B2Acos(n: number): number;
export declare function B2Asin(n: number): number;
export declare function B2Atan2(y: number, x: number): number;
export declare function B2NextPowerOfTwo(x: number): number;
export declare function B2IsPowerOfTwo(x: number): boolean;
export declare function B2Random(): number;
export declare function B2RandomRange(lo: number, hi: number): number;
export declare class B2Vec2 {
static ZERO: B2Vec2;
static UNITX: B2Vec2;
static UNITY: B2Vec2;
static s_t0: B2Vec2;
static s_t1: B2Vec2;
static s_t2: B2Vec2;
static s_t3: B2Vec2;
x: number;
y: number;
constructor(x?: number, y?: number);
Clone(): B2Vec2;
SetZero(): B2Vec2;
Set(x: number, y: number): B2Vec2;
Copy(other: B2Vec2): B2Vec2;
SelfAdd(v: B2Vec2): B2Vec2;
SelfAddXY(x: number, y: number): B2Vec2;
SelfSub(v: B2Vec2): B2Vec2;
SelfSubXY(x: number, y: number): B2Vec2;
SelfMul(s: number): B2Vec2;
SelfMulAdd(s: number, v: B2Vec2): B2Vec2;
SelfMulSub(s: number, v: B2Vec2): B2Vec2;
Dot(v: B2Vec2): number;
Cross(v: B2Vec2): number;
Length(): number;
LengthSquared(): number;
Normalize(): number;
SelfNormalize(): B2Vec2;
SelfRotate(radians: number): B2Vec2;
IsValid(): boolean;
SelfCrossVS(s: number): B2Vec2;
SelfCrossSV(s: number): B2Vec2;
SelfMinV(v: B2Vec2): B2Vec2;
SelfMaxV(v: B2Vec2): B2Vec2;
SelfAbs(): B2Vec2;
SelfNeg(): B2Vec2;
SelfSkew(): B2Vec2;
static MakeArray(length: number): B2Vec2[];
static AbsV(v: B2Vec2, out: B2Vec2): B2Vec2;
static MinV(a: B2Vec2, b: B2Vec2, out: B2Vec2): B2Vec2;
static MaxV(a: B2Vec2, b: B2Vec2, out: B2Vec2): B2Vec2;
static ClampV(v: B2Vec2, lo: B2Vec2, hi: B2Vec2, out: B2Vec2): B2Vec2;
static RotateV(v: B2Vec2, radians: number, out: B2Vec2): B2Vec2;
static DotVV(a: B2Vec2, b: B2Vec2): number;
static CrossVV(a: B2Vec2, b: B2Vec2): number;
static CrossVS(v: B2Vec2, s: number, out: B2Vec2): B2Vec2;
static CrossVOne(v: B2Vec2, out: B2Vec2): B2Vec2;
static CrossSV(s: number, v: B2Vec2, out: B2Vec2): B2Vec2;
static CrossOneV(v: B2Vec2, out: B2Vec2): B2Vec2;
static AddVV(a: B2Vec2, b: B2Vec2, out: B2Vec2): B2Vec2;
static SubVV(a: B2Vec2, b: B2Vec2, out: B2Vec2): B2Vec2;
static MulSV(s: number, v: B2Vec2, out: B2Vec2): B2Vec2;
static MulVS(v: B2Vec2, s: number, out: B2Vec2): B2Vec2;
static AddVMulSV(a: B2Vec2, s: number, b: B2Vec2, out: B2Vec2): B2Vec2;
static SubVMulSV(a: B2Vec2, s: number, b: B2Vec2, out: B2Vec2): B2Vec2;
static AddVCrossSV(a: B2Vec2, s: number, v: B2Vec2, out: B2Vec2): B2Vec2;
static MidVV(a: B2Vec2, b: B2Vec2, out: B2Vec2): B2Vec2;
static ExtVV(a: B2Vec2, b: B2Vec2, out: B2Vec2): B2Vec2;
static IsEqualToV(a: B2Vec2, b: B2Vec2): boolean;
static DistanceVV(a: B2Vec2, b: B2Vec2): number;
static DistanceSquaredVV(a: B2Vec2, b: B2Vec2): number;
static NegV(v: B2Vec2, out: B2Vec2): B2Vec2;
}
export declare const B2Vec2_zero: B2Vec2;
export declare class B2Vec3 {
static ZERO: B2Vec3;
static s_t0: B2Vec3;
x: number;
y: number;
z: number;
constructor(x?: number, y?: number, z?: number);
Clone(): B2Vec3;
SetZero(): B2Vec3;
SetXYZ(x: number, y: number, z: number): B2Vec3;
Copy(other: B2Vec3): B2Vec3;
SelfNeg(): B2Vec3;
SelfAdd(v: B2Vec3): B2Vec3;
SelfAddXYZ(x: number, y: number, z: number): B2Vec3;
SelfSub(v: B2Vec3): B2Vec3;
SelfSubXYZ(x: number, y: number, z: number): B2Vec3;
SelfMul(s: number): B2Vec3;
static DotV3V3(a: B2Vec3, b: B2Vec3): number;
static CrossV3V3(a: B2Vec3, b: B2Vec3, out: B2Vec3): B2Vec3;
}
export declare class B2Mat22 {
static IDENTITY: B2Mat22;
ex: B2Vec2;
ey: B2Vec2;
Clone(): B2Mat22;
static FromVV(c1: B2Vec2, c2: B2Vec2): B2Mat22;
static FromSSSS(r1c1: number, r1c2: number, r2c1: number, r2c2: number): B2Mat22;
static FromAngle(radians: number): B2Mat22;
SetSSSS(r1c1: number, r1c2: number, r2c1: number, r2c2: number): B2Mat22;
SetVV(c1: B2Vec2, c2: B2Vec2): B2Mat22;
SetAngle(radians: number): B2Mat22;
Copy(other: B2Mat22): B2Mat22;
SetIdentity(): B2Mat22;
SetZero(): B2Mat22;
GetAngle(): number;
GetInverse(out: B2Mat22): B2Mat22;
Solve(b_x: number, b_y: number, out: B2Vec2): B2Vec2;
SelfAbs(): B2Mat22;
SelfInv(): B2Mat22;
SelfAddM(M: B2Mat22): B2Mat22;
SelfSubM(M: B2Mat22): B2Mat22;
static AbsM(M: B2Mat22, out: B2Mat22): B2Mat22;
static MulMV(M: B2Mat22, v: B2Vec2, out: B2Vec2): B2Vec2;
static MulTMV(M: B2Mat22, v: B2Vec2, out: B2Vec2): B2Vec2;
static AddMM(A: B2Mat22, B: B2Mat22, out: B2Mat22): B2Mat22;
static MulMM(A: B2Mat22, B: B2Mat22, out: B2Mat22): B2Mat22;
static MulTMM(A: B2Mat22, B: B2Mat22, out: B2Mat22): B2Mat22;
}
export declare class B2Mat33 {
static IDENTITY: B2Mat33;
ex: B2Vec3;
ey: B2Vec3;
ez: B2Vec3;
Clone(): B2Mat33;
SetVVV(c1: B2Vec3, c2: B2Vec3, c3: B2Vec3): B2Mat33;
Copy(other: B2Mat33): B2Mat33;
SetIdentity(): B2Mat33;
SetZero(): B2Mat33;
SelfAddM(M: B2Mat33): B2Mat33;
Solve33(b_x: number, b_y: number, b_z: number, out: B2Vec3): B2Vec3;
Solve22(b_x: number, b_y: number, out: B2Vec2): B2Vec2;
GetInverse22(M: B2Mat33): void;
GetSymInverse33(M: B2Mat33): void;
static MulM33V3(A: B2Mat33, v: B2Vec3, out: B2Vec3): B2Vec3;
static MulM33XYZ(A: B2Mat33, x: number, y: number, z: number, out: B2Vec3): B2Vec3;
static MulM33V2(A: B2Mat33, v: B2Vec2, out: B2Vec2): B2Vec2;
static MulM33XY(A: B2Mat33, x: number, y: number, out: B2Vec2): B2Vec2;
}
export declare class B2Rot {
static IDENTITY: B2Rot;
s: number;
c: number;
constructor(angle?: number);
Clone(): B2Rot;
Copy(other: B2Rot): B2Rot;
SetAngle(angle: number): B2Rot;
SetIdentity(): B2Rot;
GetAngle(): number;
GetXAxis(out: B2Vec2): B2Vec2;
GetYAxis(out: B2Vec2): B2Vec2;
static MulRR(q: B2Rot, r: B2Rot, out: B2Rot): B2Rot;
static MulTRR(q: B2Rot, r: B2Rot, out: B2Rot): B2Rot;
static MulRV(q: B2Rot, v: B2Vec2, out: B2Vec2): B2Vec2;
static MulTRV(q: B2Rot, v: B2Vec2, out: B2Vec2): B2Vec2;
}
export declare class B2Transform {
static IDENTITY: B2Transform;
p: B2Vec2;
q: B2Rot;
Clone(): B2Transform;
Copy(other: B2Transform): B2Transform;
SetIdentity(): B2Transform;
SetPositionRotation(position: B2Vec2, q: B2Rot): B2Transform;
SetPositionAngle(pos: B2Vec2, a: number): B2Transform;
SetPosition(position: B2Vec2): B2Transform;
SetPositionXY(x: number, y: number): B2Transform;
SetRotation(rotation: B2Rot): B2Transform;
SetRotationAngle(radians: number): B2Transform;
GetPosition(): B2Vec2;
GetRotation(): B2Rot;
GetRotationAngle(): number;
GetAngle(): number;
static MulXV(T: B2Transform, v: B2Vec2, out: B2Vec2): B2Vec2;
static MulTXV(T: B2Transform, v: B2Vec2, out: B2Vec2): B2Vec2;
static MulXX(A: B2Transform, B: B2Transform, out: B2Transform): B2Transform;
static MulTXX(A: B2Transform, B: B2Transform, out: B2Transform): B2Transform;
}
export declare class B2Sweep {
localCenter: B2Vec2;
c0: B2Vec2;
c: B2Vec2;
a0: number;
a: number;
alpha0: number;
Clone(): B2Sweep;
Copy(other: B2Sweep): B2Sweep;
GetTransform(xf: B2Transform, beta: number): B2Transform;
Advance(alpha: number): void;
Normalize(): void;
}

Large diffs are not rendered by default.

@@ -0,0 +1,55 @@
export declare function B2Assert(condition: boolean, ...args: any[]): void;
export declare const B2_maxFloat: number;
export declare const B2_epsilon: number;
export declare const B2_epsilon_sq: number;
export declare const B2_pi: number;
export declare const B2_maxManifoldPoints: number;
export declare const B2_maxPolygonVertices: number;
export declare const B2_aabbExtension: number;
export declare const B2_aabbMultiplier: number;
export declare const B2_linearSlop: number;
export declare const B2_angularSlop: number;
export declare const B2_polygonRadius: number;
export declare const B2_maxSubSteps: number;
export declare const B2_maxTOIContacts: number;
export declare const B2_velocityThreshold: number;
export declare const B2_maxLinearCorrection: number;
export declare const B2_maxAngularCorrection: number;
export declare const B2_maxTranslation: number;
export declare const B2_maxTranslationSquared: number;
export declare const B2_maxRotation: number;
export declare const B2_maxRotationSquared: number;
export declare const B2_baumgarte: number;
export declare const B2_toiBaumgarte: number;
export declare const B2_invalidParticleIndex: number;
export declare const B2_maxParticleIndex: number;
export declare const B2_particleStride: number;
export declare const B2_minParticleWeight: number;
export declare const B2_maxParticlePressure: number;
export declare const B2_maxParticleForce: number;
export declare const B2_maxTriadDistance: number;
export declare const B2_maxTriadDistanceSquared: number;
export declare const B2_minParticleSystemBufferCapacity: number;
export declare const B2_barrierCollisionTime: number;
export declare const B2_timeToSleep: number;
export declare const B2_linearSleepTolerance: number;
export declare const B2_angularSleepTolerance: number;
export declare function B2Alloc(size: number): any;
export declare function B2Free(mem: any): void;
export declare function B2Log(message: string, ...args: any[]): void;
export declare class B2Version {
major: number;
minor: number;
revision: number;
constructor(major?: number, minor?: number, revision?: number);
toString(): string;
}
export declare const B2_version: B2Version;
export declare const B2_changelist: number;
export declare function B2ParseInt(v: string): number;
export declare function B2ParseUInt(v: string): number;
export declare function B2MakeArray(length: number, init: {
(i: number): any;
}): any[];
export declare function B2MakeNullArray(length: number): any[];
export declare function B2MakeNumberArray(length: number, init?: number): number[];
@@ -0,0 +1,168 @@
/*
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
export function B2Assert(condition, ...args) {
if (!condition) {
console.error('Here');
}
}
export const B2_maxFloat = 1E+37; // FLT_MAX instead of Number.MAX_VALUE;
export const B2_epsilon = 1E-5; // FLT_EPSILON instead of Number.MIN_VALUE;
export const B2_epsilon_sq = (B2_epsilon * B2_epsilon);
export const B2_pi = 3.14159265359; // Math.PI;
/// @file
/// Global tuning constants based on meters-kilograms-seconds (MKS) units.
///
// Collision
/// The maximum number of contact points between two convex shapes. Do
/// not change this value.
export const B2_maxManifoldPoints = 2;
/// The maximum number of vertices on a convex polygon. You cannot increase
/// this too much because B2BlockAllocator has a maximum object size.
export const B2_maxPolygonVertices = 8;
/// This is used to fatten AABBs in the dynamic tree. This allows proxies
/// to move by a small amount without triggering a tree adjustment.
/// This is in meters.
export const B2_aabbExtension = 0.1;
/// This is used to fatten AABBs in the dynamic tree. This is used to predict
/// the future position based on the current displacement.
/// This is a dimensionless multiplier.
export const B2_aabbMultiplier = 2;
/// A small length used as a collision and constraint tolerance. Usually it is
/// chosen to be numerically significant, but visually insignificant.
export const B2_linearSlop = 0.008; // 0.005;
/// A small angle used as a collision and constraint tolerance. Usually it is
/// chosen to be numerically significant, but visually insignificant.
export const B2_angularSlop = 2 / 180 * B2_pi;
/// The radius of the polygon/edge shape skin. This should not be modified. Making
/// this smaller means polygons will have an insufficient buffer for continuous collision.
/// Making it larger may create artifacts for vertex collision.
export const B2_polygonRadius = 2 * B2_linearSlop;
/// Maximum number of sub-steps per contact in continuous physics simulation.
export const B2_maxSubSteps = 8;
// Dynamics
/// Maximum number of contacts to be handled to solve a TOI impact.
export const B2_maxTOIContacts = 32;
/// A velocity threshold for elastic collisions. Any collision with a relative linear
/// velocity below this threshold will be treated as inelastic.
export const B2_velocityThreshold = 1;
/// The maximum linear position correction used when solving constraints. This helps to
/// prevent overshoot.
export const B2_maxLinearCorrection = 0.2;
/// The maximum angular position correction used when solving constraints. This helps to
/// prevent overshoot.
export const B2_maxAngularCorrection = 8 / 180 * B2_pi;
/// The maximum linear velocity of a body. This limit is very large and is used
/// to prevent numerical problems. You shouldn't need to adjust this.
export const B2_maxTranslation = 2;
export const B2_maxTranslationSquared = B2_maxTranslation * B2_maxTranslation;
/// The maximum angular velocity of a body. This limit is very large and is used
/// to prevent numerical problems. You shouldn't need to adjust this.
export const B2_maxRotation = 0.5 * B2_pi;
export const B2_maxRotationSquared = B2_maxRotation * B2_maxRotation;
/// This scale factor controls how fast overlap is resolved. Ideally this would be 1 so
/// that overlap is removed in one time step. However using values close to 1 often lead
/// to overshoot.
export const B2_baumgarte = 0.2;
export const B2_toiBaumgarte = 0.75;
/// #if B2_ENABLE_PARTICLE
// Particle
/// A symbolic constant that stands for particle allocation error.
export const B2_invalidParticleIndex = -1;
export const B2_maxParticleIndex = 0x7FFFFFFF;
/// The default distance between particles, multiplied by the particle diameter.
export const B2_particleStride = 0.75;
/// The minimum particle weight that produces pressure.
export const B2_minParticleWeight = 1.0;
/// The upper limit for particle pressure.
export const B2_maxParticlePressure = 0.25;
/// The upper limit for force between particles.
export const B2_maxParticleForce = 0.5;
/// The maximum distance between particles in a triad, multiplied by the particle diameter.
export const B2_maxTriadDistance = 2.0;
export const B2_maxTriadDistanceSquared = (B2_maxTriadDistance * B2_maxTriadDistance);
/// The initial size of particle data buffers.
export const B2_minParticleSystemBufferCapacity = 256;
/// The time into the future that collisions against barrier particles will be detected.
export const B2_barrierCollisionTime = 2.5;
/// #endif
// Sleep
/// The time that a body must be still before it will go to sleep.
export const B2_timeToSleep = 0.5;
/// A body cannot sleep if its linear velocity is above this tolerance.
export const B2_linearSleepTolerance = 0.01;
/// A body cannot sleep if its angular velocity is above this tolerance.
export const B2_angularSleepTolerance = 2 / 180 * B2_pi;
// Memory Allocation
/// Implement this function to use your own memory allocator.
export function B2Alloc(size) {
return null;
}
/// If you implement B2Alloc, you should also implement this function.
export function B2Free(mem) {
}
/// Logging function.
export function B2Log(message, ...args) {
// const args = Array.prototype.slice.call(arguments);
// const str = goog.string.format.apply(null, args.slice(0));
// console.log(message);
}
/// Version numbering scheme.
/// See http://en.wikipedia.org/wiki/Software_versioning
export class B2Version {
constructor(major = 0, minor = 0, revision = 0) {
this.major = 0; /// < significant changes
this.minor = 0; /// < incremental changes
this.revision = 0; /// < bug fixes
this.major = major;
this.minor = minor;
this.revision = revision;
}
toString() {
return this.major + '.' + this.minor + '.' + this.revision;
}
}
/// Current version.
export const B2_version = new B2Version(2, 3, 2);
export const B2_changelist = 313;
export function B2ParseInt(v) {
return parseInt(v, 10);
}
export function B2ParseUInt(v) {
return Math.abs(parseInt(v, 10));
}
export function B2MakeArray(length, init) {
let a = [];
for (let i = 0; i < length; ++i) {
a.push(init(i));
}
return a;
}
export function B2MakeNullArray(length) {
const a = [];
for (let i = 0; i < length; ++i) {
a.push(null);
}
return a;
}
export function B2MakeNumberArray(length, init = 0) {
const a = [];
for (let i = 0; i < length; ++i) {
a.push(init);
}
return a;
}
@@ -0,0 +1,2 @@
export declare class B2StackAllocator {
}
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
export class B2StackAllocator {
}
@@ -0,0 +1,18 @@
export declare class B2Timer {
m_start: number;
Reset(): B2Timer;
GetMilliseconds(): number;
}
export declare class B2Counter {
m_count: number;
m_min_count: number;
m_max_count: number;
GetCount(): number;
GetMinCount(): number;
GetMaxCount(): number;
ResetCount(): number;
ResetMinCount(): void;
ResetMaxCount(): void;
Increment(): void;
Decrement(): void;
}
@@ -0,0 +1,72 @@
/*
* Copyright (c) 2011 Erin Catto http://box2d.org
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
/// Timer for profiling. This has platform specific code and may
/// not work on every platform.
export class B2Timer {
constructor() {
this.m_start = Date.now();
}
/// Reset the timer.
Reset() {
this.m_start = Date.now();
return this;
}
/// Get the time since construction or the last reset.
GetMilliseconds() {
return Date.now() - this.m_start;
}
}
export class B2Counter {
constructor() {
this.m_count = 0;
this.m_min_count = 0;
this.m_max_count = 0;
}
GetCount() {
return this.m_count;
}
GetMinCount() {
return this.m_min_count;
}
GetMaxCount() {
return this.m_max_count;
}
ResetCount() {
const count = this.m_count;
this.m_count = 0;
return count;
}
ResetMinCount() {
this.m_min_count = 0;
}
ResetMaxCount() {
this.m_max_count = 0;
}
Increment() {
this.m_count++;
if (this.m_max_count < this.m_count) {
this.m_max_count = this.m_count;
}
}
Decrement() {
this.m_count--;
if (this.m_min_count > this.m_count) {
this.m_min_count = this.m_count;
}
}
}
@@ -0,0 +1,7 @@
export * from './b2Settings';
export * from './b2Math';
export * from './b2Draw';
export * from './b2Timer';
export * from './b2GrowableStack';
export * from './b2BlockAllocator';
export * from './b2StackAllocator';
@@ -0,0 +1,7 @@
export * from './b2Settings';
export * from './b2Math';
export * from './b2Draw';
export * from './b2Timer';
export * from './b2GrowableStack';
export * from './b2BlockAllocator';
export * from './b2StackAllocator';
@@ -0,0 +1,12 @@
import { B2Transform } from '../../Common/b2Math';
import { B2Manifold } from '../../Collision/b2Collision';
import { B2Contact } from './b2Contact';
import { B2Fixture } from '../b2Fixture';
export declare class B2ChainAndCircleContact extends B2Contact {
constructor();
static Create(allocator: any): B2Contact;
static Destroy(contact: B2Contact, allocator: any): void;
Reset(fixtureA: B2Fixture, indexA: number, fixtureB: B2Fixture, indexB: number): void;
private static Evaluate_s_edge;
Evaluate(manifold: B2Manifold, xfA: B2Transform, xfB: B2Transform): void;
}
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
import { B2CollideEdgeAndCircle } from '../../Collision/b2CollideEdge';
import { B2EdgeShape } from '../../Collision/Shapes/b2EdgeShape';
import { B2Contact } from './b2Contact';
export class B2ChainAndCircleContact extends B2Contact {
constructor() {
super();
}
static Create(allocator) {
return new B2ChainAndCircleContact();
}
static Destroy(contact, allocator) {
}
Reset(fixtureA, indexA, fixtureB, indexB) {
super.Reset(fixtureA, indexA, fixtureB, indexB);
/// b2Assert(fixtureA.GetType() === B2ShapeType.e_chainShape);
/// b2Assert(fixtureB.GetType() === B2ShapeType.e_circleShape);
}
Evaluate(manifold, xfA, xfB) {
const shapeA = this.m_fixtureA.GetShape();
const shapeB = this.m_fixtureB.GetShape();
/// b2Assert(shapeA instanceof B2ChainShape);
/// b2Assert(shapeB instanceof B2CircleShape);
const chain = shapeA;
const edge = B2ChainAndCircleContact.Evaluate_s_edge;
chain.GetChildEdge(edge, this.m_indexA);
B2CollideEdgeAndCircle(manifold, edge, xfA, shapeB, xfB);
}
}
B2ChainAndCircleContact.Evaluate_s_edge = new B2EdgeShape();
@@ -0,0 +1,12 @@
import { B2Transform } from '../../Common/b2Math';
import { B2Manifold } from '../../Collision/b2Collision';
import { B2Contact } from './b2Contact';
import { B2Fixture } from '../b2Fixture';
export declare class B2ChainAndPolygonContact extends B2Contact {
constructor();
static Create(allocator: any): B2Contact;
static Destroy(contact: B2Contact, allocator: any): void;
Reset(fixtureA: B2Fixture, indexA: number, fixtureB: B2Fixture, indexB: number): void;
private static Evaluate_s_edge;
Evaluate(manifold: B2Manifold, xfA: B2Transform, xfB: B2Transform): void;
}
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
import { B2CollideEdgeAndPolygon } from '../../Collision/b2CollideEdge';
import { B2EdgeShape } from '../../Collision/Shapes/b2EdgeShape';
import { B2Contact } from './b2Contact';
export class B2ChainAndPolygonContact extends B2Contact {
constructor() {
super();
}
static Create(allocator) {
return new B2ChainAndPolygonContact();
}
static Destroy(contact, allocator) {
}
Reset(fixtureA, indexA, fixtureB, indexB) {
super.Reset(fixtureA, indexA, fixtureB, indexB);
/// b2Assert(fixtureA.GetType() === B2ShapeType.e_chainShape);
/// b2Assert(fixtureB.GetType() === B2ShapeType.e_polygonShape);
}
Evaluate(manifold, xfA, xfB) {
const shapeA = this.m_fixtureA.GetShape();
const shapeB = this.m_fixtureB.GetShape();
/// b2Assert(shapeA instanceof B2ChainShape);
/// b2Assert(shapeB instanceof B2PolygonShape);
const chain = shapeA;
const edge = B2ChainAndPolygonContact.Evaluate_s_edge;
chain.GetChildEdge(edge, this.m_indexA);
B2CollideEdgeAndPolygon(manifold, edge, xfA, shapeB, xfB);
}
}
B2ChainAndPolygonContact.Evaluate_s_edge = new B2EdgeShape();
@@ -0,0 +1,11 @@
import { B2Transform } from '../../Common/b2Math';
import { B2Manifold } from '../../Collision/b2Collision';
import { B2Contact } from './b2Contact';
import { B2Fixture } from '../b2Fixture';
export declare class B2CircleContact extends B2Contact {
constructor();
static Create(allocator: any): B2Contact;
static Destroy(contact: B2Contact, allocator: any): void;
Reset(fixtureA: B2Fixture, indexA: number, fixtureB: B2Fixture, indexB: number): void;
Evaluate(manifold: B2Manifold, xfA: B2Transform, xfB: B2Transform): void;
}
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
import { B2CollideCircles } from '../../Collision/b2CollideCircle';
import { B2Contact } from './b2Contact';
export class B2CircleContact extends B2Contact {
constructor() {
super();
}
static Create(allocator) {
return new B2CircleContact();
}
static Destroy(contact, allocator) {
}
Reset(fixtureA, indexA, fixtureB, indexB) {
super.Reset(fixtureA, indexA, fixtureB, indexB);
}
Evaluate(manifold, xfA, xfB) {
const shapeA = this.m_fixtureA.GetShape();
const shapeB = this.m_fixtureB.GetShape();
/// b2Assert(shapeA instanceof B2CircleShape);
/// b2Assert(shapeB instanceof B2CircleShape);
B2CollideCircles(manifold, shapeA, xfA, shapeB, xfB);
}
}
@@ -0,0 +1,61 @@
import { B2Transform, B2Sweep } from '../../Common/b2Math';
import { B2Manifold, B2WorldManifold } from '../../Collision/b2Collision';
import { B2Body } from '../b2Body';
import { B2Fixture } from '../b2Fixture';
import { B2ContactListener } from '../b2WorldCallbacks';
export declare function B2MixFriction(friction1: number, friction2: number): number;
export declare function B2MixRestitution(restitution1: number, restitution2: number): number;
export declare class B2ContactEdge {
other: B2Body | null;
contact: B2Contact | null;
prev: B2ContactEdge | null;
next: B2ContactEdge | null;
}
export declare class B2Contact {
m_islandFlag: boolean;
m_touchingFlag: boolean;
m_enabledFlag: boolean;
m_filterFlag: boolean;
m_bulletHitFlag: boolean;
m_toiFlag: boolean;
m_prev: B2Contact | null;
m_next: B2Contact | null;
m_nodeA: B2ContactEdge;
m_nodeB: B2ContactEdge;
m_fixtureA: B2Fixture | null;
m_fixtureB: B2Fixture | null;
m_indexA: number;
m_indexB: number;
m_manifold: B2Manifold;
m_toiCount: number;
m_toi: number;
m_friction: number;
m_restitution: number;
m_tangentSpeed: number;
m_oldManifold: B2Manifold;
GetManifold(): B2Manifold;
GetWorldManifold(worldManifold: B2WorldManifold): void;
IsTouching(): boolean;
SetEnabled(flag: boolean): void;
IsEnabled(): boolean;
GetNext(): B2Contact | null;
GetFixtureA(): B2Fixture | null;
GetChildIndexA(): number;
GetFixtureB(): B2Fixture | null;
GetChildIndexB(): number;
Evaluate(manifold: B2Manifold, xfA: B2Transform, xfB: B2Transform): void;
FlagForFiltering(): void;
SetFriction(friction: number): void;
GetFriction(): number;
ResetFriction(): void;
SetRestitution(restitution: number): void;
GetRestitution(): number;
ResetRestitution(): void;
SetTangentSpeed(speed: number): void;
GetTangentSpeed(): number;
Reset(fixtureA: B2Fixture, indexA: number, fixtureB: B2Fixture, indexB: number): void;
Update(listener: B2ContactListener): void;
private static ComputeTOI_s_input;
private static ComputeTOI_s_output;
ComputeTOI(sweepA: B2Sweep, sweepB: B2Sweep): number;
}