51 data[0] = data[1] = data[2] = 0.0;
56 Vec3(
double x,
double y,
double z) {
62 assert(index >= 0 && index < 3);
66 assert(index >= 0 && index < 3);
71 return (data[0] == rhs[0] && data[1] == rhs[1] && data[2] == rhs[2]);
75 return (data[0] != rhs[0] || data[1] != rhs[1] || data[2] != rhs[2]);
87 const Vec3& lhs = *
this;
88 return Vec3(lhs[0] + rhs[0], lhs[1] + rhs[1], lhs[2] + rhs[2]);
100 const Vec3& lhs = *
this;
101 return Vec3(-lhs[0], -lhs[1], -lhs[2]);
106 const Vec3& lhs = *
this;
107 return Vec3(lhs[0] - rhs[0], lhs[1] - rhs[1], lhs[2] - rhs[2]);
119 const Vec3& lhs = *
this;
120 return Vec3(lhs[0]*rhs, lhs[1]*rhs, lhs[2]*rhs);
132 const Vec3& lhs = *
this;
133 double scale = 1.0/rhs;
134 return Vec3(lhs[0]*scale, lhs[1]*scale, lhs[2]*scale);
138 double scale = 1.0/rhs;
147 const Vec3& lhs = *
this;
148 return lhs[0]*rhs[0] + lhs[1]*rhs[1] + lhs[2]*rhs[2];
153 return Vec3(data[1]*rhs[2]-data[2]*rhs[1], data[2]*rhs[0]-data[0]*rhs[2], data[0]*rhs[1]-data[1]*rhs[0]);
160 template <
class CHAR,
class TRAITS>
161 std::basic_ostream<CHAR,TRAITS>& operator<<(std::basic_ostream<CHAR,TRAITS>& o,
const Vec3& v) {
162 o<<
'['<<v[0]<<
", "<<v[1]<<
", "<<v[2]<<
']';
Vec3 operator+(const Vec3 &rhs) const
Definition: Vec3.h:86
double operator[](int index) const
Definition: Vec3.h:61
Vec3()
Create a Vec3 whose elements are all 0.
Definition: Vec3.h:50
Vec3 operator*(double rhs) const
Definition: Vec3.h:118
Vec3 operator+() const
Definition: Vec3.h:81
Vec3(double x, double y, double z)
Create a Vec3 with specified x, y, and z components.
Definition: Vec3.h:56
Vec3 operator-(const Vec3 &rhs) const
Definition: Vec3.h:105
Vec3 & operator+=(const Vec3 &rhs)
Definition: Vec3.h:91
Vec3 & operator*=(double rhs)
Definition: Vec3.h:123
Vec3 & operator/=(double rhs)
Definition: Vec3.h:137
bool operator==(const Vec3 &rhs) const
Definition: Vec3.h:70
Vec3 operator-() const
Definition: Vec3.h:99
This class represents a three component vector.
Definition: Vec3.h:45
Vec3 cross(const Vec3 &rhs) const
Definition: Vec3.h:152
double dot(const Vec3 &rhs) const
Definition: Vec3.h:146
Vec3 & operator-=(const Vec3 &rhs)
Definition: Vec3.h:110
Vec3 operator/(double rhs) const
Definition: Vec3.h:131
bool operator!=(const Vec3 &rhs) const
Definition: Vec3.h:74
double & operator[](int index)
Definition: Vec3.h:65