2 // This module contains a bunch of well understood functions
3 // I apologise if the conventions used here are slightly
4 // different than what you are used to.
7 #ifndef GENERIC_VECTOR_H
8 #define GENERIC_VECTOR_H
17 Vector(float _x
=0.0,float _y
=0.0,float _z
=0.0){x
=_x
;y
=_y
;z
=_z
;};
18 operator float *() { return &x
;};
21 float magnitude(Vector v
);
22 Vector
normalize(Vector v
);
24 Vector
operator+(Vector v1
,Vector v2
);
25 Vector
operator-(Vector v
);
26 Vector
operator-(Vector v1
,Vector v2
);
27 Vector
operator*(Vector v1
,float s
) ;
28 Vector
operator*(float s
,Vector v1
) ;
29 Vector
operator/(Vector v1
,float s
) ;
30 float operator^(Vector v1
,Vector v2
); // DOT product
31 Vector
operator*(Vector v1
,Vector v2
); // CROSS product
32 Vector
planelineintersection(Vector n
,float d
,Vector p1
,Vector p2
);
37 matrix(){x
=Vector(1.0f
,0.0f
,0.0f
);
38 y
=Vector(0.0f
,1.0f
,0.0f
);
39 z
=Vector(0.0f
,0.0f
,1.0f
);};
40 matrix(Vector _x
,Vector _y
,Vector _z
){x
=_x
;y
=_y
;z
=_z
;};
42 matrix
transpose(matrix m
);
43 Vector
operator*(matrix m
,Vector v
);
44 matrix
operator*(matrix m1
,matrix m2
);
49 Quaternion(){x
=y
=z
=0.0f
;r
=1.0f
;};
50 Quaternion(Vector v
,float t
){
53 v
=v
*float(sin(t
/2.0));
58 Quaternion(float _r
,float _x
,float _y
,float _z
){r
=_r
;x
=_x
;y
=_y
;z
=_z
;};
59 float angle(){return float(acos(r
)*2.0);}
60 Vector
axis(){Vector
a(x
,y
,z
); return a
*float(1/sin(angle()/2.0));}
62 return Vector(1-2*(y
*y
+z
*z
), 2*(x
*y
+r
*z
), 2*(x
*z
-r
*y
));
65 return Vector( 2*(x
*y
-r
*z
),1-2*(x
*x
+z
*z
), 2*(y
*z
+r
*x
));
68 return Vector( 2*(x
*z
+r
*y
), 2*(y
*z
-r
*x
),1-2*(x
*x
+y
*y
));
70 matrix
getmatrix(){return matrix(xdir(),ydir(),zdir());}
71 //operator matrix(){return getmatrix();}
73 Quaternion
operator-(Quaternion q
);
74 Quaternion
operator*(Quaternion a
,Quaternion b
);
75 Vector
operator*(Quaternion q
,Vector v
);
76 Vector
operator*(Vector v
,Quaternion q
);
77 Quaternion
slerp(Quaternion a
,Quaternion b
,float interp
);