using System.Runtime.InteropServices; namespace Brutal.JoltApi; /// /// A convex object for : a box (with an optional convex radius), a sphere, or a /// point with a radius, placed by a transform. /// /// /// A sphere and a point with a radius describe the same volume, but the solver sees them differently: the sphere is /// one support shape, the point hands the radius to GJK as a convex radius, the way Jolt's own shapes do. /// [StructLayout(LayoutKind.Sequential)] public readonly struct ConvexObject { // Laid out like the shim's JoltConvexObject, 112 bytes (asserted there and in the tests) private readonly uint _kind; private readonly float _radius; private readonly float _convexRadius; private readonly float4x4 _transform; private readonly float3 _center; private readonly float3 _min; private readonly float3 _max; private ConvexObject( uint kind, float radius, float convexRadius, float4x4 transform, float3 center, float3 min, float3 max ) { _kind = kind; _radius = radius; _convexRadius = convexRadius; _transform = transform; _center = center; _min = min; _max = max; } /// A box from to in 's space, /// grown by . public static ConvexObject Box(float3 min, float3 max, float4x4 transform, float convexRadius = 0f) => new(0, 0f, convexRadius, transform, float3.Zero, min, max); /// A box in 's space, grown by . public static ConvexObject Box(AABox box, float4x4 transform, float convexRadius = 0f) => Box(box.Min, box.Max, transform, convexRadius); /// A sphere in 's space. public static ConvexObject Sphere(float3 center, float radius, float4x4 transform) => new(1, radius, 0f, transform, center, float3.Zero, float3.Zero); /// A sphere in world space. public static ConvexObject Sphere(float3 center, float radius) => Sphere(center, radius, float4x4.Identity); /// A point in world space, grown by as a convex radius. public static ConvexObject Point(float3 position, float radius) => new(2, radius, 0f, float4x4.Identity, position, float3.Zero, float3.Zero); }