1 #ifndef _CUBEMODEL_INTERNAL_H 2 #define _CUBEMODEL_INTERNAL_H 3 4 #include <math.h> 5 #include <float.h> 6 7 #include <compiz-core.h> 8 #include <compiz-cube.h> 9 10 #define LRAND() ((long) (random () & 0x7fffffff)) 11 #define NRAND(n) ((int) (LRAND () % (n))) 12 #define MAXRAND (2147483648.0) /* unsigned 1 << 31 as a float */ 13 14 /* some constants */ 15 #define PI 3.14159265358979323846 16 #define PIdiv2 1.57079632679489661923 17 #define toDegrees 57.2957795130823208768 18 #define toRadians 0.01745329251994329577 19 20 /* return random number in range [0,x) */ 21 #define randf(x) ((float) (rand () / (((double) RAND_MAX + 1) / (x)))) 22 23 extern int cubemodelDisplayPrivateIndex; 24 extern int cubeDisplayPrivateIndex; 25 26 #define GET_CUBEMODEL_DISPLAY(d) \ 27 ((CubemodelDisplay *) (d)->base.privates[cubemodelDisplayPrivateIndex].ptr) 28 #define CUBEMODEL_DISPLAY(d) \ 29 CubemodelDisplay *cmd = GET_CUBEMODEL_DISPLAY(d); 30 31 #define GET_CUBEMODEL_SCREEN(s, cmd) \ 32 ((CubemodelScreen *) (s)->base.privates[(cmd)->screenPrivateIndex].ptr) 33 #define CUBEMODEL_SCREEN(s) \ 34 CubemodelScreen *cms = GET_CUBEMODEL_SCREEN(s, GET_CUBEMODEL_DISPLAY(s->display)) 35 36 typedef struct _vect3d 37 { 38 float r[3]; 39 } vect3d; 40 41 typedef struct _vect2d 42 { 43 float r[2]; 44 } vect2d; 45 46 typedef struct _groupIndices 47 { 48 int polyCount; 49 int complexity; 50 51 int startV; 52 int numV; 53 int startT; 54 int numT; 55 int startN; 56 int numN; 57 58 int materialIndex; //negative for no new material 59 60 Bool texture; 61 Bool normal; 62 } groupIndices; 63 64 typedef struct _mtlStruct 65 { 66 char *name; 67 68 GLfloat Ka[4]; 69 GLfloat Kd[4]; 70 GLfloat Ks[4]; 71 72 GLfloat Ns[1]; /* shininess */ 73 GLfloat Ni[1]; /* optical_density - currently not used*/ 74 75 int illum; 76 77 unsigned height, width; 78 79 int map_Ka; /* index to tex, negative for none */ 80 int map_Kd; 81 int map_Ks; 82 int map_d; 83 84 int map_params; /* index tex map with height/width */ 85 } mtlStruct; 86 87 typedef struct _CubemodelObject 88 { 89 pthread_t thread; 90 Bool threadRunning; 91 Bool finishedLoading; 92 Bool updateAttributes; /* after finished loading in thread, read in 93 new attributes not read in before to avoid 94 race condition*/ 95 char *filename; 96 char *post; 97 98 int size; 99 int lenBaseFilename; 100 int startFileNum; 101 int maxNumZeros; 102 103 GLuint dList; 104 Bool compiledDList; 105 106 float rotate[4], translate[3], scale[3]; 107 float rotateSpeed, scaleGlobal; 108 float color[4]; 109 110 int fileCounter; 111 Bool animation; 112 int fps; 113 float time; 114 115 vect3d **reorderedVertex; 116 vect2d **reorderedTexture; 117 vect3d **reorderedNormal; 118 119 unsigned int *indices; 120 groupIndices *group; 121 122 vect3d *reorderedVertexBuffer; 123 vect2d *reorderedTextureBuffer; 124 vect3d *reorderedNormalBuffer; 125 126 int nVertex; 127 int nTexture; 128 int nNormal; 129 int nGroups; 130 int nIndices; 131 int nUniqueIndices; 132 int *nMaterial; 133 134 mtlStruct **material; 135 CompTexture *tex; /* stores all the textures */ 136 char **texName; 137 unsigned int *texWidth; 138 unsigned int *texHeight; 139 140 int nTex; 141 } CubemodelObject; 142 143 typedef struct _fileParser 144 { 145 FILE *fp; 146 char *oldStrline; 147 char *buf; 148 int bufferSize; 149 int cp; 150 Bool lastTokenOnLine; 151 int tokenCount; 152 } fileParser; 153 154 typedef struct _CubemodelDisplay 155 { 156 int screenPrivateIndex; 157 } CubemodelDisplay; 158 159 typedef struct _CubemodelScreen 160 { 161 DonePaintScreenProc donePaintScreen; 162 PreparePaintScreenProc preparePaintScreen; 163 164 CubeClearTargetOutputProc clearTargetOutput; 165 CubePaintInsideProc paintInside; 166 167 Bool damage; 168 169 int hsize; 170 float sideDistance; /* perpendicular distance to side wall from centre */ 171 float topDistance; /* perpendicular distance to top wall from centre */ 172 float radius; /* radius on which the hSize points lie */ 173 float arcAngle; /* 360 degrees / horizontal size */ 174 float ratio; /* screen width to height */ 175 176 GLuint objDisplayList; 177 178 CubemodelObject **models; 179 char **modelFilename; 180 int numModels; 181 } CubemodelScreen; 182 183 Bool 184 cubemodelDrawModelObject (CompScreen *s, 185 CubemodelObject *data, 186 float scale); 187 188 Bool 189 cubemodelDeleteModelObject (CompScreen *s, 190 CubemodelObject *data); 191 192 Bool 193 cubemodelModifyModelObject (CubemodelObject *data, 194 CompOption *option, 195 int nOption); 196 197 Bool 198 cubemodelUpdateModelObject (CompScreen *s, 199 CubemodelObject *data, 200 float time); 201 202 Bool 203 cubemodelAddModelObject (CompScreen *s, 204 CubemodelObject *modelData, 205 char *file, 206 float *translate, 207 float *rotate, 208 float rotateSpeed, 209 float *scale, 210 float *color, 211 Bool animation, 212 float fps); 213 214 Bool 215 cubemodelDrawVBOModel (CompScreen *s, 216 CubemodelObject *data, 217 float *vertex, 218 float *normal); 219 220 fileParser * 221 initFileParser (FILE *fp, 222 int bufferSize); 223 224 void 225 updateFileParser (fileParser *fParser, 226 FILE *fp); 227 228 void 229 freeFileParser (fileParser *); 230 231 char * 232 getLine (fileParser *); 233 234 char * 235 getLineToken (fileParser *); 236 237 char * 238 getLineToken2 (fileParser *, Bool); 239 240 void 241 skipLine (fileParser *); 242 243 char * 244 strsep2 (char **strPtr, const char *delim); 245 246 #endif 247