mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-25 20:48:24 +01:00
236 lines
11 KiB
C#
236 lines
11 KiB
C#
// <auto-generated/>
|
|
// Generated by Brutal.Jolt.Generate; do not edit by hand.
|
|
#nullable enable
|
|
|
|
using System.Runtime.CompilerServices;
|
|
using Brutal.Interop;
|
|
using Brutal.Numerics;
|
|
|
|
namespace Brutal.JoltApi
|
|
{
|
|
/// <summary>
|
|
/// <para>
|
|
/// Quaternion based constraint that constrains rotation around all axis so that only translation is allowed.
|
|
/// </para>
|
|
/// <para>
|
|
/// C++:
|
|
/// <see href="https://github.com/jrouwe/JoltPhysics/blob/e77f175595e64cb44218cc9d9d56fc365ad0e36a/Jolt/Physics/Constraints/ConstraintPart/RotationQuatConstraintPart.h#L86">Jolt/Physics/Constraints/ConstraintPart/RotationQuatConstraintPart.h:86</see>
|
|
/// <br/>
|
|
/// <c>class RotationQuatConstraintPart</c>
|
|
/// </para>
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <code>
|
|
/// Quaternion based constraint that constrains rotation around all axis so that only translation is allowed.
|
|
///
|
|
/// NOTE: This constraint part is more expensive than the RotationEulerConstraintPart and slightly more correct since
|
|
/// RotationEulerConstraintPart::SolvePositionConstraint contains an approximation. In practice the difference
|
|
/// is small, so the RotationEulerConstraintPart is probably the better choice.
|
|
///
|
|
/// Rotation is fixed between bodies like this:
|
|
///
|
|
/// q2 = q1 r0
|
|
///
|
|
/// Where:
|
|
/// q1, q2 = world space quaternions representing rotation of body 1 and 2.
|
|
/// r0 = initial rotation between bodies in local space of body 1, this can be calculated by:
|
|
///
|
|
/// q20 = q10 r0
|
|
/// <=> r0 = q10^* q20
|
|
///
|
|
/// Where:
|
|
/// q10, q20 = initial world space rotations of body 1 and 2.
|
|
/// q10^* = conjugate of quaternion q10 (which is the same as the inverse for a unit quaternion)
|
|
///
|
|
/// We exclusively use the conjugate below:
|
|
///
|
|
/// r0^* = q20^* q10
|
|
///
|
|
/// The error in the rotation is (in local space of body 1):
|
|
///
|
|
/// q2 = q1 error r0
|
|
/// <=> error = q1^* q2 r0^*
|
|
///
|
|
/// The imaginary part of the quaternion represents the rotation axis * sin(angle / 2). The real part of the quaternion
|
|
/// does not add any additional information (we know the quaternion in normalized) and we're removing 3 degrees of freedom
|
|
/// so we want 3 parameters. Therefore we define the constraint equation like:
|
|
///
|
|
/// C = A q1^* q2 r0^* = 0
|
|
///
|
|
/// Where (if you write a quaternion as [real-part, i-part, j-part, k-part]):
|
|
///
|
|
/// [0, 1, 0, 0]
|
|
/// A = [0, 0, 1, 0]
|
|
/// [0, 0, 0, 1]
|
|
///
|
|
/// or in our case since we store a quaternion like [i-part, j-part, k-part, real-part]:
|
|
///
|
|
/// [1, 0, 0, 0]
|
|
/// A = [0, 1, 0, 0]
|
|
/// [0, 0, 1, 0]
|
|
///
|
|
/// Time derivative:
|
|
///
|
|
/// d/dt C = A (q1^* d/dt(q2) + d/dt(q1^*) q2) r0^*
|
|
/// = A (q1^* (1/2 W2 q2) + (1/2 W1 q1)^* q2) r0^*
|
|
/// = 1/2 A (q1^* W2 q2 + q1^* W1^* q2) r0^*
|
|
/// = 1/2 A (q1^* W2 q2 - q1^* W1 * q2) r0^*
|
|
/// = 1/2 A ML(q1^*) MR(q2 r0^*) (W2 - W1)
|
|
/// = 1/2 A ML(q1^*) MR(q2 r0^*) A^T (w2 - w1)
|
|
///
|
|
/// Where:
|
|
/// W1 = [0, w1], W2 = [0, w2] (converting angular velocity to imaginary part of quaternion).
|
|
/// w1, w2 = angular velocity of body 1 and 2.
|
|
/// d/dt(q) = 1/2 W q (time derivative of a quaternion).
|
|
/// W^* = -W (conjugate negates angular velocity as quaternion).
|
|
/// ML(q): 4x4 matrix so that q * p = ML(q) * p, where q and p are quaternions.
|
|
/// MR(p): 4x4 matrix so that q * p = MR(p) * q, where q and p are quaternions.
|
|
/// A^T: Transpose of A.
|
|
///
|
|
/// Jacobian:
|
|
///
|
|
/// J = [0, -1/2 A ML(q1^*) MR(q2 r0^*) A^T, 0, 1/2 A ML(q1^*) MR(q2 r0^*) A^T]
|
|
/// = [0, -JP, 0, JP]
|
|
///
|
|
/// Suggested reading:
|
|
/// - 3D Constraint Derivations for Impulse Solvers - Marijn Tamis
|
|
/// - Game Physics Pearls - Section 9 - Quaternion Based Constraints - Claude Lacoursiere
|
|
/// </code>
|
|
/// </remarks>
|
|
[InteropHandle]
|
|
public readonly partial struct RotationQuatConstraintPart : IDisposable
|
|
{
|
|
public static RotationQuatConstraintPart Create() => Jolt.PInvoke.RotationQuatConstraintPart_Create();
|
|
|
|
/// <summary>
|
|
/// <para>
|
|
/// Return inverse of initial rotation from body 1 to body 2 in body 1 space
|
|
/// </para>
|
|
/// <para>
|
|
/// C++:
|
|
/// <see href="https://github.com/jrouwe/JoltPhysics/blob/e77f175595e64cb44218cc9d9d56fc365ad0e36a/Jolt/Physics/Constraints/ConstraintPart/RotationQuatConstraintPart.h#L114">Jolt/Physics/Constraints/ConstraintPart/RotationQuatConstraintPart.h:114</see>
|
|
/// <br/>
|
|
/// <c>static Quat sGetInvInitialOrientation(const Body &inBody1, const Body &inBody2)</c>
|
|
/// </para>
|
|
/// </summary>
|
|
public static floatQuat GetInvInitialOrientation(Body body1, Body body2) =>
|
|
Jolt.PInvoke.RotationQuatConstraintPart_GetInvInitialOrientation(body1, body2);
|
|
|
|
/// <summary>
|
|
/// <para>
|
|
/// Calculate properties used during the functions below
|
|
/// </para>
|
|
/// <para>
|
|
/// C++:
|
|
/// <see href="https://github.com/jrouwe/JoltPhysics/blob/e77f175595e64cb44218cc9d9d56fc365ad0e36a/Jolt/Physics/Constraints/ConstraintPart/RotationQuatConstraintPart.h#L129">Jolt/Physics/Constraints/ConstraintPart/RotationQuatConstraintPart.h:129</see>
|
|
/// <br/>
|
|
/// <c>inline void CalculateConstraintProperties(const Body &inBody1, Mat44Arg inRotation1, const Body &inBody2, Mat44Arg inRotation2, QuatArg inInvInitialOrientation)</c>
|
|
/// </para>
|
|
/// </summary>
|
|
public void CalculateConstraintProperties(
|
|
Body body1,
|
|
in float4x4 rotation1,
|
|
Body body2,
|
|
in float4x4 rotation2,
|
|
floatQuat invInitialOrientation
|
|
) =>
|
|
Jolt.PInvoke.RotationQuatConstraintPart_CalculateConstraintProperties(
|
|
this,
|
|
body1,
|
|
in rotation1,
|
|
body2,
|
|
in rotation2,
|
|
invInitialOrientation
|
|
);
|
|
|
|
/// <summary>
|
|
/// <para>
|
|
/// Deactivate this constraint
|
|
/// </para>
|
|
/// <para>
|
|
/// C++:
|
|
/// <see href="https://github.com/jrouwe/JoltPhysics/blob/e77f175595e64cb44218cc9d9d56fc365ad0e36a/Jolt/Physics/Constraints/ConstraintPart/RotationQuatConstraintPart.h#L150">Jolt/Physics/Constraints/ConstraintPart/RotationQuatConstraintPart.h:150</see>
|
|
/// <br/>
|
|
/// <c>inline void Deactivate()</c>
|
|
/// </para>
|
|
/// </summary>
|
|
public void Deactivate() => Jolt.PInvoke.RotationQuatConstraintPart_Deactivate(this);
|
|
|
|
/// <summary>
|
|
/// <para>
|
|
/// Check if constraint is active
|
|
/// </para>
|
|
/// <para>
|
|
/// C++:
|
|
/// <see href="https://github.com/jrouwe/JoltPhysics/blob/e77f175595e64cb44218cc9d9d56fc365ad0e36a/Jolt/Physics/Constraints/ConstraintPart/RotationQuatConstraintPart.h#L158">Jolt/Physics/Constraints/ConstraintPart/RotationQuatConstraintPart.h:158</see>
|
|
/// <br/>
|
|
/// <c>inline bool IsActive() const</c>
|
|
/// </para>
|
|
/// </summary>
|
|
public bool IsActive() => Jolt.PInvoke.RotationQuatConstraintPart_IsActive(this);
|
|
|
|
/// <summary>
|
|
/// <para>
|
|
/// Must be called from the WarmStartVelocityConstraint call to apply the previous frame's impulses
|
|
/// </para>
|
|
/// <para>
|
|
/// C++:
|
|
/// <see href="https://github.com/jrouwe/JoltPhysics/blob/e77f175595e64cb44218cc9d9d56fc365ad0e36a/Jolt/Physics/Constraints/ConstraintPart/RotationQuatConstraintPart.h#L164">Jolt/Physics/Constraints/ConstraintPart/RotationQuatConstraintPart.h:164</see>
|
|
/// <br/>
|
|
/// <c>inline void WarmStart(Body &ioBody1, Body &ioBody2, float inWarmStartImpulseRatio)</c>
|
|
/// </para>
|
|
/// </summary>
|
|
public void WarmStart(Body body1, Body body2, float warmStartImpulseRatio) =>
|
|
Jolt.PInvoke.RotationQuatConstraintPart_WarmStart(this, body1, body2, warmStartImpulseRatio);
|
|
|
|
/// <summary>
|
|
/// <para>
|
|
/// Iteratively update the velocity constraint. Makes sure d/dt C(...) = 0, where C is the constraint
|
|
/// equation.
|
|
/// </para>
|
|
/// <para>
|
|
/// C++:
|
|
/// <see href="https://github.com/jrouwe/JoltPhysics/blob/e77f175595e64cb44218cc9d9d56fc365ad0e36a/Jolt/Physics/Constraints/ConstraintPart/RotationQuatConstraintPart.h#L171">Jolt/Physics/Constraints/ConstraintPart/RotationQuatConstraintPart.h:171</see>
|
|
/// <br/>
|
|
/// <c>inline bool SolveVelocityConstraint(Body &ioBody1, Body &ioBody2)</c>
|
|
/// </para>
|
|
/// </summary>
|
|
public bool SolveVelocityConstraint(Body body1, Body body2) =>
|
|
Jolt.PInvoke.RotationQuatConstraintPart_SolveVelocityConstraint(this, body1, body2);
|
|
|
|
/// <summary>
|
|
/// <para>
|
|
/// Iteratively update the position constraint. Makes sure C(...) = 0.
|
|
/// </para>
|
|
/// <para>
|
|
/// C++:
|
|
/// <see href="https://github.com/jrouwe/JoltPhysics/blob/e77f175595e64cb44218cc9d9d56fc365ad0e36a/Jolt/Physics/Constraints/ConstraintPart/RotationQuatConstraintPart.h#L182">Jolt/Physics/Constraints/ConstraintPart/RotationQuatConstraintPart.h:182</see>
|
|
/// <br/>
|
|
/// <c>inline bool SolvePositionConstraint(Body &ioBody1, Body &ioBody2, QuatArg inInvInitialOrientation, float inBaumgarte) const</c>
|
|
/// </para>
|
|
/// </summary>
|
|
public bool SolvePositionConstraint(Body body1, Body body2, floatQuat invInitialOrientation, float baumgarte) =>
|
|
Jolt.PInvoke.RotationQuatConstraintPart_SolvePositionConstraint(
|
|
this,
|
|
body1,
|
|
body2,
|
|
invInitialOrientation,
|
|
baumgarte
|
|
);
|
|
|
|
/// <summary>
|
|
/// <para>
|
|
/// Return lagrange multiplier
|
|
/// </para>
|
|
/// <para>
|
|
/// C++:
|
|
/// <see href="https://github.com/jrouwe/JoltPhysics/blob/e77f175595e64cb44218cc9d9d56fc365ad0e36a/Jolt/Physics/Constraints/ConstraintPart/RotationQuatConstraintPart.h#L221">Jolt/Physics/Constraints/ConstraintPart/RotationQuatConstraintPart.h:221</see>
|
|
/// <br/>
|
|
/// <c>Vec3 GetTotalLambda() const</c>
|
|
/// </para>
|
|
/// </summary>
|
|
public float3 GetTotalLambda() => Jolt.PInvoke.RotationQuatConstraintPart_GetTotalLambda(this);
|
|
|
|
public void Dispose() => Jolt.PInvoke.RotationQuatConstraintPart_Destroy(this);
|
|
}
|
|
}
|