brutal/Brutal.Box2D/Structs.gen.cs
Rian Drake b578433e37 first
2026-10-15 17:10:50 +13:00

4679 lines
158 KiB
C#

/*
* @brief Contains the Box2D classes, ported to unmanaged structs in C#.
*
* @warning This file is auto-generated by Brutal.Box2D.Generate.
* Do not edit this file directly.
* If you want to change the generated code, modify the generation rules.
*/
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
using Brutal.Numerics;
namespace Brutal.Box2DApi
{
/// Version numbering scheme.
/// See https://semver.org/
[StructLayout(LayoutKind.Explicit, Size = 12)]
public struct B2Version
{
/// Significant changes
[FieldOffset(0)]
public int Major;
/// Incremental changes
[FieldOffset(4)]
public int Minor;
/// Bug fixes
[FieldOffset(8)]
public int Revision;
}
/// Cosine and sine pair
/// This uses a custom implementation designed for cross-platform determinism
[StructLayout(LayoutKind.Explicit, Size = 8)]
public struct B2CosSin
{
/// cosine and sine
[FieldOffset(0)]
public float Cosine;
///
[FieldOffset(4)]
public float Sine;
}
/// 2D rotation
/// This is similar to using a complex number for rotation
[StructLayout(LayoutKind.Explicit, Size = 8)]
public partial struct B2Rot
{
/// Get the angle in radians in the range [-pi, pi]
public float GetAngle()
{
return Box2D.RotGetAngle(this);
}
/// Get the x-axis
public float2 GetXAxis()
{
return Box2D.RotGetXAxis(this);
}
/// Get the y-axis
public float2 GetYAxis()
{
return Box2D.RotGetYAxis(this);
}
/// cosine and sine
[FieldOffset(0)]
public float C;
/// cosine and sine
[FieldOffset(4)]
public float S;
}
/// A 2D rigid transform
[StructLayout(LayoutKind.Explicit, Size = 16)]
public partial struct B2Transform
{
///
[FieldOffset(0)]
public float2 P;
///
[FieldOffset(8)]
public B2Rot Q;
}
/// Axis-aligned bounding box
[StructLayout(LayoutKind.Explicit, Size = 16)]
public struct B2Aabb
{
///
[FieldOffset(0)]
public float2 LowerBound;
///
[FieldOffset(8)]
public float2 UpperBound;
}
/// separation = dot(normal, point) - offset
[StructLayout(LayoutKind.Explicit, Size = 12)]
public struct B2Plane
{
///
[FieldOffset(0)]
public float2 Normal;
///
[FieldOffset(8)]
public float Offset;
}
/// Used to warm start the GJK simplex. If you call this function multiple times with nearby
/// transforms this might improve performance. Otherwise you can zero initialize this.
/// The distance cache must be initialized to zero on the first call.
/// Users should generally just zero initialize this structure for each call.
[StructLayout(LayoutKind.Explicit, Size = 8)]
public unsafe struct B2SimplexCache
{
/// The number of stored simplex points
[FieldOffset(0)]
public ushort Count;
/// The cached simplex indices on shape A
[FieldOffset(2)]
public fixed byte IndexA[3];
/// The cached simplex indices on shape B
[FieldOffset(5)]
public fixed byte IndexB[3];
}
/// A convex hull. Used to create convex polygons.
/// WARNING: Do not modify these values directly, instead use b2ComputeHull()
[StructLayout(LayoutKind.Explicit, Size = 68)]
public struct B2Hull
{
/// The final points of the hull
[FieldOffset(0)]
public float2_8 Points;
/// The number of points
[FieldOffset(64)]
public int Count;
}
/// Low level ray cast input data
[StructLayout(LayoutKind.Explicit, Size = 20)]
public struct B2RayCastInput
{
/// Start point of the ray cast
[FieldOffset(0)]
public float2 Origin;
/// Translation of the ray cast
[FieldOffset(8)]
public float2 Translation;
/// The maximum fraction of the translation to consider, typically 1
[FieldOffset(16)]
public float MaxFraction;
}
/// A distance proxy is used by the GJK algorithm. It encapsulates any shape.
/// You can provide between 1 and B2_MAX_POLYGON_VERTICES and a radius.
[StructLayout(LayoutKind.Explicit, Size = 72)]
public struct B2ShapeProxy
{
/// The point cloud
[FieldOffset(0)]
public float2_8 Points;
/// The number of points. Must be greater than 0.
[FieldOffset(64)]
public int Count;
/// The external radius of the point cloud. May be zero.
[FieldOffset(68)]
public float Radius;
}
/// Low level shape cast input in generic form. This allows casting an arbitrary point
/// cloud wrap with a radius. For example, a circle is a single point with a non-zero radius.
/// A capsule is two points with a non-zero radius. A box is four points with a zero radius.
[StructLayout(LayoutKind.Explicit, Size = 88)]
public struct B2ShapeCastInput
{
/// A generic shape
[FieldOffset(0)]
public B2ShapeProxy Proxy;
/// The translation of the shape cast
[FieldOffset(72)]
public float2 Translation;
/// The maximum fraction of the translation to consider, typically 1
[FieldOffset(80)]
public float MaxFraction;
/// Allow shape cast to encroach when initially touching. This only works if the radius is greater than zero.
[FieldOffset(84)]
public Bool8 CanEncroach;
}
/// Low level ray cast or shape-cast output data. Returns a zero fraction and normal in the case of initial overlap.
[StructLayout(LayoutKind.Explicit, Size = 28)]
public struct B2CastOutput
{
/// The surface normal at the hit point
[FieldOffset(0)]
public float2 Normal;
/// The surface hit point
[FieldOffset(8)]
public float2 Point;
/// The fraction of the input translation at collision
[FieldOffset(16)]
public float Fraction;
/// The number of iterations used
[FieldOffset(20)]
public int Iterations;
/// Did the cast hit?
[FieldOffset(24)]
public Bool8 Hit;
}
/// This holds the mass data computed for a shape.
[StructLayout(LayoutKind.Explicit, Size = 16)]
public struct B2MassData
{
/// The mass of the shape, usually in kilograms.
[FieldOffset(0)]
public float Mass;
/// The position of the shape's centroid relative to the shape's origin.
[FieldOffset(4)]
public float2 Center;
/// The rotational inertia of the shape about the local origin.
[FieldOffset(12)]
public float RotationalInertia;
}
/// A solid circle
[StructLayout(LayoutKind.Explicit, Size = 12)]
public struct B2Circle
{
/// The local center
[FieldOffset(0)]
public float2 Center;
/// The radius
[FieldOffset(8)]
public float Radius;
}
/// A solid capsule can be viewed as two semicircles connected
/// by a rectangle.
[StructLayout(LayoutKind.Explicit, Size = 20)]
public struct B2Capsule
{
/// Local center of the first semicircle
[FieldOffset(0)]
public float2 Center1;
/// Local center of the second semicircle
[FieldOffset(8)]
public float2 Center2;
/// The radius of the semicircles
[FieldOffset(16)]
public float Radius;
}
/// A solid convex polygon. It is assumed that the interior of the polygon is to
/// the left of each edge.
/// Polygons have a maximum number of vertices equal to B2_MAX_POLYGON_VERTICES.
/// In most cases you should not need many vertices for a convex polygon.
/// WARNING: DO NOT fill this out manually, instead use a helper function like b2MakePolygon or b2MakeBox.
[StructLayout(LayoutKind.Explicit, Size = 144)]
public struct B2Polygon
{
/// The polygon vertices
[FieldOffset(0)]
public float2_8 Vertices;
/// The outward normal vectors of the polygon sides
[FieldOffset(64)]
public float2_8 Normals;
/// The centroid of the polygon
[FieldOffset(128)]
public float2 Centroid;
/// The external radius for rounded polygons
[FieldOffset(136)]
public float Radius;
/// The number of polygon vertices
[FieldOffset(140)]
public int Count;
}
/// A line segment with two-sided collision.
[StructLayout(LayoutKind.Explicit, Size = 16)]
public struct B2Segment
{
/// The first point
[FieldOffset(0)]
public float2 Point1;
/// The second point
[FieldOffset(8)]
public float2 Point2;
}
/// A line segment with one-sided collision. Only collides on the right side.
/// Several of these are generated for a chain shape.
/// ghost1 -> point1 -> point2 -> ghost2
[StructLayout(LayoutKind.Explicit, Size = 36)]
public struct B2ChainSegment
{
/// The tail ghost vertex
[FieldOffset(0)]
public float2 Ghost1;
/// The line segment
[FieldOffset(8)]
public B2Segment Segment;
/// The head ghost vertex
[FieldOffset(24)]
public float2 Ghost2;
/// The owning chain shape index (internal usage only)
[FieldOffset(32)]
public int ChainId;
}
/// Result of computing the distance between two line segments
[StructLayout(LayoutKind.Explicit, Size = 28)]
public struct B2SegmentDistanceResult
{
/// The closest point on the first segment
[FieldOffset(0)]
public float2 Closest1;
/// The closest point on the second segment
[FieldOffset(8)]
public float2 Closest2;
/// The barycentric coordinate on the first segment
[FieldOffset(16)]
public float Fraction1;
/// The barycentric coordinate on the second segment
[FieldOffset(20)]
public float Fraction2;
/// The squared distance between the closest points
[FieldOffset(24)]
public float DistanceSquared;
}
/// Input for b2ShapeDistance
[StructLayout(LayoutKind.Explicit, Size = 180)]
public struct B2DistanceInput
{
/// The proxy for shape A
[FieldOffset(0)]
public B2ShapeProxy ProxyA;
/// The proxy for shape B
[FieldOffset(72)]
public B2ShapeProxy ProxyB;
/// The world transform for shape A
[FieldOffset(144)]
public B2Transform TransformA;
/// The world transform for shape B
[FieldOffset(160)]
public B2Transform TransformB;
/// Should the proxy radius be considered?
[FieldOffset(176)]
public Bool8 UseRadii;
}
/// Output for b2ShapeDistance
[StructLayout(LayoutKind.Explicit, Size = 36)]
public struct B2DistanceOutput
{
/// Closest point on shapeA
[FieldOffset(0)]
public float2 PointA;
/// Closest point on shapeB
[FieldOffset(8)]
public float2 PointB;
/// Normal vector that points from A to B. Invalid if distance is zero.
[FieldOffset(16)]
public float2 Normal;
/// The final distance, zero if overlapped
[FieldOffset(24)]
public float Distance;
/// Number of GJK iterations used
[FieldOffset(28)]
public int Iterations;
/// The number of simplexes stored in the simplex array
[FieldOffset(32)]
public int SimplexCount;
}
/// Simplex vertex for debugging the GJK algorithm
[StructLayout(LayoutKind.Explicit, Size = 36)]
public struct B2SimplexVertex
{
/// support point in proxyA
[FieldOffset(0)]
public float2 WA;
/// support point in proxyB
[FieldOffset(8)]
public float2 WB;
/// wB - wA
[FieldOffset(16)]
public float2 W;
/// barycentric coordinate for closest point
[FieldOffset(24)]
public float A;
/// wA index
[FieldOffset(28)]
public int IndexA;
/// wB index
[FieldOffset(32)]
public int IndexB;
}
/// Simplex from the GJK algorithm
[StructLayout(LayoutKind.Explicit, Size = 112)]
public struct B2Simplex
{
/// vertices
[FieldOffset(0)]
public B2SimplexVertex V1;
/// vertices
[FieldOffset(36)]
public B2SimplexVertex V2;
/// vertices
[FieldOffset(72)]
public B2SimplexVertex V3;
/// number of valid vertices
[FieldOffset(108)]
public int Count;
}
/// Input parameters for b2ShapeCast
[StructLayout(LayoutKind.Explicit, Size = 192)]
public struct B2ShapeCastPairInput
{
/// The proxy for shape A
[FieldOffset(0)]
public B2ShapeProxy ProxyA;
/// The proxy for shape B
[FieldOffset(72)]
public B2ShapeProxy ProxyB;
/// The world transform for shape A
[FieldOffset(144)]
public B2Transform TransformA;
/// The world transform for shape B
[FieldOffset(160)]
public B2Transform TransformB;
/// The translation of shape B
[FieldOffset(176)]
public float2 TranslationB;
/// The fraction of the translation to consider, typically 1
[FieldOffset(184)]
public float MaxFraction;
/// Allows shapes with a radius to move slightly closer if already touching
[FieldOffset(188)]
public Bool8 CanEncroach;
}
/// This describes the motion of a body/shape for TOI computation. Shapes are defined with respect to the body origin,
/// which may not coincide with the center of mass. However, to support dynamics we must interpolate the center of mass
/// position.
[StructLayout(LayoutKind.Explicit, Size = 40)]
public struct B2Sweep
{
/// Local center of mass position
[FieldOffset(0)]
public float2 LocalCenter;
/// Starting center of mass world position
[FieldOffset(8)]
public float2 C1;
/// Ending center of mass world position
[FieldOffset(16)]
public float2 C2;
/// Starting world rotation
[FieldOffset(24)]
public B2Rot Q1;
/// Ending world rotation
[FieldOffset(32)]
public B2Rot Q2;
}
/// Input parameters for b2TimeOfImpact
[StructLayout(LayoutKind.Explicit, Size = 228)]
public struct B2ToiInput
{
/// The proxy for shape A
[FieldOffset(0)]
public B2ShapeProxy ProxyA;
/// The proxy for shape B
[FieldOffset(72)]
public B2ShapeProxy ProxyB;
/// The movement of shape A
[FieldOffset(144)]
public B2Sweep SweepA;
/// The movement of shape B
[FieldOffset(184)]
public B2Sweep SweepB;
/// Defines the sweep interval [0, maxFraction]
[FieldOffset(224)]
public float MaxFraction;
}
/// Output parameters for b2TimeOfImpact.
[StructLayout(LayoutKind.Explicit, Size = 8)]
public struct B2ToiOutput
{
/// The type of result
[FieldOffset(0)]
public B2ToiState State;
/// The sweep time of the collision
[FieldOffset(4)]
public float Fraction;
}
/// A manifold point is a contact point belonging to a contact manifold.
/// It holds details related to the geometry and dynamics of the contact points.
/// Box2D uses speculative collision so some contact points may be separated.
/// You may use the totalNormalImpulse to determine if there was an interaction during
/// the time step.
[StructLayout(LayoutKind.Explicit, Size = 48)]
public struct B2ManifoldPoint
{
/// Location of the contact point in world space. Subject to precision loss at large coordinates.
/// NOTE: Should only be used for debugging.
[FieldOffset(0)]
public float2 Point;
/// Location of the contact point relative to shapeA's origin in world space
/// NOTE: When used internally to the Box2D solver, this is relative to the body center of mass.
[FieldOffset(8)]
public float2 AnchorA;
/// Location of the contact point relative to shapeB's origin in world space
/// NOTE: When used internally to the Box2D solver, this is relative to the body center of mass.
[FieldOffset(16)]
public float2 AnchorB;
/// The separation of the contact point, negative if penetrating
[FieldOffset(24)]
public float Separation;
/// The impulse along the manifold normal vector.
[FieldOffset(28)]
public float NormalImpulse;
/// The friction impulse
[FieldOffset(32)]
public float TangentImpulse;
/// The total normal impulse applied across sub-stepping and restitution. This is important
/// to identify speculative contact points that had an interaction in the time step.
[FieldOffset(36)]
public float TotalNormalImpulse;
/// Relative normal velocity pre-solve. Used for hit events. If the normal impulse is
/// zero then there was no hit. Negative means shapes are approaching.
[FieldOffset(40)]
public float NormalVelocity;
/// Uniquely identifies a contact point between two shapes
[FieldOffset(44)]
public ushort Id;
/// Did this contact point exist the previous step?
[FieldOffset(46)]
public Bool8 Persisted;
}
/// A contact manifold describes the contact points between colliding shapes.
/// NOTE: Box2D uses speculative collision so some contact points may be separated.
[StructLayout(LayoutKind.Explicit, Size = 112)]
public struct B2Manifold
{
/// The unit normal vector in world space, points from shape A to bodyB
[FieldOffset(0)]
public float2 Normal;
/// Angular impulse applied for rolling resistance. N * m * s = kg * m^2 / s
[FieldOffset(8)]
public float RollingImpulse;
/// The manifold points, up to two are possible in 2D
[FieldOffset(12)]
public B2ManifoldPoint_2 Points;
/// The number of contacts points, will be 0, 1, or 2
[FieldOffset(108)]
public int PointCount;
}
/// The dynamic tree structure. This should be considered private data.
/// It is placed here for performance reasons.
[StructLayout(LayoutKind.Explicit, Size = 72)]
public unsafe struct B2DynamicTree
{
/// Destroy the tree, freeing the node pool.
public void Destroy()
{
Box2D.DynamicTreeDestroy(this);
}
/// Create a proxy. Provide an AABB and a userData value.
public int CreateProxy(B2Aabb aabb, ulong categoryBits, ulong userData)
{
return Box2D.DynamicTreeCreateProxy(this, aabb, categoryBits, userData);
}
/// Destroy a proxy. This asserts if the id is invalid.
public void DestroyProxy(int proxyId)
{
Box2D.DynamicTreeDestroyProxy(this, proxyId);
}
/// Move a proxy to a new AABB by removing and reinserting into the tree.
public void MoveProxy(int proxyId, B2Aabb aabb)
{
Box2D.DynamicTreeMoveProxy(this, proxyId, aabb);
}
/// Enlarge a proxy and enlarge ancestors as necessary.
public void EnlargeProxy(int proxyId, B2Aabb aabb)
{
Box2D.DynamicTreeEnlargeProxy(this, proxyId, aabb);
}
/// Modify the category bits on a proxy. This is an expensive operation.
public void SetCategoryBits(int proxyId, ulong categoryBits)
{
Box2D.DynamicTreeSetCategoryBits(this, proxyId, categoryBits);
}
/// Get the category bits on a proxy.
public ulong GetCategoryBits(int proxyId)
{
return Box2D.DynamicTreeGetCategoryBits(this, proxyId);
}
/// Query an AABB for overlapping proxies. The callback class is called for each proxy that overlaps the supplied AABB.
/// RETURN: performance data
public B2TreeStats Query(B2Aabb aabb, ulong maskBits, B2TreeQueryCallbackFcn callback, nint context)
{
return Box2D.DynamicTreeQuery(this, aabb, maskBits, callback, context);
}
/// 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.
/// Bit-wise filtering using mask bits can greatly improve performance in some scenarios.
/// However, this filtering may be approximate, so the user should still apply filtering to results.
/// <param name="input">the ray cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1) </param>
/// <param name="maskBits">mask bit hint: `bool accept = (maskBits &amp; node-&gt;categoryBits) != 0;` </param>
/// <param name="callback">a callback class that is called for each proxy that is hit by the ray </param>
/// <param name="context">user context that is passed to the callback </param>
/// RETURN: performance data
public B2TreeStats RayCast(
in B2RayCastInput input,
ulong maskBits,
B2TreeRayCastCallbackFcn callback,
nint context
)
{
return Box2D.DynamicTreeRayCast(this, input, maskBits, callback, context);
}
/// 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 name="input">the ray cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1). </param>
/// <param name="maskBits">filter bits: `bool accept = (maskBits &amp; node-&gt;categoryBits) != 0;` </param>
/// <param name="callback">a callback class that is called for each proxy that is hit by the shape </param>
/// <param name="context">user context that is passed to the callback </param>
/// RETURN: performance data
public B2TreeStats ShapeCast(
in B2ShapeCastInput input,
ulong maskBits,
B2TreeShapeCastCallbackFcn callback,
nint context
)
{
return Box2D.DynamicTreeShapeCast(this, input, maskBits, callback, context);
}
/// Get the height of the binary tree.
public int GetHeight()
{
return Box2D.DynamicTreeGetHeight(this);
}
/// Get the ratio of the sum of the node areas to the root area.
public float GetAreaRatio()
{
return Box2D.DynamicTreeGetAreaRatio(this);
}
/// Get the bounding box that contains the entire tree
public B2Aabb GetRootBounds()
{
return Box2D.DynamicTreeGetRootBounds(this);
}
/// Get the number of proxies created
public int GetProxyCount()
{
return Box2D.DynamicTreeGetProxyCount(this);
}
/// Rebuild the tree while retaining subtrees that haven&apos;t changed. Returns the number of boxes sorted.
public int Rebuild(Bool8 fullBuild)
{
return Box2D.DynamicTreeRebuild(this, fullBuild);
}
/// Get the number of bytes used by this tree
public int GetByteCount()
{
return Box2D.DynamicTreeGetByteCount(this);
}
/// Get proxy user data
public ulong GetUserData(int proxyId)
{
return Box2D.DynamicTreeGetUserData(this, proxyId);
}
/// Get the AABB of a proxy
public B2Aabb GetAabb(int proxyId)
{
return Box2D.DynamicTreeGetAabb(this, proxyId);
}
/// Validate this tree. For testing.
public void Validate()
{
Box2D.DynamicTreeValidate(this);
}
/// Validate this tree has no enlarged AABBs. For testing.
public void ValidateNoEnlarged()
{
Box2D.DynamicTreeValidateNoEnlarged(this);
}
/// The tree nodes
[FieldOffset(0)]
public B2TreeNode* Nodes;
/// The root index
[FieldOffset(8)]
public int Root;
/// The number of nodes
[FieldOffset(12)]
public int NodeCount;
/// The allocated node space
[FieldOffset(16)]
public int NodeCapacity;
/// Node free list
[FieldOffset(20)]
public int FreeList;
/// Number of proxies created
[FieldOffset(24)]
public int ProxyCount;
/// Leaf indices for rebuild
[FieldOffset(32)]
public int* LeafIndices;
/// Leaf bounding boxes for rebuild
[FieldOffset(40)]
public B2Aabb* LeafBoxes;
/// Leaf bounding box centers for rebuild
[FieldOffset(48)]
public float2* LeafCenters;
/// Bins for sorting during rebuild
[FieldOffset(56)]
public int* BinIndices;
/// Allocated space for rebuilding
[FieldOffset(64)]
public int RebuildCapacity;
}
///
public struct B2TreeNode { }
/// These are performance results returned by dynamic tree queries.
[StructLayout(LayoutKind.Explicit, Size = 8)]
public struct B2TreeStats
{
/// Number of internal nodes visited during the query
[FieldOffset(0)]
public int NodeVisits;
/// Number of leaf nodes visited during the query
[FieldOffset(4)]
public int LeafVisits;
}
/// These are the collision planes returned from b2World_CollideMover
[StructLayout(LayoutKind.Explicit, Size = 24)]
public struct B2PlaneResult
{
/// The collision plane between the mover and a convex shape
[FieldOffset(0)]
public B2Plane Plane;
/// The collision point on the shape.
[FieldOffset(12)]
public float2 Point;
/// Did the collision register a hit? If not this plane should be ignored.
[FieldOffset(20)]
public Bool8 Hit;
}
/// These are collision planes that can be fed to b2SolvePlanes. Normally
/// this is assembled by the user from plane results in b2PlaneResult
[StructLayout(LayoutKind.Explicit, Size = 24)]
public struct B2CollisionPlane
{
/// The collision plane between the mover and some shape
[FieldOffset(0)]
public B2Plane Plane;
/// Setting this to FLT_MAX makes the plane as rigid as possible. Lower values can
/// make the plane collision soft. Usually in meters.
[FieldOffset(12)]
public float PushLimit;
/// The push on the mover determined by b2SolvePlanes. Usually in meters.
[FieldOffset(16)]
public float Push;
/// Indicates if b2ClipVector should clip against this plane. Should be false for soft collision.
[FieldOffset(20)]
public Bool8 ClipVelocity;
}
/// Result returned by b2SolvePlanes
[StructLayout(LayoutKind.Explicit, Size = 12)]
public struct B2PlaneSolverResult
{
/// The translation of the mover
[FieldOffset(0)]
public float2 Translation;
/// The number of iterations used by the plane solver. For diagnostics.
[FieldOffset(8)]
public int IterationCount;
}
/// World id references a world instance. This should be treated as an opaque handle.
[StructLayout(LayoutKind.Explicit, Size = 4)]
public readonly partial record struct B2World : IDisposable
{
/// Destroy a world
public void Dispose()
{
Box2D.Dispose(this);
}
/// World id validation. Provides validation for up to 64K allocations.
public Bool8 IsValid()
{
return Box2D.WorldIsValid(this);
}
/// Simulate a world for one time step. This performs collision detection, integration, and constraint solution.
/// <param name="timeStep">The amount of time to simulate, this should be a fixed number. Usually 1/60. </param>
/// <param name="subStepCount">The number of sub-steps, increasing the sub-step count can increase accuracy. Usually 4. </param>
public void Step(float timeStep, int subStepCount)
{
Box2D.WorldStep(this, timeStep, subStepCount);
}
/// Call this to draw shapes and other debug draw data
public void Draw(in B2DebugDraw draw)
{
Box2D.WorldDraw(this, draw);
}
/// Get the body events for the current time step. The event data is transient. Do not store a reference to this data.
public B2BodyEvents GetBodyEvents()
{
return Box2D.WorldGetBodyEvents(this);
}
/// Get sensor events for the current time step. The event data is transient. Do not store a reference to this data.
public B2SensorEvents GetSensorEvents()
{
return Box2D.WorldGetSensorEvents(this);
}
/// Get contact events for this current time step. The event data is transient. Do not store a reference to this data.
public B2ContactEvents GetContactEvents()
{
return Box2D.WorldGetContactEvents(this);
}
/// Overlap test for all shapes that *potentially* overlap the provided AABB
public B2TreeStats OverlapAabb(B2Aabb aabb, B2QueryFilter filter, B2OverlapResultFcn fcn, nint context)
{
return Box2D.WorldOverlapAabb(this, aabb, filter, fcn, context);
}
/// Overlap test for all shapes that overlap the provided shape proxy.
public B2TreeStats OverlapShape(
in B2ShapeProxy proxy,
B2QueryFilter filter,
B2OverlapResultFcn fcn,
nint context
)
{
return Box2D.WorldOverlapShape(this, proxy, filter, fcn, context);
}
/// Cast a ray into the world to collect shapes in the path of the ray.
/// Your callback function controls whether you get the closest point, any point, or n-points.
/// NOTE: The callback function may receive shapes in any order
/// <param name="origin">The start point of the ray </param>
/// <param name="translation">The translation of the ray from the start point to the end point </param>
/// <param name="filter">Contains bit flags to filter unwanted shapes from the results </param>
/// <param name="fcn">A user implemented callback function </param>
/// <param name="context">A user context that is passed along to the callback function </param>
/// RETURN: traversal performance counters
public B2TreeStats CastRay(
float2 origin,
float2 translation,
B2QueryFilter filter,
B2CastResultFcn fcn,
nint context
)
{
return Box2D.WorldCastRay(this, origin, translation, filter, fcn, context);
}
/// Cast a ray into the world to collect the closest hit. This is a convenience function. Ignores initial overlap.
/// This is less general than b2World_CastRay() and does not allow for custom filtering.
public B2RayResult CastRayClosest(float2 origin, float2 translation, B2QueryFilter filter)
{
return Box2D.WorldCastRayClosest(this, origin, translation, filter);
}
/// Cast a shape through the world. Similar to a cast ray except that a shape is cast instead of a point.
/// SEE: b2World_CastRay
public B2TreeStats CastShape(
in B2ShapeProxy proxy,
float2 translation,
B2QueryFilter filter,
B2CastResultFcn fcn,
nint context
)
{
return Box2D.WorldCastShape(this, proxy, translation, filter, fcn, context);
}
/// Cast a capsule mover through the world. This is a special shape cast that handles sliding along other shapes while reducing
/// clipping.
public float CastMover(in B2Capsule mover, float2 translation, B2QueryFilter filter)
{
return Box2D.WorldCastMover(this, mover, translation, filter);
}
/// Collide a capsule mover with the world, gathering collision planes that can be fed to b2SolvePlanes. Useful for
/// kinematic character movement.
public void CollideMover(in B2Capsule mover, B2QueryFilter filter, B2PlaneResultFcn fcn, nint context)
{
Box2D.WorldCollideMover(this, mover, filter, fcn, context);
}
/// Enable/disable sleep. If your application does not need sleeping, you can gain some performance
/// by disabling sleep completely at the world level.
/// SEE: b2WorldDef
public void EnableSleeping(Bool8 flag)
{
Box2D.WorldEnableSleeping(this, flag);
}
/// Is body sleeping enabled?
public Bool8 IsSleepingEnabled()
{
return Box2D.WorldIsSleepingEnabled(this);
}
/// Enable/disable continuous collision between dynamic and static bodies. Generally you should keep continuous
/// collision enabled to prevent fast moving objects from going through static objects. The performance gain from
/// disabling continuous collision is minor.
/// SEE: b2WorldDef
public void EnableContinuous(Bool8 flag)
{
Box2D.WorldEnableContinuous(this, flag);
}
/// Is continuous collision enabled?
public Bool8 IsContinuousEnabled()
{
return Box2D.WorldIsContinuousEnabled(this);
}
/// Adjust the restitution threshold. It is recommended not to make this value very small
/// because it will prevent bodies from sleeping. Usually in meters per second.
/// SEE: b2WorldDef
public void SetRestitutionThreshold(float value)
{
Box2D.WorldSetRestitutionThreshold(this, value);
}
/// Get the the restitution speed threshold. Usually in meters per second.
public float GetRestitutionThreshold()
{
return Box2D.WorldGetRestitutionThreshold(this);
}
/// Adjust the hit event threshold. This controls the collision speed needed to generate a b2ContactHitEvent.
/// Usually in meters per second.
/// SEE: b2WorldDef::hitEventThreshold
public void SetHitEventThreshold(float value)
{
Box2D.WorldSetHitEventThreshold(this, value);
}
/// Get the the hit event speed threshold. Usually in meters per second.
public float GetHitEventThreshold()
{
return Box2D.WorldGetHitEventThreshold(this);
}
/// Register the custom filter callback. This is optional.
public void SetCustomFilterCallback(B2CustomFilterFcn fcn, nint context)
{
Box2D.WorldSetCustomFilterCallback(this, fcn, context);
}
/// Register the pre-solve callback. This is optional.
public void SetPreSolveCallback(B2PreSolveFcn fcn, nint context)
{
Box2D.WorldSetPreSolveCallback(this, fcn, context);
}
/// Set the gravity vector for the entire world. Box2D has no concept of an up direction and this
/// is left as a decision for the application. Usually in m/s^2.
/// SEE: b2WorldDef
public void SetGravity(float2 gravity)
{
Box2D.WorldSetGravity(this, gravity);
}
/// Get the gravity vector
public float2 GetGravity()
{
return Box2D.WorldGetGravity(this);
}
/// Apply a radial explosion
/// <param name="explosionDef">The explosion definition </param>
public void Explode(in B2ExplosionDef explosionDef)
{
Box2D.WorldExplode(this, explosionDef);
}
/// Adjust contact tuning parameters
/// <param name="hertz">The contact stiffness (cycles per second) </param>
/// <param name="dampingRatio">The contact bounciness with 1 being critical damping (non-dimensional) </param>
/// <param name="pushSpeed">The maximum contact constraint push out speed (meters per second) </param>
/// NOTE: Advanced feature
public void SetContactTuning(float hertz, float dampingRatio, float pushSpeed)
{
Box2D.WorldSetContactTuning(this, hertz, dampingRatio, pushSpeed);
}
/// Set the maximum linear speed. Usually in m/s.
public void SetMaximumLinearSpeed(float maximumLinearSpeed)
{
Box2D.WorldSetMaximumLinearSpeed(this, maximumLinearSpeed);
}
/// Get the maximum linear speed. Usually in m/s.
public float GetMaximumLinearSpeed()
{
return Box2D.WorldGetMaximumLinearSpeed(this);
}
/// Enable/disable constraint warm starting. Advanced feature for testing. Disabling
/// warm starting greatly reduces stability and provides no performance gain.
public void EnableWarmStarting(Bool8 flag)
{
Box2D.WorldEnableWarmStarting(this, flag);
}
/// Is constraint warm starting enabled?
public Bool8 IsWarmStartingEnabled()
{
return Box2D.WorldIsWarmStartingEnabled(this);
}
/// Get the number of awake bodies.
public int GetAwakeBodyCount()
{
return Box2D.WorldGetAwakeBodyCount(this);
}
/// Get the current world performance profile
public B2Profile GetProfile()
{
return Box2D.WorldGetProfile(this);
}
/// Get world counters and sizes
public B2Counters GetCounters()
{
return Box2D.WorldGetCounters(this);
}
/// Set the user data pointer.
public void SetUserData(nint userData)
{
Box2D.WorldSetUserData(this, userData);
}
/// Get the user data pointer.
public unsafe void* GetUserData()
{
return Box2D.WorldGetUserData(this);
}
/// Set the friction callback. Passing NULL resets to default.
public void SetFrictionCallback(B2FrictionCallback callback)
{
Box2D.WorldSetFrictionCallback(this, callback);
}
/// Set the restitution callback. Passing NULL resets to default.
public void SetRestitutionCallback(B2RestitutionCallback callback)
{
Box2D.WorldSetRestitutionCallback(this, callback);
}
/// Dump memory stats to box2d_memory.txt
public void DumpMemoryStats()
{
Box2D.WorldDumpMemoryStats(this);
}
/// This is for internal testing
public void RebuildStaticTree()
{
Box2D.WorldRebuildStaticTree(this);
}
/// This is for internal testing
public void EnableSpeculative(Bool8 flag)
{
Box2D.WorldEnableSpeculative(this, flag);
}
/// Create a rigid body given a definition. No reference to the definition is retained. So you can create the definition
/// on the stack and pass it as a pointer.
/// WARNING: This function is locked during callbacks.
public B2Body CreateBody(in B2BodyDef def)
{
return Box2D.CreateBody(this, def);
}
/// Create a distance joint
/// SEE: b2DistanceJointDef for details
public B2DistanceJoint CreateDistanceJoint(in B2DistanceJointDef def)
{
return Box2D.CreateDistanceJoint(this, def);
}
/// Create a motor joint
/// SEE: b2MotorJointDef for details
public B2MotorJoint CreateMotorJoint(in B2MotorJointDef def)
{
return Box2D.CreateMotorJoint(this, def);
}
/// Create a mouse joint
/// SEE: b2MouseJointDef for details
public B2MouseJoint CreateMouseJoint(in B2MouseJointDef def)
{
return Box2D.CreateMouseJoint(this, def);
}
/// Create a filter joint.
/// SEE: b2FilterJointDef for details
public B2FilterJoint CreateFilterJoint(in B2FilterJointDef def)
{
return Box2D.CreateFilterJoint(this, def);
}
/// Create a prismatic (slider) joint.
/// SEE: b2PrismaticJointDef for details
public B2PrismaticJoint CreatePrismaticJoint(in B2PrismaticJointDef def)
{
return Box2D.CreatePrismaticJoint(this, def);
}
/// Create a revolute joint
/// SEE: b2RevoluteJointDef for details
public B2RevoluteJoint CreateRevoluteJoint(in B2RevoluteJointDef def)
{
return Box2D.CreateRevoluteJoint(this, def);
}
/// Create a weld joint
/// SEE: b2WeldJointDef for details
public B2WeldJoint CreateWeldJoint(in B2WeldJointDef def)
{
return Box2D.CreateWeldJoint(this, def);
}
/// Create a wheel joint
/// SEE: b2WheelJointDef for details
public B2WheelJoint CreateWheelJoint(in B2WheelJointDef def)
{
return Box2D.CreateWheelJoint(this, def);
}
///
[FieldOffset(0)]
public readonly ushort Index1;
///
[FieldOffset(2)]
public readonly ushort Generation;
}
/// Body id references a body instance. This should be treated as an opaque handle.
[StructLayout(LayoutKind.Explicit, Size = 8)]
public readonly partial record struct B2Body : IDisposable
{
/// Destroy a rigid body given an id. This destroys all shapes and joints attached to the body.
/// Do not keep references to the associated shapes and joints.
public void Dispose()
{
Box2D.Dispose(this);
}
/// Body identifier validation. Can be used to detect orphaned ids. Provides validation for up to 64K allocations.
public Bool8 IsValid()
{
return Box2D.BodyIsValid(this);
}
/// Get the body type: static, kinematic, or dynamic
public B2BodyType GetBodyType()
{
return Box2D.GetBodyType(this);
}
/// Change the body type. This is an expensive operation. This automatically updates the mass
/// properties regardless of the automatic mass setting.
public void SetType(B2BodyType type)
{
Box2D.BodySetType(this, type);
}
/// Set the body name. Up to 31 characters excluding 0 termination.
public unsafe void SetName(byte* name)
{
Box2D.BodySetName(this, name);
}
/// Get the body name. May be null.
public unsafe byte* GetName()
{
return Box2D.BodyGetName(this);
}
/// Set the user data for a body
public void SetUserData(nint userData)
{
Box2D.BodySetUserData(this, userData);
}
/// Get the user data stored in a body
public unsafe void* GetUserData()
{
return Box2D.BodyGetUserData(this);
}
/// Get the world position of a body. This is the location of the body origin.
public float2 GetPosition()
{
return Box2D.BodyGetPosition(this);
}
/// Get the world rotation of a body as a cosine/sine pair (complex number)
public B2Rot GetRotation()
{
return Box2D.BodyGetRotation(this);
}
/// Get the world transform of a body.
public B2Transform GetTransform()
{
return Box2D.BodyGetTransform(this);
}
/// Set the world transform of a body. This acts as a teleport and is fairly expensive.
/// NOTE: Generally you should create a body with then intended transform.
/// SEE: b2BodyDef::position and b2BodyDef::angle
public void SetTransform(float2 position, B2Rot rotation)
{
Box2D.BodySetTransform(this, position, rotation);
}
/// Get a local point on a body given a world point
public float2 GetLocalPoint(float2 worldPoint)
{
return Box2D.BodyGetLocalPoint(this, worldPoint);
}
/// Get a world point on a body given a local point
public float2 GetWorldPoint(float2 localPoint)
{
return Box2D.BodyGetWorldPoint(this, localPoint);
}
/// Get a local vector on a body given a world vector
public float2 GetLocalVector(float2 worldVector)
{
return Box2D.BodyGetLocalVector(this, worldVector);
}
/// Get a world vector on a body given a local vector
public float2 GetWorldVector(float2 localVector)
{
return Box2D.BodyGetWorldVector(this, localVector);
}
/// Get the linear velocity of a body&apos;s center of mass. Usually in meters per second.
public float2 GetLinearVelocity()
{
return Box2D.BodyGetLinearVelocity(this);
}
/// Get the angular velocity of a body in radians per second
public float GetAngularVelocity()
{
return Box2D.BodyGetAngularVelocity(this);
}
/// Set the linear velocity of a body. Usually in meters per second.
public void SetLinearVelocity(float2 linearVelocity)
{
Box2D.BodySetLinearVelocity(this, linearVelocity);
}
/// Set the angular velocity of a body in radians per second
public void SetAngularVelocity(float angularVelocity)
{
Box2D.BodySetAngularVelocity(this, angularVelocity);
}
/// Set the velocity to reach the given transform after a given time step.
/// The result will be close but maybe not exact. This is meant for kinematic bodies.
/// The target is not applied if the velocity would be below the sleep threshold.
/// This will automatically wake the body if asleep.
public void SetTargetTransform(B2Transform target, float timeStep)
{
Box2D.BodySetTargetTransform(this, target, timeStep);
}
/// Get the linear velocity of a local point attached to a body. Usually in meters per second.
public float2 GetLocalPointVelocity(float2 localPoint)
{
return Box2D.BodyGetLocalPointVelocity(this, localPoint);
}
/// Get the linear velocity of a world point attached to a body. Usually in meters per second.
public float2 GetWorldPointVelocity(float2 worldPoint)
{
return Box2D.BodyGetWorldPointVelocity(this, worldPoint);
}
/// Apply a force at a world point. If the force is not applied at the center of mass,
/// it will generate a torque and affect the angular velocity. This optionally wakes up the body.
/// The force is ignored if the body is not awake.
/// <param name="force">The world force vector, usually in newtons (N) </param>
/// <param name="point">The world position of the point of application </param>
/// <param name="wake">Option to wake up the body </param>
public void ApplyForce(float2 force, float2 point, Bool8 wake)
{
Box2D.BodyApplyForce(this, force, point, wake);
}
/// Apply a force to the center of mass. This optionally wakes up the body.
/// The force is ignored if the body is not awake.
/// <param name="force">the world force vector, usually in newtons (N). </param>
/// <param name="wake">also wake up the body </param>
public void ApplyForceToCenter(float2 force, Bool8 wake)
{
Box2D.BodyApplyForceToCenter(this, force, wake);
}
/// Apply a torque. This affects the angular velocity without affecting the linear velocity.
/// This optionally wakes the body. The torque is ignored if the body is not awake.
/// <param name="torque">about the z-axis (out of the screen), usually in N*m. </param>
/// <param name="wake">also wake up the body </param>
public void ApplyTorque(float torque, Bool8 wake)
{
Box2D.BodyApplyTorque(this, torque, wake);
}
/// Apply an impulse at a point. This immediately modifies the velocity.
/// It also modifies the angular velocity if the point of application
/// is not at the center of mass. This optionally wakes the body.
/// The impulse is ignored if the body is not awake.
/// <param name="impulse">the world impulse vector, usually in N*s or kg*m/s. </param>
/// <param name="point">the world position of the point of application. </param>
/// <param name="wake">also wake up the body </param>
/// WARNING: This should be used for one-shot impulses. If you need a steady force, use a force instead, which will work better with the sub-stepping solver.
public void ApplyLinearImpulse(float2 impulse, float2 point, Bool8 wake)
{
Box2D.BodyApplyLinearImpulse(this, impulse, point, wake);
}
/// Apply an impulse to the center of mass. This immediately modifies the velocity.
/// The impulse is ignored if the body is not awake. This optionally wakes the body.
/// <param name="impulse">the world impulse vector, usually in N*s or kg*m/s. </param>
/// <param name="wake">also wake up the body </param>
/// WARNING: This should be used for one-shot impulses. If you need a steady force, use a force instead, which will work better with the sub-stepping solver.
public void ApplyLinearImpulseToCenter(float2 impulse, Bool8 wake)
{
Box2D.BodyApplyLinearImpulseToCenter(this, impulse, wake);
}
/// Apply an angular impulse. The impulse is ignored if the body is not awake.
/// This optionally wakes the body.
/// <param name="impulse">the angular impulse, usually in units of kg*m*m/s </param>
/// <param name="wake">also wake up the body </param>
/// WARNING: This should be used for one-shot impulses. If you need a steady force, use a force instead, which will work better with the sub-stepping solver.
public void ApplyAngularImpulse(float impulse, Bool8 wake)
{
Box2D.BodyApplyAngularImpulse(this, impulse, wake);
}
/// Get the mass of the body, usually in kilograms
public float GetMass()
{
return Box2D.BodyGetMass(this);
}
/// Get the rotational inertia of the body, usually in kg*m^2
public float GetRotationalInertia()
{
return Box2D.BodyGetRotationalInertia(this);
}
/// Get the center of mass position of the body in local space
public float2 GetLocalCenterOfMass()
{
return Box2D.BodyGetLocalCenterOfMass(this);
}
/// Get the center of mass position of the body in world space
public float2 GetWorldCenterOfMass()
{
return Box2D.BodyGetWorldCenterOfMass(this);
}
/// Override the body&apos;s mass properties. Normally this is computed automatically using the
/// shape geometry and density. This information is lost if a shape is added or removed or if the
/// body type changes.
public void SetMassData(B2MassData massData)
{
Box2D.BodySetMassData(this, massData);
}
/// Get the mass data for a body
public B2MassData GetMassData()
{
return Box2D.BodyGetMassData(this);
}
/// This update the mass properties to the sum of the mass properties of the shapes.
/// This normally does not need to be called unless you called SetMassData to override
/// the mass and you later want to reset the mass.
/// You may also use this when automatic mass computation has been disabled.
/// You should call this regardless of body type.
/// Note that sensor shapes may have mass.
public void ApplyMassFromShapes()
{
Box2D.BodyApplyMassFromShapes(this);
}
/// Adjust the linear damping. Normally this is set in b2BodyDef before creation.
public void SetLinearDamping(float linearDamping)
{
Box2D.BodySetLinearDamping(this, linearDamping);
}
/// Get the current linear damping.
public float GetLinearDamping()
{
return Box2D.BodyGetLinearDamping(this);
}
/// Adjust the angular damping. Normally this is set in b2BodyDef before creation.
public void SetAngularDamping(float angularDamping)
{
Box2D.BodySetAngularDamping(this, angularDamping);
}
/// Get the current angular damping.
public float GetAngularDamping()
{
return Box2D.BodyGetAngularDamping(this);
}
/// Adjust the gravity scale. Normally this is set in b2BodyDef before creation.
/// SEE: b2BodyDef::gravityScale
public void SetGravityScale(float gravityScale)
{
Box2D.BodySetGravityScale(this, gravityScale);
}
/// Get the current gravity scale
public float GetGravityScale()
{
return Box2D.BodyGetGravityScale(this);
}
/// RETURN: true if this body is awake
public Bool8 IsAwake()
{
return Box2D.BodyIsAwake(this);
}
/// Wake a body from sleep. This wakes the entire island the body is touching.
/// WARNING: Putting a body to sleep will put the entire island of bodies touching this body to sleep, which can be expensive and possibly unintuitive.
public void SetAwake(Bool8 awake)
{
Box2D.BodySetAwake(this, awake);
}
/// Enable or disable sleeping for this body. If sleeping is disabled the body will wake.
public void EnableSleep(Bool8 enableSleep)
{
Box2D.BodyEnableSleep(this, enableSleep);
}
/// Returns true if sleeping is enabled for this body
public Bool8 IsSleepEnabled()
{
return Box2D.BodyIsSleepEnabled(this);
}
/// Set the sleep threshold, usually in meters per second
public void SetSleepThreshold(float sleepThreshold)
{
Box2D.BodySetSleepThreshold(this, sleepThreshold);
}
/// Get the sleep threshold, usually in meters per second.
public float GetSleepThreshold()
{
return Box2D.BodyGetSleepThreshold(this);
}
/// Returns true if this body is enabled
public Bool8 IsEnabled()
{
return Box2D.BodyIsEnabled(this);
}
/// Disable a body by removing it completely from the simulation. This is expensive.
public void Disable()
{
Box2D.BodyDisable(this);
}
/// Enable a body by adding it to the simulation. This is expensive.
public void Enable()
{
Box2D.BodyEnable(this);
}
/// Set this body to have fixed rotation. This causes the mass to be reset in all cases.
public void SetFixedRotation(Bool8 flag)
{
Box2D.BodySetFixedRotation(this, flag);
}
/// Does this body have fixed rotation?
public Bool8 IsFixedRotation()
{
return Box2D.BodyIsFixedRotation(this);
}
/// Set this body to be a bullet. A bullet does continuous collision detection
/// against dynamic bodies (but not other bullets).
public void SetBullet(Bool8 flag)
{
Box2D.BodySetBullet(this, flag);
}
/// Is this body a bullet?
public Bool8 IsBullet()
{
return Box2D.BodyIsBullet(this);
}
/// Enable/disable contact events on all shapes.
/// SEE: b2ShapeDef::enableContactEvents
/// WARNING: changing this at runtime may cause mismatched begin/end touch events
public void EnableContactEvents(Bool8 flag)
{
Box2D.BodyEnableContactEvents(this, flag);
}
/// Enable/disable hit events on all shapes
/// SEE: b2ShapeDef::enableHitEvents
public void EnableHitEvents(Bool8 flag)
{
Box2D.BodyEnableHitEvents(this, flag);
}
/// Get the world that owns this body
public B2World GetWorld()
{
return Box2D.BodyGetWorld(this);
}
/// Get the number of shapes on this body
public int GetShapeCount()
{
return Box2D.BodyGetShapeCount(this);
}
/// Get the shape ids for all shapes on this body, up to the provided capacity.
/// RETURNS: the number of shape ids stored in the user array
public int GetShapes(in B2Shape shapeArray, int capacity)
{
return Box2D.BodyGetShapes(this, shapeArray, capacity);
}
/// Get the number of joints on this body
public int GetJointCount()
{
return Box2D.BodyGetJointCount(this);
}
/// Get the maximum capacity required for retrieving all the touching contacts on a body
public int GetContactCapacity()
{
return Box2D.BodyGetContactCapacity(this);
}
/// Get the touching contact data for a body.
/// NOTE: Box2D uses speculative collision so some contact points may be separated.
/// RETURNS: the number of elements filled in the provided array
/// WARNING: do not ignore the return value, it specifies the valid number of elements
public int GetContactData(in B2ContactData contactData, int capacity)
{
return Box2D.BodyGetContactData(this, contactData, capacity);
}
/// Get the current world AABB that contains all the attached shapes. Note that this may not encompass the body origin.
/// If there are no shapes attached then the returned AABB is empty and centered on the body origin.
public B2Aabb ComputeAabb()
{
return Box2D.BodyComputeAabb(this);
}
/// Create a circle shape and attach it to a body. The shape definition and geometry are fully cloned.
/// Contacts are not created until the next time step.
/// RETURN: the shape id for accessing the shape
public B2Shape CreateCircleShape(in B2ShapeDef def, in B2Circle circle)
{
return Box2D.CreateCircleShape(this, def, circle);
}
/// Create a line segment shape and attach it to a body. The shape definition and geometry are fully cloned.
/// Contacts are not created until the next time step.
/// RETURN: the shape id for accessing the shape
public B2Shape CreateSegmentShape(in B2ShapeDef def, in B2Segment segment)
{
return Box2D.CreateSegmentShape(this, def, segment);
}
/// Create a capsule shape and attach it to a body. The shape definition and geometry are fully cloned.
/// Contacts are not created until the next time step.
/// RETURN: the shape id for accessing the shape
public B2Shape CreateCapsuleShape(in B2ShapeDef def, in B2Capsule capsule)
{
return Box2D.CreateCapsuleShape(this, def, capsule);
}
/// Create a polygon shape and attach it to a body. The shape definition and geometry are fully cloned.
/// Contacts are not created until the next time step.
/// RETURN: the shape id for accessing the shape
public B2Shape CreatePolygonShape(in B2ShapeDef def, in B2Polygon polygon)
{
return Box2D.CreatePolygonShape(this, def, polygon);
}
/// Create a chain shape
/// SEE: b2ChainDef for details
public B2Chain CreateChain(in B2ChainDef def)
{
return Box2D.CreateChain(this, def);
}
///
[FieldOffset(0)]
public readonly int Index1;
///
[FieldOffset(4)]
public readonly ushort World0;
///
[FieldOffset(6)]
public readonly ushort Generation;
}
/// Shape id references a shape instance. This should be treated as an opaque handle.
[StructLayout(LayoutKind.Explicit, Size = 8)]
public readonly partial record struct B2Shape
{
/// Destroy a shape. You may defer the body mass update which can improve performance if several shapes on a
/// body are destroyed at once.
/// SEE: b2Body_ApplyMassFromShapes
public void Dispose(Bool8 updateBodyMass)
{
Box2D.Dispose(this, updateBodyMass);
}
/// Shape identifier validation. Provides validation for up to 64K allocations.
public Bool8 IsValid()
{
return Box2D.ShapeIsValid(this);
}
/// Get the type of a shape
public B2ShapeType GetShapeType()
{
return Box2D.GetShapeType(this);
}
/// Get the id of the body that a shape is attached to
public B2Body GetBody()
{
return Box2D.ShapeGetBody(this);
}
/// Get the world that owns this shape
public B2World GetWorld()
{
return Box2D.ShapeGetWorld(this);
}
/// Returns true if the shape is a sensor. It is not possible to change a shape
/// from sensor to solid dynamically because this breaks the contract for
/// sensor events.
public Bool8 IsSensor()
{
return Box2D.ShapeIsSensor(this);
}
/// Set the user data for a shape
public void SetUserData(nint userData)
{
Box2D.ShapeSetUserData(this, userData);
}
/// Get the user data for a shape. This is useful when you get a shape id
/// from an event or query.
public unsafe void* GetUserData()
{
return Box2D.ShapeGetUserData(this);
}
/// Set the mass density of a shape, usually in kg/m^2.
/// This will optionally update the mass properties on the parent body.
/// SEE: b2ShapeDef::density, b2Body_ApplyMassFromShapes
public void SetDensity(float density, Bool8 updateBodyMass)
{
Box2D.ShapeSetDensity(this, density, updateBodyMass);
}
/// Get the density of a shape, usually in kg/m^2
public float GetDensity()
{
return Box2D.ShapeGetDensity(this);
}
/// Set the friction on a shape
/// SEE: b2ShapeDef::friction
public void SetFriction(float friction)
{
Box2D.ShapeSetFriction(this, friction);
}
/// Get the friction of a shape
public float GetFriction()
{
return Box2D.ShapeGetFriction(this);
}
/// Set the shape restitution (bounciness)
/// SEE: b2ShapeDef::restitution
public void SetRestitution(float restitution)
{
Box2D.ShapeSetRestitution(this, restitution);
}
/// Get the shape restitution
public float GetRestitution()
{
return Box2D.ShapeGetRestitution(this);
}
/// Set the shape material identifier
/// SEE: b2ShapeDef::material
public void SetMaterial(int material)
{
Box2D.ShapeSetMaterial(this, material);
}
/// Get the shape material identifier
public int GetMaterial()
{
return Box2D.ShapeGetMaterial(this);
}
/// Set the shape surface material
public void SetSurfaceMaterial(B2SurfaceMaterial surfaceMaterial)
{
Box2D.ShapeSetSurfaceMaterial(this, surfaceMaterial);
}
/// Get the shape surface material
public B2SurfaceMaterial GetSurfaceMaterial()
{
return Box2D.ShapeGetSurfaceMaterial(this);
}
/// Get the shape filter
public B2Filter GetFilter()
{
return Box2D.ShapeGetFilter(this);
}
/// Set the current filter. This is almost as expensive as recreating the shape. This may cause
/// contacts to be immediately destroyed. However contacts are not created until the next world step.
/// Sensor overlap state is also not updated until the next world step.
/// SEE: b2ShapeDef::filter
public void SetFilter(B2Filter filter)
{
Box2D.ShapeSetFilter(this, filter);
}
/// Enable sensor events for this shape.
/// SEE: b2ShapeDef::enableSensorEvents
public void EnableSensorEvents(Bool8 flag)
{
Box2D.ShapeEnableSensorEvents(this, flag);
}
/// Returns true if sensor events are enabled.
public Bool8 AreSensorEventsEnabled()
{
return Box2D.ShapeAreSensorEventsEnabled(this);
}
/// Enable contact events for this shape. Only applies to kinematic and dynamic bodies. Ignored for sensors.
/// SEE: b2ShapeDef::enableContactEvents
/// WARNING: changing this at run-time may lead to lost begin/end events
public void EnableContactEvents(Bool8 flag)
{
Box2D.ShapeEnableContactEvents(this, flag);
}
/// Returns true if contact events are enabled
public Bool8 AreContactEventsEnabled()
{
return Box2D.ShapeAreContactEventsEnabled(this);
}
/// Enable pre-solve contact events for this shape. Only applies to dynamic bodies. These are expensive
/// and must be carefully handled due to multithreading. Ignored for sensors.
/// SEE: b2PreSolveFcn
public void EnablePreSolveEvents(Bool8 flag)
{
Box2D.ShapeEnablePreSolveEvents(this, flag);
}
/// Returns true if pre-solve events are enabled
public Bool8 ArePreSolveEventsEnabled()
{
return Box2D.ShapeArePreSolveEventsEnabled(this);
}
/// Enable contact hit events for this shape. Ignored for sensors.
/// SEE: b2WorldDef.hitEventThreshold
public void EnableHitEvents(Bool8 flag)
{
Box2D.ShapeEnableHitEvents(this, flag);
}
/// Returns true if hit events are enabled
public Bool8 AreHitEventsEnabled()
{
return Box2D.ShapeAreHitEventsEnabled(this);
}
/// Test a point for overlap with a shape
public Bool8 TestPoint(float2 point)
{
return Box2D.ShapeTestPoint(this, point);
}
/// Ray cast a shape directly
public B2CastOutput RayCast(in B2RayCastInput input)
{
return Box2D.ShapeRayCast(this, input);
}
/// Get a copy of the shape&apos;s circle. Asserts the type is correct.
public B2Circle GetCircle()
{
return Box2D.ShapeGetCircle(this);
}
/// Get a copy of the shape&apos;s line segment. Asserts the type is correct.
public B2Segment GetSegment()
{
return Box2D.ShapeGetSegment(this);
}
/// Get a copy of the shape&apos;s chain segment. These come from chain shapes.
/// Asserts the type is correct.
public B2ChainSegment GetChainSegment()
{
return Box2D.ShapeGetChainSegment(this);
}
/// Get a copy of the shape&apos;s capsule. Asserts the type is correct.
public B2Capsule GetCapsule()
{
return Box2D.ShapeGetCapsule(this);
}
/// Get a copy of the shape&apos;s convex polygon. Asserts the type is correct.
public B2Polygon GetPolygon()
{
return Box2D.ShapeGetPolygon(this);
}
/// Allows you to change a shape to be a circle or update the current circle.
/// This does not modify the mass properties.
/// SEE: b2Body_ApplyMassFromShapes
public void SetCircle(in B2Circle circle)
{
Box2D.ShapeSetCircle(this, circle);
}
/// Allows you to change a shape to be a capsule or update the current capsule.
/// This does not modify the mass properties.
/// SEE: b2Body_ApplyMassFromShapes
public void SetCapsule(in B2Capsule capsule)
{
Box2D.ShapeSetCapsule(this, capsule);
}
/// Allows you to change a shape to be a segment or update the current segment.
public void SetSegment(in B2Segment segment)
{
Box2D.ShapeSetSegment(this, segment);
}
/// Allows you to change a shape to be a polygon or update the current polygon.
/// This does not modify the mass properties.
/// SEE: b2Body_ApplyMassFromShapes
public void SetPolygon(in B2Polygon polygon)
{
Box2D.ShapeSetPolygon(this, polygon);
}
/// Get the parent chain id if the shape type is a chain segment, otherwise
/// returns b2_nullChainId.
public B2Chain GetParentChain()
{
return Box2D.ShapeGetParentChain(this);
}
/// Get the maximum capacity required for retrieving all the touching contacts on a shape
public int GetContactCapacity()
{
return Box2D.ShapeGetContactCapacity(this);
}
/// Get the touching contact data for a shape. The provided shapeId will be either shapeIdA or shapeIdB on the contact data.
/// NOTE: Box2D uses speculative collision so some contact points may be separated.
/// RETURNS: the number of elements filled in the provided array
/// WARNING: do not ignore the return value, it specifies the valid number of elements
public int GetContactData(in B2ContactData contactData, int capacity)
{
return Box2D.ShapeGetContactData(this, contactData, capacity);
}
/// Get the maximum capacity required for retrieving all the overlapped shapes on a sensor shape.
/// This returns 0 if the provided shape is not a sensor.
/// RETURNS: the required capacity to get all the overlaps in b2Shape_GetSensorOverlaps
public int GetSensorCapacity()
{
return Box2D.ShapeGetSensorCapacity(this);
}
/// Get the overlapped shapes for a sensor shape.
/// <param name="overlaps">a user allocated array that is filled with the overlapping shapes </param>
/// <param name="capacity">the capacity of overlappedShapes </param>
/// RETURNS: the number of elements filled in the provided array
/// WARNING: do not ignore the return value, it specifies the valid number of elements
/// WARNING: overlaps may contain destroyed shapes so use b2Shape_IsValid to confirm each overlap
public int GetSensorOverlaps(in B2Shape overlaps, int capacity)
{
return Box2D.ShapeGetSensorOverlaps(this, overlaps, capacity);
}
/// Get the current world AABB
public B2Aabb GetAabb()
{
return Box2D.ShapeGetAabb(this);
}
/// Get the mass data for a shape
public B2MassData GetMassData()
{
return Box2D.ShapeGetMassData(this);
}
/// Get the closest point on a shape to a target point. Target and result are in world space.
/// todo need sample
public float2 GetClosestPoint(float2 target)
{
return Box2D.ShapeGetClosestPoint(this, target);
}
///
[FieldOffset(0)]
public readonly int Index1;
///
[FieldOffset(4)]
public readonly ushort World0;
///
[FieldOffset(6)]
public readonly ushort Generation;
}
/// Chain id references a chain instances. This should be treated as an opaque handle.
[StructLayout(LayoutKind.Explicit, Size = 8)]
public readonly partial record struct B2Chain : IDisposable
{
/// Destroy a chain shape
public void Dispose()
{
Box2D.Dispose(this);
}
/// Get the world that owns this chain shape
public B2World GetWorld()
{
return Box2D.ChainGetWorld(this);
}
/// Get the number of segments on this chain
public int GetSegmentCount()
{
return Box2D.ChainGetSegmentCount(this);
}
/// Fill a user array with chain segment shape ids up to the specified capacity. Returns
/// the actual number of segments returned.
public int GetSegments(in B2Shape segmentArray, int capacity)
{
return Box2D.ChainGetSegments(this, segmentArray, capacity);
}
/// Set the chain friction
/// SEE: b2ChainDef::friction
public void SetFriction(float friction)
{
Box2D.ChainSetFriction(this, friction);
}
/// Get the chain friction
public float GetFriction()
{
return Box2D.ChainGetFriction(this);
}
/// Set the chain restitution (bounciness)
/// SEE: b2ChainDef::restitution
public void SetRestitution(float restitution)
{
Box2D.ChainSetRestitution(this, restitution);
}
/// Get the chain restitution
public float GetRestitution()
{
return Box2D.ChainGetRestitution(this);
}
/// Set the chain material
/// SEE: b2ChainDef::material
public void SetMaterial(int material)
{
Box2D.ChainSetMaterial(this, material);
}
/// Get the chain material
public int GetMaterial()
{
return Box2D.ChainGetMaterial(this);
}
/// Chain identifier validation. Provides validation for up to 64K allocations.
public Bool8 IsValid()
{
return Box2D.ChainIsValid(this);
}
///
[FieldOffset(0)]
public readonly int Index1;
///
[FieldOffset(4)]
public readonly ushort World0;
///
[FieldOffset(6)]
public readonly ushort Generation;
}
/// Joint id references a joint instance. This should be treated as an opaque handle.
[StructLayout(LayoutKind.Explicit, Size = 8)]
public partial class B2Joint : IDisposable
{
/// Destroy a joint
public void Dispose()
{
Box2D.Dispose(this);
}
/// Joint identifier validation. Provides validation for up to 64K allocations.
public Bool8 IsValid()
{
return Box2D.JointIsValid(this);
}
/// Get the joint type
public B2JointType GetJointType()
{
return Box2D.GetJointType(this);
}
/// Get body A id on a joint
public B2Body GetBodyA()
{
return Box2D.JointGetBodyA(this);
}
/// Get body B id on a joint
public B2Body GetBodyB()
{
return Box2D.JointGetBodyB(this);
}
/// Get the world that owns this joint
public B2World GetWorld()
{
return Box2D.JointGetWorld(this);
}
/// Set the local anchor on bodyA
public void SetLocalAnchorA(float2 localAnchor)
{
Box2D.JointSetLocalAnchorA(this, localAnchor);
}
/// Get the local anchor on bodyA
public float2 GetLocalAnchorA()
{
return Box2D.JointGetLocalAnchorA(this);
}
/// Set the local anchor on bodyB
public void SetLocalAnchorB(float2 localAnchor)
{
Box2D.JointSetLocalAnchorB(this, localAnchor);
}
/// Get the local anchor on bodyB
public float2 GetLocalAnchorB()
{
return Box2D.JointGetLocalAnchorB(this);
}
/// Get the joint reference angle in radians (revolute, prismatic, and weld)
public float GetReferenceAngle()
{
return Box2D.JointGetReferenceAngle(this);
}
/// Set the joint reference angle in radians, must be in [-pi,pi]. (revolute, prismatic, and weld)
public void SetReferenceAngle(float angleInRadians)
{
Box2D.JointSetReferenceAngle(this, angleInRadians);
}
/// Set the local axis on bodyA (prismatic and wheel)
public void SetLocalAxisA(float2 localAxis)
{
Box2D.JointSetLocalAxisA(this, localAxis);
}
/// Get the local axis on bodyA (prismatic and wheel)
public float2 GetLocalAxisA()
{
return Box2D.JointGetLocalAxisA(this);
}
/// Toggle collision between connected bodies
public void SetCollideConnected(Bool8 shouldCollide)
{
Box2D.JointSetCollideConnected(this, shouldCollide);
}
/// Is collision allowed between connected bodies?
public Bool8 GetCollideConnected()
{
return Box2D.JointGetCollideConnected(this);
}
/// Set the user data on a joint
public void SetUserData(nint userData)
{
Box2D.JointSetUserData(this, userData);
}
/// Get the user data on a joint
public unsafe void* GetUserData()
{
return Box2D.JointGetUserData(this);
}
/// Wake the bodies connect to this joint
public void WakeBodies()
{
Box2D.JointWakeBodies(this);
}
/// Get the current constraint force for this joint. Usually in Newtons.
public float2 GetConstraintForce()
{
return Box2D.JointGetConstraintForce(this);
}
/// Get the current constraint torque for this joint. Usually in Newton * meters.
public float GetConstraintTorque()
{
return Box2D.JointGetConstraintTorque(this);
}
/// Get the current linear separation error for this joint. Does not consider admissible movement. Usually in meters.
public float GetLinearSeparation()
{
return Box2D.JointGetLinearSeparation(this);
}
/// Get the current angular separation error for this joint. Does not consider admissible movement. Usually in meters.
public float GetAngularSeparation()
{
return Box2D.JointGetAngularSeparation(this);
}
/// Get the joint constraint tuning. Advanced feature.
public void GetConstraintTuning(in float hertz, in float dampingRatio)
{
Box2D.JointGetConstraintTuning(this, hertz, dampingRatio);
}
/// Set the joint constraint tuning. Advanced feature.
/// <param name="hertz">the stiffness in Hertz (cycles per second) </param>
/// <param name="dampingRatio">the non-dimensional damping ratio (one for critical damping) </param>
public void SetConstraintTuning(float hertz, float dampingRatio)
{
Box2D.JointSetConstraintTuning(this, hertz, dampingRatio);
}
///
[FieldOffset(0)]
public int Index1;
///
[FieldOffset(4)]
public ushort World0;
///
[FieldOffset(6)]
public ushort Generation;
}
/// Result from b2World_RayCastClosest
/// If there is initial overlap the fraction and normal will be zero while the point is an arbitrary point in the overlap region.
[StructLayout(LayoutKind.Explicit, Size = 40)]
public struct B2RayResult
{
///
[FieldOffset(0)]
public B2Shape ShapeId;
///
[FieldOffset(8)]
public float2 Point;
///
[FieldOffset(16)]
public float2 Normal;
///
[FieldOffset(24)]
public float Fraction;
///
[FieldOffset(28)]
public int NodeVisits;
///
[FieldOffset(32)]
public int LeafVisits;
///
[FieldOffset(36)]
public Bool8 Hit;
}
/// World definition used to create a simulation world.
/// Must be initialized using b2DefaultWorldDef().
[StructLayout(LayoutKind.Explicit, Size = 96)]
public unsafe partial struct B2WorldDef
{
/// <summary>
/// Initializes a new instance of the B2WorldDef class using default values provided by Box2D.
/// </summary>
public B2WorldDef()
{
this = Default;
}
/// Gravity vector. Box2D has no up-vector defined.
[FieldOffset(0)]
public float2 Gravity;
/// Restitution speed threshold, usually in m/s. Collisions above this
/// speed have restitution applied (will bounce).
[FieldOffset(8)]
public float RestitutionThreshold;
/// Threshold speed for hit events. Usually meters per second.
[FieldOffset(12)]
public float HitEventThreshold;
/// Contact stiffness. Cycles per second. Increasing this increases the speed of overlap recovery, but can introduce jitter.
[FieldOffset(16)]
public float ContactHertz;
/// Contact bounciness. Non-dimensional. You can speed up overlap recovery by decreasing this with
/// the trade-off that overlap resolution becomes more energetic.
[FieldOffset(20)]
public float ContactDampingRatio;
/// This parameter controls how fast overlap is resolved and usually has units of meters per second. This only
/// puts a cap on the resolution speed. The resolution speed is increased by increasing the hertz and/or
/// decreasing the damping ratio.
[FieldOffset(24)]
public float MaxContactPushSpeed;
/// Maximum linear speed. Usually meters per second.
[FieldOffset(28)]
public float MaximumLinearSpeed;
[FieldOffset(32)]
private nint _frictionCallbackCallback;
/// Optional mixing callback for friction. The default uses sqrt(frictionA * frictionB).
public B2FrictionCallback? FrictionCallbackCallback
{
set => _frictionCallbackCallback = value != null ? Marshal.GetFunctionPointerForDelegate(value) : 0;
}
[FieldOffset(40)]
private nint _restitutionCallbackCallback;
/// Optional mixing callback for restitution. The default uses max(restitutionA, restitutionB).
public B2RestitutionCallback? RestitutionCallbackCallback
{
set => _restitutionCallbackCallback = value != null ? Marshal.GetFunctionPointerForDelegate(value) : 0;
}
/// Can bodies go to sleep to improve performance
[FieldOffset(48)]
public Bool8 EnableSleep;
/// Enable continuous collision
[FieldOffset(49)]
public Bool8 EnableContinuous;
/// Number of workers to use with the provided task system. Box2D performs best when using only
/// performance cores and accessing a single L2 cache. Efficiency cores and hyper-threading provide
/// little benefit and may even harm performance.
/// NOTE: Box2D does not create threads. This is the number of threads your applications has created that you are allocating to b2World_Step.
/// WARNING: Do not modify the default value unless you are also providing a task system and providing task callbacks (enqueueTask and finishTask).
[FieldOffset(52)]
public int WorkerCount;
[FieldOffset(56)]
private nint _enqueueTaskCallback;
/// Function to spawn tasks
public B2EnqueueTaskCallback? EnqueueTaskCallback
{
set => _enqueueTaskCallback = value != null ? Marshal.GetFunctionPointerForDelegate(value) : 0;
}
[FieldOffset(64)]
private nint _finishTaskCallback;
/// Function to finish a task
public B2FinishTaskCallback? FinishTaskCallback
{
set => _finishTaskCallback = value != null ? Marshal.GetFunctionPointerForDelegate(value) : 0;
}
/// User context that is provided to enqueueTask and finishTask
[FieldOffset(72)]
public void* UserTaskContext;
/// User data
[FieldOffset(80)]
public void* UserData;
/// Used internally to detect a valid definition. DO NOT SET.
[FieldOffset(88)]
public int InternalValue;
}
/// A body definition holds all the data needed to construct a rigid body.
/// You can safely re-use body definitions. Shapes are added to a body after construction.
/// Body definitions are temporary objects used to bundle creation parameters.
/// Must be initialized using b2DefaultBodyDef().
[StructLayout(LayoutKind.Explicit, Size = 80)]
public unsafe partial struct B2BodyDef
{
/// <summary>
/// Initializes a new instance of the B2BodyDef class using default values provided by Box2D.
/// </summary>
public B2BodyDef()
{
this = Default;
}
/// The body type: static, kinematic, or dynamic.
[FieldOffset(0)]
public B2BodyType Type;
/// The initial world position of the body. Bodies should be created with the desired position.
/// NOTE: Creating bodies at the origin and then moving them nearly doubles the cost of body creation, especially if the body is moved after shapes have been added.
[FieldOffset(4)]
public float2 Position;
/// The initial world rotation of the body. Use b2MakeRot() if you have an angle.
[FieldOffset(12)]
public B2Rot Rotation;
/// The initial linear velocity of the body&apos;s origin. Usually in meters per second.
[FieldOffset(20)]
public float2 LinearVelocity;
/// The initial angular velocity of the body. Radians per second.
[FieldOffset(28)]
public float AngularVelocity;
/// Linear damping is used to reduce the linear velocity. The damping parameter
/// can be larger than 1 but the damping effect becomes sensitive to the
/// time step when the damping parameter is large.
/// Generally linear damping is undesirable because it makes objects move slowly
/// as if they are floating.
[FieldOffset(32)]
public float LinearDamping;
/// Angular damping is used to reduce the angular velocity. The damping parameter
/// can be larger than 1.0f but the damping effect becomes sensitive to the
/// time step when the damping parameter is large.
/// Angular damping can be use slow down rotating bodies.
[FieldOffset(36)]
public float AngularDamping;
/// Scale the gravity applied to this body. Non-dimensional.
[FieldOffset(40)]
public float GravityScale;
/// Sleep speed threshold, default is 0.05 meters per second
[FieldOffset(44)]
public float SleepThreshold;
/// Optional body name for debugging. Up to 31 characters (excluding null termination)
[FieldOffset(48)]
public byte* Name;
/// Use this to store application specific body data.
[FieldOffset(56)]
public void* UserData;
/// Set this flag to false if this body should never fall asleep.
[FieldOffset(64)]
public Bool8 EnableSleep;
/// Is this body initially awake or sleeping?
[FieldOffset(65)]
public Bool8 IsAwake;
/// Should this body be prevented from rotating? Useful for characters.
[FieldOffset(66)]
public Bool8 FixedRotation;
/// Treat this body as high speed object that performs continuous collision detection
/// against dynamic and kinematic bodies, but not other bullet bodies.
/// WARNING: Bullets should be used sparingly. They are not a solution for general dynamic-versus-dynamic continuous collision. They may interfere with joint constraints.
[FieldOffset(67)]
public Bool8 IsBullet;
/// Used to disable a body. A disabled body does not move or collide.
[FieldOffset(68)]
public Bool8 IsEnabled;
/// This allows this body to bypass rotational speed limits. Should only be used
/// for circular objects, like wheels.
[FieldOffset(69)]
public Bool8 AllowFastRotation;
/// Used internally to detect a valid definition. DO NOT SET.
[FieldOffset(72)]
public int InternalValue;
}
/// This is used to filter collision on shapes. It affects shape-vs-shape collision
/// and shape-versus-query collision (such as b2World_CastRay).
[StructLayout(LayoutKind.Explicit, Size = 24)]
public partial struct B2Filter
{
/// <summary>
/// Initializes a new instance of the B2Filter class using default values provided by Box2D.
/// </summary>
public B2Filter()
{
this = Default;
}
/// The collision category bits. Normally you would just set one bit. The category bits should
/// represent your application object types. For example:
[FieldOffset(0)]
public ulong CategoryBits;
/// The collision mask bits. This states the categories that this
/// shape would accept for collision.
/// For example, you may want your player to only collide with static objects
/// and other players.
[FieldOffset(8)]
public ulong MaskBits;
/// Collision groups allow a certain group of objects to never collide (negative)
/// or always collide (positive). A group index of zero has no effect. Non-zero group filtering
/// always wins against the mask bits.
/// For example, you may want ragdolls to collide with other ragdolls but you don&apos;t want
/// ragdoll self-collision. In this case you would give each ragdoll a unique negative group index
/// and apply that group index to all shapes on the ragdoll.
[FieldOffset(16)]
public int GroupIndex;
}
/// The query filter is used to filter collisions between queries and shapes. For example,
/// you may want a ray-cast representing a projectile to hit players and the static environment
/// but not debris.
[StructLayout(LayoutKind.Explicit, Size = 16)]
public partial struct B2QueryFilter
{
/// <summary>
/// Initializes a new instance of the B2QueryFilter class using default values provided by Box2D.
/// </summary>
public B2QueryFilter()
{
this = Default;
}
/// The collision category bits of this query. Normally you would just set one bit.
[FieldOffset(0)]
public ulong CategoryBits;
/// The collision mask bits. This states the shape categories that this
/// query would accept for collision.
[FieldOffset(8)]
public ulong MaskBits;
}
/// Surface materials allow chain shapes to have per segment surface properties.
[StructLayout(LayoutKind.Explicit, Size = 24)]
public partial struct B2SurfaceMaterial
{
/// <summary>
/// Initializes a new instance of the B2SurfaceMaterial class using default values provided by Box2D.
/// </summary>
public B2SurfaceMaterial()
{
this = Default;
}
/// The Coulomb (dry) friction coefficient, usually in the range [0,1].
[FieldOffset(0)]
public float Friction;
/// The coefficient of restitution (bounce) usually in the range [0,1].
/// https://en.wikipedia.org/wiki/Coefficient_of_restitution
[FieldOffset(4)]
public float Restitution;
/// The rolling resistance usually in the range [0,1].
[FieldOffset(8)]
public float RollingResistance;
/// The tangent speed for conveyor belts
[FieldOffset(12)]
public float TangentSpeed;
/// User material identifier. This is passed with query results and to friction and restitution
/// combining functions. It is not used internally.
[FieldOffset(16)]
public int UserMaterialId;
/// Custom debug draw color.
[FieldOffset(20)]
public uint CustomColor;
}
/// Used to create a shape.
/// This is a temporary object used to bundle shape creation parameters. You may use
/// the same shape definition to create multiple shapes.
/// Must be initialized using b2DefaultShapeDef().
[StructLayout(LayoutKind.Explicit, Size = 80)]
public unsafe partial struct B2ShapeDef
{
/// <summary>
/// Initializes a new instance of the B2ShapeDef class using default values provided by Box2D.
/// </summary>
public B2ShapeDef()
{
this = Default;
}
/// Use this to store application specific shape data.
[FieldOffset(0)]
public void* UserData;
/// The surface material for this shape.
[FieldOffset(8)]
public B2SurfaceMaterial Material;
/// The density, usually in kg/m^2.
/// This is not part of the surface material because this is for the interior, which may have
/// other considerations, such as being hollow. For example a wood barrel may be hollow or full of water.
[FieldOffset(32)]
public float Density;
/// Collision filtering data.
[FieldOffset(40)]
public B2Filter Filter;
/// A sensor shape generates overlap events but never generates a collision response.
/// Sensors do not have continuous collision. Instead, use a ray or shape cast for those scenarios.
/// Sensors still contribute to the body mass if they have non-zero density.
/// NOTE: Sensor events are disabled by default.
/// SEE: enableSensorEvents
[FieldOffset(64)]
public Bool8 IsSensor;
/// Enable sensor events for this shape. This applies to sensors and non-sensors. False by default, even for sensors.
[FieldOffset(65)]
public Bool8 EnableSensorEvents;
/// Enable contact events for this shape. Only applies to kinematic and dynamic bodies. Ignored for sensors. False by default.
[FieldOffset(66)]
public Bool8 EnableContactEvents;
/// Enable hit events for this shape. Only applies to kinematic and dynamic bodies. Ignored for sensors. False by default.
[FieldOffset(67)]
public Bool8 EnableHitEvents;
/// Enable pre-solve contact events for this shape. Only applies to dynamic bodies. These are expensive
/// and must be carefully handled due to threading. Ignored for sensors.
[FieldOffset(68)]
public Bool8 EnablePreSolveEvents;
/// When shapes are created they will scan the environment for collision the next time step. This can significantly slow down
/// static body creation when there are many static shapes.
/// This is flag is ignored for dynamic and kinematic shapes which always invoke contact creation.
[FieldOffset(69)]
public Bool8 InvokeContactCreation;
/// Should the body update the mass properties when this shape is created. Default is true.
[FieldOffset(70)]
public Bool8 UpdateBodyMass;
/// Used internally to detect a valid definition. DO NOT SET.
[FieldOffset(72)]
public int InternalValue;
}
/// Used to create a chain of line segments. This is designed to eliminate ghost collisions with some limitations.
/// - chains are one-sided
/// - chains have no mass and should be used on static bodies
/// - chains have a counter-clockwise winding order (normal points right of segment direction)
/// - chains are either a loop or open
/// - a chain must have at least 4 points
/// - the distance between any two points must be greater than B2_LINEAR_SLOP
/// - a chain shape should not self intersect (this is not validated)
/// - an open chain shape has NO COLLISION on the first and final edge
/// - you may overlap two open chains on their first three and/or last three points to get smooth collision
/// - a chain shape creates multiple line segment shapes on the body
/// https://en.wikipedia.org/wiki/Polygonal_chain
/// Must be initialized using b2DefaultChainDef().
/// WARNING: Do not use chain shapes unless you understand the limitations. This is an advanced feature.
[StructLayout(LayoutKind.Explicit, Size = 72)]
public unsafe partial struct B2ChainDef
{
/// <summary>
/// Initializes a new instance of the B2ChainDef class using default values provided by Box2D.
/// </summary>
public B2ChainDef()
{
this = Default;
}
/// Use this to store application specific shape data.
[FieldOffset(0)]
public void* UserData;
/// An array of at least 4 points. These are cloned and may be temporary.
[FieldOffset(8)]
public float2* Points;
/// The point count, must be 4 or more.
[FieldOffset(16)]
public int Count;
/// Surface materials for each segment. These are cloned.
[FieldOffset(24)]
public B2SurfaceMaterial* Materials;
/// The material count. Must be 1 or count. This allows you to provide one
/// material for all segments or a unique material per segment.
[FieldOffset(32)]
public int MaterialCount;
/// Contact filtering data.
[FieldOffset(40)]
public B2Filter Filter;
/// Indicates a closed chain formed by connecting the first and last points
[FieldOffset(64)]
public Bool8 IsLoop;
/// Enable sensors to detect this chain. False by default.
[FieldOffset(65)]
public Bool8 EnableSensorEvents;
/// Used internally to detect a valid definition. DO NOT SET.
[FieldOffset(68)]
public int InternalValue;
}
/// Profiling data. Times are in milliseconds.
[StructLayout(LayoutKind.Explicit, Size = 88)]
public struct B2Profile
{
///
[FieldOffset(0)]
public float Step;
///
[FieldOffset(4)]
public float Pairs;
///
[FieldOffset(8)]
public float Collide;
///
[FieldOffset(12)]
public float Solve;
///
[FieldOffset(16)]
public float MergeIslands;
///
[FieldOffset(20)]
public float PrepareStages;
///
[FieldOffset(24)]
public float SolveConstraints;
///
[FieldOffset(28)]
public float PrepareConstraints;
///
[FieldOffset(32)]
public float IntegrateVelocities;
///
[FieldOffset(36)]
public float WarmStart;
///
[FieldOffset(40)]
public float SolveImpulses;
///
[FieldOffset(44)]
public float IntegratePositions;
///
[FieldOffset(48)]
public float RelaxImpulses;
///
[FieldOffset(52)]
public float ApplyRestitution;
///
[FieldOffset(56)]
public float StoreImpulses;
///
[FieldOffset(60)]
public float SplitIslands;
///
[FieldOffset(64)]
public float Transforms;
///
[FieldOffset(68)]
public float HitEvents;
///
[FieldOffset(72)]
public float Refit;
///
[FieldOffset(76)]
public float Bullets;
///
[FieldOffset(80)]
public float SleepIslands;
///
[FieldOffset(84)]
public float Sensors;
}
/// Counters that give details of the simulation size.
[StructLayout(LayoutKind.Explicit, Size = 88)]
public unsafe struct B2Counters
{
///
[FieldOffset(0)]
public int BodyCount;
///
[FieldOffset(4)]
public int ShapeCount;
///
[FieldOffset(8)]
public int ContactCount;
///
[FieldOffset(12)]
public int JointCount;
///
[FieldOffset(16)]
public int IslandCount;
///
[FieldOffset(20)]
public int StackUsed;
///
[FieldOffset(24)]
public int StaticTreeHeight;
///
[FieldOffset(28)]
public int TreeHeight;
///
[FieldOffset(32)]
public int ByteCount;
///
[FieldOffset(36)]
public int TaskCount;
///
[FieldOffset(40)]
public fixed int ColorCounts[12];
}
/// Distance joint definition
/// This requires defining an anchor point on both
/// bodies and the non-zero distance of the distance joint. The definition uses
/// local anchor points so that the initial configuration can violate the
/// constraint slightly. This helps when saving and loading a game.
[StructLayout(LayoutKind.Explicit, Size = 96)]
public unsafe partial struct B2DistanceJointDef
{
/// <summary>
/// Initializes a new instance of the B2DistanceJointDef class using default values provided by Box2D.
/// </summary>
public B2DistanceJointDef()
{
this = Default;
}
/// The first attached body
[FieldOffset(0)]
public B2Body BodyIdA;
/// The second attached body
[FieldOffset(8)]
public B2Body BodyIdB;
/// The local anchor point relative to bodyA&apos;s origin
[FieldOffset(16)]
public float2 LocalAnchorA;
/// The local anchor point relative to bodyB&apos;s origin
[FieldOffset(24)]
public float2 LocalAnchorB;
/// The rest length of this joint. Clamped to a stable minimum value.
[FieldOffset(32)]
public float Length;
/// Enable the distance constraint to behave like a spring. If false
/// then the distance joint will be rigid, overriding the limit and motor.
[FieldOffset(36)]
public Bool8 EnableSpring;
/// The spring linear stiffness Hertz, cycles per second
[FieldOffset(40)]
public float Hertz;
/// The spring linear damping ratio, non-dimensional
[FieldOffset(44)]
public float DampingRatio;
/// Enable/disable the joint limit
[FieldOffset(48)]
public Bool8 EnableLimit;
/// Minimum length. Clamped to a stable minimum value.
[FieldOffset(52)]
public float MinLength;
/// Maximum length. Must be greater than or equal to the minimum length.
[FieldOffset(56)]
public float MaxLength;
/// Enable/disable the joint motor
[FieldOffset(60)]
public Bool8 EnableMotor;
/// The maximum motor force, usually in newtons
[FieldOffset(64)]
public float MaxMotorForce;
/// The desired motor speed, usually in meters per second
[FieldOffset(68)]
public float MotorSpeed;
/// Set this flag to true if the attached bodies should collide
[FieldOffset(72)]
public Bool8 CollideConnected;
/// User data pointer
[FieldOffset(80)]
public void* UserData;
/// Used internally to detect a valid definition. DO NOT SET.
[FieldOffset(88)]
public int InternalValue;
}
/// A motor joint is used to control the relative motion between two bodies
/// A typical usage is to control the movement of a dynamic body with respect to the ground.
[StructLayout(LayoutKind.Explicit, Size = 64)]
public unsafe partial struct B2MotorJointDef
{
/// <summary>
/// Initializes a new instance of the B2MotorJointDef class using default values provided by Box2D.
/// </summary>
public B2MotorJointDef()
{
this = Default;
}
/// The first attached body
[FieldOffset(0)]
public B2Body BodyIdA;
/// The second attached body
[FieldOffset(8)]
public B2Body BodyIdB;
/// Position of bodyB minus the position of bodyA, in bodyA&apos;s frame
[FieldOffset(16)]
public float2 LinearOffset;
/// The bodyB angle minus bodyA angle in radians
[FieldOffset(24)]
public float AngularOffset;
/// The maximum motor force in newtons
[FieldOffset(28)]
public float MaxForce;
/// The maximum motor torque in newton-meters
[FieldOffset(32)]
public float MaxTorque;
/// Position correction factor in the range [0,1]
[FieldOffset(36)]
public float CorrectionFactor;
/// Set this flag to true if the attached bodies should collide
[FieldOffset(40)]
public Bool8 CollideConnected;
/// User data pointer
[FieldOffset(48)]
public void* UserData;
/// Used internally to detect a valid definition. DO NOT SET.
[FieldOffset(56)]
public int InternalValue;
}
/// A mouse joint is used to make a point on a body track a specified world point.
/// This a soft constraint and allows the constraint to stretch without
/// applying huge forces. This also applies rotation constraint heuristic to improve control.
[StructLayout(LayoutKind.Explicit, Size = 56)]
public unsafe partial struct B2MouseJointDef
{
/// <summary>
/// Initializes a new instance of the B2MouseJointDef class using default values provided by Box2D.
/// </summary>
public B2MouseJointDef()
{
this = Default;
}
/// The first attached body. This is assumed to be static.
[FieldOffset(0)]
public B2Body BodyIdA;
/// The second attached body.
[FieldOffset(8)]
public B2Body BodyIdB;
/// The initial target point in world space
[FieldOffset(16)]
public float2 Target;
/// Stiffness in hertz
[FieldOffset(24)]
public float Hertz;
/// Damping ratio, non-dimensional
[FieldOffset(28)]
public float DampingRatio;
/// Maximum force, typically in newtons
[FieldOffset(32)]
public float MaxForce;
/// Set this flag to true if the attached bodies should collide.
[FieldOffset(36)]
public Bool8 CollideConnected;
/// User data pointer
[FieldOffset(40)]
public void* UserData;
/// Used internally to detect a valid definition. DO NOT SET.
[FieldOffset(48)]
public int InternalValue;
}
/// A filter joint is used to disable collision between two specific bodies.
[StructLayout(LayoutKind.Explicit, Size = 32)]
public unsafe partial struct B2FilterJointDef
{
/// <summary>
/// Initializes a new instance of the B2FilterJointDef class using default values provided by Box2D.
/// </summary>
public B2FilterJointDef()
{
this = Default;
}
/// The first attached body.
[FieldOffset(0)]
public B2Body BodyIdA;
/// The second attached body.
[FieldOffset(8)]
public B2Body BodyIdB;
/// User data pointer
[FieldOffset(16)]
public void* UserData;
/// Used internally to detect a valid definition. DO NOT SET.
[FieldOffset(24)]
public int InternalValue;
}
/// 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.
[StructLayout(LayoutKind.Explicit, Size = 104)]
public unsafe partial struct B2PrismaticJointDef
{
/// <summary>
/// Initializes a new instance of the B2PrismaticJointDef class using default values provided by Box2D.
/// </summary>
public B2PrismaticJointDef()
{
this = Default;
}
/// The first attached body
[FieldOffset(0)]
public B2Body BodyIdA;
/// The second attached body
[FieldOffset(8)]
public B2Body BodyIdB;
/// The local anchor point relative to bodyA&apos;s origin
[FieldOffset(16)]
public float2 LocalAnchorA;
/// The local anchor point relative to bodyB&apos;s origin
[FieldOffset(24)]
public float2 LocalAnchorB;
/// The local translation unit axis in bodyA
[FieldOffset(32)]
public float2 LocalAxisA;
/// The constrained angle between the bodies: bodyB_angle - bodyA_angle
[FieldOffset(40)]
public float ReferenceAngle;
/// The target translation for the joint in meters. The spring-damper will drive
/// to this translation.
[FieldOffset(44)]
public float TargetTranslation;
/// Enable a linear spring along the prismatic joint axis
[FieldOffset(48)]
public Bool8 EnableSpring;
/// The spring stiffness Hertz, cycles per second
[FieldOffset(52)]
public float Hertz;
/// The spring damping ratio, non-dimensional
[FieldOffset(56)]
public float DampingRatio;
/// Enable/disable the joint limit
[FieldOffset(60)]
public Bool8 EnableLimit;
/// The lower translation limit
[FieldOffset(64)]
public float LowerTranslation;
/// The upper translation limit
[FieldOffset(68)]
public float UpperTranslation;
/// Enable/disable the joint motor
[FieldOffset(72)]
public Bool8 EnableMotor;
/// The maximum motor force, typically in newtons
[FieldOffset(76)]
public float MaxMotorForce;
/// The desired motor speed, typically in meters per second
[FieldOffset(80)]
public float MotorSpeed;
/// Set this flag to true if the attached bodies should collide
[FieldOffset(84)]
public Bool8 CollideConnected;
/// User data pointer
[FieldOffset(88)]
public void* UserData;
/// Used internally to detect a valid definition. DO NOT SET.
[FieldOffset(96)]
public int InternalValue;
}
/// 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&apos;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
[StructLayout(LayoutKind.Explicit, Size = 104)]
public unsafe partial struct B2RevoluteJointDef
{
/// <summary>
/// Initializes a new instance of the B2RevoluteJointDef class using default values provided by Box2D.
/// </summary>
public B2RevoluteJointDef()
{
this = Default;
}
/// The first attached body
[FieldOffset(0)]
public B2Body BodyIdA;
/// The second attached body
[FieldOffset(8)]
public B2Body BodyIdB;
/// The local anchor point relative to bodyA&apos;s origin
[FieldOffset(16)]
public float2 LocalAnchorA;
/// The local anchor point relative to bodyB&apos;s origin
[FieldOffset(24)]
public float2 LocalAnchorB;
/// The bodyB angle minus bodyA angle in the reference state (radians).
/// This defines the zero angle for the joint limit.
[FieldOffset(32)]
public float ReferenceAngle;
/// The target angle for the joint in radians. The spring-damper will drive
/// to this angle.
[FieldOffset(36)]
public float TargetAngle;
/// Enable a rotational spring on the revolute hinge axis
[FieldOffset(40)]
public Bool8 EnableSpring;
/// The spring stiffness Hertz, cycles per second
[FieldOffset(44)]
public float Hertz;
/// The spring damping ratio, non-dimensional
[FieldOffset(48)]
public float DampingRatio;
/// A flag to enable joint limits
[FieldOffset(52)]
public Bool8 EnableLimit;
/// The lower angle for the joint limit in radians. Minimum of -0.99*pi radians.
[FieldOffset(56)]
public float LowerAngle;
/// The upper angle for the joint limit in radians. Maximum of 0.99*pi radians.
[FieldOffset(60)]
public float UpperAngle;
/// A flag to enable the joint motor
[FieldOffset(64)]
public Bool8 EnableMotor;
/// The maximum motor torque, typically in newton-meters
[FieldOffset(68)]
public float MaxMotorTorque;
/// The desired motor speed in radians per second
[FieldOffset(72)]
public float MotorSpeed;
/// Scale the debug draw
[FieldOffset(76)]
public float DrawSize;
/// Set this flag to true if the attached bodies should collide
[FieldOffset(80)]
public Bool8 CollideConnected;
/// User data pointer
[FieldOffset(88)]
public void* UserData;
/// Used internally to detect a valid definition. DO NOT SET.
[FieldOffset(96)]
public int InternalValue;
}
/// Weld joint definition
/// A weld joint connect to bodies together rigidly. This constraint provides springs to mimic
/// soft-body simulation.
/// NOTE: The approximate solver in Box2D cannot hold many bodies together rigidly
[StructLayout(LayoutKind.Explicit, Size = 72)]
public unsafe partial struct B2WeldJointDef
{
/// <summary>
/// Initializes a new instance of the B2WeldJointDef class using default values provided by Box2D.
/// </summary>
public B2WeldJointDef()
{
this = Default;
}
/// The first attached body
[FieldOffset(0)]
public B2Body BodyIdA;
/// The second attached body
[FieldOffset(8)]
public B2Body BodyIdB;
/// The local anchor point relative to bodyA&apos;s origin
[FieldOffset(16)]
public float2 LocalAnchorA;
/// The local anchor point relative to bodyB&apos;s origin
[FieldOffset(24)]
public float2 LocalAnchorB;
/// The bodyB angle minus bodyA angle in the reference state (radians)
/// todo maybe make this a b2Rot
[FieldOffset(32)]
public float ReferenceAngle;
/// Linear stiffness expressed as Hertz (cycles per second). Use zero for maximum stiffness.
[FieldOffset(36)]
public float LinearHertz;
/// Angular stiffness as Hertz (cycles per second). Use zero for maximum stiffness.
[FieldOffset(40)]
public float AngularHertz;
/// Linear damping ratio, non-dimensional. Use 1 for critical damping.
[FieldOffset(44)]
public float LinearDampingRatio;
/// Linear damping ratio, non-dimensional. Use 1 for critical damping.
[FieldOffset(48)]
public float AngularDampingRatio;
/// Set this flag to true if the attached bodies should collide
[FieldOffset(52)]
public Bool8 CollideConnected;
/// User data pointer
[FieldOffset(56)]
public void* UserData;
/// Used internally to detect a valid definition. DO NOT SET.
[FieldOffset(64)]
public int InternalValue;
}
/// Wheel 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.
[StructLayout(LayoutKind.Explicit, Size = 96)]
public unsafe partial struct B2WheelJointDef
{
/// <summary>
/// Initializes a new instance of the B2WheelJointDef class using default values provided by Box2D.
/// </summary>
public B2WheelJointDef()
{
this = Default;
}
/// The first attached body
[FieldOffset(0)]
public B2Body BodyIdA;
/// The second attached body
[FieldOffset(8)]
public B2Body BodyIdB;
/// The local anchor point relative to bodyA&apos;s origin
[FieldOffset(16)]
public float2 LocalAnchorA;
/// The local anchor point relative to bodyB&apos;s origin
[FieldOffset(24)]
public float2 LocalAnchorB;
/// The local translation unit axis in bodyA
[FieldOffset(32)]
public float2 LocalAxisA;
/// Enable a linear spring along the local axis
[FieldOffset(40)]
public Bool8 EnableSpring;
/// Spring stiffness in Hertz
[FieldOffset(44)]
public float Hertz;
/// Spring damping ratio, non-dimensional
[FieldOffset(48)]
public float DampingRatio;
/// Enable/disable the joint linear limit
[FieldOffset(52)]
public Bool8 EnableLimit;
/// The lower translation limit
[FieldOffset(56)]
public float LowerTranslation;
/// The upper translation limit
[FieldOffset(60)]
public float UpperTranslation;
/// Enable/disable the joint rotational motor
[FieldOffset(64)]
public Bool8 EnableMotor;
/// The maximum motor torque, typically in newton-meters
[FieldOffset(68)]
public float MaxMotorTorque;
/// The desired motor speed in radians per second
[FieldOffset(72)]
public float MotorSpeed;
/// Set this flag to true if the attached bodies should collide
[FieldOffset(76)]
public Bool8 CollideConnected;
/// User data pointer
[FieldOffset(80)]
public void* UserData;
/// Used internally to detect a valid definition. DO NOT SET.
[FieldOffset(88)]
public int InternalValue;
}
/// The explosion definition is used to configure options for explosions. Explosions
/// consider shape geometry when computing the impulse.
[StructLayout(LayoutKind.Explicit, Size = 32)]
public partial struct B2ExplosionDef
{
/// <summary>
/// Initializes a new instance of the B2ExplosionDef class using default values provided by Box2D.
/// </summary>
public B2ExplosionDef()
{
this = Default;
}
/// Mask bits to filter shapes
[FieldOffset(0)]
public ulong MaskBits;
/// The center of the explosion in world space
[FieldOffset(8)]
public float2 Position;
/// The radius of the explosion
[FieldOffset(16)]
public float Radius;
/// The falloff distance beyond the radius. Impulse is reduced to zero at this distance.
[FieldOffset(20)]
public float Falloff;
/// Impulse per unit length. This applies an impulse according to the shape perimeter that
/// is facing the explosion. Explosions only apply to circles, capsules, and polygons. This
/// may be negative for implosions.
[FieldOffset(24)]
public float ImpulsePerLength;
}
/// A begin touch event is generated when a shape starts to overlap a sensor shape.
[StructLayout(LayoutKind.Explicit, Size = 16)]
public struct B2SensorBeginTouchEvent
{
/// The id of the sensor shape
[FieldOffset(0)]
public B2Shape SensorShapeId;
/// The id of the dynamic shape that began touching the sensor shape
[FieldOffset(8)]
public B2Shape VisitorShapeId;
}
/// An end touch event is generated when a shape stops overlapping a sensor shape.
/// These include things like setting the transform, destroying a body or shape, or changing
/// a filter. You will also get an end event if the sensor or visitor are destroyed.
/// Therefore you should always confirm the shape id is valid using b2Shape_IsValid.
[StructLayout(LayoutKind.Explicit, Size = 16)]
public struct B2SensorEndTouchEvent
{
/// The id of the sensor shape
/// WARNING: this shape may have been destroyed
/// SEE: b2Shape_IsValid
[FieldOffset(0)]
public B2Shape SensorShapeId;
/// The id of the dynamic shape that stopped touching the sensor shape
/// WARNING: this shape may have been destroyed
/// SEE: b2Shape_IsValid
[FieldOffset(8)]
public B2Shape VisitorShapeId;
}
/// Sensor events are buffered in the Box2D world and are available
/// as begin/end overlap event arrays after the time step is complete.
/// Note: these may become invalid if bodies and/or shapes are destroyed
[StructLayout(LayoutKind.Explicit, Size = 24)]
public unsafe struct B2SensorEvents
{
/// Array of sensor begin touch events
[FieldOffset(0)]
public B2SensorBeginTouchEvent* BeginEvents;
/// Array of sensor end touch events
[FieldOffset(8)]
public B2SensorEndTouchEvent* EndEvents;
/// The number of begin touch events
[FieldOffset(16)]
public int BeginCount;
/// The number of end touch events
[FieldOffset(20)]
public int EndCount;
}
/// A begin touch event is generated when two shapes begin touching.
[StructLayout(LayoutKind.Explicit, Size = 128)]
public struct B2ContactBeginTouchEvent
{
/// Id of the first shape
[FieldOffset(0)]
public B2Shape ShapeIdA;
/// Id of the second shape
[FieldOffset(8)]
public B2Shape ShapeIdB;
/// The initial contact manifold. This is recorded before the solver is called,
/// so all the impulses will be zero.
[FieldOffset(16)]
public B2Manifold Manifold;
}
/// An end touch event is generated when two shapes stop touching.
/// You will get an end event if you do anything that destroys contacts previous to the last
/// world step. These include things like setting the transform, destroying a body
/// or shape, or changing a filter or body type.
[StructLayout(LayoutKind.Explicit, Size = 16)]
public struct B2ContactEndTouchEvent
{
/// Id of the first shape
/// WARNING: this shape may have been destroyed
/// SEE: b2Shape_IsValid
[FieldOffset(0)]
public B2Shape ShapeIdA;
/// Id of the second shape
/// WARNING: this shape may have been destroyed
/// SEE: b2Shape_IsValid
[FieldOffset(8)]
public B2Shape ShapeIdB;
}
/// A hit touch event is generated when two shapes collide with a speed faster than the hit speed threshold.
/// This may be reported for speculative contacts that have a confirmed impulse.
[StructLayout(LayoutKind.Explicit, Size = 36)]
public struct B2ContactHitEvent
{
/// Id of the first shape
[FieldOffset(0)]
public B2Shape ShapeIdA;
/// Id of the second shape
[FieldOffset(8)]
public B2Shape ShapeIdB;
/// Point where the shapes hit at the beginning of the time step.
/// This is a mid-point between the two surfaces. It could be at speculative
/// point where the two shapes were not touching at the beginning of the time step.
[FieldOffset(16)]
public float2 Point;
/// Normal vector pointing from shape A to shape B
[FieldOffset(24)]
public float2 Normal;
/// The speed the shapes are approaching. Always positive. Typically in meters per second.
[FieldOffset(32)]
public float ApproachSpeed;
}
/// Contact events are buffered in the Box2D world and are available
/// as event arrays after the time step is complete.
/// Note: these may become invalid if bodies and/or shapes are destroyed
[StructLayout(LayoutKind.Explicit, Size = 40)]
public unsafe struct B2ContactEvents
{
/// Array of begin touch events
[FieldOffset(0)]
public B2ContactBeginTouchEvent* BeginEvents;
/// Array of end touch events
[FieldOffset(8)]
public B2ContactEndTouchEvent* EndEvents;
/// Array of hit events
[FieldOffset(16)]
public B2ContactHitEvent* HitEvents;
/// Number of begin touch events
[FieldOffset(24)]
public int BeginCount;
/// Number of end touch events
[FieldOffset(28)]
public int EndCount;
/// Number of hit events
[FieldOffset(32)]
public int HitCount;
}
/// Body move events triggered when a body moves.
/// Triggered when a body moves due to simulation. Not reported for bodies moved by the user.
/// This also has a flag to indicate that the body went to sleep so the application can also
/// sleep that actor/entity/object associated with the body.
/// On the other hand if the flag does not indicate the body went to sleep then the application
/// can treat the actor/entity/object associated with the body as awake.
/// This is an efficient way for an application to update game object transforms rather than
/// calling functions such as b2Body_GetTransform() because this data is delivered as a contiguous array
/// and it is only populated with bodies that have moved.
/// NOTE: If sleeping is disabled all dynamic and kinematic bodies will trigger move events.
[StructLayout(LayoutKind.Explicit, Size = 40)]
public unsafe struct B2BodyMoveEvent
{
///
[FieldOffset(0)]
public B2Transform Transform;
///
[FieldOffset(16)]
public B2Body BodyId;
///
[FieldOffset(24)]
public void* UserData;
///
[FieldOffset(32)]
public Bool8 FellAsleep;
}
/// Body events are buffered in the Box2D world and are available
/// as event arrays after the time step is complete.
/// Note: this data becomes invalid if bodies are destroyed
[StructLayout(LayoutKind.Explicit, Size = 16)]
public unsafe struct B2BodyEvents
{
/// Array of move events
[FieldOffset(0)]
public B2BodyMoveEvent* MoveEvents;
/// Number of move events
[FieldOffset(8)]
public int MoveCount;
}
/// The contact data for two shapes. By convention the manifold normal points
/// from shape A to shape B.
/// SEE: b2Shape_GetContactData() and b2Body_GetContactData()
[StructLayout(LayoutKind.Explicit, Size = 128)]
public struct B2ContactData
{
///
[FieldOffset(0)]
public B2Shape ShapeIdA;
///
[FieldOffset(8)]
public B2Shape ShapeIdB;
///
[FieldOffset(16)]
public B2Manifold Manifold;
}
/// This struct holds callbacks you can implement to draw a Box2D world.
/// This structure should be zero initialized.
[StructLayout(LayoutKind.Explicit, Size = 112)]
public unsafe partial struct B2DebugDraw
{
/// <summary>
/// Initializes a new instance of the B2DebugDraw class using default values provided by Box2D.
/// </summary>
public B2DebugDraw()
{
this = Default;
}
/// Draw a closed polygon provided in CCW order.
[FieldOffset(0)]
public nint DrawPolygonFcn;
/// Draw a solid closed polygon provided in CCW order.
[FieldOffset(8)]
public nint DrawSolidPolygonFcn;
/// Draw a circle.
[FieldOffset(16)]
public nint DrawCircleFcn;
/// Draw a solid circle.
[FieldOffset(24)]
public nint DrawSolidCircleFcn;
/// Draw a solid capsule.
[FieldOffset(32)]
public nint DrawSolidCapsuleFcn;
/// Draw a line segment.
[FieldOffset(40)]
public nint DrawSegmentFcn;
/// Draw a transform. Choose your own length scale.
[FieldOffset(48)]
public nint DrawTransformFcn;
/// Draw a point.
[FieldOffset(56)]
public nint DrawPointFcn;
/// Draw a string in world space
[FieldOffset(64)]
public nint DrawStringFcn;
/// Bounds to use if restricting drawing to a rectangular region
[FieldOffset(72)]
public B2Aabb DrawingBounds;
/// Option to restrict drawing to a rectangular region. May suffer from unstable depth sorting.
[FieldOffset(88)]
public Bool8 UseDrawingBounds;
/// Option to draw shapes
[FieldOffset(89)]
public Bool8 DrawShapes;
/// Option to draw joints
[FieldOffset(90)]
public Bool8 DrawJoints;
/// Option to draw additional information for joints
[FieldOffset(91)]
public Bool8 DrawJointExtras;
/// Option to draw the bounding boxes for shapes
[FieldOffset(92)]
public Bool8 DrawBounds;
/// Option to draw the mass and center of mass of dynamic bodies
[FieldOffset(93)]
public Bool8 DrawMass;
/// Option to draw body names
[FieldOffset(94)]
public Bool8 DrawBodyNames;
/// Option to draw contact points
[FieldOffset(95)]
public Bool8 DrawContacts;
/// Option to visualize the graph coloring used for contacts and joints
[FieldOffset(96)]
public Bool8 DrawGraphColors;
/// Option to draw contact normals
[FieldOffset(97)]
public Bool8 DrawContactNormals;
/// Option to draw contact normal impulses
[FieldOffset(98)]
public Bool8 DrawContactImpulses;
/// Option to draw contact feature ids
[FieldOffset(99)]
public Bool8 DrawContactFeatures;
/// Option to draw contact friction impulses
[FieldOffset(100)]
public Bool8 DrawFrictionImpulses;
/// Option to draw islands as bounding boxes
[FieldOffset(101)]
public Bool8 DrawIslands;
/// User context that is passed as an argument to drawing callback functions
[FieldOffset(104)]
public void* Context;
}
/// <summary>
/// Represents an inline array of float2 with a fixed size of 8.
/// </summary>
[InlineArray(8)]
public struct float2_8
{
/// <summary>
/// Internal member used to represent the type we have an inline array for.
/// </summary>
public float2 Items;
}
/// <summary>
/// Represents an inline array of B2ManifoldPoint with a fixed size of 2.
/// </summary>
[InlineArray(2)]
public struct B2ManifoldPoint_2
{
/// <summary>
/// Internal member used to represent the type we have an inline array for.
/// </summary>
public B2ManifoldPoint Items;
}
/// <summary>
/// Custom class built to enable member-function access.
/// </summary>
public readonly partial struct B2Contact { }
/// <summary>
/// Custom class built to enable member-function access.
/// </summary>
[NativeMarshalling(typeof(B2JointMarshaller<B2DistanceJoint>))]
public class B2DistanceJoint : B2Joint
{
/// Set the rest length of a distance joint
/// <param name="length">The new distance joint length </param>
public void SetLength(float length)
{
Box2D.DistanceJointSetLength(this, length);
}
/// Get the rest length of a distance joint
public float GetLength()
{
return Box2D.DistanceJointGetLength(this);
}
/// Enable/disable the distance joint spring. When disabled the distance joint is rigid.
public void EnableSpring(Bool8 enableSpring)
{
Box2D.DistanceJointEnableSpring(this, enableSpring);
}
/// Is the distance joint spring enabled?
public Bool8 IsSpringEnabled()
{
return Box2D.DistanceJointIsSpringEnabled(this);
}
/// Set the spring stiffness in Hertz
public void SetSpringHertz(float hertz)
{
Box2D.DistanceJointSetSpringHertz(this, hertz);
}
/// Set the spring damping ratio, non-dimensional
public void SetSpringDampingRatio(float dampingRatio)
{
Box2D.DistanceJointSetSpringDampingRatio(this, dampingRatio);
}
/// Get the spring Hertz
public float GetSpringHertz()
{
return Box2D.DistanceJointGetSpringHertz(this);
}
/// Get the spring damping ratio
public float GetSpringDampingRatio()
{
return Box2D.DistanceJointGetSpringDampingRatio(this);
}
/// Enable joint limit. The limit only works if the joint spring is enabled. Otherwise the joint is rigid
/// and the limit has no effect.
public void EnableLimit(Bool8 enableLimit)
{
Box2D.DistanceJointEnableLimit(this, enableLimit);
}
/// Is the distance joint limit enabled?
public Bool8 IsLimitEnabled()
{
return Box2D.DistanceJointIsLimitEnabled(this);
}
/// Set the minimum and maximum length parameters of a distance joint
public void SetLengthRange(float minLength, float maxLength)
{
Box2D.DistanceJointSetLengthRange(this, minLength, maxLength);
}
/// Get the distance joint minimum length
public float GetMinLength()
{
return Box2D.DistanceJointGetMinLength(this);
}
/// Get the distance joint maximum length
public float GetMaxLength()
{
return Box2D.DistanceJointGetMaxLength(this);
}
/// Get the current length of a distance joint
public float GetCurrentLength()
{
return Box2D.DistanceJointGetCurrentLength(this);
}
/// Enable/disable the distance joint motor
public void EnableMotor(Bool8 enableMotor)
{
Box2D.DistanceJointEnableMotor(this, enableMotor);
}
/// Is the distance joint motor enabled?
public Bool8 IsMotorEnabled()
{
return Box2D.DistanceJointIsMotorEnabled(this);
}
/// Set the distance joint motor speed, usually in meters per second
public void SetMotorSpeed(float motorSpeed)
{
Box2D.DistanceJointSetMotorSpeed(this, motorSpeed);
}
/// Get the distance joint motor speed, usually in meters per second
public float GetMotorSpeed()
{
return Box2D.DistanceJointGetMotorSpeed(this);
}
/// Set the distance joint maximum motor force, usually in newtons
public void SetMaxMotorForce(float force)
{
Box2D.DistanceJointSetMaxMotorForce(this, force);
}
/// Get the distance joint maximum motor force, usually in newtons
public float GetMaxMotorForce()
{
return Box2D.DistanceJointGetMaxMotorForce(this);
}
/// Get the distance joint current motor force, usually in newtons
public float GetMotorForce()
{
return Box2D.DistanceJointGetMotorForce(this);
}
}
/// <summary>
/// Custom class built to enable member-function access.
/// </summary>
[NativeMarshalling(typeof(B2JointMarshaller<B2FilterJoint>))]
public class B2FilterJoint : B2Joint { }
/// <summary>
/// Custom class built to enable member-function access.
/// </summary>
[NativeMarshalling(typeof(B2JointMarshaller<B2MotorJoint>))]
public class B2MotorJoint : B2Joint
{
/// Set the motor joint linear offset target
public void SetLinearOffset(float2 linearOffset)
{
Box2D.MotorJointSetLinearOffset(this, linearOffset);
}
/// Get the motor joint linear offset target
public float2 GetLinearOffset()
{
return Box2D.MotorJointGetLinearOffset(this);
}
/// Set the motor joint angular offset target in radians. This angle will be unwound
/// so the motor will drive along the shortest arc.
public void SetAngularOffset(float angularOffset)
{
Box2D.MotorJointSetAngularOffset(this, angularOffset);
}
/// Get the motor joint angular offset target in radians
public float GetAngularOffset()
{
return Box2D.MotorJointGetAngularOffset(this);
}
/// Set the motor joint maximum force, usually in newtons
public void SetMaxForce(float maxForce)
{
Box2D.MotorJointSetMaxForce(this, maxForce);
}
/// Get the motor joint maximum force, usually in newtons
public float GetMaxForce()
{
return Box2D.MotorJointGetMaxForce(this);
}
/// Set the motor joint maximum torque, usually in newton-meters
public void SetMaxTorque(float maxTorque)
{
Box2D.MotorJointSetMaxTorque(this, maxTorque);
}
/// Get the motor joint maximum torque, usually in newton-meters
public float GetMaxTorque()
{
return Box2D.MotorJointGetMaxTorque(this);
}
/// Set the motor joint correction factor, usually in [0, 1]
public void SetCorrectionFactor(float correctionFactor)
{
Box2D.MotorJointSetCorrectionFactor(this, correctionFactor);
}
/// Get the motor joint correction factor, usually in [0, 1]
public float GetCorrectionFactor()
{
return Box2D.MotorJointGetCorrectionFactor(this);
}
}
/// <summary>
/// Custom class built to enable member-function access.
/// </summary>
[NativeMarshalling(typeof(B2JointMarshaller<B2MouseJoint>))]
public class B2MouseJoint : B2Joint
{
/// Set the mouse joint target
public void SetTarget(float2 target)
{
Box2D.MouseJointSetTarget(this, target);
}
/// Get the mouse joint target
public float2 GetTarget()
{
return Box2D.MouseJointGetTarget(this);
}
/// Set the mouse joint spring stiffness in Hertz
public void SetSpringHertz(float hertz)
{
Box2D.MouseJointSetSpringHertz(this, hertz);
}
/// Get the mouse joint spring stiffness in Hertz
public float GetSpringHertz()
{
return Box2D.MouseJointGetSpringHertz(this);
}
/// Set the mouse joint spring damping ratio, non-dimensional
public void SetSpringDampingRatio(float dampingRatio)
{
Box2D.MouseJointSetSpringDampingRatio(this, dampingRatio);
}
/// Get the mouse joint damping ratio, non-dimensional
public float GetSpringDampingRatio()
{
return Box2D.MouseJointGetSpringDampingRatio(this);
}
/// Set the mouse joint maximum force, usually in newtons
public void SetMaxForce(float maxForce)
{
Box2D.MouseJointSetMaxForce(this, maxForce);
}
/// Get the mouse joint maximum force, usually in newtons
public float GetMaxForce()
{
return Box2D.MouseJointGetMaxForce(this);
}
}
/// <summary>
/// Custom class built to enable member-function access.
/// </summary>
[NativeMarshalling(typeof(B2JointMarshaller<B2PrismaticJoint>))]
public class B2PrismaticJoint : B2Joint
{
/// Enable/disable the joint spring.
public void EnableSpring(Bool8 enableSpring)
{
Box2D.PrismaticJointEnableSpring(this, enableSpring);
}
/// Is the prismatic joint spring enabled or not?
public Bool8 IsSpringEnabled()
{
return Box2D.PrismaticJointIsSpringEnabled(this);
}
/// Set the prismatic joint stiffness in Hertz.
/// This should usually be less than a quarter of the simulation rate. For example, if the simulation
/// runs at 60Hz then the joint stiffness should be 15Hz or less.
public void SetSpringHertz(float hertz)
{
Box2D.PrismaticJointSetSpringHertz(this, hertz);
}
/// Get the prismatic joint stiffness in Hertz
public float GetSpringHertz()
{
return Box2D.PrismaticJointGetSpringHertz(this);
}
/// Set the prismatic joint damping ratio (non-dimensional)
public void SetSpringDampingRatio(float dampingRatio)
{
Box2D.PrismaticJointSetSpringDampingRatio(this, dampingRatio);
}
/// Get the prismatic spring damping ratio (non-dimensional)
public float GetSpringDampingRatio()
{
return Box2D.PrismaticJointGetSpringDampingRatio(this);
}
/// Set the prismatic joint spring target angle, usually in meters
public void SetTargetTranslation(float translation)
{
Box2D.PrismaticJointSetTargetTranslation(this, translation);
}
/// Get the prismatic joint spring target translation, usually in meters
public float GetTargetTranslation()
{
return Box2D.PrismaticJointGetTargetTranslation(this);
}
/// Enable/disable a prismatic joint limit
public void EnableLimit(Bool8 enableLimit)
{
Box2D.PrismaticJointEnableLimit(this, enableLimit);
}
/// Is the prismatic joint limit enabled?
public Bool8 IsLimitEnabled()
{
return Box2D.PrismaticJointIsLimitEnabled(this);
}
/// Get the prismatic joint lower limit
public float GetLowerLimit()
{
return Box2D.PrismaticJointGetLowerLimit(this);
}
/// Get the prismatic joint upper limit
public float GetUpperLimit()
{
return Box2D.PrismaticJointGetUpperLimit(this);
}
/// Set the prismatic joint limits
public void SetLimits(float lower, float upper)
{
Box2D.PrismaticJointSetLimits(this, lower, upper);
}
/// Enable/disable a prismatic joint motor
public void EnableMotor(Bool8 enableMotor)
{
Box2D.PrismaticJointEnableMotor(this, enableMotor);
}
/// Is the prismatic joint motor enabled?
public Bool8 IsMotorEnabled()
{
return Box2D.PrismaticJointIsMotorEnabled(this);
}
/// Set the prismatic joint motor speed, usually in meters per second
public void SetMotorSpeed(float motorSpeed)
{
Box2D.PrismaticJointSetMotorSpeed(this, motorSpeed);
}
/// Get the prismatic joint motor speed, usually in meters per second
public float GetMotorSpeed()
{
return Box2D.PrismaticJointGetMotorSpeed(this);
}
/// Set the prismatic joint maximum motor force, usually in newtons
public void SetMaxMotorForce(float force)
{
Box2D.PrismaticJointSetMaxMotorForce(this, force);
}
/// Get the prismatic joint maximum motor force, usually in newtons
public float GetMaxMotorForce()
{
return Box2D.PrismaticJointGetMaxMotorForce(this);
}
/// Get the prismatic joint current motor force, usually in newtons
public float GetMotorForce()
{
return Box2D.PrismaticJointGetMotorForce(this);
}
/// Get the current joint translation, usually in meters.
public float GetTranslation()
{
return Box2D.PrismaticJointGetTranslation(this);
}
/// Get the current joint translation speed, usually in meters per second.
public float GetSpeed()
{
return Box2D.PrismaticJointGetSpeed(this);
}
}
/// <summary>
/// Custom class built to enable member-function access.
/// </summary>
[NativeMarshalling(typeof(B2JointMarshaller<B2RevoluteJoint>))]
public class B2RevoluteJoint : B2Joint
{
/// Enable/disable the revolute joint spring
public void EnableSpring(Bool8 enableSpring)
{
Box2D.RevoluteJointEnableSpring(this, enableSpring);
}
/// It the revolute angular spring enabled?
public Bool8 IsSpringEnabled()
{
return Box2D.RevoluteJointIsSpringEnabled(this);
}
/// Set the revolute joint spring stiffness in Hertz
public void SetSpringHertz(float hertz)
{
Box2D.RevoluteJointSetSpringHertz(this, hertz);
}
/// Get the revolute joint spring stiffness in Hertz
public float GetSpringHertz()
{
return Box2D.RevoluteJointGetSpringHertz(this);
}
/// Set the revolute joint spring damping ratio, non-dimensional
public void SetSpringDampingRatio(float dampingRatio)
{
Box2D.RevoluteJointSetSpringDampingRatio(this, dampingRatio);
}
/// Get the revolute joint spring damping ratio, non-dimensional
public float GetSpringDampingRatio()
{
return Box2D.RevoluteJointGetSpringDampingRatio(this);
}
/// Set the revolute joint spring target angle, radians
public void SetTargetAngle(float angle)
{
Box2D.RevoluteJointSetTargetAngle(this, angle);
}
/// Get the revolute joint spring target angle, radians
public float GetTargetAngle()
{
return Box2D.RevoluteJointGetTargetAngle(this);
}
/// Get the revolute joint current angle in radians relative to the reference angle
/// SEE: b2RevoluteJointDef::referenceAngle
public float GetAngle()
{
return Box2D.RevoluteJointGetAngle(this);
}
/// Enable/disable the revolute joint limit
public void EnableLimit(Bool8 enableLimit)
{
Box2D.RevoluteJointEnableLimit(this, enableLimit);
}
/// Is the revolute joint limit enabled?
public Bool8 IsLimitEnabled()
{
return Box2D.RevoluteJointIsLimitEnabled(this);
}
/// Get the revolute joint lower limit in radians
public float GetLowerLimit()
{
return Box2D.RevoluteJointGetLowerLimit(this);
}
/// Get the revolute joint upper limit in radians
public float GetUpperLimit()
{
return Box2D.RevoluteJointGetUpperLimit(this);
}
/// Set the revolute joint limits in radians. It is expected that lower
/// &lt;
/// = upper
/// and that -0.99 * B2_PI
/// &lt;
/// = lower
/// &amp;
/// &amp;
/// upper
/// &lt;
/// = -0.99 * B2_PI.
public void SetLimits(float lower, float upper)
{
Box2D.RevoluteJointSetLimits(this, lower, upper);
}
/// Enable/disable a revolute joint motor
public void EnableMotor(Bool8 enableMotor)
{
Box2D.RevoluteJointEnableMotor(this, enableMotor);
}
/// Is the revolute joint motor enabled?
public Bool8 IsMotorEnabled()
{
return Box2D.RevoluteJointIsMotorEnabled(this);
}
/// Set the revolute joint motor speed in radians per second
public void SetMotorSpeed(float motorSpeed)
{
Box2D.RevoluteJointSetMotorSpeed(this, motorSpeed);
}
/// Get the revolute joint motor speed in radians per second
public float GetMotorSpeed()
{
return Box2D.RevoluteJointGetMotorSpeed(this);
}
/// Get the revolute joint current motor torque, usually in newton-meters
public float GetMotorTorque()
{
return Box2D.RevoluteJointGetMotorTorque(this);
}
/// Set the revolute joint maximum motor torque, usually in newton-meters
public void SetMaxMotorTorque(float torque)
{
Box2D.RevoluteJointSetMaxMotorTorque(this, torque);
}
/// Get the revolute joint maximum motor torque, usually in newton-meters
public float GetMaxMotorTorque()
{
return Box2D.RevoluteJointGetMaxMotorTorque(this);
}
}
/// <summary>
/// Custom class built to enable member-function access.
/// </summary>
[NativeMarshalling(typeof(B2JointMarshaller<B2WeldJoint>))]
public class B2WeldJoint : B2Joint
{
/// Set the weld joint linear stiffness in Hertz. 0 is rigid.
public void SetLinearHertz(float hertz)
{
Box2D.WeldJointSetLinearHertz(this, hertz);
}
/// Get the weld joint linear stiffness in Hertz
public float GetLinearHertz()
{
return Box2D.WeldJointGetLinearHertz(this);
}
/// Set the weld joint linear damping ratio (non-dimensional)
public void SetLinearDampingRatio(float dampingRatio)
{
Box2D.WeldJointSetLinearDampingRatio(this, dampingRatio);
}
/// Get the weld joint linear damping ratio (non-dimensional)
public float GetLinearDampingRatio()
{
return Box2D.WeldJointGetLinearDampingRatio(this);
}
/// Set the weld joint angular stiffness in Hertz. 0 is rigid.
public void SetAngularHertz(float hertz)
{
Box2D.WeldJointSetAngularHertz(this, hertz);
}
/// Get the weld joint angular stiffness in Hertz
public float GetAngularHertz()
{
return Box2D.WeldJointGetAngularHertz(this);
}
/// Set weld joint angular damping ratio, non-dimensional
public void SetAngularDampingRatio(float dampingRatio)
{
Box2D.WeldJointSetAngularDampingRatio(this, dampingRatio);
}
/// Get the weld joint angular damping ratio, non-dimensional
public float GetAngularDampingRatio()
{
return Box2D.WeldJointGetAngularDampingRatio(this);
}
}
/// <summary>
/// Custom class built to enable member-function access.
/// </summary>
[NativeMarshalling(typeof(B2JointMarshaller<B2WheelJoint>))]
public class B2WheelJoint : B2Joint
{
/// Enable/disable the wheel joint spring
public void EnableSpring(Bool8 enableSpring)
{
Box2D.WheelJointEnableSpring(this, enableSpring);
}
/// Is the wheel joint spring enabled?
public Bool8 IsSpringEnabled()
{
return Box2D.WheelJointIsSpringEnabled(this);
}
/// Set the wheel joint stiffness in Hertz
public void SetSpringHertz(float hertz)
{
Box2D.WheelJointSetSpringHertz(this, hertz);
}
/// Get the wheel joint stiffness in Hertz
public float GetSpringHertz()
{
return Box2D.WheelJointGetSpringHertz(this);
}
/// Set the wheel joint damping ratio, non-dimensional
public void SetSpringDampingRatio(float dampingRatio)
{
Box2D.WheelJointSetSpringDampingRatio(this, dampingRatio);
}
/// Get the wheel joint damping ratio, non-dimensional
public float GetSpringDampingRatio()
{
return Box2D.WheelJointGetSpringDampingRatio(this);
}
/// Enable/disable the wheel joint limit
public void EnableLimit(Bool8 enableLimit)
{
Box2D.WheelJointEnableLimit(this, enableLimit);
}
/// Is the wheel joint limit enabled?
public Bool8 IsLimitEnabled()
{
return Box2D.WheelJointIsLimitEnabled(this);
}
/// Get the wheel joint lower limit
public float GetLowerLimit()
{
return Box2D.WheelJointGetLowerLimit(this);
}
/// Get the wheel joint upper limit
public float GetUpperLimit()
{
return Box2D.WheelJointGetUpperLimit(this);
}
/// Set the wheel joint limits
public void SetLimits(float lower, float upper)
{
Box2D.WheelJointSetLimits(this, lower, upper);
}
/// Enable/disable the wheel joint motor
public void EnableMotor(Bool8 enableMotor)
{
Box2D.WheelJointEnableMotor(this, enableMotor);
}
/// Is the wheel joint motor enabled?
public Bool8 IsMotorEnabled()
{
return Box2D.WheelJointIsMotorEnabled(this);
}
/// Set the wheel joint motor speed in radians per second
public void SetMotorSpeed(float motorSpeed)
{
Box2D.WheelJointSetMotorSpeed(this, motorSpeed);
}
/// Get the wheel joint motor speed in radians per second
public float GetMotorSpeed()
{
return Box2D.WheelJointGetMotorSpeed(this);
}
/// Set the wheel joint maximum motor torque, usually in newton-meters
public void SetMaxMotorTorque(float torque)
{
Box2D.WheelJointSetMaxMotorTorque(this, torque);
}
/// Get the wheel joint maximum motor torque, usually in newton-meters
public float GetMaxMotorTorque()
{
return Box2D.WheelJointGetMaxMotorTorque(this);
}
/// Get the wheel joint current motor torque, usually in newton-meters
public float GetMotorTorque()
{
return Box2D.WheelJointGetMotorTorque(this);
}
}
}