Improve presentation

This commit is contained in:
gingerBill
2024-08-14 10:18:36 +01:00
parent 660b6ff0f1
commit 0b26115805
4 changed files with 392 additions and 379 deletions
+310 -307
View File
File diff suppressed because it is too large Load Diff
+48 -48
View File
@@ -10,7 +10,7 @@ maxPolygonVertices :: 8
// Low level ray-cast input data // Low level ray-cast input data
RayCastInput :: struct { RayCastInput :: struct {
// Start point of the ray cast // Start point of the ray cast
origin: Vec2, origin: Vec2,
// Translation of the ray cast // Translation of the ray cast
translation: Vec2, translation: Vec2,
@@ -24,13 +24,13 @@ RayCastInput :: struct {
// A capsule is two points with a non-zero radius. A box is four points with a zero radius. // A capsule is two points with a non-zero radius. A box is four points with a zero radius.
ShapeCastInput :: struct { ShapeCastInput :: struct {
// A point cloud to cast // A point cloud to cast
points: [maxPolygonVertices]Vec2 `fmt:"v,count"`, points: [maxPolygonVertices]Vec2 `fmt:"v,count"`,
// The number of points // The number of points
count: i32, count: i32,
// The radius around the point cloud // The radius around the point cloud
radius: f32, radius: f32,
// The translation of the shape cast // The translation of the shape cast
translation: Vec2, translation: Vec2,
@@ -42,28 +42,28 @@ ShapeCastInput :: struct {
// Low level ray-cast or shape-cast output data // Low level ray-cast or shape-cast output data
CastOutput :: struct { CastOutput :: struct {
// The surface normal at the hit point // The surface normal at the hit point
normal: Vec2, normal: Vec2,
// The surface hit point // The surface hit point
point: Vec2, point: Vec2,
// The fraction of the input translation at collision // The fraction of the input translation at collision
fraction: f32, fraction: f32,
// The number of iterations used // The number of iterations used
iterations: i32, iterations: i32,
// Did the cast hit? // Did the cast hit?
hit: bool, hit: bool,
} }
// This holds the mass data computed for a shape. // This holds the mass data computed for a shape.
MassData :: struct { MassData :: struct {
// The mass of the shape, usually in kilograms. // The mass of the shape, usually in kilograms.
mass: f32, mass: f32,
// The position of the shape's centroid relative to the shape's origin. // The position of the shape's centroid relative to the shape's origin.
center: Vec2, center: Vec2,
// The rotational inertia of the shape about the local origin. // The rotational inertia of the shape about the local origin.
rotationalInertia: f32, rotationalInertia: f32,
@@ -88,7 +88,7 @@ Capsule :: struct {
center2: Vec2, center2: Vec2,
// The radius of the semicircles // The radius of the semicircles
radius: f32, radius: f32,
} }
// A solid convex polygon. It is assumed that the interior of the polygon is to // A solid convex polygon. It is assumed that the interior of the polygon is to
@@ -102,16 +102,16 @@ Polygon :: struct {
vertices: [maxPolygonVertices]Vec2 `fmt:"v,count"`, vertices: [maxPolygonVertices]Vec2 `fmt:"v,count"`,
// The outward normal vectors of the polygon sides // The outward normal vectors of the polygon sides
normals: [maxPolygonVertices]Vec2 `fmt:"v,count"`, normals: [maxPolygonVertices]Vec2 `fmt:"v,count"`,
// The centroid of the polygon // The centroid of the polygon
centroid: Vec2, centroid: Vec2,
// The external radius for rounded polygons // The external radius for rounded polygons
radius: f32, radius: f32,
// The number of polygon vertices // The number of polygon vertices
count: i32, count: i32,
} }
// A line segment with two-sided collision. // A line segment with two-sided collision.
@@ -128,13 +128,13 @@ Segment :: struct {
// ghost1 -> point1 -> point2 -> ghost2 // ghost1 -> point1 -> point2 -> ghost2
SmoothSegment :: struct { SmoothSegment :: struct {
// The tail ghost vertex // The tail ghost vertex
ghost1: Vec2, ghost1: Vec2,
// The line segment // The line segment
segment: Segment, segment: Segment,
// The head ghost vertex // The head ghost vertex
ghost2: Vec2, ghost2: Vec2,
// The owning chain shape index (internal usage only) // The owning chain shape index (internal usage only)
chainId: i32, chainId: i32,
@@ -148,7 +148,7 @@ Hull :: struct {
points: [maxPolygonVertices]Vec2 `fmt:"v,count"`, points: [maxPolygonVertices]Vec2 `fmt:"v,count"`,
// The number of points // The number of points
count: i32, count: i32,
} }
/** /**
@@ -163,16 +163,16 @@ Hull :: struct {
// Result of computing the distance between two line segments // Result of computing the distance between two line segments
SegmentDistanceResult :: struct { SegmentDistanceResult :: struct {
// The closest point on the first segment // The closest point on the first segment
closest1: Vec2, closest1: Vec2,
// The closest point on the second segment // The closest point on the second segment
closest2: Vec2, closest2: Vec2,
// The barycentric coordinate on the first segment // The barycentric coordinate on the first segment
fraction1: f32, fraction1: f32,
// The barycentric coordinate on the second segment // The barycentric coordinate on the second segment
fraction2: f32, fraction2: f32,
// The squared distance between the closest points // The squared distance between the closest points
distanceSquared: f32, distanceSquared: f32,
@@ -184,7 +184,7 @@ DistanceProxy :: struct {
points: [maxPolygonVertices]Vec2 `fmt:"v,count"`, points: [maxPolygonVertices]Vec2 `fmt:"v,count"`,
// The number of points // The number of points
count: i32, count: i32,
// The external radius of the point cloud // The external radius of the point cloud
radius: f32, radius: f32,
@@ -291,7 +291,7 @@ TOIState :: enum c.int {
// Output parameters for b2TimeOfImpact. // Output parameters for b2TimeOfImpact.
TOIOutput :: struct { TOIOutput :: struct {
state: TOIState, // The type of result state: TOIState, // The type of result
t: f32, // The time of the collision t: f32, // The time of the collision
} }
@@ -307,23 +307,23 @@ TOIOutput :: struct {
ManifoldPoint :: struct { ManifoldPoint :: struct {
// Location of the contact point in world space. Subject to precision loss at large coordinates. // Location of the contact point in world space. Subject to precision loss at large coordinates.
// @note Should only be used for debugging. // @note Should only be used for debugging.
point: Vec2, point: Vec2,
// Location of the contact point relative to bodyA's origin in world space // Location of the contact point relative to bodyA's origin in world space
// @note When used internally to the Box2D solver, these are relative to the center of mass. // @note When used internally to the Box2D solver, these are relative to the center of mass.
anchorA: Vec2, anchorA: Vec2,
// Location of the contact point relative to bodyB's origin in world space // Location of the contact point relative to bodyB's origin in world space
anchorB: Vec2, anchorB: Vec2,
// The separation of the contact point, negative if penetrating // The separation of the contact point, negative if penetrating
separation: f32, separation: f32,
// The impulse along the manifold normal vector. // The impulse along the manifold normal vector.
normalImpulse: f32, normalImpulse: f32,
// The friction impulse // The friction impulse
tangentImpulse: f32, tangentImpulse: f32,
// The maximum normal impulse applied during sub-stepping // The maximum normal impulse applied during sub-stepping
// todo not sure this is needed // todo not sure this is needed
@@ -331,22 +331,22 @@ ManifoldPoint :: struct {
// Relative normal velocity pre-solve. Used for hit events. If the normal impulse is // 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. // zero then there was no hit. Negative means shapes are approaching.
normalVelocity: f32, normalVelocity: f32,
// Uniquely identifies a contact point between two shapes // Uniquely identifies a contact point between two shapes
id: u16, id: u16,
// Did this contact point exist the previous step? // Did this contact point exist the previous step?
persisted: bool, persisted: bool,
} }
// A contact manifold describes the contact points between colliding shapes // A contact manifold describes the contact points between colliding shapes
Manifold :: struct { Manifold :: struct {
// The manifold points, up to two are possible in 2D // The manifold points, up to two are possible in 2D
points: [2]ManifoldPoint, points: [2]ManifoldPoint,
// The unit normal vector in world space, points from shape A to bodyB // The unit normal vector in world space, points from shape A to bodyB
normal: Vec2, normal: Vec2,
// The number of contacts points, will be 0, 1, or 2 // The number of contacts points, will be 0, 1, or 2
pointCount: i32, pointCount: i32,
@@ -393,7 +393,7 @@ TreeNode :: struct {
parent: i32, parent: i32,
// The node freelist next index // The node freelist next index
next: i32, next: i32,
}, // 4 }, // 4
// Child 1 index // Child 1 index
@@ -413,41 +413,41 @@ TreeNode :: struct {
enlarged: bool, // 1 enlarged: bool, // 1
// Padding for clarity // Padding for clarity
pad: [9]byte, _: [9]byte,
} }
// The dynamic tree structure. This should be considered private data. // The dynamic tree structure. This should be considered private data.
// It is placed here for performance reasons. // It is placed here for performance reasons.
DynamicTree :: struct { DynamicTree :: struct {
// The tree nodes // The tree nodes
nodes: [^]TreeNode `fmt"v,nodeCount"`, nodes: [^]TreeNode `fmt"v,nodeCount"`,
// The root index // The root index
root: i32, root: i32,
// The number of nodes // The number of nodes
nodeCount: i32, nodeCount: i32,
// The allocated node space // The allocated node space
nodeCapacity: i32, nodeCapacity: i32,
// Node free list // Node free list
freeList: i32, freeList: i32,
// Number of proxies created // Number of proxies created
proxyCount: i32, proxyCount: i32,
// Leaf indices for rebuild // Leaf indices for rebuild
leafIndices: [^]i32, leafIndices: [^]i32,
// Leaf bounding boxes for rebuild // Leaf bounding boxes for rebuild
leafBoxes: [^]AABB, leafBoxes: [^]AABB,
// Leaf bounding box centers for rebuild // Leaf bounding box centers for rebuild
leafCenters: [^]Vec2, leafCenters: [^]Vec2,
// Bins for sorting during rebuild // Bins for sorting during rebuild
binIndices: [^]i32, binIndices: [^]i32,
// Allocated space for rebuilding // Allocated space for rebuilding
rebuildCapacity: i32, rebuildCapacity: i32,
@@ -455,7 +455,7 @@ DynamicTree :: struct {
// This function receives proxies found in the AABB query. // This function receives proxies found in the AABB query.
// @return true if the query should continue // @return true if the query should continue
TreeQueryCallbackFcn :: #type proc "c" (proxyId: i32, userData: i32, ctx: rawptr) -> bool TreeQueryCallbackFcn :: #type proc "c" (proxyId: i32, userData: i32, ctx: rawptr) -> bool
// This function receives clipped ray-cast input for a proxy. The function // This function receives clipped ray-cast input for a proxy. The function
// returns the new ray fraction. // returns the new ray fraction.
@@ -470,4 +470,4 @@ TreeShapeCastCallbackFcn :: #type proc "c" (#by_ptr input: ShapeCastInput, proxy
// - return a value of 0 to terminate the ray cast // - return a value of 0 to terminate the ray cast
// - return a value less than input->maxFraction to clip the ray // - return a value less than input->maxFraction to clip the ray
// - return a value of input->maxFraction to continue the ray cast without clipping // - return a value of input->maxFraction to continue the ray cast without clipping
TreeRayCastCallbackFcn :: #type proc "c" (#by_ptr input: RayCastInput, proxyId: i32, userData: i32, ctx: rawptr) -> f32 TreeRayCastCallbackFcn :: #type proc "c" (#by_ptr input: RayCastInput, proxyId: i32, userData: i32, ctx: rawptr) -> f32
+23 -13
View File
@@ -1,5 +1,7 @@
package vendor_box2d package vendor_box2d
import "base:intrinsics"
/** /**
* @defgroup id Ids * @defgroup id Ids
* These ids serve as handles to internal Box2D objects. * These ids serve as handles to internal Box2D objects.
@@ -7,19 +9,13 @@ package vendor_box2d
* Include this header if you need the id types and not the whole Box2D API. * Include this header if you need the id types and not the whole Box2D API.
* All ids are considered null if initialized to zero. * All ids are considered null if initialized to zero.
* *
* For example in C++: * For example in Odin:
* *
* @code{.cxx} * @code{.odin}
* b2WorldId worldId = {}; * worldId := b2.WorldId{}
* @endcode * @endcode
* *
* Or in C: * This is considered null.
*
* @code{.c}
* b2WorldId worldId = {0};
* @endcode
*
* These are both considered null.
* *
* @warning Do not use the internals of these ids. They are subject to change. Ids should be treated as opaque objects. * @warning Do not use the internals of these ids. They are subject to change. Ids should be treated as opaque objects.
* @warning You should use ids to access objects in Box2D. Do not access files within the src folder. Such usage is unsupported. * @warning You should use ids to access objects in Box2D. Do not access files within the src folder. Such usage is unsupported.
@@ -68,10 +64,24 @@ nullJointId :: JointId{}
nullChainId :: ChainId{} nullChainId :: ChainId{}
/// Macro to determine if any id is null. /// Macro to determine if any id is null.
IS_NULL :: proc "c" (id: $T) -> bool { return id.index1 == 0 } IS_NULL :: #force_inline proc "c" (id: $T) -> bool
where intrinsics.type_is_struct(T),
intrinsics.type_has_field(T, "index1") {
return id.index1 == 0
}
/// Macro to determine if any id is non-null. /// Macro to determine if any id is non-null.
IS_NON_NULL :: proc "c" (id: $T) -> bool { return id.index1 != 0 } IS_NON_NULL :: #force_inline proc "c" (id: $T) -> bool
where intrinsics.type_is_struct(T),
intrinsics.type_has_field(T, "index1") {
return id.index1 != 0
}
/// Compare two ids for equality. Doesn't work for b2WorldId. /// Compare two ids for equality. Doesn't work for b2WorldId.
ID_EQUALS :: proc "c" (id1, id2: $T) -> bool { return id1.index1 == id2.index1 && id1.world0 == id2.world0 && id1.revision == id2.revision } ID_EQUALS :: #force_inline proc "c" (id1, id2: $T) -> bool
where intrinsics.type_is_struct(T),
intrinsics.type_has_field(T, "index1"),
intrinsics.type_has_field(T, "world0"),
intrinsics.type_has_field(T, "revision") {
return id1.index1 == id2.index1 && id1.world0 == id2.world0 && id1.revision == id2.revision
}
+11 -11
View File
@@ -199,24 +199,24 @@ BodyDef :: struct {
Filter :: struct { Filter :: struct {
// The collision category bits. Normally you would just set one bit. The category bits should // The collision category bits. Normally you would just set one bit. The category bits should
// represent your application object types. For example: // represent your application object types. For example:
// @code{.cpp} // @code{.odin}
// enum MyCategories // My_Categories :: enum u32 {
// { // Static = 0x00000001,
// Static = 0x00000001, // Dynamic = 0x00000002,
// Dynamic = 0x00000002, // Debris = 0x00000004,
// Debris = 0x00000004, // Player = 0x00000008,
// Player = 0x00000008, // // etc
// // etc // };
// };
// @endcode // @endcode
// Or use a bit_set.
categoryBits: u32, categoryBits: u32,
// The collision mask bits. This states the categories that this // The collision mask bits. This states the categories that this
// shape would accept for collision. // shape would accept for collision.
// For example, you may want your player to only collide with static objects // For example, you may want your player to only collide with static objects
// and other players. // and other players.
// @code{.c} // @code{.odin}
// maskBits = Static | Player; // maskBits = u32(My_Categories.Static | My_Categories.Player);
// @endcode // @endcode
maskBits: u32, maskBits: u32,