diff options
Diffstat (limited to 'src/math/vector3f.cc')
-rw-r--r-- | src/math/vector3f.cc | 170 |
1 files changed, 87 insertions, 83 deletions
diff --git a/src/math/vector3f.cc b/src/math/vector3f.cc index da3ff12..277795b 100644 --- a/src/math/vector3f.cc +++ b/src/math/vector3f.cc @@ -1,7 +1,7 @@ /* common/vector3f.cc - This file is part of the Osirion project and is distributed under - the terms of the GNU General Public License version 2 + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 */ // project headers @@ -10,151 +10,155 @@ // C++ headers #include <cmath> -namespace math { +namespace math +{ -Vector3f::Vector3f() : - x(coord[0]), y(coord[1]), z(coord[2]) +Vector3f::Vector3f() : + x(coord[0]), y(coord[1]), z(coord[2]) { - for (int i=0; i < 3; i++) - coord[i] = 0; + for (int i=0; i < 3; i++) + coord[i] = 0; } - -Vector3f::Vector3f(const Vector3f &other) : - x(coord[0]), y(coord[1]), z(coord[2]) +Vector3f::Vector3f(const Vector3f &other) : + x(coord[0]), y(coord[1]), z(coord[2]) { for (int i=0; i < 3; i++) coord[i] = other.coord[i]; } -Vector3f::Vector3f(const float xv, const float yv, const float zv) : - x(coord[0]), y(coord[1]), z(coord[2]) +Vector3f::Vector3f(const float xv, const float yv, const float zv) : + x(coord[0]), y(coord[1]), z(coord[2]) { coord[0] = xv; coord[1] = yv; coord[2] = zv; } -Vector3f::~Vector3f() +Vector3f::~Vector3f() { } - -Vector3f & Vector3f::operator=(const Vector3f & other) +Vector3f & Vector3f::operator=(const Vector3f & other) { for (int i=0; i < 3; i++) coord[i] = other.coord[i]; return (*this); } - -Vector3f & Vector3f::operator*=(const float scalar) +Vector3f & Vector3f::operator*=(const float scalar) { - for (int i=0; i < 3; i++) - coord[i] *= scalar; - return (*this); + for (int i=0; i < 3; i++) + coord[i] *= scalar; + return (*this); } - -Vector3f & Vector3f::operator/=(const float scalar) { - for (int i=0; i < 3; i++) - coord[i] /= scalar; - return (*this); +Vector3f & Vector3f::operator/=(const float scalar) +{ + for (int i=0; i < 3; i++) + coord[i] /= scalar; + return (*this); } - -Vector3f &Vector3f::operator-=(const Vector3f & other) { - for (int i=0; i < 3; i++) - coord[i] -= other[i]; - return (*this); +Vector3f &Vector3f::operator-=(const Vector3f & other) +{ + for (int i=0; i < 3; i++) + coord[i] -= other[i]; + return (*this); } - -Vector3f &Vector3f::operator+=(const Vector3f &other) { - for (int i=0; i < 3; i++) - coord[i] += other[i]; - return (*this); +Vector3f &Vector3f::operator+=(const Vector3f &other) +{ + for (int i=0; i < 3; i++) + coord[i] += other[i]; + return (*this); } - -Vector3f Vector3f::operator*(const float scalar) const { - Vector3f r(*this); - for (int i=0; i < 3; i++) - r.coord[i] *= scalar; - return (r); - } - - -Vector3f Vector3f::operator/(const float scalar) const { - Vector3f r(*this); - for (int i=0; i < 3; i++) - r.coord[i] /= scalar; - return (r); +Vector3f Vector3f::operator*(const float scalar) const +{ + Vector3f r(*this); + for (int i=0; i < 3; i++) + r.coord[i] *= scalar; + return (r); } - -Vector3f Vector3f::operator-(const Vector3f& other) const { - Vector3f r(*this); - for (int i=0; i < 3; i++) - r.coord[i] -= other.coord[i]; - return (r); +Vector3f Vector3f::operator/(const float scalar) const +{ + Vector3f r(*this); + for (int i=0; i < 3; i++) + r.coord[i] /= scalar; + return (r); } - -Vector3f Vector3f::operator+(const Vector3f& other) const { - Vector3f r(*this); - for (int i=0; i < 3; i++) - r.coord[i] += other.coord[i]; - return (r); +Vector3f Vector3f::operator-(const Vector3f& other) const +{ + Vector3f r(*this); + for (int i=0; i < 3; i++) + r.coord[i] -= other.coord[i]; + return (r); } - -float Vector3f::operator*(const Vector3f& other) const { - float r = 0; - for (int i=0; i < 3; i++) - r += coord[i] * other.coord[i]; - return (r); +Vector3f Vector3f::operator+(const Vector3f& other) const +{ + Vector3f r(*this); + for (int i=0; i < 3; i++) + r.coord[i] += other.coord[i]; + return (r); } +float Vector3f::operator*(const Vector3f& other) const +{ + float r = 0; + for (int i=0; i < 3; i++) + r += coord[i] * other.coord[i]; + return (r); +} -bool Vector3f::operator==(const Vector3f& other) const { +bool Vector3f::operator==(const Vector3f& other) const +{ for (int i=0; i < 3; i++) if (coord[i] != other.coord[i]) return (false); return (true); } -float Vector3f::lengthsquared() const { - double r = 0; - for (int i=0; i < 3; i++) - r += coord[i]*coord[i]; - return ((float) r); +float Vector3f::lengthsquared() const +{ + double r = 0; + for (int i=0; i < 3; i++) + r += coord[i]*coord[i]; + return ((float) r); } -float Vector3f::length() const { - double r = 0; - for (int i=0; i < 3; i++) - r += coord[i]*coord[i]; +float Vector3f::length() const +{ + double r = 0; + for (int i=0; i < 3; i++) + r += coord[i]*coord[i]; - return ((float) sqrt(r)); + return ((float) sqrt(r)); } -void Vector3f::normalize() { - (*this) /= this->length(); +void Vector3f::normalize() +{ + (*this) /= this->length(); } -std::ostream &operator<<(std::ostream & os, const Vector3f & vector) { +std::ostream &operator<<(std::ostream & os, const Vector3f & vector) +{ os << vector[0] << " " << vector[1] << " " << vector[2]; return os; } -std::istream &operator>>(std::istream & is, Vector3f & vector) { +std::istream &operator>>(std::istream & is, Vector3f & vector) +{ for (int i=0; i < 3; i++) is >> vector[i]; return is; } -Vector3f operator*(float scalar, const Vector3f& vector) { +Vector3f operator*(float scalar, const Vector3f& vector) +{ return vector * scalar; } |