save commit
[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
14 #define Epsilon 1E-4
15 #define Infinity HUGE_VAL
16
17 //! Standard operators and useful methods for 3d vectors
18 //! Fill in the missing parts in Vec3f.cxx
19 class Vec3f
20 {
21 public:
22 Vec3f();
23 Vec3f(float x, float y, float z);
24
25 ~Vec3f();
26
27 Vec3f(const Vec3f& o);
28 Vec3f& operator=(const Vec3f& o);
29
30 //! dot product
31 float operator|(const Vec3f& o) const;
32 float dot(const Vec3f& o) const;
33
34 //! cross product
35 Vec3f operator%(const Vec3f& o) const;
36 Vec3f cross(const Vec3f& o) const;
37
38 //! normalize vector
39 void normalize();
40 //! length of a vector
41 float norm() const;
42
43 //! (self-)multiply with scalar
44 Vec3f operator*(const float t) const;
45 Vec3f& operator*=(const float t);
46
47 //! (self-)division by scalar
48 Vec3f operator/(const float t) const;
49 Vec3f& operator/=(const float t);
50
51 //! vector (self-)addition
52 Vec3f operator+(const Vec3f& o) const;
53 Vec3f& operator+=(const Vec3f& o);
54
55 //! vector (self-)subtraction
56 Vec3f operator-(const Vec3f& o) const;
57 Vec3f& operator-=(const Vec3f& o);
58
59 //! component-wise multiplication of two vectors
60 Vec3f operator*(const Vec3f& o) const;
61 Vec3f& operator*=(const Vec3f& o);
62
63 //! component-wise division of two vectors
64 Vec3f operator/(const Vec3f& o) const;
65 Vec3f& operator/=(const Vec3f& o);
66
67 //! element access functions ( read-only and read-write )
68 float operator[](unsigned int i) const;
69 float& operator[](unsigned int i);
70
71 //! clamp each element to [0,1]
72 void clamp();
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.041923 seconds and 5 git commands to generate.