My Project
math.h
1 #pragma once
2 
3 namespace ParaEngine
4 {
5 
7 // MATH STUFF
8 typedef float vec;
9 
10 class Vec2
11 {
12  friend class Vec3;
13 
14 private:
15  vec v[2];
16 
17 public:
18  inline Vec2 ( void ) { set( 0, 0 ); }
19  inline Vec2 ( vec x, vec y ) { set( x, y); }
20 
21  inline void set ( vec x, vec y ) { v[0] = x; v[1] = y; }
22  inline void set ( const vec *vP ) { v[0] = vP[0]; v[1] = vP[1]; }
23 
24  inline vec& operator[] ( int i ) { return v[i]; }
25  inline vec* raw ( void ) { return v; }
26 
27  inline operator const vec* ( void ) const { return v; }
28 
29  inline Vec2& operator+= ( const Vec2& v2 ) { v[0] += v2.v[0]; v[1] += v2.v[1]; return *this; }
30  inline Vec2& operator-= ( const Vec2& v2 ) { v[0] -= v2.v[0]; v[1] -= v2.v[1]; return *this; }
31  inline Vec2 operator+ ( const Vec2& v2 ) const { return Vec2( v[0] + v2.v[0], v[1] + v2.v[1] ); }
32  inline Vec2 operator- ( const Vec2& v2 ) const { return Vec2( v[0] - v2.v[0], v[1] - v2.v[1] ); }
33  inline Vec2 operator* ( vec s ) const { return Vec2( v[0] * s, v[1] * s ); }
34  inline void normalize ( void ) { vec l = length(); v[0] /= l; v[1] /= l; }
35 
36  inline float length (void)
37  {
38  return (float)sqrt(v[0]*v[0]+v[1]*v[1]);
39  }
40 };
41 
42 class Vec3
43 {
44  friend class Vec2;
45  friend class Mat4;
46 
47 private:
48  vec v[3];
49 
50 public:
51  Vec3 ( void ) { set( 0, 0, 0); }
52  Vec3 ( vec x, vec y, vec z ) { set( x, y, z ); }
53  inline void set ( vec x, vec y, vec z ) { v[0] = x; v[1] = y; v[2] = z; }
54  inline void set ( const vec *vP ) { v[0] = vP[0]; v[1] = vP[1]; v[2] = vP[2]; }
55 
56  inline vec& operator[] ( int i ) { return v[i]; }
57  inline vec* raw ( void ) { return v; }
58 
59  inline operator const vec* ( void ) const { return v; }
60 
61  inline Vec3& operator+= ( const Vec3& v3 ) { v[0] += v3.v[0]; v[1] += v3.v[1]; v[2] += v3.v[2]; return *this; }
62  inline Vec3& operator-= ( const Vec3& v3 ) { v[0] -= v3.v[0]; v[1] -= v3.v[1]; v[2] -= v3.v[2]; return *this; }
63  inline Vec3 operator+ ( const Vec3& v3 ) const { return Vec3( v[0] + v3.v[0] , v[1] + v3.v[1] , v[2] + v3.v[2] ); }
64  inline Vec3 operator- ( const Vec3& v3 ) const { return Vec3( v[0] - v3.v[0] , v[1] - v3.v[1] , v[2] - v3.v[2] ); }
65  inline Vec3 operator* ( vec s ) const { return Vec3( v[0] * s , v[1] * s , v[2] * s ); }
66  inline float operator* ( const Vec3& v3 ) const { return ( v[0] * v3[0] + v[1] * v3[1] + v[2] * v3[2] ); }
67  inline Vec3 operator~ ( void ) const { return Vec3( -v[0] , -v[1], -v[2] ); }
68  inline Vec3 operator^ ( const Vec3& v3 ) const { return Vec3( v[1]*v3.v[2] - v3.v[1]*v[2], -v[0]*v3.v[2] + v3.v[0]*v[2], v[0]*v3.v[1] - v3.v[0]*v[1] ); }
69 
70  inline vec length ( void ) const { return (vec)sqrt( v[0] * v[0] + v[1] * v[1] + v[2] * v[2] ); }
71  inline void normalize ( void ) { vec l = length(); v[0] /= l; v[1] /= l; v[2] /= l; }
72 };
73 }
74 // END OF MATH STUFF
75 /////////////////////////////////
Definition: math.h:42
Definition: math.h:10
different physics engine has different winding order.
Definition: EventBinding.h:32