UNPKG

phaser-ce

Version:

Phaser CE (Community Edition) is a fast, free and fun HTML5 Game Framework for Desktop and Mobile web browsers.

1,199 lines (1,128 loc) 158 kB
declare class box2d { static DEBUG: boolean; static ENABLE_ASSERTS: boolean; static b2Assert(condition: boolean, opt_message?: string, ...var_args: any[]): void; static b2_maxFloat: number; static b2_epsilon: number; static b2_epsilon_sq: number; static b2_pi: number; // The maximum number of contact points between two convex // shapes. Do not change this value. static b2_maxManifoldPoints: number; // The maximum number of vertices on a convex polygon. You // cannot increase this too much because b2BlockAllocator has a // maximum object size. static b2_maxPolygonVertices: number; // 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. static b2_aabbExtension: number; // 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. static b2_aabbMultiplier: number; // A small length used as a collision and constraint tolerance. // Usually it is chosen to be numerically significant, but // visually insignificant. static b2_linearSlop: number; // A small angle used as a collision and constraint tolerance. // Usually it is chosen to be numerically significant, but // visually insignificant. static b2_angularSlop: number; // 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. static b2_polygonRadius: number; // Maximum number of sub-steps per contact in continuous physics // simulation. static b2_maxSubSteps: number; // Maximum number of contacts to be handled to solve a TOI // impact. static b2_maxTOIContacts: number; // A velocity threshold for elastic collisions. Any collision // with a relative linear velocity below this threshold will be // treated as inelastic. static b2_velocityThreshold: number; // The maximum linear position correction used when solving // constraints. This helps to prevent overshoot. static b2_maxLinearCorrection: number; // The maximum angular position correction used when solving // constraints. This helps to prevent overshoot. static b2_maxAngularCorrection: number; // 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. static b2_maxTranslation: number; static b2_maxTranslationSquared: number; // 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. static b2_maxRotation: number; static b2_maxRotationSquared: number; // 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. static b2_baumgarte: number; static b2_toiBaumgarte: number; // The time that a body must be still before it will go to // sleep. static b2_timeToSleep: number; // A body cannot sleep if its linear velocity is above this // tolerance. static b2_linearSleepTolerance: number; // A body cannot sleep if its angular velocity is above this // tolerance. static b2_angularSleepTolerance: number; // Implement this function to use your own memory allocator. static b2Alloc(size: number): any; // If you implement b2Alloc, you should also implement this // function. static b2Free(mem: any): void; // Logging function. // You can modify this to use your logging facility. static b2Log(...var_args: any[]): void; // Current version. static b2_version: box2d.b2Version; static b2_changelist: number; static b2ParseInt(v: string): number; static b2ParseUInt(v: string): number; static b2MakeArray(length?: number, init?: (length: number) => any): Array<any>; static b2MakeNumberArray(length?: number): Array<number>; static b2_pi_over_180: number; static b2_180_over_pi: number; static b2_two_pi: number; static b2Abs(n: number): number; static b2Min(a: number, b: number): number; static b2Max(a: number, b: number): number; static b2Clamp(a: number, lo: number, hi: number): number; static b2Swap(a: Array<number>, b: Array<number>): void; // This function is used to ensure that a floating point number // is not a NaN or infinity. static b2IsValid(n: number): boolean; static b2Sq(n: number): number; // This is a approximate yet fast inverse square-root. static b2InvSqrt(n: number): number; static b2Sqrt(n: number): number; static b2Pow(x: number, y: number): number; static b2DegToRad(degrees: number): number; static b2RadToDeg(radians: number): number; static b2Cos(radians: number): number; static b2Sin(radians: number): number; static b2Acos(n: number): number; static b2Asin(n: number): number; static b2Atan2(y: number, x: number): number; // Next Largest Power of 2 // Given a binary integer value x, the next largest power of 2 // can be computed by a SWAR algorithm that recursively "folds" // the upper bits into the lower bits. This process yields a bit // vector with the same most significant 1 as x, but all 1's // below it. Adding 1 to that value yields the next largest // power of 2. For a 32-bit value: static b2NextPowerOfTwo(x: number): number; static b2IsPowerOfTwo(x: number): boolean; static b2Random(): number; static b2RandomRange(lo: number, hi: number): number; static b2Vec2_zero: box2d.b2Vec2; static b2AbsV(v: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2; static b2MinV(a: box2d.b2Vec2, b: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2; static b2MaxV(a: box2d.b2Vec2, b: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2; static b2ClampV(v: box2d.b2Vec2, lo: box2d.b2Vec2, hi: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2; static b2RotateV(v: box2d.b2Vec2, c: number, s: number, out: box2d.b2Vec2): box2d.b2Vec2; static b2RotateRadiansV(v: box2d.b2Vec2, radians: number, out: box2d.b2Vec2): box2d.b2Vec2; static b2RotateDegreesV(v: box2d.b2Vec2, degrees: number, out: box2d.b2Vec2): box2d.b2Vec2; // Perform the dot product on two vectors. // a.x * b.x + a.y * b.y static b2DotVV(a: box2d.b2Vec2, b: box2d.b2Vec2): number; // Perform the cross product on two vectors. In 2D this produces a scalar. // a.x * b.y - a.y * b.x static b2CrossVV(a: box2d.b2Vec2, b: box2d.b2Vec2): number; // Perform the cross product on a vector and a scalar. In 2D // this produces a vector. static b2CrossVS(v: box2d.b2Vec2, s: number, out: box2d.b2Vec2): box2d.b2Vec2; // box2d.b2CrossVS(v, 1.0, out) static b2CrossVOne(v: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2; // Perform the cross product on a scalar and a vector. In 2D // this produces a vector. static b2CrossSV(s: number, v: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2; // box2d.b2CrossSV(1.0, v, out) static b2CrossOneV(v: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2; // Add two vectors component-wise. static b2AddVV(a: box2d.b2Vec2, b: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2; // Subtract two vectors component-wise. static b2SubVV(a: box2d.b2Vec2, b: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2; static b2MulSV(s: number, v: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2; // out = a + (s * b) static b2AddVMulSV(a: box2d.b2Vec2, s: number, b: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2; // out = a - (s * b) static b2SubVMulSV(a: box2d.b2Vec2, s: number, b: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2; // out = a + b2CrossSV(s, v) static b2AddVCrossSV(a: box2d.b2Vec2, s: number, v: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2; // Get the center of two vectors. static b2MidVV(a: box2d.b2Vec2, b: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2; // Get the extent of two vectors (half-widths). static b2ExtVV(a: box2d.b2Vec2, b: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2; static b2IsEqualToV(a: box2d.b2Vec2, b: box2d.b2Vec2): boolean; static b2DistanceVV(a: box2d.b2Vec2, b: box2d.b2Vec2): number; static b2DistanceSquaredVV(a: box2d.b2Vec2, b: box2d.b2Vec2): number; static b2NegV(v: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2; // Perform the dot product on two vectors. static b2DotV3V3(a: box2d.b2Vec3, b: box2d.b2Vec3): number; // Perform the cross product on two vectors. static b2CrossV3V3(a: box2d.b2Vec3, b: box2d.b2Vec3, out: box2d.b2Vec3): box2d.b2Vec3; static b2AbsM(M: box2d.b2Mat22, out: box2d.b2Mat22): box2d.b2Mat22; // Multiply a matrix times a vector. If a rotation matrix is // provided, then this transforms the vector from one frame to // another. static b2MulMV(M: box2d.b2Mat22, v: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2; // Multiply a matrix transpose times a vector. If a rotation // matrix is provided, then this transforms the vector from one // frame to another (inverse transform). static b2MulTMV(M: box2d.b2Mat22, v: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2; static b2AddMM(A: box2d.b2Mat22, B: box2d.b2Mat22, out: box2d.b2Mat22): box2d.b2Mat22; static b2MulMM(A: box2d.b2Mat22, B: box2d.b2Mat22, out: box2d.b2Mat22): box2d.b2Mat22; static b2MulTMM(A: box2d.b2Mat22, B: box2d.b2Mat22, out: box2d.b2Mat22): box2d.b2Mat22; // Multiply a matrix times a vector. static b2MulM33V3(A: box2d.b2Mat33, v: box2d.b2Vec3, out: box2d.b2Vec3): box2d.b2Vec3; static b2MulM33XYZ(A: box2d.b2Mat33, x: number, y: number, z: number, out: box2d.b2Vec3): box2d.b2Vec3; static b2MulM33V2(A: box2d.b2Mat33, v: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2; static b2MulM33XY(A: box2d.b2Mat33, x: number, y: number, out: box2d.b2Vec2): box2d.b2Vec2; // Multiply two rotations: q * r static b2MulRR(q: box2d.b2Rot, r: box2d.b2Rot, out: box2d.b2Rot): box2d.b2Rot; // Transpose multiply two rotations: qT * r static b2MulTRR(q: box2d.b2Rot, r: box2d.b2Rot, out: box2d.b2Rot): box2d.b2Rot; // Rotate a vector static b2MulRV(q: box2d.b2Rot, v: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2; // Inverse rotate a vector static b2MulTRV(q: box2d.b2Rot, v: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2; static b2MulXV(T: box2d.b2Transform, v: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2; static b2MulTXV(T: box2d.b2Transform, v: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2; // v2 = A.q.Rot(B.q.Rot(v1) + B.p) + A.p // = (A.q * B.q).Rot(v1) + A.q.Rot(B.p) + A.p static b2MulXX(A: box2d.b2Transform, B: box2d.b2Transform, out: box2d.b2Transform): box2d.b2Transform; // v2 = A.q' * (B.q * v1 + B.p - A.p) // = A.q' * B.q * v1 + A.q' * (B.p - A.p) static b2MulTXX(A: box2d.b2Transform, B: box2d.b2Transform, out: box2d.b2Transform): box2d.b2Transform; static b2_gjkCalls: number; static b2_gjkIters: number; static b2_gjkMaxIters: number; // Compute the closest points between two shapes. Supports any combination of: // box2d.b2CircleShape, box2d.b2PolygonShape, box2d.b2EdgeShape. The simplex cache is input/output. // On the first call set box2d.b2SimplexCache.count to zero. static b2Distance(output: box2d.b2DistanceOutput, cache: box2d.b2SimplexCache, input: box2d.b2DistanceInput): void; // 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. static b2GetPointStates(state1: Array<box2d.b2PointState>, state2: Array<box2d.b2PointState>, manifold1: box2d.b2Manifold, manifold2: box2d.b2Manifold): void; static b2TestOverlapAABB(a: box2d.b2AABB, b: box2d.b2AABB): boolean; // Clipping for contact manifolds. // Sutherland-Hodgman clipping. static b2ClipSegmentToLine(vOut: Array<box2d.b2ClipVertex>, vIn: Array<box2d.b2ClipVertex>, normal: box2d.b2Vec2, offset: number, vertexIndexA: number): number; static b2TestOverlapShape(shapeA: box2d.b2Shape, shapeB: box2d.b2Shape, xfA: box2d.b2Transform, xfB: box2d.b2Transform): boolean; static b2_toiTime: number; static b2_toiMaxTime: number; static b2_toiCalls: number; static b2_toiIters: number; static b2_toiMaxIters: number; static b2_toiRootIters: number; static b2_toiMaxRootIters: number; // Compute the upper bound on time before two shapes penetrate. // Time is represented as a fraction between [0,tMax]. This uses // a swept separating axis and may miss some intermediate, // non-tunneling collision. If you change the time interval, you // should call this function again. // Note: use box2d.b2Distance to compute the contact point and // normal at the time of impact. static b2TimeOfImpact(output: box2d.b2TOIOutput, input: box2d.b2TOIInput): void; // Friction mixing law. The idea is to allow either fixture to // drive the restitution to zero. For example, anything slides // on ice. static b2MixFriction(friction1: number, friction2: number): number; // Restitution mixing law. The idea is allow for anything to // bounce off an inelastic surface. For example, a superball // bounces on anything. static b2MixRestitution(restitution1: number, restitution2: number): number; // Compute the collision manifold between an edge and a circle. // Compute contact points for edge versus circle. // This accounts for edge connectivity. static b2CollideEdgeAndCircle(manifold: box2d.b2Manifold, edgeA: box2d.b2EdgeShape, xfA: box2d.b2Transform, circleB: box2d.b2CircleShape, xfB: box2d.b2Transform): void; // Compute the collision manifold between an edge and a polygon. static b2CollideEdgeAndPolygon(manifold: box2d.b2Manifold, edgeA: box2d.b2EdgeShape, xfA: box2d.b2Transform, polygonB: box2d.b2PolygonShape, xfB: box2d.b2Transform): void; // Find the max separation between poly1 and poly2 using edge // normals from poly1. static b2FindMaxSeparation(edgeIndex: Array<number>, poly1: box2d.b2PolygonShape, xf1: box2d.b2Transform, poly2: box2d.b2PolygonShape, xf2: box2d.b2Transform): number; static b2FindIncidentEdge(c: Array<box2d.b2ClipVertex>, poly1: box2d.b2PolygonShape, xf1: box2d.b2Transform, edge1: number, poly2: box2d.b2PolygonShape, xf2: box2d.b2Transform): void; // Find edge normal of max separation on A - return if separating axis is found // Find edge normal of max separation on B - return if separation axis is found // Choose reference edge as min(minA, minB) // Find incident edge // Clip // The normal points from 1 to 2 static b2CollidePolygons(manifold: box2d.b2Manifold, polyA: box2d.b2PolygonShape, xfA: box2d.b2Transform, polyB: box2d.b2PolygonShape, xfB: box2d.b2Transform): void; // Compute the collision manifold between two circles. static b2CollideCircles(manifold: box2d.b2Manifold, circleA: box2d.b2CircleShape, xfA: box2d.b2Transform, circleB: box2d.b2CircleShape, xfB: box2d.b2Transform): void; // Compute the collision manifold between a polygon and a // circle. static b2CollidePolygonAndCircle(manifold: box2d.b2Manifold, polygonA: box2d.b2PolygonShape, xfA: box2d.b2Transform, circleB: box2d.b2CircleShape, xfB: box2d.b2Transform): void; // This is used to sort pairs. static b2PairLessThan(pair1: box2d.b2Pair, pair2: box2d.b2Pair): number; static b2_minPulleyLength: number; } declare module box2d { enum b2JointType { e_unknownJoint = 0, e_revoluteJoint = 1, e_prismaticJoint = 2, e_distanceJoint = 3, e_pulleyJoint = 4, e_mouseJoint = 5, e_gearJoint = 6, e_wheelJoint = 7, e_weldJoint = 8, e_frictionJoint = 9, e_ropeJoint = 10, e_motorJoint = 11, e_areaJoint = 12 } enum b2LimitState { e_inactiveLimit = 0, e_atLowerLimit = 1, e_atUpperLimit = 2, e_equalLimits = 3 } enum b2ContactFeatureType { e_vertex = 0, e_face = 1 } enum b2ManifoldType { e_unknown = -1, e_circles = 0, e_faceA = 1, e_faceB = 2 } // This is used for determining the state of contact points. enum b2PointState { b2_nullState = 0, ///< point does not exist b2_addState = 1, ///< point was added in the update b2_persistState = 2, ///< point persisted across the update b2_removeState = 3 ///< point was removed in the update } enum b2TOIOutputState { e_unknown = 0, e_failed = 1, e_overlapped = 2, e_touching = 3, e_separated = 4 } enum b2SeparationFunctionType { e_unknown = -1, e_points = 0, e_faceA = 1, e_faceB = 2 } // Flags stored in m_flags enum b2ContactFlag { e_none = 0, e_islandFlag = 0x0001, /// Used when crawling contact graph when forming islands. e_touchingFlag = 0x0002, /// Set when the shapes are touching. e_enabledFlag = 0x0004, /// This contact can be disabled (by user) e_filterFlag = 0x0008, /// This contact needs filtering because a fixture filter was changed. e_bulletHitFlag = 0x0010, /// This bullet contact had a TOI event e_toiFlag = 0x0020 /// This contact has a valid TOI in m_toi } enum b2ShapeType { e_unknown = -1, e_circleShape = 0, e_edgeShape = 1, e_polygonShape = 2, e_chainShape = 3, e_shapeTypeCount = 4 } enum b2EPAxisType { e_unknown = 0, e_edgeA = 1, e_edgeB = 2 } enum b2EPColliderVertexType { e_isolated = 0, e_concave = 1, e_convex = 2 } enum b2DrawFlags { e_none = 0, e_shapeBit = 0x0001, ///< draw shapes e_jointBit = 0x0002, ///< draw joint connections e_aabbBit = 0x0004, ///< draw axis aligned bounding boxes e_pairBit = 0x0008, ///< draw broad-phase pairs e_centerOfMassBit = 0x0010, ///< draw center of mass frame e_controllerBit = 0x0020, /// @see box2d.b2Controller list e_all = 0x003f } // The body type. // enum= zero mass, zero velocity, may be manually moved // kinematic= zero mass, non-zero velocity set by user, moved by solver // dynamic= positive mass, non-zero velocity determined by forces, moved by solver enum b2BodyType { b2_unknown = -1, b2_staticBody = 0, b2_kinematicBody = 1, b2_dynamicBody = 2, b2_bulletBody = 3 // TODO_ERIN } enum b2BodyFlag { e_none = 0, e_islandFlag = 0x0001, e_awakeFlag = 0x0002, e_autoSleepFlag = 0x0004, e_bulletFlag = 0x0008, e_fixedRotationFlag = 0x0010, e_activeFlag = 0x0020, e_toiFlag = 0x0040 } enum b2WorldFlag { e_none = 0, e_newFixture = 0x1, e_locked = 0x2, e_clearForces = 0x4 } class b2Version { // Version numberinf scheme See // http://en.wikipedia.org/wiki/Software_versioning constructor(major?: number, minor?: number, revision?: number); major: number; minor: number; revision: number; toString(): string; } class b2Vec2 { // A 2D column vector. constructor(x?: number, y?: number); x: number; y: number; 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; static MakeArray(length?: number): Array<b2Vec2>; Clone(): b2Vec2; // Set this vector to all zeros. SetZero(): b2Vec2; // Set this vector to some specified coordinates. SetXY(x: number, y: number): b2Vec2; Copy(other: b2Vec2): b2Vec2; // Add a vector to this vector. SelfAdd(v: b2Vec2): b2Vec2; SelfAddXY(x: number, y: number): b2Vec2; // Subtract a vector from this vector. SelfSub(v: b2Vec2): b2Vec2; SelfSubXY(x: number, y: number): b2Vec2; // Multiply this vector by a scalar. SelfMul(s: number): b2Vec2; // this += s * v SelfMulAdd(s: number, v: b2Vec2): b2Vec2; // this -= s * v SelfMulSub(s: number, v: b2Vec2): b2Vec2; Dot(v: b2Vec2): number; Cross(v: b2Vec2): number; // Get the length of this vector (the norm). Length(): number; GetLength(): number; // Get the length squared. For performance, use this instead of // b2Vec2::Length (if possible). LengthSquared(): number; GetLengthSquared(): number; // Convert this vector into a unit vector. Returns the length. Normalize(): number; SelfNormalize(): b2Vec2; SelfRotate(c: number, s: number): b2Vec2; SelfRotateRadians(radians: number): b2Vec2; SelfRotateDegrees(degrees: number): b2Vec2; // Does this vector contain finite coordinates? IsValid(): boolean; SelfCrossVS(s: number): b2Vec2; SelfCrossSV(s: number): b2Vec2; SelfMinV(v: b2Vec2): b2Vec2; SelfMaxV(v: b2Vec2): b2Vec2; SelfAbs(): b2Vec2; SelfNeg(): b2Vec2; // Get the skew vector such that dot(skew_vec, other) === // cross(vec, other) SelfSkew(): b2Vec2; } class b2Vec3 { constructor(x?: number, y?: number, z?: number); x: number; y: number; z: number; static ZERO: b2Vec3; static s_t0: b2Vec3; 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; } class b2Mat22 { // A 2-by-2 matrix. Stored in column-major order. constructor(); ex: b2Vec2; ey: b2Vec2; static IDENTITY: b2Mat22; Clone(): b2Mat22; // Construct this matrix using columns. static FromVV(c1: b2Vec2, c2: b2Vec2): b2Mat22; // Construct this matrix using scalars. static FromSSSS(r1c1: number, r1c2: number, r2c1: number, r2c2: number): b2Mat22; // Construct this matrix using an angle. This matrix becomes an // orthonormal rotation matrix. static FromAngleRadians(radians: number): b2Mat22; // Initialize this matrix using scalars. SetSSSS(r1c1: number, r1c2: number, r2c1: number, r2c2: number): b2Mat22; // Initialize this matrix using columns. SetVV(c1: b2Vec2, c2: b2Vec2): b2Mat22; // Initialize this matrix using an angle. This matrix becomes an // orthonormal rotation matrix. SetAngle(radians: number): b2Mat22; Copy(other: b2Mat22): b2Mat22; // Set this to the identity matrix. SetIdentity(): b2Mat22; // Set this matrix to all zeros. SetZero(): b2Mat22; // Extract the angle from this matrix (assumed to be a rotation // matrix). GetAngle(): number; GetInverse(out: b2Mat22): b2Mat22; // Solve A * x = b, where b is a column vector. This is more // efficient than computing the inverse in one-shot cases. Solve(b_x: number, b_y: number, out: b2Vec2): b2Vec2; SelfAbs(): b2Mat22; SelfInv(): b2Mat22; SelfAddM(M: b2Mat22): b2Mat22; SelfSubM(M: b2Mat22): b2Mat22; } class b2Mat33 { // A 3-by-3 matrix. Stored in column-major order. constructor(); ex: b2Vec3; ey: b2Vec3; ez: b2Vec3; static IDENTITY: b2Mat33; Clone(): b2Mat33; SetVVV(c1: b2Vec3, c2: b2Vec3, c3: b2Vec3): b2Mat33; Copy(other: b2Mat33): b2Mat33; SetIdentity(): b2Mat33; // Set this matrix to all zeros. SetZero(): b2Mat33; SelfAddM(M: b2Mat33): b2Mat33; // Solve A * x = b, where b is a column vector. This is more // efficient than computing the inverse in one-shot cases. Solve33(b_x: number, b_y: number, b_z: number, out: b2Vec3): b2Vec3; // Solve A * x = b, where b is a column vector. This is more // efficient than computing the inverse in one-shot cases. Solve // only the upper 2-by-2 matrix equation. Solve22(b_x: number, b_y: number, out: b2Vec2): b2Vec2; // Get the inverse of this matrix as a 2-by-2. // Returns the zero matrix if singular. GetInverse22(M: b2Mat33): void; // Get the symmetric inverse of this matrix as a 3-by-3. // Returns the zero matrix if singular. GetSymInverse33(M: b2Mat33): void; } class b2Rot { // Rotation // Initialize from an angle in radians constructor(angle?: number); angle: number; s: number; c: number; static IDENTITY: b2Rot; Clone(): b2Rot; Copy(other: b2Rot): b2Rot; // Set using an angle in radians. SetAngle(angle: number): b2Rot; // Set to the identity rotation SetIdentity(): b2Rot; // Get the angle in radians GetAngle(): number; // Get the x-axis GetXAxis(out: b2Vec2): b2Vec2; // Get the y-axis GetYAxis(out: b2Vec2): b2Vec2; } class b2Transform { // A transform contains translation and rotation. It is used to // represent the position and orientation of rigid frames. constructor(); p: b2Vec2; q: b2Rot; static IDENTITY: b2Transform; Clone(): b2Transform; Copy(other: b2Transform): b2Transform; // Set this to the identity transform. SetIdentity(): b2Transform; // Set this based on the position and angle. SetPositionRotation(position: b2Vec2, q: b2Rot): b2Transform; SetPositionAngleRadians(pos: b2Vec2, a: number): b2Transform; SetPosition(position: b2Vec2): b2Transform; SetPositionXY(x: number, y: number): b2Transform; SetRotation(rotation: b2Rot): b2Transform; SetRotationAngleRadians(radians: number): b2Transform; GetPosition(): b2Vec2; GetRotation(): b2Rot; GetRotationAngle(): number; GetAngle(): number; } class b2Sweep { // This describes the motion of a body/shape for TOI computation. // Shapes are defined with respect to the body origin, which may // no coincide with the center of mass. However, to support dynamics // we must interpolate the center of mass position. constructor(); localCenter: b2Vec2; c0: b2Vec2; c: b2Vec2; a0: number; a: number; // Fraction of the current time step in the range [0,1] // c0 and a0 are the positions at alpha0. alpha0: number; Clone(): b2Sweep; Copy(other: b2Sweep): b2Sweep; // Get the interpolated transform at a specific time. GetTransform(xf: b2Transform, beta: number): b2Transform; // Advance the sweep forward, yielding a new initial state. Advance(alpha: number): void; // Normalize an angle in radians to be between -pi and pi // (actually 0 and 2*pi) Normalize(): void; } class b2ControllerEdge { // A controller edge is used to connect bodies and controllers // together in a bipartite graph. constructor(); controller: b2Controller; body: b2Body; prevBody: b2ControllerEdge; nextBody: b2ControllerEdge; prevController: b2ControllerEdge; nextController: b2ControllerEdge; } class b2Controller { // Base class for controllers. Controllers are a convience for // encapsulating common per-step functionality. constructor(); m_world: b2World; m_bodyList: b2ControllerEdge; m_bodyCount: number; m_prev: b2Controller; m_next: b2Controller; // Controllers override this to implement per-step // functionality. Step(step: b2TimeStep): void; // Controllers override this to provide debug drawing. Draw(debugDraw: b2Draw): void; // Get the next controller in the world's body list. GetNext(): b2Controller; // Get the previous controller in the world's body list. GetPrev(): b2Controller; // Get the parent world of this body. GetWorld(): b2World; // Get the attached body list GetBodyList(): b2ControllerEdge; // Adds a body to the controller list. AddBody(body: b2Body): void; // Removes a body from the controller list. RemoveBody(body: b2Body): void; // Removes all bodies from the controller list. Clear(): void; } class b2ConstantAccelController extends b2Controller { // Applies a force every frame constructor(); // The acceleration to apply A: b2Vec2; Step(step: b2TimeStep): void; // The force to apply F: b2Vec2; } class b2Jacobian { constructor(); linear: b2Vec2; angularA: number; angularB: number; SetZero(): b2Jacobian; Set(x: b2Vec2, a1: number, a2: number): b2Jacobian; } class b2JointEdge { // A joint edge is used to connect bodies and joints together in // a joint graph where each body is a node and each joint is an // edge. A joint edge belongs to a doubly linked list maintained // in each attached body. Each joint has two joint nodes, one // for each attached body. constructor(); other: b2Body; joint: b2Joint; prev: b2JointEdge; next: b2JointEdge; } class b2JointDef { // Joint definitions are used to construct joints. constructor(type: b2JointType); // The joint type is set automatically for concrete joint types. type: b2JointType; // Use this to attach application specific data to your joints. userData: any; // The first attached body. bodyA: b2Body; // The second attached body. bodyB: b2Body; // Set this flag to true if the attached bodies should collide. collideConnected: boolean; } class b2Joint { // The base joint class. Joints are used to constraint two // bodies together in various fashions. Some joints also feature // limits and motors. constructor(); m_type: b2JointType; m_prev: b2Joint; m_next: b2Joint; m_edgeA: b2JointEdge; m_edgeB: b2JointEdge; m_bodyA: b2Body; m_bodyB: b2Body; m_index: number; m_islandFlag: boolean; m_collideConnected: boolean; m_userData: any; // Get the anchor point on bodyA in world coordinates. GetAnchorA(out: b2Vec2): b2Vec2; // Get the anchor point on bodyB in world coordinates. GetAnchorB(out: b2Vec2): b2Vec2; // Get the reaction force on bodyB at the joint anchor in // Newtons. GetReactionForce(inv_dt: number, out: b2Vec2): b2Vec2; // Get the reaction torque on bodyB in N*m. GetReactionTorque(inv_dt: number): number; InitVelocityConstraints(data: b2SolverData): void; SolveVelocityConstraints(data: b2SolverData): void; // This returns true if the position errors are within // tolerance. SolvePositionConstraints(data: b2SolverData): boolean; // Get the type of the concrete joint. GetType(): b2JointType; // Get the first body attached to this joint. GetBodyA(): b2Body; // Get the second body attached to this joint. GetBodyB(): b2Body; // Get the next joint the world joint list. GetNext(): b2Joint; // Get the user data pointer. GetUserData(): any; // Set the user data pointer. SetUserData(data: any): void; // Get collide connected. // Note: modifying the collide connect flag won't work correctly // because the flag is only checked when fixture AABBs begin to // overlap. GetCollideConnected(): boolean; // Dump this joint to the log file. Dump(): void; // Short-cut function to determine if either body is inactive. IsActive(): boolean; // Shift the origin for any points stored in world coordinates. ShiftOrigin(newOrigin: b2Vec2): void; } class b2RevoluteJointDef extends b2JointDef { // Revolute joint definition. This requires defining an anchor // point where the bodies are joined. The definition uses local // anchor points so that the initial configuration can violate // the constraint slightly. You also need to specify the initial // relative angle for joint limits. This helps when saving and // loading a game. // The local anchor points are measured from the body's origin // rather than the center of mass because: // 1. you might not know where the center of mass will be. // 2. if you add/remove shapes from a body and recompute the // mass, the joints will be broken. constructor(); // The local anchor point relative to bodyA's origin. localAnchorA: b2Vec2; // The local anchor point relative to bodyB's origin. localAnchorB: b2Vec2; // The bodyB angle minus bodyA angle in the reference state // (radians). referenceAngle: number; // A flag to enable joint limits. enableLimit: boolean; // The lower angle for the joint limit (radians). lowerAngle: number; // The upper angle for the joint limit (radians). upperAngle: number; // A flag to enable the joint motor. enableMotor: boolean; // The desired motor speed. Usually in radians per second. motorSpeed: number; // The maximum motor torque used to achieve the desired motor // speed. // Usually in N-m. maxMotorTorque: number; Initialize(bA: b2Body, bB: b2Body, anchor: b2Vec2): void; } class b2RevoluteJoint extends b2Joint { // A revolute joint constrains two bodies to share a common // point while they are free to rotate about the point. The // relative rotation about the shared point is the joint angle. // You can limit the relative rotation with a joint limit that // specifies a lower and upper angle. You can use a motor to // drive the relative rotation about the shared point. A maximum // motor torque is provided so that infinite forces are not // generated. constructor(def: b2RevoluteJointDef); m_localAnchorA: b2Vec2; m_localAnchorB: b2Vec2; m_impulse: b2Vec3; m_motorImpulse: number; m_enableMotor: boolean; m_maxMotorTorque: number; m_motorSpeed: number; m_enableLimit: boolean; m_referenceAngle: number; m_lowerAngle: number; m_upperAngle: number; m_indexA: number; m_indexB: number; m_rA: b2Vec2; m_rB: b2Vec2; m_localCenterA: b2Vec2; m_localCenterB: b2Vec2; m_invMassA: number; m_invMassB: number; m_invIA: number; m_invIB: number; m_mass: b2Mat33; m_motorMass: number; m_limitState: b2LimitState; m_qA: b2Rot; m_qB: b2Rot; m_lalcA: b2Vec2; m_lalcB: b2Vec2; m_K: b2Mat22; InitVelocityConstraints(data: b2SolverData): void; SolveVelocityConstraints(data: b2SolverData): void; SolvePositionConstraints(data: b2SolverData): boolean; GetAnchorA(out: b2Vec2): b2Vec2; GetAnchorB(out: b2Vec2): b2Vec2; // Get the reaction force given the inverse time step. // Unit is N. GetReactionForce(inv_dt: number, out: b2Vec2): b2Vec2; // Get the reaction torque due to the joint limit given the // inverse time step. // Unit is N*m. GetReactionTorque(inv_dt: number): number; // The local anchor point relative to bodyA's origin. GetLocalAnchorA(out: b2Vec2): b2Vec2; // The local anchor point relative to bodyB's origin. GetLocalAnchorB(out?: b2Vec2): b2Vec2; // Get the reference angle. GetReferenceAngle(): number; GetJointAngleRadians(): number; GetJointSpeed(): number; IsMotorEnabled(): boolean; EnableMotor(flag: boolean): void; // Get the current motor torque given the inverse time step. // Unit is N*m. GetMotorTorque(inv_dt: number): number; GetMotorSpeed(): number; SetMaxMotorTorque(torque: number): void; GetMaxMotorTorque(): number; IsLimitEnabled(): boolean; EnableLimit(flag: boolean): void; GetLowerLimit(): number; GetUpperLimit(): number; SetLimits(lower: number, upper: number): void; SetMotorSpeed(speed: number): void; // Dump to b2Log. Dump(): void; } class b2PrismaticJointDef extends b2JointDef { // Prismatic joint definition. This requires defining a line of // motion using an axis and an anchor point. The definition uses // local anchor points and a local axis so that the initial // configuration can violate the constraint slightly. The joint // translation is zero when the local anchor points coincide in // world space. Using local anchors and a local axis helps when // saving and loading a game. constructor(); // The local anchor point relative to bodyA's origin. localAnchorA: b2Vec2; // The local anchor point relative to bodyB's origin. localAnchorB: b2Vec2; // The local translation unit axis in bodyA. localAxisA: b2Vec2; // The constrained angle between the bodies: bodyB_angle - // bodyA_angle. referenceAngle: number; // Enable/disable the joint limit. enableLimit: boolean; // The lower translation limit, usually in meters. lowerTranslation: number; // The upper translation limit, usually in meters. upperTranslation: number; // Enable/disable the joint motor. enableMotor: boolean; // The maximum motor torque, usually in N-m. maxMotorForce: number; // The desired motor speed in radians per second. motorSpeed: number; // Initialize the bodies, anchors, axis, and reference angle // using the world anchor and unit world axis. Initialize(bA: b2Body, bB: b2Body, anchor: b2Vec2, axis: b2Vec2): void; } class b2PrismaticJoint extends b2Joint { // A prismatic joint. This joint provides one degree of freedom: // translation along an axis fixed in bodyA. Relative rotation // is prevented. You can use a joint limit to restrict the range // of motion and a joint motor to drive the motion or to model // joint friction. constructor(def: b2PrismaticJointDef); m_localAnchorA: b2Vec2; m_localAnchorB: b2Vec2; m_localXAxisA: b2Vec2; m_localYAxisA: b2Vec2; m_referenceAngle: number; m_impulse: b2Vec3; m_motorImpulse: number; m_lowerTranslation: number; m_upperTranslation: number; m_maxMotorForce: number; m_motorSpeed: number; m_enableLimit: boolean; m_enableMotor: boolean; m_limitState: b2LimitState; m_indexA: number; m_indexB: number; m_localCenterA: b2Vec2; m_localCenterB: b2Vec2; m_invMassA: number; m_invMassB: number; m_invIA: number; m_invIB: number; m_axis: b2Vec2; m_perp: b2Vec2; m_s1: number; m_s2: number; m_a1: number; m_a2: number; m_K: b2Mat33; m_K3: b2Mat33; m_K2: b2Mat22; m_motorMass: number; m_qA: b2Rot; m_qB: b2Rot; m_lalcA: b2Vec2; m_lalcB: b2Vec2; m_rA: b2Vec2; m_rB: b2Vec2; InitVelocityConstraints(data: b2SolverData): void; SolveVelocityConstraints(data: b2SolverData): void; SolvePositionConstraints(data: b2SolverData): boolean; GetAnchorA(out: b2Vec2): b2Vec2; GetAnchorB(out: b2Vec2): b2Vec2; GetReactionForce(inv_dt: number, out: b2Vec2): b2Vec2; GetReactionTorque(inv_dt: number): number; // The local anchor point relative to bodyA's origin. GetLocalAnchorA(out: b2Vec2): b2Vec2; // The local anchor point relative to bodyB's origin. GetLocalAnchorB(out: b2Vec2): b2Vec2; // The local joint axis relative to bodyA. GetLocalAxisA(out: b2Vec2): b2Vec2; // Get the reference angle. GetReferenceAngle(): number; GetJointTranslation(): number; GetJointSpeed(): number; IsLimitEnabled(): boolean; EnableLimit(flag: boolean): void; GetLowerLimit(): number; GetUpperLimit(): number; SetLimits(upper: number, lower: number): void; IsMotorEnabled(): boolean; EnableMotor(flag: boolean): void; SetMotorSpeed(speed: number): void; GetMotorSpeed(): number; SetMaxMotorForce(force: number): void; GetMaxMotorForce(): number; GetMotorForce(inv_dt: number): number; // Dump to b2Log Dump(): void; } class b2GearJointDef extends b2JointDef { // Gear joint definition. This definition requires two existing // revolute or prismatic joints (any combination will work). constructor(); // The first revolute/prismatic joint attached to the gear // joint. joint1: b2Joint; // The second revolute/prismatic joint attached to the gear // joint. joint2: b2Joint; // The gear ratio. ratio: number; } class b2GearJoint extends b2Joint { // A gear joint is used to connect two joints together. Either // joint can be a revolute or prismatic joint. You specify a // gear ratio to bind the motions together: // coordinateA + ratio * coordinateB = constant // The ratio can be negative or positive. If one joint is a // revolute joint and the other joint is a prismatic joint, then // the ratio will have units of length or units of 1/length. // warning You have to manually destroy the gear joint if jointA // or jointB is destroyed. constructor(def: b2GearJointDef); m_joint1: b2Joint; m_joint2: b2Joint; m_typeA: b2JointType; m_typeB: b2JointType; m_bodyC: b2Body; m_bodyD: b2Body; m_localAnchorA: b2Vec2; m_localAnchorB: b2Vec2; m_localAnchorC: b2Vec2; m_localAnchorD: b2Vec2; m_localAxisC: b2Vec2; m_localAxisD: b2Vec2; m_referenceAngleA: number; m_referenceAngleB: number; m_constant: number; m_ratio: number; m_impulse: number; m_indexA: number; m_indexB: number; m_indexC: number; m_indexD: number; m_lcA: b2Vec2; m_lcB: b2Vec2; m_lcC: b2Vec2; m_lcD: b2Vec2; m_mA: number; m_mB: number; m_mC: number; m_mD: number; m_iA: number; m_iB: number; m_iC: number; m_iD: number; m_JvAC: b2Vec2; m_JvBD: b2Vec2; m_JwA: number; m_JwB: number; m_JwC: number; m_JwD: number; m_mass: number; m_qA: b2Rot; m_qB: b2Rot; m_qC: b2Rot; m_qD: b2Rot; m_lalcA: b2Vec2; m_lalcB: b2Vec2; m_lalcC: b2Vec2; m_lalcD: b2Vec2; InitVelocityConstraints(data: b2SolverData): void; SolveVelocityConstraints(data: b2SolverData): void; SolvePositionConstraints(data: b2SolverData): boolean; GetAnchorA(out: b2Vec2): b2Vec2; GetAnchorB(out: b2Vec2): b2Vec2; GetReactionForce(inv_dt: number, out: b2Vec2): b2Vec2; GetReactionTorque(inv_dt: number): number; // Get the first joint. GetJoint1(): b2Joint; // Get the second joint. GetJoint2(): b2Joint; GetRatio(): number; SetRatio(ratio: number): void; // Dump joint to dmLog Dump(): void; } class b2DistanceProxy { // A distance proxy is used by the GJK algorithm. // It encapsulates any shape. constructor(); m_buffer: Array<b2Vec2>; m_vertices: Array<b2Vec2>; m_count: number; m_radius: number; Reset(): b2DistanceProxy; // Initialize the proxy using the given shape. The shape must // remain in scope while the proxy is in use. SetShape(shape: b2Shape, index: number): void; // Get the supporting vertex index in the given direction. GetSupport(d: b2Vec2): number; // Get the supporting vertex in the given direction. GetSupportVertex(d: b2Vec2, out: b2Vec2): b2Vec2; // Get the vertex count. GetVertexCount(): number; // Get a vertex by index. Used by box2d.b2Distance. GetVertex(index: number): b2Vec2; } class b2SimplexCache { // Used to warm start box2d.b2Distance. // Set count to zero on first call. constructor(); metric: number; count: number; indexA: Array<number>; indexB: Array<number>; Reset(): b2SimplexCache; } class b2DistanceInput { // Input for box2d.b2Distance. // You have to option to use the shape radii in the computation. constructor(); proxyA: b2DistanceProxy; proxyB: b2DistanceProxy; transformA: b2Transform; transformB: b2Transform; useRadii: boolean; Reset(): b2DistanceInput; } class b2DistanceOutput { // Output for box2d.b2Distance. constructor(); pointA: b2Vec2; pointB: b2Vec2; distance: number; iterations: number; Reset(): b2DistanceOutput; } class b2SimplexVertex { constructor(); wA: b2Vec2; wB: b2Vec2; w: b2Vec2; a: number; indexA: number; indexB: number; Copy(other: b2SimplexVertex): b2SimplexVertex; } class b2Simplex { constructor(); m_v1: b2SimplexVertex; m_v2: b2SimplexVertex; m_v3: b2SimplexVertex; m_vertices: Array<b2SimplexVertex>; m_count: number; ReadCache(cache: b2SimplexCache, proxyA: b2DistanceProxy, transformA: b2Transform, proxyB: b2DistanceProxy, transformB: b2Transform): void; WriteCache(cache: b2SimplexCache): void;