namespace Brutal.JoltApi;
/// What says about the body it was read from.
[Flags]
public enum BodyStateFlags : uint
{
/// The ID named no body (removed, or a stale sequence number); the rest of the state is zeroed.
None = 0,
/// The ID named a body and the state was read from it.
Valid = 1,
/// The body is awake and being simulated.
Active = 2,
}
///
/// One body's pose, velocities, user data and activation, as reads them
/// for many bodies under one lock.
///
///
/// A snapshot for syncing an ECS, a network state or render interpolation from the simulation. A static body reads
/// as zero velocity. An ID that no longer names a body reads as the origin with the identity rotation and
/// clear of .
///
[StructLayout(LayoutKind.Explicit, Size = 64)]
public struct BodyState
{
// Laid out like the shim's JoltBodyState, 64 bytes (asserted there and in the tests)
/// The body's position (its centre of mass is offset from this by the shape).
[FieldOffset(0)]
public float3 Position;
/// Whether the ID named a body, and whether that body is active.
[FieldOffset(12)]
public BodyStateFlags Flags;
/// The body's rotation.
[FieldOffset(16)]
public floatQuat Rotation;
/// Linear velocity of the centre of mass, in m/s.
[FieldOffset(32)]
public float3 LinearVelocity;
/// Angular velocity, in rad/s.
[FieldOffset(44)]
public float3 AngularVelocity;
/// The body's user data, as reads it.
[FieldOffset(56)]
public ulong UserData;
/// Whether the ID named a body.
public readonly bool IsValid => (Flags & BodyStateFlags.Valid) != 0;
/// Whether the body is awake and being simulated.
public readonly bool IsActive => (Flags & BodyStateFlags.Active) != 0;
}