74f304bf6515fdc6e243627cf1bf9ef47ab8e87c
[MicroTrace.git] / Vec3f.hxx
1 #ifndef VEC3F_HXX
2 #define VEC3F_HXX
3
4 #include <cmath>
5 #include <iostream>
6
7
8 #ifndef MIN
9 #define MIN(a,b) ((a)<(b)?(a):(b))
10 #define MAX(a,b) ((a)>(b)?(a):(b))
11 #endif
12
13 #define max(a,b) MAX(a,b)
14 #define min(a,b) MIN(a,b)
15
16 #define Epsilon 1E-4
17 #define Infinity HUGE_VAL
18
19 //! Standard operators and useful methods for 3d vectors
20 //! Fill in the missing parts in Vec3f.cxx
21 class Vec3f
22 {
23 public:
24 Vec3f();
25 Vec3f(float x, float y, float z);
26
27 ~Vec3f();
28
29 Vec3f(const Vec3f& o);
30 Vec3f& operator=(const Vec3f& o);
31
32 //! dot product
33 float operator|(const Vec3f& o);
34 float dot(const Vec3f& o);
35
36 //! cross product
37 Vec3f operator%(const Vec3f& o);
38 Vec3f cross(const Vec3f& o);
39
40 //! normalize vector
41 void normalize();
42 //! length of a vector
43 float norm() const;
44
45 //! (self-)multiply with scalar
46 Vec3f operator*(const float t) const;
47 Vec3f& operator*=(const float t);
48
49 //! (self-)division by scalar
50 Vec3f operator/(const float t) const;
51 Vec3f& operator/=(const float t);
52
53 //! vector (self-)addition
54 Vec3f operator+(const Vec3f& o) const;
55 Vec3f& operator+=(const Vec3f& o);
56
57 //! vector (self-)subtraction
58 Vec3f operator-(const Vec3f& o) const;
59 Vec3f& operator-=(const Vec3f& o);
60
61 //! component-wise multiplication of two vectors
62 Vec3f operator*(const Vec3f& o) const;
63 Vec3f& operator*=(const Vec3f& o);
64
65 //! component-wise division of two vectors
66 Vec3f operator/(const Vec3f& o) const;
67 Vec3f& operator/=(const Vec3f& o);
68
69 //! element access functions ( read-only and read-write )
70 float operator[](unsigned int i) const;
71 float& operator[](unsigned int i);
72
73 private:
74 float m_values[3];
75 };
76
77 inline std::ostream& operator<<(std::ostream& o, const Vec3f& v)
78 {
79 o << "(" << v[0] << "," << v[1] << "," << v[2] << ")";
80 return o;
81 }
82
83 #endif
84
85
This page took 0.041783 seconds and 3 git commands to generate.