00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef QSPROJECTION_H
00020 #define QSPROJECTION_H
00021
00022 #ifdef HAVE_CONFIG_H
00023 #include <config.h>
00024 #endif
00025
00026 #include"qscoord.h"
00027 #include"qsgattr.h"
00028
00029 class QSAxes;
00045 class QSProjection {
00046 public:
00050 static const double pi;
00054 static inline double degToRad( double deg ) { return deg*pi/180.0; }
00058 static inline double radToDeg( double rad ) { return rad*180.0/pi; }
00064 enum ClipResult { Rejected = 0, Clipped, Accepted };
00068 QSProjection();
00072 virtual ~QSProjection();
00076 virtual void setLight( bool enabled );
00080 virtual void setLightParameters( const QSPt3f& lightVector, int ambientLight, int directedLight );
00084 bool light() const { return m_light; }
00088 QSPt3f lightVector() const { return m_light_vector; }
00092 int ambientLight() const { return m_ambient_light; }
00096 int directedLight() const { return m_directed_light; }
00100 virtual QSPt3f world2DToCanvas3( const QSPt2f& p ) const = 0;
00106 virtual QSPt2f world2DToCanvas( const QSPt2f& p ) const = 0;
00110 virtual QSPt3f world3DToCanvas3( const QSPt3f &p ) const = 0;
00116 virtual QSPt2f world3DToCanvas( const QSPt3f &p ) const = 0;
00120 virtual QSPt3f canvas3ToWorld3D( const QSPt3f &p ) const = 0;
00124 QSPt2f map( const QSPt3f& pos ) const { return QSPt2f( pos.x, pos.y ); }
00128 QSPt3f map( const QSPt2f& pos ) const { return QSPt3f( pos.x, pos.y, 0.0 ); }
00134 virtual QSPt3f furthest() const;
00138 virtual QSPt2f middle() const;
00142 virtual ClipResult clipPoint2( const QSPt2f& p1 ) const;
00151 virtual ClipResult clipLine2( QSPt2f* p1, QSPt2f* p2 ) const;
00163 virtual ClipResult clipPoly2( const QSPt2f in[], int inpoints, QSPt2f out[], int *outpoints, int maxout, bool outedges[] = NULL, const bool inedges[] = NULL ) const;
00167 virtual ClipResult clipPoint3( const QSPt3f& pos ) const;
00171 virtual ClipResult clipLine3( QSPt3f* p1, QSPt3f* p2 ) const;
00183 virtual ClipResult clipPoly3( const QSPt3f in[], int inpoints, QSPt3f out[], int *outpoints, int maxpoints, const QSPt3f cube[2], bool outedges[] = NULL, const bool inedges[] = NULL ) const;
00187 virtual void shade( QSGFill &fill, const QSPt3f& normal, const QSPt2f* canvas_pts, int npoints, QSGFill *bottomFill ) const;
00188
00189
00190
00194 static bool pointInPoly( const QSPt2f& pos, const QSPt2f* pts, int npts );
00195
00196
00197
00201 static double dotProduct( const QSPt3f& p1, const QSPt3f& p2 );
00205 static QSPt3f vectorProduct( const QSPt3f& p1, const QSPt3f& p2 );
00209 static QSPt3f normal( const QSPt3f vertices[4], bool normalize = true );
00213 static QSPt3f normal( const QSPt3f *v, int npoints, bool normalize = true );
00217 static QSPt3f normalize( QSPt3f vector );
00222 static void getPoly3Cube( const QSPt3f in[], int inpoints, QSPt3f cube[2] );
00226 static ClipResult clipLine( QSPt2f* p0, QSPt2f* p1, const QSPt2f& clip_pos, const QSPt2f& clip_area );
00233 static void clipVertexNormals( const QSPt3f in[], int inpoints, const QSPt3f clip[], int clipoints, const QSPt3f innors[], QSPt3f outnor[] );
00240 static void clipVertexColors( const QSPt3f in[], int inpoints, const QSPt3f clip[], int clipoints, const QSGFill incol[], QSGFill outcol[] );
00244 static bool isBottom( const QSPt2f pts[], int npoints );
00248 static bool isBottom( const QSPt3f pts[], int npoints );
00252 static inline bool isBottom( const QSPt3f &p0,const QSPt3f &p1, const QSPt3f &p2 ) {
00253 return 0.0 > p2.x*p0.y - p0.x*p2.y + p0.x*p1.y - p1.x*p0.y + p1.x*p2.y - p2.x*p1.y;
00254 }
00258 static bool isFlat( const QSPt3f pts[], int npoints );
00259 static bool isCorrect( const QSPt3f pts[4] );
00260 static bool isCorrect( const double values[4] );
00261
00262
00263
00264 static void triangulate1( int triangleNumber, const QSPt3f pts[], int npoints, QSPt3f triangle[3], bool edges[3] );
00265
00266 protected:
00267 bool m_light;
00268 QSPt3f m_light_vector;
00269 int m_ambient_light;
00270 int m_directed_light;
00271
00272 private:
00273 static QSPt3f interpolation( const QSPt3f& p1, const QSPt3f& p2, double t );
00274 static QSGFill interpolation( const QSGFill& f1, const QSGFill& f2, double t );
00275 static void get_interpolation_params(const QSPt3f in[], int inpoints, const QSPt3f& clip, int p1[2], int p2[2], double *t1, double *t2, double *t3 );
00276 };
00277
00278 #endif
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313