00001 #ifndef MATH_VECTOR3_H
00002 #define MATH_VECTOR3_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00033 #include <iosfwd>
00034 #include <string>
00035
00036 #include <glt/config.h>
00037 #include <math/real.h>
00038
00039 class Matrix;
00040 class GltViewport;
00041
00043
00050 class Vector
00051 {
00052 friend std::ostream &operator<<(std::ostream &os, const Vector &x);
00053 friend std::istream &operator>>(std::istream &is, Vector &x);
00054
00055 friend Vector operator*(const Vector &v, const real x);
00056 friend Vector operator/(const Vector &v, const real x);
00057 friend Vector operator*(const real x, const Vector &v);
00058 friend Vector operator+(const Vector &v1, const Vector &v2);
00059 friend Vector operator-(const Vector &v1, const Vector &v2);
00060 friend Vector xProduct (const Vector &v1, const Vector &v2);
00061
00062 friend Vector planeNormal(const Vector &v1, const Vector &v2,const Vector &v3);
00063
00064 friend Vector polar(const real lat,const real longitude);
00065
00066 friend void orthogonalSystem(Vector &a,Vector &b,Vector &c);
00067
00068 public:
00070 Vector();
00072 Vector(const Vector &v);
00074 Vector(const real x, const real y,const real z);
00076 Vector(const float *v);
00078 Vector(const double *v);
00080 Vector(const std::string &str);
00081
00083 real &x();
00085 const real &x() const;
00086
00088 real &y();
00090 const real &y() const;
00091
00093 real &z();
00095 const real &z() const;
00096
00098 real &operator[](const int i);
00100 const real &operator[](const int i) const;
00101
00103 operator real *();
00104
00106 bool operator==(const Vector &v) const;
00108 bool operator!=(const Vector &v) const;
00110 bool operator==(const real &a) const;
00111
00113 bool operator< (const Vector &c) const;
00115 bool operator> (const Vector &c) const;
00116
00118 Vector &operator= (const Vector &v);
00120 Vector &operator= (const float *);
00122 Vector &operator= (const double *);
00124 Vector &operator+=(const Vector &v);
00126 Vector &operator-=(const Vector &v);
00127
00129 real operator*(const Vector &v) const;
00131 Vector &operator*=(const real &x);
00133 Vector &operator*=(const Matrix &m);
00135 Vector operator-() const;
00136
00138 void scale(const real &x);
00140 void scale(const Vector &x);
00141
00143 void normalize();
00145 void abs();
00147 int dominant() const;
00148
00150 real norm() const;
00152 real dist(const Vector &x) const;
00153
00155 real length() const;
00156
00158 bool project(const Matrix &model,const Matrix &proj,const GltViewport &view);
00159
00161 Vector &vmin(const Vector &v);
00163 Vector &vmax(const Vector &v);
00164
00166 void glVertex() const;
00168 void glNormal() const;
00170 void glColor() const;
00172 void glTexCoord() const;
00173
00175 std::ostream &writePov(std::ostream &os) const;
00176
00177 protected:
00179 real _vector[3];
00180 };
00181
00183 extern const Vector VectorX;
00185 extern const Vector VectorY;
00187 extern const Vector VectorZ;
00189 extern const Vector Vector0;
00191 extern const Vector Vector1;
00192
00193 #endif