1 module dash.utility.math;
2 
3 version( DashUseGl3n )
4 {
5 public:
6     // Linear Algebra types
7     import gl3n.linalg;
8 
9     // Vectors
10     alias vec2f = Vector!( float, 2 );
11     alias vec2ui = Vector!( uint, 2 );
12     alias vec3f = Vector!( float, 3 );
13     alias vec4f = Vector!( float, 4 );
14 
15     // Quaternions
16     alias quatf = Quaternion!float;
17 
18     inout(Matrix!( Floating, Size, Size )) toMatrix( uint Size, Floating )( inout Quaternion!Floating q ) @property
19         if( Size == 3 || Size == 4 )
20     {
21         return q.to_matrix!( Size, Size );
22     }
23 
24     inout(Vector!( Floating, 3 )) toEulerAngles( Floating )( inout Quaternion!Floating q ) @property
25     {
26         return typeof(return)( q.pitch, q.yaw, q.roll );
27     }
28 
29     Quaternion!Floating fromEulerAngles( Floating = float )( Floating pitch, Floating yaw, Floating roll )
30     {
31         return Quaternion!Floating.identity.rotatex( pitch.radians ).rotatey( yaw.radians ).rotatez( roll.radians );
32     }
33 
34     Quaternion!Floating fromEulerAngles( Floating = float )( Vector!( Floating, 3 ) vec )
35     {
36         return fromEulerAngles( vec.x, vec.y, vec.z );
37     }
38 
39     Quaternion!Floating fromEulerAngles( Floating = float )( Floating[] angles )
40     in
41     {
42         assert( angles.length >= 3, "Invalid array given." );
43     }
44     body
45     {
46         return fromEulerAngles( angles[ 0 ], angles[ 1 ], angles[ 2 ] );
47     }
48 
49     // Matrices
50     alias mat4f = Matrix!( float, 4, 4 );
51 
52     mat4f perspectiveMat( float width, float height, float fov, float near, float far )
53     {
54         return mat4f.perspective( width, height, fov, near, far );
55     }
56 
57     // Interpolation functions
58     import gl3n.interpolate;
59 
60     // AABB types
61     import gl3n.aabb;
62     alias box3f = AABBT!float;
63 
64     void expandInPlace( Floating )( ref AABBT!Floating box, Vector!( Floating, 3 ) v )
65     {
66         box.expand( v );
67     }
68 
69     // Other functions
70     import gl3n.frustum;
71     import gl3n.math;
72 }
73 else version( DashUseGfmMath )
74 {
75 
76 }