Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-10-12 11:14:22 +0000
committerStijn Buys <ingar@osirion.org>2008-10-12 11:14:22 +0000
commit18383a5fc596bf9546f14d7393ee66c57720b116 (patch)
tree5382c3b380a72149eabbc4f75a2c5744b895e48a /src/math/vector3f.cc
parent0d831968949b1119db48530a86c2d1651c6cbfc6 (diff)
libmath API cleanup
Diffstat (limited to 'src/math/vector3f.cc')
-rw-r--r--src/math/vector3f.cc68
1 files changed, 14 insertions, 54 deletions
diff --git a/src/math/vector3f.cc b/src/math/vector3f.cc
index bf2cb8d..8a6dd5e 100644
--- a/src/math/vector3f.cc
+++ b/src/math/vector3f.cc
@@ -13,7 +13,7 @@ namespace math
{
Vector3f::Vector3f() :
- x(coord[0]), y(coord[1]), z(coord[2])
+ x(coord[0]), y(coord[1]), z(coord[2])
{
clear();
}
@@ -24,10 +24,10 @@ Vector3f::Vector3f(const Vector3f &other) :
assign(other);
}
-Vector3f::Vector3f(const float vx, const float vy, const float vz) :
+Vector3f::Vector3f(const float x, const float y, const float z) :
x(coord[0]), y(coord[1]), z(coord[2])
{
- assign(vx, vy, vz);
+ assign(x, y, z);
}
Vector3f::~Vector3f()
@@ -36,26 +36,18 @@ Vector3f::~Vector3f()
void Vector3f::clear()
{
- /*
- for (size_t i =0; i < 3; i++)
- coord[i] = 0;
- */
memset(coord, 0, sizeof(coord));
}
-void Vector3f::assign(const float vx, const float vy, const float vz)
+void Vector3f::assign(const float x, const float y, const float z)
{
- coord[0] = vx;
- coord[1] = vy;
- coord[2] = vz;
+ coord[0] = x;
+ coord[1] = y;
+ coord[2] = z;
}
-void Vector3f::assign(Vector3f const & other)
+void Vector3f::assign(const Vector3f & other)
{
- /*
- for (size_t i =0; i < 3; i++)
- coord[i] = other.coord[i];
- */
memcpy(coord, other.coord, sizeof(coord));
}
@@ -93,38 +85,6 @@ Vector3f &Vector3f::operator+=(const Vector3f &other)
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 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);
-}
-
bool Vector3f::operator==(const Vector3f& other) const
{
for (int i=0; i < 3; i++)
@@ -146,7 +106,7 @@ float Vector3f::length() const
float r = 0;
for (int i=0; i < 3; i++)
r += coord[i]*coord[i];
-
+
return (sqrtf(r));
}
@@ -155,12 +115,12 @@ void Vector3f::normalize()
(*this) /= this->length();
}
-Vector3f operator*(float scalar, const Vector3f& vector)
+Vector3f operator*(float scalar, const Vector3f &vector)
{
return vector * scalar;
}
-std::ostream &operator<<(std::ostream & os, Vector3f const & vector)
+std::ostream &operator<<(std::ostream & os, const Vector3f & vector)
{
os << vector[0] << " " << vector[1] << " " << vector[2];
return os;
@@ -173,12 +133,12 @@ std::istream &operator>>(std::istream & is, Vector3f & vector)
return is;
}
-const Vector3f crossproduct(Vector3f const & first, Vector3f const& second)
+const Vector3f crossproduct(const Vector3f & first, Vector3f const &second)
{
float vx = first[1]*second[2] - first[2]*second[1];
float vy = first[2]*second[0] - first[0]*second[2];
float vz = first[0]*second[1] - first[1]*second[0];
-
+
return(Vector3f(vx,vy,vz));
}
@@ -195,7 +155,7 @@ float distance(const Vector3f& first, const Vector3f& second)
float r = 0;
for (int i=0; i < 3; i++)
r += (first[i]-second[i])*(first[i]-second[i]);
-
+
return (sqrtf(r));
}