Home > other >  C# library similar to Unity's Transform component
C# library similar to Unity's Transform component

Time:10-11

I use Unity to make a number of small engineering specific applications, because I find the Transform component and the Quaternion and Vector3 classes have some great native functionality that makes spatial work much easier.

I need to step outside the Unity editor/engine for some projects, and was wondering if there is a C# library with similar functionality that is highly portable that I could drop into a VS project?

CodePudding user response:

I think one of the best for you work is Vim.Math3D, the package contais classes for

  • Vectors

     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 - the following classes lack some of the operations of 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
    
  • Rotations and Transformations

     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)
    
  • Geometric structures and shapes

     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
    
  • Lines

     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 and Bounding Structure

     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)
    
  • Alternative Coordinate Representations

     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
    
  • Motion

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

You can also check some libraries related to the above

System.Numerics

SharpDX Mathematics

MonoGame

Math.NET Spatial

Math.NET Numerics

Stride

CodePudding user response:

You may find Unity's source code implementation for the classes / structs you mentioned here:

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

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

Transform - related stuff: https://github.com/Unity-Technologies/UnityCsReference/tree/master/Runtime/Transform/ScriptBindings

Perhaps you can use this code as reference or even copy it in your project. Mind you, I do not know what the licence permits or not.

  • Related