5 #include "../../x3d/src/X3DDefs.h"
10 Size3D* gFuncSize3D(){
return &gVarSize3D; }
12 #if defined (WIN32) || defined (__MWERKS__)
13 void FillX3DBuffer (X3DBuffer *buff) { }
14 int AllocateX3DBuffer () {
return 0;}
27 int AllocateX3DBuffer ()
45 if (gSize3D.numPoints) {
46 points = (point *) calloc(gSize3D.numPoints, sizeof (point));
48 puts (
"Unable to allocate memory for points !");
60 colors = (Color *) calloc(28+4,
sizeof (Color));
62 puts (
"Unable to allocate memory for colors !");
66 colors[ 0].red = 92; colors[ 0].green = 92; colors[0].blue = 92;
67 colors[ 1].red = 122; colors[ 1].green = 122; colors[1].blue = 122;
68 colors[ 2].red = 184; colors[ 2].green = 184; colors[2].blue = 184;
69 colors[ 3].red = 215; colors[ 3].green = 215; colors[3].blue = 215;
70 colors[ 4].red = 138; colors[ 4].green = 15; colors[4].blue = 15;
71 colors[ 5].red = 184; colors[ 5].green = 20; colors[5].blue = 20;
72 colors[ 6].red = 235; colors[ 6].green = 71; colors[6].blue = 71;
73 colors[ 7].red = 240; colors[ 7].green = 117; colors[7].blue = 117;
74 colors[ 8].red = 15; colors[ 8].green = 138; colors[8].blue = 15;
75 colors[ 9].red = 20; colors[ 9].green = 184; colors[9].blue = 20;
76 colors[10].red = 71; colors[10].green = 235; colors[10].blue = 71;
77 colors[11].red = 117; colors[11].green = 240; colors[11].blue = 117;
78 colors[12].red = 15; colors[12].green = 15; colors[12].blue = 138;
79 colors[13].red = 20; colors[13].green = 20; colors[13].blue = 184;
80 colors[14].red = 71; colors[14].green = 71; colors[14].blue = 235;
81 colors[15].red = 117; colors[15].green = 117; colors[15].blue = 240;
82 colors[16].red = 138; colors[16].green = 138; colors[16].blue = 15;
83 colors[17].red = 184; colors[17].green = 184; colors[17].blue = 20;
84 colors[18].red = 235; colors[18].green = 235; colors[18].blue = 71;
85 colors[19].red = 240; colors[19].green = 240; colors[19].blue = 117;
86 colors[20].red = 138; colors[20].green = 15; colors[20].blue = 138;
87 colors[21].red = 184; colors[21].green = 20; colors[21].blue = 184;
88 colors[22].red = 235; colors[22].green = 71; colors[22].blue = 235;
89 colors[23].red = 240; colors[23].green = 117; colors[23].blue = 240;
90 colors[24].red = 15; colors[24].green = 138; colors[24].blue = 138;
91 colors[25].red = 20; colors[25].green = 184; colors[25].blue = 184;
92 colors[26].red = 71; colors[26].green = 235; colors[26].blue = 235;
93 colors[27].red = 117; colors[27].green = 240; colors[27].blue = 240;
101 if (gSize3D.numSegs) {
102 segs = (segment *) calloc (gSize3D.numSegs, sizeof (segment));
104 puts (
"Unable to allocate memory for segments !");
114 if (gSize3D.numPolys) {
115 polys = (polygon *) calloc(gSize3D.numPolys, sizeof (polygon));
117 puts (
"Unable to allocate memory for polygons !");
128 if (points) free (points);
129 if (colors) free (colors);
130 if (segs) free (segs);
131 if (polys) free (polys);
142 void FillX3DBuffer (X3DBuffer *buff)
149 int n, i, j, p, q, c;
150 int oldNumOfPoints, oldNumOfSegments;
154 oldNumOfPoints = currPoint;
155 oldNumOfSegments = currSeg;
161 for (i = 0; i < buff->numPoints; i++, currPoint++) {
162 points[currPoint].x = buff->points[3*i ];
163 points[currPoint].y = buff->points[3*i+1];
164 points[currPoint].z = buff->points[3*i+2];
172 for (i = 0; i < buff->numSegs; i++, currSeg++) {
174 p = oldNumOfPoints + buff->segs[3*i+1];
175 q = oldNumOfPoints + buff->segs[3*i+2];
177 segs[currSeg].color = &(colors[c]);
178 segs[currSeg].P = &(points[p]);
179 segs[currSeg].Q = &(points[q]);
185 if(points[p].numSegs == 0){
186 if((points[p].segs = (segment **)calloc(1,
sizeof(segment *))) == NULL){
187 puts(
"Unable to allocate memory for point segments !");
191 if((points[p].segs = (segment **)realloc(points[p].segs,
192 (points[p].numSegs + 1) *
sizeof(segment *))) == NULL){
193 puts(
"Unable to allocate memory for point segments !");
198 if(points[q].numSegs == 0){
199 if((points[q].segs = (segment **)calloc(1,
sizeof(segment *))) == NULL){
200 puts(
"Unable to allocate memory for point segments !");
204 if((points[q].segs = (segment **)realloc(points[q].segs,
205 (points[q].numSegs + 1) *
sizeof(segment *))) == NULL){
206 puts(
"Unable to allocate memory for point segments !");
210 points[p].segs[points[p].numSegs] = &(segs[currSeg]);
211 points[q].segs[points[q].numSegs] = &(segs[currSeg]);
223 for (i = 0; i < buff->numPolys; i++, currPoly++) {
224 c = buff->polys[n++];
225 polys[currPoly].color = &(colors)[c];
226 polys[currPoly].numSegs = buff->polys[n++];
228 polys[currPoly].segs = (segment **) calloc(polys[currPoly].numSegs,
sizeof(segment *));
229 if (!polys[currPoly].segs) {
230 puts(
"Unable to allocate memory for polygon segments !");
233 for (j = 0; j < polys[currPoly].numSegs; j++) {
234 int seg = oldNumOfSegments + buff->polys[n++];
235 polys[currPoly].segs[j] = &(segs[seg]);
241 if(segs[seg].numPolys == 0) {
242 if((segs[seg].polys = (polygon **) calloc(1,
sizeof(polygon *)))== NULL){
243 puts(
"Unable to allocate memory for segment polygons !");
248 if((segs[seg].polys = (polygon **) realloc(segs[seg].polys,
249 (segs[seg].numPolys + 1) *
sizeof(polygon *))) == NULL){
250 puts(
"Unable to allocate memory for segment polygons !");
254 segs[seg].polys[segs[seg].numPolys] = &(polys[currPoly]);
255 segs[seg].numPolys++;