daily update on 20240413 by nitload youmu, camera complete
This commit is contained in:
@@ -76,7 +76,7 @@ namespace StgSharp.Graphic
|
||||
return _lookAt;
|
||||
}
|
||||
Matrix44 move = Matrix44.Unit;
|
||||
move.Colum3.vec -= cameraCoord.vec;
|
||||
move.colum3.vec -= cameraCoord.vec;
|
||||
_lookAt = cameraAtt.Transpose * move;
|
||||
_isLookAtAvailable = true;
|
||||
return _lookAt;
|
||||
@@ -112,13 +112,13 @@ namespace StgSharp.Graphic
|
||||
width = Scaler.Abs(GeometryScaler.Tan(fovRadius / 2) * near *2),
|
||||
height = width * size.Y / size.X;
|
||||
|
||||
_projection.Colum0.X = 2 * near / width;
|
||||
_projection.Colum1.Y = 2 * near / height;
|
||||
_projection.Colum2.X = 2 * offsetX / width;
|
||||
_projection.Colum2.Y = 2 * offsetY / height;
|
||||
_projection.Colum2.Z = (far + near) / (near - far);
|
||||
_projection.Colum2.W = -1;
|
||||
_projection.Colum3.Z = 2 * near * far / (near - far);
|
||||
_projection.colum0.X = 2 * near / width;
|
||||
_projection.colum1.Y = 2 * near / height;
|
||||
_projection.colum2.X = 2 * offsetX / width;
|
||||
_projection.colum2.Y = 2 * offsetY / height;
|
||||
_projection.colum2.Z = (far + near) / (near - far);
|
||||
_projection.colum2.W = -1;
|
||||
_projection.colum3.Z = 2 * near * far / (near - far);
|
||||
|
||||
}
|
||||
|
||||
@@ -135,24 +135,71 @@ namespace StgSharp.Graphic
|
||||
|
||||
public void Pitch(Radius r)
|
||||
{
|
||||
_isLookAtAvailable = false;
|
||||
Matrix32 partialCoord = new Matrix32(
|
||||
cameraAtt.Colum1.vec,
|
||||
cameraAtt.Colum2.vec
|
||||
cameraAtt.colum1.vec,
|
||||
cameraAtt.colum2.vec
|
||||
);
|
||||
float angle = -r._radius;
|
||||
Console.WriteLine(angle);
|
||||
Matrix22 rotation = new Matrix22(
|
||||
GeometryScaler.Cos(r), -GeometryScaler.Sin(r),
|
||||
GeometryScaler.Sin(r), -GeometryScaler.Cos(r)
|
||||
Scaler.Cos(angle), -Scaler.Sin(angle),
|
||||
Scaler.Sin(angle), Scaler.Cos( angle)
|
||||
);
|
||||
|
||||
partialCoord *= rotation;
|
||||
cameraAtt.Colum1.vec = partialCoord.colum0.vec;
|
||||
cameraAtt.Colum2.vec = partialCoord.colum1.vec;
|
||||
cameraAtt.colum1.vec = partialCoord.colum0.vec;
|
||||
cameraAtt.colum2.vec = partialCoord.colum1.vec;
|
||||
|
||||
cameraAtt.isTransposed = false;
|
||||
}
|
||||
|
||||
public void Row(Radius r)
|
||||
{
|
||||
_isLookAtAvailable = false;
|
||||
Matrix32 partialCoord = new Matrix32(
|
||||
cameraAtt.colum0.vec,
|
||||
cameraAtt.colum1.vec
|
||||
);
|
||||
float angle = -r._radius;
|
||||
Console.WriteLine(angle);
|
||||
Matrix22 rotation = new Matrix22(
|
||||
Scaler.Cos(angle), -Scaler.Sin(angle),
|
||||
Scaler.Sin(angle), Scaler.Cos(angle)
|
||||
);
|
||||
|
||||
partialCoord *= rotation;
|
||||
cameraAtt.colum0.vec = partialCoord.colum0.vec;
|
||||
cameraAtt.colum1.vec = partialCoord.colum1.vec;
|
||||
|
||||
cameraAtt.isTransposed = false;
|
||||
}
|
||||
|
||||
public void Yaw(Radius r)
|
||||
{
|
||||
_isLookAtAvailable = false;
|
||||
Matrix32 partialCoord = new Matrix32(
|
||||
cameraAtt.colum0.vec,
|
||||
cameraAtt.colum2.vec
|
||||
);
|
||||
float angle = -r._radius;
|
||||
Console.WriteLine(angle);
|
||||
Matrix22 rotation = new Matrix22(
|
||||
Scaler.Cos(angle), -Scaler.Sin(angle),
|
||||
Scaler.Sin(angle), Scaler.Cos(angle)
|
||||
);
|
||||
|
||||
partialCoord *= rotation;
|
||||
cameraAtt.colum0.vec = partialCoord.colum0.vec;
|
||||
cameraAtt.colum2.vec = partialCoord.colum1.vec;
|
||||
|
||||
cameraAtt.isTransposed = false;
|
||||
}
|
||||
|
||||
public void SetViewDirection(vec3d position, vec3d target, vec3d up)
|
||||
{
|
||||
vec3d direction = position - target;
|
||||
if (position == cameraCoord && this.up == up && cameraAtt.Colum2.vec == direction.vec)
|
||||
if (position == cameraCoord && this.up == up && cameraAtt.colum2.vec == direction.vec)
|
||||
{
|
||||
//no difference with precious value
|
||||
return;
|
||||
@@ -176,10 +223,10 @@ namespace StgSharp.Graphic
|
||||
|
||||
vec3d right = Linear.Normalize(Linear.Cross(up,direction));
|
||||
|
||||
cameraAtt.Colum0.vec = right.vec;
|
||||
cameraAtt.Colum1.vec = up.vec;
|
||||
cameraAtt.Colum2.vec = direction.vec;
|
||||
|
||||
cameraAtt.colum0.vec = right.vec;
|
||||
cameraAtt.colum1.vec = up.vec;
|
||||
cameraAtt.colum2.vec = direction.vec;
|
||||
cameraAtt.isTransposed = false;
|
||||
}
|
||||
|
||||
public void DisplayGLtypeDefinition()
|
||||
|
||||
@@ -36,7 +36,7 @@ using System.Runtime.InteropServices;
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Size = ((3 + 2) * 4 * sizeof(float)) + sizeof(bool), Pack = 16)]
|
||||
public struct Matrix23
|
||||
public struct Matrix23:IMat
|
||||
{
|
||||
|
||||
[FieldOffset(5 * 4 * sizeof(float))] internal bool isTransposed;
|
||||
|
||||
@@ -36,7 +36,7 @@ using System.Runtime.InteropServices;
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Size = ((4 + 2) * 4 * sizeof(float)) + sizeof(bool), Pack = 16)]
|
||||
public struct Matrix24
|
||||
public struct Matrix24:IMat
|
||||
{
|
||||
|
||||
[FieldOffset(6 * 4 * sizeof(float))] internal bool isTransposed;
|
||||
|
||||
@@ -36,7 +36,7 @@ using System.Runtime.InteropServices;
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Size = (5 * 4 * sizeof(float)) + sizeof(bool), Pack = 16)]
|
||||
public struct Matrix32
|
||||
public struct Matrix32:IMat
|
||||
{
|
||||
|
||||
[FieldOffset(0)] internal vec3d colum0;
|
||||
@@ -62,13 +62,13 @@ namespace StgSharp.Math
|
||||
float a20, float a21
|
||||
)
|
||||
{
|
||||
mat.colum0 = new Vector4(a00, a10, a20, 0);
|
||||
mat.colum0 = new Vector4(a01, a11, a21, 0);
|
||||
#if NET5_0_OR_GREATER
|
||||
Unsafe.SkipInit(out colum0);
|
||||
Unsafe.SkipInit(out colum1);
|
||||
Unsafe.SkipInit(out transpose);
|
||||
#endif
|
||||
mat.colum0 = new Vector4(a00, a10, a20, 0);
|
||||
mat.colum1 = new Vector4(a01, a11, a21, 0);
|
||||
}
|
||||
|
||||
public unsafe float this[int rowNum, int columNum]
|
||||
|
||||
@@ -36,7 +36,7 @@ using System.Runtime.InteropServices;
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Size = (6 * 4 * sizeof(float)) + sizeof(bool), Pack = 16)]
|
||||
public struct Matrix33
|
||||
public struct Matrix33:IMat
|
||||
{
|
||||
|
||||
[FieldOffset(6 * 4 * sizeof(float))] internal bool isTransposed;
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace StgSharp.Math
|
||||
{
|
||||
|
||||
[StructLayout(LayoutKind.Explicit, Size = (7 * 4 * sizeof(float)) + sizeof(bool), Pack = 16)]
|
||||
public struct Matrix34
|
||||
public struct Matrix34:IMat
|
||||
{
|
||||
|
||||
[FieldOffset(7 * 4 * sizeof(float))] internal bool isTransposed;
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace StgSharp.Math
|
||||
|
||||
|
||||
[StructLayout(LayoutKind.Explicit, Size = ((16 + 8) * sizeof(float)) + sizeof(bool), Pack = 16)]
|
||||
public struct Matrix42
|
||||
public struct Matrix42:IMat
|
||||
{
|
||||
|
||||
[FieldOffset((16 + 8) * sizeof(float))] internal bool isTransposed;
|
||||
|
||||
@@ -37,7 +37,7 @@ using System.Runtime.InteropServices;
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Size = (7 * 4 * sizeof(float)) + sizeof(bool), Pack = 16)]
|
||||
public struct Matrix43 : IEquatable<Matrix43>
|
||||
public struct Matrix43 : IEquatable<Matrix43>,IMat
|
||||
{
|
||||
|
||||
[FieldOffset(7 * 4 * sizeof(float))]
|
||||
|
||||
@@ -49,10 +49,10 @@ namespace StgSharp.Math
|
||||
|
||||
[FieldOffset(0)] internal Mat4 mat;
|
||||
[FieldOffset(16 * sizeof(float))] internal Mat4 transpose;
|
||||
[FieldOffset(0 * sizeof(float))] public vec4d Colum0;
|
||||
[FieldOffset(4 * sizeof(float))] public vec4d Colum1;
|
||||
[FieldOffset(8 * sizeof(float))] public vec4d Colum2;
|
||||
[FieldOffset(12 * sizeof(float))] public vec4d Colum3;
|
||||
[FieldOffset(0 * sizeof(float))] internal vec4d colum0;
|
||||
[FieldOffset(4 * sizeof(float))] internal vec4d colum1;
|
||||
[FieldOffset(8 * sizeof(float))] internal vec4d colum2;
|
||||
[FieldOffset(12 * sizeof(float))] internal vec4d colum3;
|
||||
|
||||
internal Matrix44(Mat4 mat)
|
||||
{
|
||||
@@ -223,7 +223,7 @@ namespace StgSharp.Math
|
||||
{
|
||||
if (!isTransposed)
|
||||
{
|
||||
fixed (Mat4* source = &this.mat, target = &this.transpose)
|
||||
fixed (Mat4* source = &mat, target = &transpose)
|
||||
{
|
||||
InternalIO.Transpose4to4_internal(source, target);
|
||||
}
|
||||
|
||||
@@ -71,12 +71,12 @@ namespace StgSharp
|
||||
#region transpose
|
||||
|
||||
|
||||
[DllImport(InternalIO.SSC_libname, EntryPoint = "transmpose2to4",
|
||||
[DllImport(InternalIO.SSC_libname, EntryPoint = "transpose2to4",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static extern unsafe void Transpose2to4_internal(Mat2* source, Mat4* target);
|
||||
|
||||
[DllImport(InternalIO.SSC_libname, EntryPoint = "transmpose2to3",
|
||||
[DllImport(InternalIO.SSC_libname, EntryPoint = "transpose2to3",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static extern unsafe void Transpose2to3_internal(Mat2* source, Mat3* target);
|
||||
@@ -97,7 +97,6 @@ namespace StgSharp.Math
|
||||
[FieldOffset(4 * sizeof(float))] internal Vector4 colum1;
|
||||
|
||||
[FieldOffset(0 * sizeof(float))] internal float m00;
|
||||
|
||||
[FieldOffset(4 * sizeof(float))] internal float m01;
|
||||
[FieldOffset(1 * sizeof(float))] internal float m10;
|
||||
[FieldOffset(5 * sizeof(float))] internal float m11;
|
||||
|
||||
@@ -51,15 +51,15 @@ namespace StgSharp
|
||||
|
||||
#region transpose
|
||||
|
||||
[DllImport(InternalIO.SSC_libname, EntryPoint = "transpose3to4",
|
||||
[DllImport(SSC_libname, EntryPoint = "transpose3to4",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern unsafe void Transpose3to4_internal(Mat3* source, Mat4* target);
|
||||
|
||||
[DllImport("StgsharpGra[hic", EntryPoint = "transpose3to4",
|
||||
[DllImport(SSC_libname, EntryPoint = "transpose3to3",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern unsafe void Transpose3to3_internal(Mat3* source, Mat3* target);
|
||||
|
||||
[DllImport("StgsharpGra[hic", EntryPoint = "transpose3to2",
|
||||
[DllImport(SSC_libname, EntryPoint = "transpose3to2",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern unsafe void Transpose3to2_internal(Mat3* source, Mat2* target);
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace StgSharp
|
||||
#region deinit_mat4
|
||||
|
||||
|
||||
[DllImport(InternalIO.SSC_libname, EntryPoint = "deinit_mat4",
|
||||
[DllImport(SSC_libname, EntryPoint = "deinit_mat4",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static extern void deinit_mat4(Mat4* mat);
|
||||
@@ -53,7 +53,7 @@ namespace StgSharp
|
||||
|
||||
#region det
|
||||
|
||||
[DllImport(InternalIO.SSC_libname, EntryPoint = "det_mat4",
|
||||
[DllImport(SSC_libname, EntryPoint = "det_mat4",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static extern unsafe float det_mat4(Mat4* matPtr, Mat4* transpose);
|
||||
@@ -63,15 +63,15 @@ namespace StgSharp
|
||||
|
||||
#region transpose
|
||||
|
||||
[DllImport(InternalIO.SSC_libname, EntryPoint = "transpose4to4",
|
||||
[DllImport(SSC_libname, EntryPoint = "transpose4to4",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern unsafe void Transpose4to4_internal(Mat4* source, Mat4* target);
|
||||
|
||||
[DllImport(InternalIO.SSC_libname, EntryPoint = "transpose4to3",
|
||||
[DllImport(SSC_libname, EntryPoint = "transpose4to3",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern unsafe void Transpose4to3_internal(Mat4* source, Mat3* target);
|
||||
|
||||
[DllImport(InternalIO.SSC_libname, EntryPoint = "transpose4to2",
|
||||
[DllImport(SSC_libname, EntryPoint = "transpose4to2",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern unsafe void Transpose4to2_internal(Mat4* source, Mat2* target);
|
||||
|
||||
|
||||
@@ -28,13 +28,17 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static partial class Scaler
|
||||
{
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float Cos(float x)
|
||||
{
|
||||
/*
|
||||
float refer = x / 360.0f;
|
||||
refer -= (int)refer;
|
||||
|
||||
@@ -47,6 +51,8 @@ namespace StgSharp.Math
|
||||
|
||||
return ((-sinData[a]) * ((0.1570796327f * refer) - (6.459640975e-4f * refer * refer2)))
|
||||
+ (cosData[a] * ((1 - (0.0123370055f * refer2)) + (2.536695709e-5f * refer2 * refer2)));
|
||||
*/
|
||||
return MathF.Cos(x);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,7 +28,9 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
@@ -65,8 +67,10 @@ namespace StgSharp.Math
|
||||
|
||||
};
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe float Sin(float x)
|
||||
{
|
||||
/*
|
||||
float refer = x / 360.0f;
|
||||
refer -= (int)refer;
|
||||
|
||||
@@ -79,6 +83,8 @@ namespace StgSharp.Math
|
||||
|
||||
return (sinData[a] * ((1 - (0.0123370055f * refer2)) + (2.536695709e-5f * refer2 * refer2)))
|
||||
+ (cosData[a] * ((0.1570796327f * refer) - (6.459640975e-4f * refer * refer2)));
|
||||
*/
|
||||
return MathF.Sin(x);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user