fart/util/Vector.cc
Josh Holtrop 3f0d6cd83e moved most Vector functionality into the header so it could be inlined
git-svn-id: svn://anubis/fart/trunk@307 7f9b0f55-74a9-4bce-be96-3c2cd072584d
2010-09-28 16:55:39 +00:00

30 lines
632 B
C++

#include <stdlib.h> /* rand() */
#include <math.h>
#include <iostream>
#include "Vector.h"
const Vector Vector::X(1, 0, 0);
const Vector Vector::Y(0, 1, 0);
const Vector Vector::Z(0, 0, 1);
Vector Vector::randomVector()
{
double x, y, z;
do
{
x = 2.0 * rand() / RAND_MAX - 1.0;
y = 2.0 * rand() / RAND_MAX - 1.0;
z = 2.0 * rand() / RAND_MAX - 1.0;
} while (x*x + y*y + z*z > 1.0);
return Vector(x, y, z).normalize();
}
std::ostream & operator<<(std::ostream & out, const Vector & v)
{
out << "[" << v[0] << ", " << v[1] << ", " << v[2] << "]";
return out;
}