mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-25 12:38:24 +01:00
93 lines
3.2 KiB
C#
93 lines
3.2 KiB
C#
// <auto-generated /> - edit Vector.math.tt to modify
|
|
#nullable enable
|
|
|
|
namespace Brutal.Numerics;
|
|
|
|
public partial struct float4
|
|
{
|
|
/// <inheritdoc cref="float4.Multiply(float4, float4x4)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static float4 Multiply(float4 vector, float4x4 matrix)
|
|
{
|
|
var result = matrix.X * vector.X;
|
|
|
|
result += matrix.Y * vector.Y;
|
|
result += matrix.Z * vector.Z;
|
|
result += matrix.W * vector.W;
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <inheritdoc cref="Multiply(float4, float4x4)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static float4 operator *(float4 vector, float4x4 matrix)
|
|
{
|
|
return Multiply(vector, matrix);
|
|
}
|
|
|
|
/// <summary>Reflects a vector off the hyperplane with the given unit normal.</summary>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static float4 Reflect(float4 vector, float4 normal)
|
|
{
|
|
return vector - 2 * Dot(vector, normal) * normal;
|
|
}
|
|
|
|
/// <inheritdoc cref="Vector4.Transform(Vector2, Matrix4x4)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static float4 Transform(float2 position, float4x4 matrix)
|
|
{
|
|
var result = matrix.X * position.X;
|
|
|
|
result += matrix.Y * position.Y;
|
|
result += matrix.W;
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <inheritdoc cref="Vector4.Transform(Vector2, Quaternion)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static float4 Transform(float2 value, floatQuat rotation)
|
|
{
|
|
// widen in a register: x, y, 0, 1
|
|
var wide = Unsafe.BitCast<Vector128<float>, float4>(Vector128.Create(value.X, value.Y, 0.0f, 1.0f));
|
|
return Transform(wide, rotation);
|
|
}
|
|
|
|
/// <inheritdoc cref="Vector4.Transform(Vector3, Matrix4x4)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static float4 Transform(float3 position, float4x4 matrix)
|
|
{
|
|
var result = matrix.X * position.X;
|
|
|
|
result += matrix.Y * position.Y;
|
|
result += matrix.Z * position.Z;
|
|
result += matrix.W;
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <inheritdoc cref="Vector4.Transform(Vector3, Quaternion)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static float4 Transform(float3 value, floatQuat rotation)
|
|
{
|
|
// widen in a register: x, y, z, 1
|
|
var wide = Unsafe.BitCast<Vector128<float>, float4>(Vector128.Create(value.X, value.Y, value.Z, 1.0f));
|
|
return Transform(wide, rotation);
|
|
}
|
|
|
|
/// <inheritdoc cref="Vector4.Transform(Vector4, Matrix4x4)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static float4 Transform(float4 vector, float4x4 matrix)
|
|
{
|
|
return Multiply(vector, matrix);
|
|
}
|
|
|
|
/// <inheritdoc cref="Vector4.Transform(Vector4, Quaternion)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static float4 Transform(float4 value, floatQuat rotation)
|
|
{
|
|
var conjugate = floatQuat.Conjugate(rotation);
|
|
var temp = floatQuat.Concatenate(conjugate, Unsafe.BitCast<float4, floatQuat>(value));
|
|
return Unsafe.BitCast<floatQuat, float4>(floatQuat.Concatenate(temp, rotation));
|
|
}
|
|
}
|