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