projects
/
MicroTrace.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
drand() needs <cstdlib>
[MicroTrace.git]
/
Vec3f.cxx
diff --git
a/Vec3f.cxx
b/Vec3f.cxx
index
c063913
..
7c39435
100644
(file)
--- a/
Vec3f.cxx
+++ b/
Vec3f.cxx
@@
-4,12
+4,17
@@
Vec3f::Vec3f()
{
Vec3f::Vec3f()
{
-
+ for(int i = 0; i < 3; ++i)
+ {
+ m_values[i] = 0.0f;
+ }
}
Vec3f::Vec3f(float x, float y, float z)
{
}
Vec3f::Vec3f(float x, float y, float z)
{
-
+ m_values[0] = x;
+ m_values[1] = y;
+ m_values[2] = z;
}
Vec3f::~Vec3f()
}
Vec3f::~Vec3f()
@@
-18,77
+23,103
@@
Vec3f::~Vec3f()
Vec3f::Vec3f(const Vec3f& o)
{
Vec3f::Vec3f(const Vec3f& o)
{
-
+ for(int i = 0; i < 3; ++i)
+ {
+ m_values[i] = o.m_values[i];
+ }
}
Vec3f&
Vec3f::operator=(const Vec3f& o)
{
}
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;
}
float
return *this;
}
float
-Vec3f::operator|(const Vec3f& o)
+Vec3f::operator|(const Vec3f& o)
const
{
{
-
- return 0.0f;
+ return this->dot(o);
}
float
}
float
-Vec3f::dot(const Vec3f& o)
+Vec3f::dot(const Vec3f& o)
const
{
{
-
- return 0.0f;
+ float dot = 0.0f;
+ for(int i = 0; i < 3; ++i)
+ {
+ dot += m_values[i]*o.m_values[i];
+ }
+ return dot;
}
Vec3f
}
Vec3f
-Vec3f::operator%(const Vec3f& o)
+Vec3f::operator%(const Vec3f& o)
const
{
{
-
- return Vec3f();
+ return this->cross(o);
}
Vec3f
}
Vec3f
-Vec3f::cross(const Vec3f& o)
+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();
+ return Vec3f(
x,y,z
);
}
void
Vec3f::normalize()
{
}
void
Vec3f::normalize()
{
-
+ float norm = this->norm();
+ *this *= 1.0f/norm;
}
float
Vec3f::norm() const
{
}
float
Vec3f::norm() const
{
- return 0.0f;
+ float n = this->dot(*this);
+ return sqrtf(n);
}
Vec3f
Vec3f::operator*(const float t) const
{
}
Vec3f
Vec3f::operator*(const float t) const
{
- return Vec3f();
+ Vec3f v(*this);
+ return v *= t;
}
Vec3f&
Vec3f::operator*=(const float t)
{
}
Vec3f&
Vec3f::operator*=(const float t)
{
+ for(int i = 0; i < 3; ++i)
+ {
+ m_values[i] *= t;
+ }
return *this;
}
Vec3f
Vec3f::operator/(const float t) const
{
return *this;
}
Vec3f
Vec3f::operator/(const float t) const
{
- return Vec3f();
+ Vec3f v(*this);
+ return v /= t;
}
Vec3f&
Vec3f::operator/=(const float t)
{
}
Vec3f&
Vec3f::operator/=(const float t)
{
+ for(int i = 0; i < 3; ++i)
+ {
+ m_values[i] /= t;
+ }
return *this;
}
return *this;
}
@@
-116,43
+147,62
@@
Vec3f::operator+=(const Vec3f& o)
Vec3f
Vec3f::operator-(const Vec3f& o) const
{
Vec3f
Vec3f::operator-(const Vec3f& o) const
{
- return Vec3f();
+ Vec3f v(*this);
+
+ return v -= o;
}
Vec3f&
Vec3f::operator-=(const Vec3f& 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
{
return *this;
}
Vec3f
Vec3f::operator*(const Vec3f& o) const
{
- return Vec3f();
+ Vec3f v(*this);
+
+ return v *= o;
}
Vec3f&
Vec3f::operator*=(const Vec3f& 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
{
return *this;
}
Vec3f
Vec3f::operator/(const Vec3f& o) const
{
- return Vec3f();
+ Vec3f v(*this);
+
+ return v /= o;
}
Vec3f&
Vec3f::operator/=(const Vec3f& o)
{
}
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
{
return *this;
}
float
Vec3f::operator[](unsigned int i) const
{
- return 0.0f;
+ assert( i < 3 );
+ return m_values[i];
}
float&
}
float&
@@
-161,3
+211,15
@@
Vec3f::operator[](unsigned int i)
assert(i < 3);
return m_values[i];
}
assert(i < 3);
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.028254 seconds
and
4
git commands to generate.