fixed Box::Extend(Vec3f&)
[MicroTrace.git] / Vec3f.cxx
index 8dfa3d7..7c39435 100644 (file)
--- a/Vec3f.cxx
+++ b/Vec3f.cxx
 
 #include "Vec3f.hxx"
 
-Vec3f::Vec3f() {
-}
-
-Vec3f::Vec3f(float x, float y, float z) {
-       m_values[0] = x;
-       m_values[0] = y;
-       m_values[0] = z;
-}
-
-Vec3f::~Vec3f() {
-}
-
-Vec3f::Vec3f(const Vec3f& o) {
-       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;
-}
-
-float Vec3f::operator|(const Vec3f& 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;
+Vec3f::Vec3f()
+{
+  for(int i = 0; i < 3; ++i)
+    {
+      m_values[i] = 0.0f;
+    }
 }
 
-Vec3f Vec3f::operator%(const Vec3f& o) {
-       return cross(o);
+Vec3f::Vec3f(float x, float y, float z)
+{
+  m_values[0] = x;
+  m_values[1] = y;
+  m_values[2] = z;
 }
 
-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]);
+Vec3f::~Vec3f()
+{
 }
 
-void Vec3f::normalize() {
-
+Vec3f::Vec3f(const Vec3f& o)
+{
+  for(int i = 0; i < 3; ++i)
+    {
+      m_values[i] = o.m_values[i];
+    }
 }
 
-float Vec3f::norm() const {
-       return sqrt(m_values[0] * m_values[0] + m_values[1] * m_values[1]
-               + m_values[2] * m_values[2]);
+Vec3f& 
+Vec3f::operator=(const Vec3f& o)
+{
+  if(this != &o)
+    {
+      for(int i = 0; i < 3; ++i)
+       {
+         m_values[i] = o.m_values[i];
+       } 
+    }
+  return *this;
 }
 
-Vec3f Vec3f::operator*(const float t) const {
-       Vec3f v(*this);
-       return v *= t;
+float 
+Vec3f::operator|(const Vec3f& o) const
+{
+  return this->dot(o);
 }
 
-Vec3f& Vec3f::operator*=(const float t) {
-    for (unsigned int i = 0; i < 3; ++i) {
-        m_values[i] *= f;
+float 
+Vec3f::dot(const Vec3f& o) const
+{
+  float dot = 0.0f;
+  for(int i = 0; i < 3; ++i)
+    {
+      dot += m_values[i]*o.m_values[i];
+    }
+  return dot;
+}
+  
+Vec3f 
+Vec3f::operator%(const Vec3f& o) const
+{
+  return this->cross(o);
+}
+
+Vec3f 
+Vec3f::cross(const Vec3f& o) const
+{
+  float x = m_values[1]*o.m_values[2] - m_values[2]*o.m_values[1];
+  float y = m_values[2]*o.m_values[0] - m_values[0]*o.m_values[2];
+  float z = m_values[0]*o.m_values[1] - m_values[1]*o.m_values[0];
+  
+  return Vec3f(x,y,z);
+}
+  
+void 
+Vec3f::normalize()
+{
+  float norm = this->norm();
+  *this *= 1.0f/norm;
+}
+
+float 
+Vec3f::norm() const
+{
+  float n = this->dot(*this);
+  return sqrtf(n);
+}
+
+Vec3f 
+Vec3f::operator*(const float t) const
+{
+  Vec3f v(*this);
+  return v *= t;
+}
+
+Vec3f& 
+Vec3f::operator*=(const float t)
+{
+  for(int i = 0; i < 3; ++i)
+    {
+      m_values[i] *= t;
     }
-       return *this;
+  return *this;
 }
 
-Vec3f Vec3f::operator/(const float t) const {
-       Vec3f v(*this);
-    return v /= f;
+Vec3f 
+Vec3f::operator/(const float t) const
+{
+  Vec3f v(*this);
+  return v /= t;
 }
 
-Vec3f& Vec3f::operator/=(const float t) {
-    for (unsigned int i = 0; i < 3; ++i) {
-        m_values[i] /= f;
+Vec3f& 
+Vec3f::operator/=(const float t)
+{
+  for(int i = 0; i < 3; ++i)
+    {
+      m_values[i] /= t;
     }
-       return *this;
+  return *this;
 }
 
 // example implementation of a standard operator
-Vec3f Vec3f::operator+(const Vec3f& o) const {
-       Vec3f v(*this);
-       return v += o;
+Vec3f 
+Vec3f::operator+(const Vec3f& o) const
+{
+  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;
+Vec3f& 
+Vec3f::operator+=(const Vec3f& o)
+{
+  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& 
+Vec3f::operator-=(const Vec3f& o)
+{
+  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);
 
-Vec3f Vec3f::operator-(const Vec3f& o) const {
-    Vec3f v(*this);
-    return v -= o;
+  return v *= o;
 }
 
-Vec3f& Vec3f::operator-=(const Vec3f& o) {
-    for (unsigned int i = 0; i < 3; ++i) {
-        m_values[i] -= o.m_values[i];
+Vec3f& 
+Vec3f::operator*=(const Vec3f& o)
+{
+  for(unsigned int i = 0; i < 3; ++i)
+    {
+      m_values[i] *= o.m_values[i];
     }
-       return *this;
+  return *this;
 }
 
-Vec3f Vec3f::operator*(const Vec3f& o) const {
-    Vec3f v(*this);
-    return v *= o;
+Vec3f 
+Vec3f::operator/(const Vec3f& o) const
+{
+  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];
+Vec3f& 
+Vec3f::operator/=(const Vec3f& o)
+{
+  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;
+  return *this;
 }
 
-Vec3f& Vec3f::operator/=(const Vec3f& o) {
-    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 < 3 );
+  return m_values[i];
 }
 
-float Vec3f::operator[](unsigned int i) const {
-       assert(i < DIM);
-       return m_values[i];
+float& 
+Vec3f::operator[](unsigned int i)
+{
+  assert(i < 3);
+  return m_values[i];
 }
 
-float& Vec3f::operator[](unsigned int i) {
-       assert(i < DIM);
-       return m_values[i];
+void
+Vec3f::clamp()
+{
+  for(unsigned int i = 0; i < 3; ++i)
+    {
+      if(m_values[i] < 0.0)
+       m_values[i] = 0.0;
+      if(m_values[i] > 1.0)
+       m_values[i] = 1.0;
+    }
 }
This page took 0.02795 seconds and 4 git commands to generate.