00001
00002
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
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 #ifndef _PRIMITIVE_H_
00046 #define _PRIMITIVE_H_
00047
00048 #include <vector>
00049 #include "AxisAlignedBox.h"
00050 #include "Vector3.h"
00051 #include "NVector3.h"
00052 #include "Types.h"
00053
00054 #ifdef WIN32
00055 # include <windows.h>
00056 #endif
00057
00058 #ifdef __APPLE__
00059 # include <OpenGL/gl.h>
00060 #else
00061 # include <GL/gl.h>
00062 #endif
00063
00064 namespace vrender
00065 {
00066 class Feedback3DColor ;
00067 class Primitive ;
00068
00069
00070 #define EPS_SMOOTH_LINE_FACTOR 0.06
00071
00072
00073
00074
00075 class Feedback3DColor
00076 {
00077 public:
00078 Feedback3DColor(GLfloat *loc)
00079 : _pos(loc[0],loc[1],loc[2]),
00080 _red(loc[3]),_green(loc[4]),_blue(loc[5]),_alpha(loc[6]) {}
00081
00082 inline FLOAT x() const { return _pos[0] ; }
00083 inline FLOAT y() const { return _pos[1] ; }
00084 inline FLOAT z() const { return _pos[2] ; }
00085 inline GLfloat red() const { return _red ; }
00086 inline GLfloat green() const { return _green ; }
00087 inline GLfloat blue() const { return _blue ; }
00088 inline GLfloat alpha() const { return _alpha ; }
00089 inline const Vector3& pos() const { return _pos ; }
00090
00091 inline Feedback3DColor operator+(const Feedback3DColor & v) const
00092 {
00093 return Feedback3DColor(x()+v.x(),y()+v.y(),z()+v.z(),red()+v.red(),green()+v.green(),blue()+v.blue(),alpha()+v.alpha()) ;
00094 }
00095 inline Feedback3DColor operator*(const GLFLOAT & f) const
00096 {
00097 return Feedback3DColor(x()*f,y()*f,z()*f,red()*GLfloat(f),green()*GLfloat(f),blue()*GLfloat(f),alpha()*GLfloat(f)) ;
00098 }
00099 friend inline Feedback3DColor operator*(const GLFLOAT & f,const Feedback3DColor& F)
00100 {
00101 return F*f ;
00102 }
00103
00104 static int sizeInBuffer() { return 7 ; }
00105
00106 friend std::ostream& operator<<(std::ostream&,const Feedback3DColor&) ;
00107
00108 protected:
00109 Feedback3DColor(FLOAT x, FLOAT y, FLOAT z, GLfloat r, GLfloat g, GLfloat b, GLfloat a)
00110 :_pos(x,y,z), _red(r), _green(g), _blue(b), _alpha(a) {}
00111
00112 Vector3 _pos ;
00113 GLfloat _red;
00114 GLfloat _green;
00115 GLfloat _blue;
00116 GLfloat _alpha;
00117 } ;
00118
00119
00120
00121 class Primitive
00122 {
00123 public:
00124 virtual ~Primitive() {}
00125
00126
00127 virtual const Feedback3DColor& sommet3DColor(int) const =0 ;
00128
00129
00130 virtual const Vector3& vertex(int) const = 0 ;
00131 #ifdef A_FAIRE
00132 virtual FLOAT Get_I_EPS(Primitive *) const ;
00133 Vect3 VerticalProjectPointOnSupportPlane(const Vector3 &) const ;
00134 void IntersectPrimitiveWithSupportPlane(Primitive *,int[],FLOAT[],Vect3 *&,Vect3 *&) ;
00135 inline FLOAT Equation(const Vect3& p) { return p*_normal-_C ; }
00136 virtual void Split(Vect3,FLOAT,Primitive * &,Primitive * &) = 0 ;
00137 void GetSigns(Primitive *,int * &,FLOAT * &,int &,int &,FLOAT) ;
00138 FLOAT Const() const { return _C ; }
00139
00140 int depth() const { return _depth ; }
00141 void setDepth(int d) const { _depth = d ; }
00142 #endif
00143 virtual AxisAlignedBox_xyz bbox() const = 0 ;
00144 virtual unsigned int nbVertices() const = 0 ;
00145
00146 protected:
00147
00148 int _vibility ;
00149 } ;
00150
00151 class Point: public Primitive
00152 {
00153 public:
00154 Point(const Feedback3DColor& f);
00155 virtual ~Point() {}
00156
00157 virtual const Vector3& vertex(int) const ;
00158 virtual unsigned int nbVertices() const { return 1 ; }
00159 virtual const Feedback3DColor& sommet3DColor(int) const ;
00160 virtual AxisAlignedBox_xyz bbox() const ;
00161
00162 private:
00163 Feedback3DColor _position_and_color ;
00164 };
00165
00166 class Segment: public Primitive
00167 {
00168 public:
00169 Segment(const Feedback3DColor & p1, const Feedback3DColor & p2): P1(p1), P2(p2) {}
00170 virtual ~Segment() {}
00171 virtual unsigned int nbVertices() const { return 2 ; }
00172 virtual const Vector3& vertex(int) const ;
00173 virtual const Feedback3DColor& sommet3DColor(int i) const ;
00174 virtual AxisAlignedBox_xyz bbox() const ;
00175 #ifdef A_FAIRE
00176 virtual void Split(const Vector3&,FLOAT,Primitive * &,Primitive * &) ;
00177 #endif
00178
00179 protected:
00180 Feedback3DColor P1 ;
00181 Feedback3DColor P2 ;
00182 } ;
00183
00184
00185 class Polygone: public Primitive
00186 {
00187 public:
00188 Polygone(const std::vector<Feedback3DColor>&) ;
00189 virtual ~Polygone() {}
00190 #ifdef A_FAIRE
00191 virtual int IsAPolygon() { return 1 ; }
00192 virtual void Split(const Vector3&,FLOAT,Primitive * &,Primitive * &) ;
00193 void InitEquation(double &,double &,double &,double &) ;
00194 #endif
00195 virtual const Feedback3DColor& sommet3DColor(int) const ;
00196 virtual const Vector3& vertex(int) const ;
00197 virtual unsigned int nbVertices() const { return _vertices.size() ; }
00198 virtual AxisAlignedBox_xyz bbox() const ;
00199 double equation(const Vector3& p) const ;
00200 const NVector3& normal() const { return _normal ; }
00201 double c() const { return _c ; }
00202
00203 FLOAT FlatFactor() const { return anglefactor ; }
00204
00205 protected:
00206 virtual void initNormal() ;
00207 void CheckInfoForPositionOperators() ;
00208
00209 AxisAlignedBox_xyz _bbox ;
00210 std::vector<Feedback3DColor> _vertices ;
00211
00212
00213 double anglefactor ;
00214
00215 double _c ;
00216 NVector3 _normal ;
00217 } ;
00218 }
00219 #endif
00220