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-03-24 20:40:57 +0000
committerStijn Buys <ingar@osirion.org>2008-03-24 20:40:57 +0000
commit78572764acf68b94b9992f488a725bc4be96a5b3 (patch)
tree03d4c6b55b413b8f147b2b8d62028bca9bf7c6cb /src/math/vector3f.cc
parentbd647ce0f411c1a78407762e0a01511694e76e6f (diff)
libmath optimizations and cleanups
Diffstat (limited to 'src/math/vector3f.cc')
-rw-r--r--src/math/vector3f.cc35
1 files changed, 21 insertions, 14 deletions
diff --git a/src/math/vector3f.cc b/src/math/vector3f.cc
index a9e7e00..3d8e5ac 100644
--- a/src/math/vector3f.cc
+++ b/src/math/vector3f.cc
@@ -16,33 +16,40 @@ namespace math
Vector3f::Vector3f() :
x(coord[0]), y(coord[1]), z(coord[2])
{
- for (int i=0; i < 3; i++)
- coord[i] = 0;
+ assign(0,0,0);
}
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];
+ assign(other);
}
-Vector3f::Vector3f(const float xv, const float yv, const float zv) :
+Vector3f::Vector3f(const float vx, const float vy, const float vz) :
x(coord[0]), y(coord[1]), z(coord[2])
{
- coord[0] = xv;
- coord[1] = yv;
- coord[2] = zv;
+ assign(vx, vy, vz);
}
Vector3f::~Vector3f()
{
}
+void Vector3f::assign(const float vx, const float vy, const float vz)
+{
+ coord[0] = vx;
+ coord[1] = vy;
+ coord[2] = vz;
+}
+
+void Vector3f::assign(Vector3f const & other)
+{
+ memcpy(coord, other.coord, sizeof(coord));
+}
+
Vector3f & Vector3f::operator=(const Vector3f & other)
{
- for (int i=0; i < 3; i++)
- coord[i] = other.coord[i];
+ assign(other);
return (*this);
}
@@ -156,11 +163,11 @@ std::istream &operator>>(std::istream & is, Vector3f & vector)
const Vector3f crossproduct(Vector3f const & first, Vector3f const& second)
{
- float x = first[1]*second[2] - first[2]*second[1];
- float y = first[2]*second[0] - first[0]*second[2];
- float z = first[0]*second[1] - first[1]*second[0];
+ 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(x,y,z));
+ return(Vector3f(vx,vy,vz));
}
float dotproduct(const Vector3f& first, const Vector3f& second)