clu.h

Go to the documentation of this file.
00001 
00114 #ifndef CLU_H
00115 #define CLU_H
00116 
00117 #ifdef __cplusplus
00118 extern "C" {
00119 #endif
00120   
00121 #include <stdlib.h>
00122 #include <stdio.h>
00123 #include <math.h>
00124 #include <limits.h>
00125 #include <string.h>
00126   
00127 #ifdef __linux__
00128 #include <GL/gl.h>
00129 #include <GL/glu.h>
00130 #endif
00131 
00132 #ifdef __APPLE__
00133 #include <OpenGL/gl.h>
00134 #include <OpenGL/glu.h>
00135 #endif
00136 
00137 #include <cl.h>
00138 
00139 #define CLU_VERSION 1.0
00140 
00141 typedef struct CLUquaternion CLUquaternion;
00142 typedef struct CLUplane      CLUplane;
00143 typedef struct CLUfrustum    CLUfrustum;
00144 typedef struct CLUsphere     CLUsphere;
00145 typedef struct CLUcone       CLUcone;
00146 typedef struct CLUray        CLUray;
00147 typedef struct CLUalignedbox CLUalignedbox;
00148 
00149 
00178 struct CLUquaternion
00179 {
00180   GLfloat x;
00181   GLfloat y;
00182   GLfloat z;
00183   GLfloat w;
00184 };
00185 
00210 struct CLUplane
00211 {
00212   GLfloat a;
00213   GLfloat b;
00214   GLfloat c;
00215   GLfloat d;
00216 };
00217 
00263 struct CLUfrustum
00264 {
00265     CLUplane left;
00266     CLUplane right;
00267     CLUplane bottom;
00268     CLUplane top;
00269     CLUplane near;
00270     CLUplane far;
00271 };
00272 
00292 struct CLUsphere
00293 {
00294   CLvertex origin;
00295   GLfloat  radius;
00296 };
00297 
00315 struct CLUcone
00316 {
00317   CLvertex origin;
00318   CLnormal direction;
00319   GLfloat  half_angle; /* in degrees */
00320 };
00321 
00322 
00326 struct CLUray
00327 {
00328     CLvertex origin;
00329     CLnormal direction;
00330 };
00331 
00332 
00354 struct CLUalignedbox
00355 {
00356     CLvertex min;
00357     CLvertex max;
00358 };
00359 
00360 
00439 CLUquaternion* cluNewQuaternion(GLvoid);
00440 CLUplane*      cluNewPlane(GLvoid);
00441 CLUsphere*     cluNewSphere(GLvoid);
00442 CLUcone*       cluNewCone(GLvoid);
00443 CLUray*        cluNewRay(GLvoid);
00444 CLUalignedbox* cluNewAlignedBox(GLvoid);
00469 GLvoid         cluDeleteQuaternion(CLUquaternion* quaternion);
00470 GLvoid         cluDeletePlane(CLUplane* plane);
00471 GLvoid         cluDeleteSphere(CLUsphere* sphere);
00472 GLvoid         cluDeleteCone(CLUcone* cone);
00473 GLvoid         cluDeleteRay(CLUray* ray);
00474 GLvoid         cluDeleteAlignedBox(CLUalignedbox* box);
00499 CLUquaternion* cluCopyQuaternion(CLUquaternion* dest,
00500                                  const CLUquaternion* src);
00501 CLUplane*      cluCopyPlane(CLUplane* dest,const CLUplane* src);
00502 CLUsphere*     cluCopySphere(CLUsphere* dest, const CLUsphere* src);
00503 CLUcone*       cluCopyCone(CLUcone* dest, const CLUcone* src);
00504 CLUray*        cluCopyRay(CLUray* dest, const CLUray* src);
00505 CLUalignedbox* cluCopyAlignedBox(CLUalignedbox* dest, const CLUalignedbox* src);
00506 
00534 CLUquaternion* cluDefaultQuaternion(CLUquaternion* quaternion);
00535 CLUplane*      cluDefaultPlane(CLUplane* plane);
00536 CLUsphere*     cluDefaultSphere(CLUsphere* sphere);
00537 CLUcone*       cluDefaultCone(CLUcone* cone);
00538 CLUray*        cluDefaultRay(CLUray* ray);
00539 CLUalignedbox* cluDefaultAlignedBox(CLUalignedbox* box);
00570 GLboolean      cluWriteQuaternion(const CLUquaternion* src, FILE* file);
00571 GLboolean      cluWritePlane(const CLUplane* src, FILE* file);
00572 GLboolean      cluWriteSphere(const CLUsphere* src, FILE* file);
00573 GLboolean      cluWriteCone(const CLUcone* src, FILE* file);
00574 GLboolean      cluWriteRay(const CLUray* src, FILE* file);
00575 GLboolean      cluWriteAlignedBox(const CLUalignedbox* src, FILE* file);
00606 GLboolean      cluReadQuaternion(CLUquaternion* dest, FILE* file);
00607 GLboolean      cluReadPlane(CLUplane* dest, FILE* file);
00608 GLboolean      cluReadSphere(CLUsphere* dest, FILE* file);
00609 GLboolean      cluReadCone(CLUcone* dest, FILE* file);
00610 GLboolean      cluReadRay(CLUray* dest, FILE* file);
00611 GLboolean      cluReadAlignedBox(CLUalignedbox* dest, FILE* file);
00612 
00637 GLboolean      cluPrintQuaternion(const CLUquaternion* quaternion);
00638 GLboolean      cluPrintPlane(const CLUplane* plane);
00639 GLboolean      cluPrintSphere(const CLUsphere* sphere);
00640 GLboolean      cluPrintCone(const CLUcone* cone);
00641 GLboolean      cluPrintRay(const CLUray* ray);
00642 GLboolean      cluPrintAlignedBox(const CLUalignedbox* box);
00671 CLcolour*   cluSetColour(CLcolour* colour, 
00672                          GLfloat r, 
00673                          GLfloat g,
00674                          GLfloat b,
00675                          GLfloat a);
00676 
00677 CLvertex*   cluSetVertex(CLvertex* vertex, 
00678                          GLfloat x,
00679                          GLfloat y,
00680                          GLfloat z);
00681 
00682 CLnormal*   cluSetNormal(CLnormal* normal,
00683                          GLfloat i, 
00684                          GLfloat j, 
00685                          GLfloat k);
00686 
00687 CLtexcoord* cluSetTexCoord(CLtexcoord* texcoord,
00688                            GLfloat s, 
00689                            GLfloat t);
00690 
00691 CLedgeflag* cluSetEdgeFlag(CLedgeflag* edgeflag, 
00692                            GLboolean b);
00693 
00694 CLmatrix*   cluSetMatrix(CLmatrix* matrix, 
00695                          GLfloat m00,
00696                          GLfloat m01,
00697                          GLfloat m02,
00698                          GLfloat m03,   
00699                          GLfloat m10,
00700                          GLfloat m11,
00701                          GLfloat m12,
00702                          GLfloat m13,
00703                          GLfloat m20,
00704                          GLfloat m21,
00705                          GLfloat m22,
00706                          GLfloat m23,   
00707                          GLfloat m30,
00708                          GLfloat m31,
00709                          GLfloat m32,
00710                          GLfloat m33);
00711 
00712 CLUquaternion* cluSetQuaternion(CLUquaternion* quaternion,
00713                                 GLfloat x,
00714                                 GLfloat y,
00715                                 GLfloat z,
00716                                 GLfloat w);
00717 
00718 CLUplane*      cluSetPlane(CLUplane* plane,
00719                            GLfloat a,
00720                            GLfloat b,
00721                            GLfloat c,
00722                            GLfloat d);
00723 
00763 CLmatrix*      cluSetMatrixAxesOrigin(CLmatrix* matrix,
00764                                       const CLnormal* axis_x,
00765                                       const CLnormal* axis_y,
00766                                       const CLnormal* axis_z,
00767                                       const CLvertex* origin);
00768 
00769 CLvertex*      cluSetVertexMatrixOrigin(CLvertex* vertex,
00770                                         const CLmatrix* matrix);
00771 
00772 CLvertex*      cluSetVertexRayDistance(CLvertex* vf,
00773                                        const CLUray* ray, float t);
00774 
00775 CLnormal*      cluSetNormalMatrixAxisX(CLnormal* normal,
00776                                        const CLmatrix* matrix);
00777 
00778 CLnormal*      cluSetNormalMatrixAxisY(CLnormal* normal,
00779                                        const CLmatrix* matrix);
00780 
00781 CLnormal*      cluSetNormalMatrixAxisZ(CLnormal* normal,
00782                                        const CLmatrix* matrix);
00783 
00784 CLnormal*      cluSetNormalPlane(CLnormal* normal, const CLUplane* plane);
00785 CLnormal*      cluSetNormalQuaternionAxis(CLnormal* normal,
00786                                           const CLUquaternion* quaternion);
00787 CLnormal*      cluSetNormalTriangle(CLnormal* normal,
00788                                     const CLvertex* vertex0,
00789                                     const CLvertex* vertex1,
00790                                     const CLvertex* vertex2);
00791 
00792 CLmatrix*      cluSetMatrixOrientation(CLmatrix* matrix,
00793                                        const CLUquaternion* orientation);
00794 CLmatrix*      cluSetMatrixPosition(CLmatrix* matrix,
00795                                     const CLvertex* position);
00796 
00797 CLimage*       cluSetImageChessBoard(CLimage* image);
00798 CLimage*       cluSetImageColorBuffer(CLimage* image);
00799 
00800 CLlight*       cluSetLightSubtle(CLlight* light);
00801 CLlight*       cluSetLightPoint(CLlight* light, const CLvertex* pos);
00802 CLlight*       cluSetLightDirectional(CLlight* light, const CLnormal* dir);
00803 CLlight*       cluSetLightSpotLight(CLlight* light,
00804                                     const CLvertex* pos,
00805                                     const CLnormal* dir,
00806                                     GLfloat cutoff);
00807 
00808 CLtexture*     cluSetTextureImage(CLtexture* texture, const CLimage* image);
00809 
00810 CLUquaternion* cluSetQuaternionAxisAngle(CLUquaternion* quaternion,
00811                                          const CLnormal* axis,
00812                                          GLfloat angle);
00813 
00814 CLUquaternion* cluSetQuaternionMatrix(CLUquaternion* quaternion,
00815                                      const CLmatrix* matrix); 
00816 
00817 
00818 CLUplane*      cluSetPlaneVertexNormal(CLUplane* plane,
00819                                        const CLvertex* vertex,
00820                                        const CLnormal* normal);
00821 CLUplane*      cluSetPlaneTriangle(CLUplane* plane,
00822                                    const CLvertex* vertex0,
00823                                    const CLvertex* vertex1,
00824                                    const CLvertex* vertex2);
00825 
00826 CLUfrustum*    cluSetFrustumModelviewProjection(CLUfrustum* frustum,
00827                                                 const CLmatrix* modelview,
00828                                                 const CLmatrix* projection);
00829 
00830 CLUsphere*     cluSetSphereVertices(CLUsphere* sphere,
00831                                     unsigned int num_vertices,
00832                                     const CLvertex* vertices);
00833 CLUsphere*     cluSetSphereMesh(CLUsphere* sphere,
00834                                 const CLmesh* mesh);
00835 CLUsphere*     cluSetSphereModel(CLUsphere* sphere,
00836                                  const CLmodel* model);
00837 
00838 CLUcone*       cluSetConeSphereVertex(CLUcone* cone,
00839                                       const CLUsphere* sphere,
00840                                       const CLvertex* vertex);
00841 
00842 
00843 CLUray*        cluSetRay(CLUray* ray,
00844                          GLfloat x,
00845                          GLfloat y,
00846                          GLfloat z,
00847                          GLfloat i,
00848                          GLfloat j,
00849                          GLfloat k);
00850 
00851 CLUalignedbox* cluSetAlignedBox(CLUalignedbox* box,
00852                                 CLvertex* min, 
00853                                 CLvertex* max);
00854 
00855 
00867 CLvertex*      cluVertexAdd(CLvertex* vf, const CLnormal* n);
00868 CLvertex*      cluVertexSubtract(CLvertex* vf, const CLnormal* n);
00869 CLvertex*      cluVertexTransform(CLvertex* vf, const CLmatrix* m);
00870 GLfloat        cluVertexDifference(CLvertex* v0, CLvertex* v1);
00871 
00872 CLnormal*      cluNormalAdd(CLnormal* nf, const CLnormal* n);
00873 CLnormal*      cluNormalSubtract(CLnormal* nf, const CLnormal* n);
00874 CLnormal*      cluNormalScale(CLnormal* nf, GLfloat s);
00875 CLnormal*      cluNormalTransform(CLnormal* nf, const CLmatrix* m);
00876 CLnormal*      cluNormalNormalise(CLnormal* nf);
00877 GLfloat        cluNormalMagnitude(const CLnormal* n);
00878 /*
00879   cluSetNormalDifference?
00880 */
00881 CLnormal*      cluNormalDifference(CLnormal* nf,
00882                                    const CLvertex* v0,
00883                                    const CLvertex* v1);
00884 GLfloat        cluNormalDotProduct(const CLnormal* n0, const CLnormal* n1);
00885 CLnormal*      cluNormalCrossProduct(CLnormal* nf,
00886                                      const CLnormal* n0, const CLnormal* n1);
00887 CLmatrix*      cluMatrixTranslate(CLmatrix* mf, const CLnormal* n);
00888 
00889 CLmatrix*      cluMatrixTransform(CLmatrix* mf, const CLmatrix* m);
00890 
00891 CLmatrix*      cluMatrixInvert(CLmatrix* mf);
00892 
00893 
00894 CLUquaternion* cluQuaternionAdd(CLUquaternion* qf, const CLUquaternion* q);
00895 CLUquaternion* cluQuaternionSubtract(CLUquaternion* qf,
00896                                      const CLUquaternion* q);
00897 CLUquaternion* cluQuaternionScale(CLUquaternion* qf, GLfloat s);
00898 CLUquaternion* cluQuaternionPower(CLUquaternion* qf, GLfloat n);
00899 GLfloat        cluQuaternionDotProduct(const CLUquaternion* q0,
00900                                        const CLUquaternion* q1);
00901 CLUquaternion* cluQuaternionMultiply(CLUquaternion* qf,
00902                                      const CLUquaternion* q);
00903 CLUquaternion* cluQuaternionNormalise(CLUquaternion* qf);
00904 GLfloat        cluQuaternionMagnitude(const CLUquaternion* q);
00905 GLfloat        cluQuaternionAngle(const CLUquaternion* q);
00906 CLUquaternion* cluQuaternionConjugate(CLUquaternion* qf);
00907 CLUquaternion* cluQuaternionInvert(CLUquaternion* qf);
00908 GLboolean      cluQuaternionEquals(const CLUquaternion* q0,
00909                                    const CLUquaternion* q1,
00910                                    GLfloat threshold);
00911 
00912 CLUplane*      cluPlaneNormalise(CLUplane* plane);
00913 CLUplane*      cluPlaneTransform(CLUplane* pf, const CLmatrix* m);
00914 
00915 CLUray*        cluRayTransform(CLUray* ray, const CLmatrix* matrix);
00916 
00917 GLfloat        cluAlignedBoxWidth(const CLUalignedbox* box);
00918 GLfloat        cluAlginedBoxHeight(const CLUalignedbox* box);
00919 GLfloat        cluAlginedBoxDepth(const CLUalignedbox* box);
00920 CLvertex*      cluAlignedBoxOrigin(CLvertex* v, const CLUalignedbox* box);
00921 
00939 GLfloat   cluVertexDistance(const CLvertex* v0, const CLvertex* v1);
00940 GLfloat   cluPlaneDistance(const CLUplane* plane, const CLvertex* v);
00941 GLfloat   cluSphereDistance(const CLUsphere* sphere, const CLvertex* v);
00942 GLfloat   cluSphereDistanceSphere(const CLUsphere* sphere0,
00943                                   const CLUsphere* sphere1);
00944 
00945 
00966 GLboolean cluPlaneIntersect(const CLUplane* plane,const CLvertex* vertex);
00967 GLboolean cluPlaneIntersectSphere(const CLUplane* plane,
00968                                   const CLUsphere* sphere);
00969 GLboolean cluFrustumIntercept(const CLUfrustum* frustum,
00970                               const CLvertex* vertex);
00971 GLboolean cluFrustumInterceptSphere(const CLUfrustum* frustum,
00972                                     const CLUsphere* sphere);
00973 GLboolean cluSphereIntersect(const CLUsphere* sphere, const CLvertex* vertex);
00974 GLboolean cluSphereIntersectSphere(const CLUsphere* sphere0,
00975                                    const CLUsphere* sphere1);
00976 GLboolean cluConeIntersect(const CLUcone* cone, const CLvertex* vertex);
00977 GLboolean cluConeIntersectSphere(const CLUcone* cone, const CLUsphere* sphere);
00978 
00979 #if 0
00980 GLboolean cluRayInterceptSphere(const CLUray* ray, const CLUsphere* sphere);
00981 #endif
00982 
00983 bool cluRayIntersectSphere(float* t, const CLUray* ray, const CLUsphere* sphere);
00984 
00985 bool cluRayIntersectTriangle(CLvertex* result,
00986                              const CLUray* ray,
00987                              const CLvertex* v0,
00988                              const CLvertex* v1,
00989                              const CLvertex* v2);
00990 
00991 CLvertex* cluSetVertexRayT(CLvertex* vf, const CLUray* ray, float t);
00992 CLUray* cluSetRayOriginDestination(CLUray* ray,
00993                                    CLvertex* origin,
00994                                    CLvertex* destination);
00995 
01007 CLUsphere* cluSphereAddSphere(CLUsphere* sf, 
01008                               const CLUsphere* s0, const CLUsphere* s1);
01009 CLUcone*   cluConeAddCone(CLUcone* cf, const CLUcone* c0, const CLUcone* c1);
01010 
01011 float   cluSphereVolume(const CLUsphere* sphere);
01012 float   cluConeVolume(const CLUcone* cone);
01030 GLuint     cluMeshAddVertex(CLmesh* mesh, 
01031                             const CLvertex* vertex, 
01032                             const CLcolour* colour, 
01033                             const CLnormal* normal, 
01034                             const CLtexcoord* texcoord, 
01035                             const CLedgeflag* edgeflag);
01036 GLboolean  cluMeshRemoveVertex(CLmesh* mesh, GLuint index);
01037 CLmesh*    cluMeshGenerateNormals(CLmesh* mesh);
01038 CLmesh*    cluMeshRemoveUnusedVertices(CLmesh* mesh);
01039 GLfloat    cluMeshWidth(CLmesh* mesh);
01040 GLfloat    cluMeshHeight(CLmesh* mesh);
01041 GLfloat    cluMeshDepth(CLmesh* mesh);
01042 CLvertex*  cluMeshLocalOrigin(CLvertex* v, const CLmesh* mesh);
01043 CLmesh*    cluMeshCentre(CLmesh* mesh);
01044 CLmesh*    cluMeshSetOrigin(CLmesh* mesh, const CLvertex* v);
01045 CLmesh*    cluMeshScale(CLmesh* mesh, GLfloat scale);
01046 CLmesh*    cluMeshScaleUnitCube(CLmesh* mesh);
01047 CLmesh*    cluMeshResize(CLmesh* mesh, GLfloat sx, GLfloat sy, GLfloat sz);
01048 GLvoid     cluMeshMergePrimitiveSets(CLmesh* mesh);
01058 CLmodel*   cluModelGenerateNormals(CLmodel* model);
01059 CLmodel*   cluModelRemoveUnusedVertices(CLmodel* model);
01060 GLfloat    cluModelWidth(CLmodel* model);
01061 GLfloat    cluModelHeight(CLmodel* model);
01062 GLfloat    cluModelDepth(CLmodel* model);
01063 CLvertex*  cluModelLocalOrigin(CLvertex* v, const CLmodel* model);
01064 CLmodel*   cluModelCentre(CLmodel* model);
01065 CLmodel*   cluModelSetOrigin(CLmodel* model, const CLvertex* v);
01066 CLmodel*   cluModelScale(CLmodel* model, GLfloat scale);
01067 CLmodel*   cluModelScaleUnitCube(CLmodel* model);
01068 CLmodel*   cluModelResize(CLmodel* model, GLfloat sx, GLfloat sy, GLfloat sz);
01069 CLmodel*   cluModelMergeMeshes(CLmodel* model);
01070 
01080 CLcolour* cluColourGeneratePalette(unsigned int red_separation, unsigned int green_separation, unsigned int blue_separation);
01081 
01091 GLvoid cluRenderMesh(CLmesh* mesh);
01092 GLvoid cluRenderModel(CLmodel* model);
01093 
01094 #ifdef __cplusplus
01095 }
01096 #endif
01097 
01098 #endif

Generated on Thu Dec 27 13:53:42 2007 for CLU by  doxygen 1.4.6