fart/util/Vector.h
Josh Holtrop 437fa8b07a added Box intersect() optimization... ~2% faster
git-svn-id: svn://anubis/fart/trunk@305 7f9b0f55-74a9-4bce-be96-3c2cd072584d
2010-09-28 15:52:52 +00:00

48 lines
1.5 KiB
C++

#ifndef VECTOR_H
#define VECTOR_H VECTOR_H
#include <iostream>
class Vector
{
public:
Vector();
Vector(double x, double y, double z);
static Vector randomVector();
double & operator[](int idx) { return m_array[idx]; }
double operator[](int idx) const { return m_array[idx]; }
Vector & normalize();
double mag() const;
double mag2() const;
double dist_to(const Vector & other) const;
Vector proj(const Vector & target) const;
Vector reflect(const Vector & target) const;
Vector getPerpendicular() const;
Vector mult(const Vector & v2) const;
Vector div(const Vector & v2) const;
Vector operator-() const;
double operator%(const Vector & v2) const;
Vector operator*(const Vector & v2) const;
Vector operator+(const Vector & v2) const;
Vector operator-(const Vector & v2) const;
Vector operator*(double scale) const;
Vector operator/(double scale) const;
Vector & operator+=(const Vector & v2);
Vector & operator-=(const Vector & v2);
static const Vector X;
static const Vector Y;
static const Vector Z;
protected:
double m_array[3];
};
std::ostream & operator<<(std::ostream & out, const Vector & v);
static inline Vector operator*(double d, const Vector & v) { return v * d; }
static inline Vector operator/(double d, const Vector & v) { return v / d; }
#endif