类似于Unity的Transform组件的C#库

C# library similar to Unity's Transform component

我使用 Unity 制作了许多小型工程特定应用程序,因为我发现 Transform 组件以及四元数和 Vector3 类 具有一些很棒的本机功能,可以使空间工作变得更加容易。

对于某些项目,我需要走出 Unity editor/engine,想知道是否有一个具有类似功能的高度可移植的 C# 库,我可以将其放入 VS 项目中?

我认为最适合你的作品之一是 Vim.Math3D,包裹中包含 类 for

  • 向量

     Vector2 - Single precision X, Y
     Vector3 - Single precision X, Y, Z
     Vector4 - Single precision X, Y, Z, W
     DVector2 - Double precision X, Y, Z
     DVector3 - Single precision X, Y, Z
     DVector4 - Single precision X, Y, Z, W
     Int2 - Integer X, Y
     Int3 - Integer X, Y, Z
     Int4 - Integer X, Y
     Complex - Double precision Imaginary, Real
    
  • Pseudo-Vectors - 以下类缺少一些操作 向量

     Byte2 - Byte X, Y
     Byte3 - Byte X, Y, Z
     Byte4 - Byte X, Y, Z, W
     ColorRGB - Byte representation of color R, G, B
     ColorRGBA - Byte representation of color with Alpha R, G, B, A
     ColorHDR - High Defintion Range color representation, 4 floats, R, G, B, A
    
  • 旋转和变换

     Quaternion - Single precision quaternion rotation X, Y, Z, W
     DQuaternion - Single precision quaternion rotation X, Y, Z, W
     AxisAngle - Single precison rotation as Axis (Vector3) and Angle in radians
     Matrix4x4 - 4 x 4 Single Precision matrix in Row-Column - corder
     Transform - Single precision Position (Vector3) and Orientation (Quaternion)
     Euler - Single precision Euler engle rotation as Yaw (Z rotation), Pitch (X rotation), Roll (y rotation)
    
  • 几何结构和形状

     Plane - Single precision plane stored Normal (Vector3) and D (distance along normal from Origin)
     DPlane - Double precision plane stored Normal (Vector3) and D (distance along normal from Origin)
     Triangle - Single precision representation of triangle in 3 dimension as 3 Vector3 Points, A, B, and C
     Triangle2 - Single precision representation of triangle in 3 dimension as 3 Vector3 Points, A, B, and C
     Quad - Single precision representation of quadrilateral in 3 dimension as 4 Vector3 Points, A, B, C, and D
     DQuad - Double precision representation of quadrilateral in 3 dimension as 4 Vector3 Points, A, B, C, and D
    
  • 行数

     Line - Single precision line segment A and B
     Ray - Single precision Point and Direction in 3 dimensional space
     DRay - Double precision Point and Direction in 3 dimensional space
    
  • 区间和边界结构

     Interval - Single precision float interval (float Min, float Max)
     AABox - Single precision 3 dimensional axis-aligned bouncing box (Vector3 Min, Vector3 Max)
     AABox2D - Single precision 2 dimensional axis-aligned bouncing box (Vector2 Min, Vector2 Max)
     AABox4D - Single precision 4 dimensional axis-aligned bouncing box (Vector4 Min, Vector4 Max)
     DInterval - Double precision float interval (double Min, double Max)
     DAABox - Double precision 3 dimensional axis-aligned bouncing box (DVector3 Min, DVector3 Max)
     DAABox2D - Double precision 2 dimensional axis-aligned bouncing box (DVector2 Min, DVector2 Max)
     DAABox4D - Double precision 4 dimensional axis-aligned bouncing box (DVector4 Min, DVector4 Max)
     Sphere - Bounding sphere (Vector3 Center, float Radius)
     DSphere - Double precision bounding spehere (DVector3 Center, double Radius)
    
  • 替代坐标表示法

     SphericalCoordinate - Radius, Azimuth (bearing), and Inclination (elevation angle)
     PolarCoordinate - Radius and Azimuth (bearing)
     LogPolarCoordinate - Rho (log of radial distance) and Azimuth
     CylindricalCoordinate - Radius, Azimuth (bearing) and Height
     HorizontalCoordinate - Azimuth (bearing) and Inclination
     GeoCoordinate - Latitude and Longitude
    
  • 运动

     LinearMotion - Velocity, Acceleration, and Scalar Friction
     AngularMotion - Velocity, Acceleration, and Scalar Friction
     Motion - LinearMotion and AngularMotion
    

你也可以查看一些与上述相关的库

System.Numerics

SharpDX Mathematics

MonoGame

Math.NET Spatial

Math.NET Numerics

Stride

您可能会找到您在此处提到的 类/结构的 Unity 源代码实现:

矢量 3:https://github.com/Unity-Technologies/UnityCsReference/blob/master/Runtime/Export/Math/Vector3.cs

四元数:https://github.com/Unity-Technologies/UnityCsReference/blob/master/Runtime/Export/Math/Quaternion.cs

变换 - 相关内容:https://github.com/Unity-Technologies/UnityCsReference/tree/master/Runtime/Transform/ScriptBindings

也许您可以将此代码用作参考,甚至可以将其复制到您的项目中。请注意,我不知道许可证是否允许。