daily uodate on 20240411 by nitload youmu, camera complete

This commit is contained in:
YoumuLiu
2024-04-11 02:15:22 +08:00
parent e1e416bb41
commit f0f80f72f1
144 changed files with 111879 additions and 1249 deletions
+4 -4
View File
@@ -44,10 +44,10 @@ namespace StgSharp.Math
[FieldOffset(0)] internal Mat4 mat;
[FieldOffset(4 * 4 * sizeof(float))] internal Mat2 transpose;
[FieldOffset(0)] public Vec2d Colum0;
[FieldOffset(16)] public Vec2d Colum1;
[FieldOffset(32)] public Vec2d Colum2;
[FieldOffset(48)] public Vec2d Colum3;
[FieldOffset(0)] public vec2d Colum0;
[FieldOffset(16)] public vec2d Colum1;
[FieldOffset(32)] public vec2d Colum2;
[FieldOffset(48)] public vec2d Colum3;
internal Matrix24(
Vector4 c0,
+1 -1
View File
@@ -114,7 +114,7 @@ namespace StgSharp.Math
}
}
public vec3d VerticalVecMultiply(Vec2d vec)
public vec3d VerticalVecMultiply(vec2d vec)
{
return (colum0 * vec.X) + (colum1 * vec.Y);
}
+31 -2
View File
@@ -42,7 +42,7 @@ namespace StgSharp.Math
[StructLayout(LayoutKind.Explicit, Size = (2 * 16 * sizeof(float)) + sizeof(bool), Pack = 16)]
public unsafe struct Matrix44 : IEquatable<Matrix44>
public unsafe struct Matrix44 : IEquatable<Matrix44>, IMat
{
[FieldOffset(2 * 64 * sizeof(float))] internal bool isTransposed;
@@ -152,6 +152,36 @@ namespace StgSharp.Math
0, 0, 0, 1
);
public static Matrix44 XNegativeUnit
=> new Matrix44(
-1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
);
public static Matrix44 YNegativeUnit
=> new Matrix44(
1, 0, 0, 0,
0, -1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
);
public static Matrix44 ZNegativeUnit
=> new Matrix44(
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, -1, 0,
0, 0, 0, 1
);
public static Matrix44 WNegativeUnit
=> new Matrix44(
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, -1
);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe float Det()
{
@@ -295,7 +325,6 @@ namespace StgSharp.Math
Vector4.Dot(left.transpose.colum3, right.mat.colum1),
Vector4.Dot(left.transpose.colum3, right.mat.colum2),
Vector4.Dot(left.transpose.colum3, right.mat.colum3)
);
}
@@ -33,7 +33,7 @@ namespace StgSharp.Math
public static unsafe partial class Linear
{
public static float Cross(Vec2d vec1, Vec2d vec2)
public static float Cross(vec2d vec1, vec2d vec2)
{
return (vec1.X * vec2.Y) - (vec1.Y * vec2.X);
}
@@ -33,7 +33,7 @@ namespace StgSharp.Math
public static unsafe partial class Linear
{
public static float GetAngle(Vec2d vec1, Vec2d vec2)
public static float GetAngle(vec2d vec1, vec2d vec2)
{
return Scaler.ACos(1
//vec1.multiple(vec2)
@@ -35,19 +35,12 @@ namespace StgSharp.Math
public static float GetLength(this vec3d vec)
{
return Scaler.Sqrt(
(vec.X * vec.X) +
(vec.Y * vec.Y) +
(vec.Z * vec.Z)
);
return Scaler.Sqrt(vec.Dot(vec));
}
public static float GetLength(this Vec2d vec)
public static float GetLength(this vec2d vec)
{
return Scaler.Sqrt(
(vec.X * vec.X) +
(vec.Y * vec.Y)
);
return Scaler.Sqrt(vec.Dot(vec));
}
}
@@ -43,18 +43,16 @@ namespace StgSharp.Math
public static unsafe void Normalize(ref vec3d source, ref vec3d target)
{
Vector4 s = source.vec;
Vector4 t = target.vec;
s = Vector4.Normalize(s);
float dotProduct = Vector4.Dot(s, t);
Vector4 projection = Vector4.Multiply(s, t);
Vector3 s = source.v;
Vector3 t = target.v;
s = Vector3.Normalize(s);
Vector3 projection = Vector3.Dot(t, s) / Vector3.Dot(s, s) * s;
t -= projection;
t = Vector3.Normalize(t);
source.vec = s;
target.vec = t;
source.v = s;
target.v = t;
}
public static vec4d Normalize(vec4d vec)
@@ -36,25 +36,25 @@ namespace StgSharp.Math
public static unsafe partial class VectorCalc
{
public static Vec2d To2D(vec3d vec, CordinatePlain plain)
public static vec2d To2D(vec3d vec, CordinatePlain plain)
{
switch (plain)
{
case CordinatePlain.XY:
return new Vec2d(vec.X, vec.Y);
return new vec2d(vec.X, vec.Y);
break;
case CordinatePlain.YZ:
return new Vec2d(vec.Y, vec.Z);
return new vec2d(vec.Y, vec.Z);
break;
case CordinatePlain.XZ:
return new Vec2d(vec.X, vec.Z);
return new vec2d(vec.X, vec.Z);
break;
default:
return default(Vec2d);
return default(vec2d);
break;
}
}
public static vec3d To3D(Vec2d vec)
public static vec3d To3D(vec2d vec)
{
return new vec3d(vec.X, vec.Y, 0.0f);
}
+35 -17
View File
@@ -39,7 +39,7 @@ namespace StgSharp.Math
/// Vec2Ds in StgSharp are defaultly usaed as colum vector.
/// </summary>
[StructLayout(LayoutKind.Explicit, Size = 16, Pack = 16)]
public struct Vec2d
public struct vec2d
{
[FieldOffset(0)]
@@ -55,56 +55,74 @@ namespace StgSharp.Math
[FieldOffset(4)]
public float Y;
internal Vec2d(Vector2 vec)
internal vec2d(Vector2 vec)
{
v = vec;
}
public Vec2d(float x, float y)
public vec2d(float x, float y)
{
v = new Vector2(x, y);
}
public static Vec2d Unit => new Vec2d(1, 1);
public static Vec2d Zero => new Vec2d(0, 0);
public float Cross(Vec2d right)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public float Cross(vec2d right)
{
return (X * right.Y) - (Y * right.X);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vec2d operator -(Vec2d left, Vec2d right)
public float Dot(vec2d vec)
{
return new Vec2d(left.v - right.v);
return Vector2.Dot(v, vec.v);
}
public static bool operator !=(Vec2d left, Vec2d right)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static vec2d operator -(vec2d left, vec2d right)
{
return new vec2d(left.v - right.v);
}
public static bool operator !=(vec2d left, vec2d right)
{
return !(left == right);
}
public static Vec2d operator *(Vec2d vec, float value)
public static vec2d operator *(vec2d vec, float value)
{
return new Vec2d(vec.v * value);
return new vec2d(vec.v * value);
}
public static Vec2d operator /(Vec2d vec, float value)
public static vec2d operator /(vec2d vec, float value)
{
return new Vec2d(vec.v / value);
return new vec2d(vec.v / value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vec2d operator +(Vec2d left, Vec2d right)
public static vec2d operator +(vec2d left, vec2d right)
{
return new Vec2d(left.v + right.v);
return new vec2d(left.v + right.v);
}
public static bool operator ==(Vec2d left, Vec2d right)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(vec2d left, vec2d right)
{
return left.v == right.v;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator vec2d((float, float) tuple)
{
return new vec2d(tuple.Item1, tuple.Item2);
}
}
public static class Vec2d
{
public static vec2d Unit => new vec2d(1, 1);
public static vec2d Zero => new vec2d(0, 0);
}
}
+17 -5
View File
@@ -88,10 +88,7 @@ namespace StgSharp.Math
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public float Dot(vec3d right)
{
Vector4 vector4 = this.vec * right.vec;
return vector4.X
+ vector4.Y
+ vector4.Z;
return Vector3.Dot(v,right.v);
}
public bool Equals(vec3d other)
@@ -200,8 +197,23 @@ namespace StgSharp.Math
public static class Vec3d
{
public static vec3d Unit => new vec3d(1, 1, 1);
public static bool IsParallel(vec3d left, vec3d right)
{
return Cross(left,right) == Zero;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static vec3d Cross(vec3d left, vec3d right)
{
return Linear.Cross(left, right);
}
public static vec3d One => new vec3d(1, 1, 1);
public static vec3d Zero => new vec3d(0, 0, 0);
public static vec3d UnitZ => new vec3d(0, 0, 1);
public static vec3d UnitX => new vec3d(1, 0, 0);
public static vec3d UnitY => new vec3d(0, 1, 0);
}
}
+18
View File
@@ -34,6 +34,7 @@ using StgSharp.Math;
using System;
using System.Data.Common;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StgSharp.Math
@@ -58,6 +59,11 @@ namespace StgSharp.Math
[FieldOffset(8)] public float Z;
[FieldOffset(12)] public float W;
public override string ToString()
{
return vec.ToString();
}
public vec4d(float x, float y, float z, float w)
{
vec = new Vector4(x, y, z, w);
@@ -68,5 +74,17 @@ namespace StgSharp.Math
return vec.reg;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static vec4d operator *(Matrix44 mat, vec4d vec)
{
mat.InternalTranspose();
return new vec4d(
Vector4.Dot( mat.transpose.colum0,vec.vec),
Vector4.Dot( mat.transpose.colum1, vec.vec),
Vector4.Dot( mat.transpose.colum2, vec.vec),
Vector4.Dot( mat.transpose.colum3, vec.vec)
);
}
}
}