X-Git-Url: https://git.rohieb.name/MicroTrace.git/blobdiff_plain/5fb5dec08b41015ffe80a2607d244c248e21c4ad..fb7298729078489a4b3d27f5be46d664ccdad57a:/Vec3f.cxx diff --git a/Vec3f.cxx b/Vec3f.cxx index 8dfa3d7..b68f9e8 100644 --- a/Vec3f.cxx +++ b/Vec3f.cxx @@ -6,139 +6,139 @@ Vec3f::Vec3f() { } Vec3f::Vec3f(float x, float y, float z) { - m_values[0] = x; - m_values[0] = y; - m_values[0] = z; + m_values[0] = x; + m_values[1] = y; + m_values[2] = z; } Vec3f::~Vec3f() { } Vec3f::Vec3f(const Vec3f& o) { - for (size_t i = 0; i < DIM; i++) { - m_values[i] = o.m_values[i]; - } + for(size_t i = 0; i < DIM; i++) { + m_values[i] = o.m_values[i]; + } } Vec3f& Vec3f::operator=(const Vec3f& o) { - for (size_t i = 0; i < DIM; i++) { - m_values[i] = o.m_values[i]; - } - return *this; + for(size_t i = 0; i < DIM; i++) { + m_values[i] = o.m_values[i]; + } + return *this; } float Vec3f::operator|(const Vec3f& o) { - return dot(o); + return dot(o); } float Vec3f::dot(const Vec3f& o) { - float prod = 0; - for (size_t i = 0; i < DIM; i++) { - prod += m_values[i] * o.m_values[i]; - } - return prod; + float prod = 0; + for(size_t i = 0; i < DIM; i++) { + prod += m_values[i] * o.m_values[i]; + } + return prod; } Vec3f Vec3f::operator%(const Vec3f& o) { - return cross(o); + return cross(o); } Vec3f Vec3f::cross(const Vec3f& o) { - return Vec3f(m_values[1] * o.m_values[2] - m_values[2] * o.m_values[1], - m_values[2] * o.m_values[0] - m_values[0] * o.m_values[2], m_values[0] - * o.m_values[1] - m_values[1] * o.m_values[0]); + return Vec3f(m_values[1] * o.m_values[2] - m_values[2] * o.m_values[1], + m_values[2] * o.m_values[0] - m_values[0] * o.m_values[2], m_values[0] + * o.m_values[1] - m_values[1] * o.m_values[0]); } void Vec3f::normalize() { - + *this /= norm(); } float Vec3f::norm() const { - return sqrt(m_values[0] * m_values[0] + m_values[1] * m_values[1] - + m_values[2] * m_values[2]); + return sqrt(m_values[0] * m_values[0] + m_values[1] * m_values[1] + + m_values[2] * m_values[2]); } Vec3f Vec3f::operator*(const float t) const { - Vec3f v(*this); - return v *= t; + Vec3f v(*this); + return v *= t; } Vec3f& Vec3f::operator*=(const float t) { - for (unsigned int i = 0; i < 3; ++i) { - m_values[i] *= f; - } - return *this; + for(unsigned int i = 0; i < 3; ++i) { + m_values[i] *= t; + } + return *this; } Vec3f Vec3f::operator/(const float t) const { - Vec3f v(*this); - return v /= f; + Vec3f v(*this); + return v /= t; } Vec3f& Vec3f::operator/=(const float t) { - for (unsigned int i = 0; i < 3; ++i) { - m_values[i] /= f; - } - return *this; + for(unsigned int i = 0; i < 3; ++i) { + m_values[i] /= t; + } + return *this; } // example implementation of a standard operator Vec3f Vec3f::operator+(const Vec3f& o) const { - Vec3f v(*this); - return v += o; + Vec3f v(*this); + return v += o; } // example implementation of an in-place operator Vec3f& Vec3f::operator+=(const Vec3f& o) { - for (unsigned int i = 0; i < 3; ++i) { - m_values[i] += o.m_values[i]; - } - return *this; + for(unsigned int i = 0; i < 3; ++i) { + m_values[i] += o.m_values[i]; + } + return *this; } Vec3f Vec3f::operator-(const Vec3f& o) const { - Vec3f v(*this); - return v -= o; + Vec3f v(*this); + return v -= o; } Vec3f& Vec3f::operator-=(const Vec3f& o) { - for (unsigned int i = 0; i < 3; ++i) { - m_values[i] -= o.m_values[i]; - } - return *this; + for(unsigned int i = 0; i < 3; ++i) { + m_values[i] -= o.m_values[i]; + } + return *this; } Vec3f Vec3f::operator*(const Vec3f& o) const { - Vec3f v(*this); - return v *= o; + Vec3f v(*this); + return v *= o; } Vec3f& Vec3f::operator*=(const Vec3f& o) { - for (unsigned int i = 0; i < 3; ++i) { - m_values[i] *= o.m_values[i]; - } - return *this; + for(unsigned int i = 0; i < 3; ++i) { + m_values[i] *= o.m_values[i]; + } + return *this; } Vec3f Vec3f::operator/(const Vec3f& o) const { - Vec3f v(*this); - return v /= o; + Vec3f v(*this); + return v /= o; } Vec3f& Vec3f::operator/=(const Vec3f& o) { - for (unsigned int i = 0; i < 3; ++i) { - m_values[i] /= o.m_values[i]; - } - return *this; + for(unsigned int i = 0; i < 3; ++i) { + m_values[i] /= o.m_values[i]; + } + return *this; } float Vec3f::operator[](unsigned int i) const { - assert(i < DIM); - return m_values[i]; + assert(i < DIM); + return m_values[i]; } float& Vec3f::operator[](unsigned int i) { - assert(i < DIM); - return m_values[i]; + assert(i < DIM); + return m_values[i]; }