00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __glu3_h__
00025 #define __glu3_h__
00026
00032 #ifdef _WIN32
00033 #define WIN32_LEAN_AND_MEAN 1
00034 #include <windows.h>
00035 #endif
00036
00037 #include <GL/gl.h>
00038 #include <GL/glext.h>
00039
00040 #define GLU3_VERSION_0_1
00041
00042 struct GLUmat4;
00043
00047 struct GLUvec4 {
00049 GLfloat values[4];
00050
00051 #ifdef __cplusplus
00052
00053 inline GLUvec4(void)
00054 {
00055 }
00056
00058 inline GLUvec4(GLfloat v)
00059 {
00060 values[0] = v;
00061 values[1] = v;
00062 values[2] = v;
00063 values[3] = v;
00064 }
00065
00067 inline GLUvec4(GLfloat x , GLfloat y, GLfloat z, GLfloat w)
00068 {
00069 values[0] = x;
00070 values[1] = y;
00071 values[2] = z;
00072 values[3] = w;
00073 }
00074
00076 inline GLUvec4(const GLUvec4 &v)
00077 {
00078 values[0] = v.values[0];
00079 values[1] = v.values[1];
00080 values[2] = v.values[2];
00081 values[3] = v.values[3];
00082 }
00083
00090 GLUvec4 operator *(const GLUmat4 &) const;
00091
00097 GLUvec4 operator *(const GLUvec4 &) const;
00098
00104 GLUvec4 operator *(GLfloat) const;
00105
00107 GLUvec4 operator +(const GLUvec4 &) const;
00108
00110 GLUvec4 operator -(const GLUvec4 &) const;
00111 #endif
00112 };
00113
00114
00115 #ifdef __cplusplus
00116 inline GLUvec4 operator *(GLfloat f, const GLUvec4 &v)
00117 {
00118 return v * f;
00119 }
00120
00121 inline GLUvec4 &operator +=(GLUvec4 &l, const GLUvec4 &r)
00122 {
00123 l = l + r;
00124 return l;
00125 }
00126
00127 inline GLUvec4 &operator -=(GLUvec4 &l, const GLUvec4 &r)
00128 {
00129 l = l - r;
00130 return l;
00131 }
00132
00133 inline GLUvec4 &operator *=(GLUvec4 &l, const GLUvec4 &r)
00134 {
00135 l = l * r;
00136 return l;
00137 }
00138
00139 inline GLUvec4 &operator *=(GLUvec4 &l, GLfloat r)
00140 {
00141 l = l * r;
00142 return l;
00143 }
00144 #endif
00145
00146
00150 struct GLUmat4 {
00152 struct GLUvec4 col[4];
00153
00154 #ifdef __cplusplus
00155
00156 inline GLUmat4(void)
00157 {
00158 }
00159
00163 inline GLUmat4(const GLUvec4 & c0, const GLUvec4 & c1,
00164 const GLUvec4 & c2, const GLUvec4 & c3)
00165 {
00166 col[0] = c0;
00167 col[1] = c1;
00168 col[2] = c2;
00169 col[3] = c3;
00170 }
00171
00173 inline GLUmat4(const GLUmat4 &m)
00174 {
00175 col[0] = m.col[0];
00176 col[1] = m.col[1];
00177 col[2] = m.col[2];
00178 col[3] = m.col[3];
00179 }
00180
00181
00190 GLUvec4 operator *(const GLUvec4 &) const;
00191
00197 GLUmat4 operator *(const GLUmat4 &) const;
00198
00200 GLUmat4 operator *(GLfloat) const;
00201
00203 GLUmat4 operator +(const GLUmat4 &) const;
00204
00206 GLUmat4 operator -(const GLUmat4 &) const;
00207 #endif
00208 };
00209
00210 #define GLU_MAX_STACK_DEPTH 32
00211
00212 struct GLUmat4Stack {
00213 struct GLUmat4 stack[GLU_MAX_STACK_DEPTH];
00214 unsigned top;
00215
00216 #ifdef __cplusplus
00217 GLUmat4Stack() : top(0)
00218 {
00219
00220 }
00221 #endif
00222 };
00223
00224
00225 struct GLUarcball {
00230 unsigned viewport_x;
00231 unsigned viewport_y;
00238 unsigned viewport_width;
00239 unsigned viewport_height;
00246 unsigned click_x;
00247 unsigned click_y;
00251 #ifdef __cplusplus
00252 void viewport(unsigned x, unsigned y, unsigned width, unsigned height)
00253 {
00254 viewport_x = x;
00255 viewport_y = y;
00256 viewport_width = width;
00257 viewport_height = height;
00258 }
00259
00260 void click(unsigned x, unsigned y)
00261 {
00262 click_x = x;
00263 click_y = y;
00264 }
00265
00266 GLUmat4 drag(unsigned end_x, unsigned end_y);
00267 #endif
00268 };
00269
00270
00271 #ifdef __cplusplus
00272
00284 class GLUshapeConsumer {
00285 public:
00296 virtual void vertex(const GLUvec4 &position,
00297 const GLUvec4 &normal,
00298 const GLUvec4 &tangent,
00299 const GLUvec4 &uv) = 0;
00300
00306 virtual void begin_primitive(GLenum mode) = 0;
00307
00311 virtual void index(unsigned idx) = 0;
00312
00316 virtual void end_primitive(void) = 0;
00317 };
00318
00319
00330 class GLUshapeProducer {
00331 public:
00332 virtual ~GLUshapeProducer()
00333 {
00334 }
00335
00342 void orientation(bool outside);
00343
00350 virtual unsigned vertex_count(void) const = 0;
00351
00358 virtual unsigned element_count(void) const = 0;
00359
00368 virtual unsigned primitive_count(void) const = 0;
00369
00378 virtual void generate(GLUshapeConsumer *consumer) const = 0;
00379
00380 protected:
00381 GLUshapeProducer(void) :
00382 normals_point_out(true)
00383 {
00384 }
00385
00386 bool normals_point_out;
00387 };
00388
00389
00393 class GLUsphereProducer : public GLUshapeProducer {
00394 public:
00406 GLUsphereProducer(GLdouble radius, GLint slices, GLint stacks);
00407 virtual unsigned vertex_count(void) const;
00408 virtual unsigned element_count(void) const;
00409 virtual unsigned primitive_count(void) const;
00410 virtual void generate(GLUshapeConsumer *consumer) const;
00411
00412 private:
00413 double radius;
00414 unsigned slices;
00415 unsigned stacks;
00416 };
00417
00418
00422 class GLUcubeProducer : public GLUshapeProducer {
00423 public:
00430 GLUcubeProducer(GLdouble radius);
00431 virtual unsigned vertex_count(void) const;
00432 virtual unsigned element_count(void) const;
00433 virtual unsigned primitive_count(void) const;
00434 virtual void generate(GLUshapeConsumer *consumer) const;
00435
00436 private:
00437 double radius;
00438 };
00439 #endif
00440
00441 #ifndef __cplusplus
00442 typedef struct GLUvec4 GLUvec4;
00443 typedef struct GLUmat4 GLUmat4;
00444 typedef struct GLUmat4Stack GLUmat4Stack;
00445 typedef struct GLUarcball GLUarcball;
00446 #endif
00447
00448
00449 #if defined(__cplusplus)
00450 extern "C" {
00451 #endif
00452
00458 GLfloat gluDot4_4v(const GLUvec4 *, const GLUvec4 *);
00459
00465 GLfloat gluDot3_4v(const GLUvec4 *, const GLUvec4 *);
00466
00472 GLfloat gluDot2_4v(const GLUvec4 *, const GLUvec4 *);
00473
00483 void gluCross4v(GLUvec4 *result, const GLUvec4 *u, const GLUvec4 *v);
00484
00492 void gluNormalize4v(GLUvec4 *result, const GLUvec4 *u);
00493
00501 GLfloat gluLength4v(const GLUvec4 *u);
00502
00510 GLfloat gluLengthSqr4v(const GLUvec4 *);
00511
00524 void gluOuter4v(GLUmat4 *result, const GLUvec4 *u, const GLUvec4 *v);
00525
00526
00532 void gluMult4v_4v(GLUvec4 *result, const GLUvec4 *, const GLUvec4 *);
00533
00537 void gluDiv4v_4v(GLUvec4 *result, const GLUvec4 *, const GLUvec4 *);
00538
00544 void gluAdd4v_4v(GLUvec4 *result, const GLUvec4 *, const GLUvec4 *);
00545
00551 void gluSub4v_4v(GLUvec4 *result, const GLUvec4 *, const GLUvec4 *);
00552
00558 void gluMult4v_f(GLUvec4 *result, const GLUvec4 *, GLfloat);
00559
00561 void gluDiv4v_f(GLUvec4 *result, const GLUvec4 *, GLfloat);
00562
00564 void gluAdd4v_f(GLUvec4 *result, const GLUvec4 *, GLfloat);
00565
00567 void gluSub4v_f(GLUvec4 *result, const GLUvec4 *, GLfloat);
00568
00574 void gluMult4m_4m(GLUmat4 *result, const GLUmat4 *, const GLUmat4 *);
00575
00581 void gluAdd4m_4m(GLUmat4 *result, const GLUmat4 *, const GLUmat4 *);
00582
00588 void gluSub4m_4m(GLUmat4 *result, const GLUmat4 *, const GLUmat4 *);
00589
00598 void gluMult4m_4v(GLUvec4 *result, const GLUmat4 *m, const GLUvec4 *v);
00599
00605 void gluMult4m_f(GLUmat4 *result, const GLUmat4 *, GLfloat);
00606
00622 void gluScale4v(GLUmat4 *result, const GLUvec4 *u);
00623
00641 void gluTranslate3f(GLUmat4 *result, GLfloat x, GLfloat y, GLfloat z);
00642
00657 void gluTranslate4v(GLUmat4 *result, const GLUvec4 *v);
00670 void gluRotate4v(GLUmat4 *result, const GLUvec4 *axis, GLfloat angle);
00671
00710 void gluLookAt4v(GLUmat4 *result, const GLUvec4 *eye, const GLUvec4 *center,
00711 const GLUvec4 *up);
00712
00748 void gluFrustum6f(GLUmat4 *result, GLfloat left, GLfloat right, GLfloat bottom,
00749 GLfloat top, GLfloat near, GLfloat far);
00750
00775 void gluPerspective4f(GLUmat4 *result, GLfloat fovy, GLfloat aspect,
00776 GLfloat near, GLfloat far);
00777
00807 void gluOrtho4f(GLUmat4 *result, GLfloat left, GLfloat right, GLfloat bottom,
00808 GLfloat top);
00809
00838 void gluOrtho6f(GLUmat4 *result, GLfloat left, GLfloat right, GLfloat bottom,
00839 GLfloat top, GLfloat near, GLfloat far);
00845 void gluTranspose4m(GLUmat4 *result, const GLUmat4 *m);
00846
00852 GLfloat gluDeterminant4_4m(const GLUmat4 *m);
00853
00866 GLboolean gluInverse4_4m(GLUmat4 *result, const GLUmat4 *m);
00867
00868
00881 extern const GLUmat4 gluIdentityMatrix;
00882
00903 extern const GLchar *gluLoadTextFile(const char *file_name);
00904
00910 extern void gluUnloadTextFile(const GLchar *text);
00911
00912 extern void gluArcballViewport(GLUarcball *ball, unsigned x, unsigned y,
00913 unsigned width, unsigned height);
00914
00915 extern void gluArcballClick(GLUarcball *ball, unsigned start_x,
00916 unsigned start_y);
00917
00918 extern void gluArcballDrag(GLUarcball *ball, GLUmat4 *transformation,
00919 unsigned end_x, unsigned end_y);
00920
00921 #ifdef __cplusplus
00922 };
00923 #endif
00924
00925 #ifdef __cplusplus
00926
00931 GLfloat gluDot4(const GLUvec4 &, const GLUvec4 &);
00932
00938 GLfloat gluDot3(const GLUvec4 &, const GLUvec4 &);
00939
00945 GLfloat gluDot2(const GLUvec4 &, const GLUvec4 &);
00946
00956 inline GLUvec4 gluCross(const GLUvec4 &u, const GLUvec4 &v)
00957 {
00958 GLUvec4 t;
00959
00960 gluCross4v(& t, & u, & v);
00961 return t;
00962 }
00963
00971 inline GLUvec4 gluNormalize(const GLUvec4 &v)
00972 {
00973 GLUvec4 t;
00974
00975 gluNormalize4v(& t, & v);
00976 return t;
00977 }
00978
00986 inline GLfloat gluLength(const GLUvec4 &u)
00987 {
00988 return gluLength4v(& u);
00989 }
00990
00998 inline GLfloat gluLengthSqr(const GLUvec4 &u)
00999 {
01000 return gluLengthSqr4v(& u);
01001 }
01002
01018 inline GLUmat4 gluScale(const GLUvec4 &u)
01019 {
01020 GLUmat4 result;
01021
01022 gluScale4v(& result, & u);
01023 return result;
01024 }
01025
01041 inline GLUmat4 gluScale(GLfloat x, GLfloat y, GLfloat z)
01042 {
01043 GLUvec4 u(x, y, z, 1.0);
01044 GLUmat4 result;
01045
01046 gluScale4v(& result, & u);
01047 return result;
01048 }
01049
01067 inline GLUmat4 gluTranslate(GLfloat x, GLfloat y, GLfloat z)
01068 {
01069 GLUmat4 result;
01070
01071 gluTranslate3f(& result, x, y, z);
01072 return result;
01073 }
01074
01089 inline GLUmat4 gluTranslate(const GLUvec4 &v)
01090 {
01091 GLUmat4 result;
01092
01093 gluTranslate4v(& result, & v);
01094 return result;
01095 }
01108 inline GLUmat4 gluRotate(const GLUvec4 &axis, GLfloat angle)
01109 {
01110 GLUmat4 result;
01111
01112 gluRotate4v(& result, & axis, angle);
01113 return result;
01114 }
01115
01154 inline GLUmat4 gluLookAt(const GLUvec4 &eye, const GLUvec4 ¢er,
01155 const GLUvec4 &up)
01156 {
01157 GLUmat4 result;
01158
01159 gluLookAt4v(& result, & eye, & center, & up);
01160 return result;
01161 }
01162
01168 inline GLfloat gluDeterminant4(const GLUmat4 &m)
01169 {
01170 return gluDeterminant4_4m(& m);
01171 }
01172
01185 inline GLboolean gluInverse4(GLUmat4 &result, const GLUmat4 &m)
01186 {
01187 return gluInverse4_4m(& result, & m);
01188 }
01189
01204 inline GLUmat4 gluInverse4(const GLUmat4 &m)
01205 {
01206 GLUmat4 result;
01207
01208 gluInverse4_4m(& result, & m);
01209 return result;
01210 }
01211
01212
01213 inline GLUmat4 GLUarcball::drag(unsigned end_x, unsigned end_y)
01214 {
01215 GLUmat4 result;
01216
01217 gluArcballDrag(this, & result, end_x, end_y);
01218 return result;
01219 }
01220 #endif
01221
01222 #include "glu3_scalar.h"
01223
01224 #endif