daily update on 20231016 by nitload youmu, vao,vbo,ebo struct added

This commit is contained in:
Nitload
2023-10-17 01:22:30 +08:00
parent 6c3349f5a2
commit 614fabe26c
135 changed files with 28619 additions and 5432 deletions
+93 -21
View File
@@ -1,13 +1,19 @@
using StgSharp.Controlling;
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StgSharp.Math
{
public static class Vec3d
{
public static vec3d Zero => new vec3d(0, 0, 0);
public static vec3d Unit => new vec3d(1, 1, 1);
}
[StructLayout(LayoutKind.Explicit, Size = 16, Pack = 16)]
public struct Vec3d
public struct vec3d : IEquatable<vec3d>
{
[FieldOffset(0)]
internal Vector4 vec;
@@ -16,42 +22,67 @@ namespace StgSharp.Math
[FieldOffset(4)] public float Y;
[FieldOffset(8)] public float Z;
public Vec3d(
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public vec3d Zero()
{
return new vec3d(0, 0, 0);
}
public vec3d(
float x, float y, float z)
{
X = x; Y = y; Z = z;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal Vec3d(Vector4 vector)
public float Dot(vec3d right)
{
Vector4 vector4 = this.vec * right.vec;
return vector4.X
+ vector4.Y
+ vector4.Z;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public vec3d Cross(vec3d right)
{
return new vec3d(
this.Y * right.Z - this.Z * right.Y,
this.X * right.Z - this.Z * right.X,
this.X * right.Y - this.Y * right.X
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal vec3d(Vector4 vector)
{
vec = vector;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vec3d operator +(Vec3d vec1, Vec3d vec2)
public static vec3d operator +(vec3d left, vec3d right)
{
return new Vec3d(
vec1.X + vec2.X,
vec1.Y + vec2.Y,
vec1.Z + vec2.Z
return new vec3d(
left.X + right.X,
left.Y + right.Y,
left.Z + right.Z
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vec3d operator -(Vec3d vec1, Vec3d vec2)
public static vec3d operator -(vec3d left, vec3d right)
{
return new Vec3d(
vec1.X - vec2.X,
vec1.Y - vec2.Y,
vec1.Z - vec2.Z
return new vec3d(
left.X - right.X,
left.Y - right.Y,
left.Z - right.Z
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vec3d operator *(Vec3d vec, float value)
public static vec3d operator *(vec3d vec, float value)
{
return new Vec3d(
return new vec3d(
vec.X * value,
vec.Y * value,
vec.Z * value
@@ -59,9 +90,9 @@ namespace StgSharp.Math
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vec3d operator /(Vec3d vec, float value)
public static vec3d operator /(vec3d vec, float value)
{
return new Vec3d(
return new vec3d(
vec.X / value,
vec.Y / value,
vec.Z / value
@@ -69,12 +100,28 @@ namespace StgSharp.Math
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float operator *(Vec3d vec1, Vec3d vec2)
public static float operator *(vec3d left, vec3d right)
{
return
vec1.X * vec2.X +
vec1.Y * vec2.Y +
vec1.Z * vec2.Z;
left.X * right.X +
left.Y * right.Y +
left.Z * right.Z;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(vec3d left, vec3d right)
{
return left.X == right.X
&& left.Y == right.Y
&& left.Z == right.Z;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(vec3d left, vec3d right)
{
return left.X != right.X
&& left.Y != right.Y
&& left.Z != right.Z;
}
public string ToString(string sample)
@@ -82,7 +129,32 @@ namespace StgSharp.Math
return $"{this.X}\t{this.Y}\t{this.Z}\t";
}
public bool Equals(vec3d other)
{
return this.vec == other.vec;
}
public override bool Equals(object obj)
{
if (obj is vec3d)
{
return this == (vec3d)obj;
}
else
{
return false;
}
}
public unsafe override int GetHashCode()
{
fixed (float* add = &X)
return HashCode.Combine(X, Y, Z, (ulong)add);
}
public override string ToString()
{
return $"[{X},{Y},{Z}]";
}
}
}