Vector3.h
00001 #ifndef _VECTOR3_H_
00002 #define _VECTOR3_H_
00003
00004 #include <math.h>
00005 #include <iostream>
00006
00007 #ifndef PRECISION_HACK
00008 #define float double
00009 #endif
00010
00011 using namespace std;
00012
00013 class Vector3 {
00014 private:
00015 float _v[3];
00016 public:
00017
00018
00019 static const unsigned int type = 3;
00020
00021 Vector3() ;
00022 Vector3(const float x, const float y, const float z) ;
00023 Vector3(const float v[3]) ;
00024 Vector3(const Vector3& v) ;
00025 ~Vector3() ;
00026
00027 float &operator[](const int c);
00028 const float &operator[](const int c) const;
00029
00030 Vector3 & zero() ;
00031
00032 void getValues(float& X, float& Y, float& Z) const;
00033 Vector3 & setValues(const float X, const float Y, const float Z);
00034 Vector3 & setValues(const float v[3]);
00035
00036 float dot(const Vector3 &v) const;
00037 Vector3 cross(const Vector3 &v) const;
00038 float norm() const;
00039 float norm2() const;
00040 Vector3 &normalize();
00041 float max();
00042 float min();
00043
00044 Vector3 reflect(const Vector3 &v) const;
00045 Vector3 rotPtAroundAxis(float angle, Vector3 axis) const;
00046
00047 Vector3 operator*(const Vector3 &v) const;
00048
00049
00050 friend Vector3 operator*(const Vector3 & v, float d);
00051 friend Vector3 operator*(float d, const Vector3 & v);
00052 friend Vector3 operator/(const Vector3 & v, float d);
00053
00054 Vector3 operator+(const Vector3 &v) const;
00055 Vector3 operator-(const Vector3 &v) const;
00056 Vector3 operator-() const;
00057
00058
00059 Vector3& operator+=(const Vector3 &v);
00060 Vector3& operator-=(const Vector3 &v);
00061 Vector3& operator*=(const float s);
00062 Vector3& operator/=(const float s);
00063
00064 int operator==(const Vector3 &v) const;
00065 int operator!=(const Vector3 &v) const;
00066
00067 void print(ostream &out) const;
00068 friend ostream & operator << (ostream &out, const Vector3 &v);
00069 friend istream & operator >> (istream &in, Vector3 &v);
00070
00071 };
00072
00073 inline float & Vector3::operator [](const int c) {
00074 return this->_v[c];
00075 }
00076
00077 inline const float & Vector3::operator [](const int c) const {
00078 return this->_v[c];
00079 }
00080
00081 inline ostream & operator<< (ostream &out, const Vector3 &v) {
00082 v.print(out);
00083 return out;
00084 }
00085
00086 inline istream & operator>> (istream &in, Vector3 &v) {
00087 in >> v[0] >> v[1] >> v[2];
00088 return in;
00089 }
00090
00091 #endif // _VECTOR3_H_