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