Creation of physics project
[physics.git] / src / mathw.cpp
1 #include "mathw.h"
2
3
4 /// ***** Private Varibles *****
5
6 const float PI = 3.141592653;
7
8
9 /// ***** Public Methods *****
10
11 int mod(int x, int y)
12 {
13   return x % y + (x < 0 ? y : 0);
14 }
15
16 float radsToA(float rads)
17 {
18   return ftofix(rads * 128/PI);
19 }
20
21 float atanA(float c)
22 {
23   return radsToA(atan(c)) + itofix(64);
24 }
25
26 float atan2A(float y, float x)
27 {
28   return radsToA(atan2(y,x)) + itofix(64);
29 }
30
31 /// Vector2 Math
32
33 Vector2 perp(const Vector2& vec)
34 {
35   return Vector2(-vec.y, vec.x);
36 }
37
38 float dot(const Vector2& vec1, const Vector2& vec2)
39 {
40   return vec1.x * vec2.x + vec1.y * vec2.y;
41 }
42
43 //TODO float Vector2::projectionCoeff(const Vector2* vec) const;
44 //TODO Vector2* Vector2::projection(const Vector2* vec) const;
45