source: GTP/trunk/App/Demos/Illum/pathmap/World.cpp @ 2197

Revision 2197, 21.5 KB checked in by szirmay, 17 years ago (diff)
Line 
1#include "dxstdafx.h"
2#include "World.hpp"
3
4World::World()
5{
6        virtualWorldObjects = 0x0;
7        virtualWorldVertices = 0x0;
8        virtualWorldLights = 0x0;
9        nVirtualWorldObjects = 0;
10        nVirtualWorldVertices = 0;
11        nVirtualWorldLights = 0;
12}
13
14void World::createScene(Intersectable* obj)
15{
16        obliterate();
17        nVirtualWorldLights = 0;
18        virtualWorldLights = new Light*[1];
19        nVirtualWorldObjects = 1;
20        virtualWorldObjects = new Intersectable*[nVirtualWorldObjects];
21        nVirtualWorldVertices = 4;
22        virtualWorldVertices = new Vector[nVirtualWorldVertices];
23
24        virtualWorldObjects[0] = obj;
25        kdtree = new KDTree(virtualWorldObjects, nVirtualWorldObjects);
26}
27
28void World::createScene()
29{
30        obliterate();
31        eyePosition = Vector(10.0f, 0.0f, 0.0f);
32        lookPosition = Vector(0.0f, 0.0f, 0.0f);
33
34        nVirtualWorldLights = 1;
35        virtualWorldLights = new Light*[1];
36        nVirtualWorldObjects = 9;
37        virtualWorldObjects = new Intersectable*[nVirtualWorldObjects];
38
39        nVirtualWorldVertices = 4;
40        virtualWorldVertices = new Vector[nVirtualWorldVertices];
41        virtualWorldVertices[0] = Vector(2.0f, 1.9f, 2.0f);
42        virtualWorldVertices[1] = Vector(2.0f, 1.9f, -2.0f);
43        virtualWorldVertices[2] = Vector(-2.0f, 1.9f, -2.0f);
44        virtualWorldVertices[3] = Vector(-2.0f, 1.9f, 2.0f);
45
46        virtualWorldLights[0] = new SquareLight(virtualWorldVertices, 4, Vector(500.0f, 500.0f, 500.0f));
47        virtualWorldSummedLightLuminance = virtualWorldLights[0]->getLuminance();
48
49        int iObject = 0;
50
51        virtualWorldObjects[iObject++] = new PlaneXAligned(-2.0f, true, &Material::DIFFUSEBLUE);
52        virtualWorldObjects[iObject++] = new PlaneXAligned(11.0f, false, &Material::DIFFUSEGREEN);
53        virtualWorldObjects[iObject++] = new PlaneYAligned(-2.0f, true, &Material::DIFFUSEGREEN);
54        virtualWorldObjects[iObject++] = new PlaneYAligned(2.0f, false, &Material::DIFFUSEYELLOW);
55        virtualWorldObjects[iObject++] = new PlaneZAligned(-2.0f, true, &Material::DIFFUSERED);
56        virtualWorldObjects[iObject++] = new PlaneZAligned(2.0f, false, &Material::DIFFUSEORANGE);
57
58        virtualWorldObjects[iObject++] = new Triangle(
59                                virtualWorldVertices + 1,
60                                virtualWorldVertices,
61                                virtualWorldVertices + 2, new Material(Vector::RGBWHITE, Vector::RGBBLACK, 0.0f,
62                                        Vector(100000.0f, 100000.0f, 10000.0f), Vector::RGBBLACK, 0.0f));
63        virtualWorldObjects[iObject++] = new Triangle(
64                                virtualWorldVertices,
65                                virtualWorldVertices + 3,
66                                virtualWorldVertices + 2, new Material(Vector::RGBWHITE, Vector::RGBBLACK, 0.0f,
67                                        Vector(100000.0f, 100000.0f, 10000.0f), Vector::RGBBLACK, 0.0f));
68
69        virtualWorldObjects[iObject++] = new Sphere(Vector(0.0f, 0.0f, 0.0f), 1.0f, &Material::SHINYBLACK);
70
71        nVirtualWorldObjects = iObject;
72        kdtree = new KDTree(virtualWorldObjects, nVirtualWorldObjects);
73}
74
75void World::createScene(std::istream& isc)
76{
77        obliterate();
78
79        nVirtualWorldMaterials = nVirtualWorldObjects = 0;
80
81        objectArraySize = materialArraySize = lightArraySize = 8;
82        virtualWorldMaterials = new Material*[8];
83        virtualWorldObjects = new Intersectable*[8];
84
85        eyePosition = Vector(10.0f, 0.0f, 0.0f);
86        lookPosition = Vector(0.0f, 0.0f, 0.0f);
87        upwards = Vector(0.0f, 1.0f, 0.0f);
88        char keyword[200];
89        do{
90                isc >> keyword;
91                if(strcmp(keyword,"eyePosition") == 0)  isc >> eyePosition;
92                else if(strcmp(keyword,"lookPosition") == 0)    isc >> lookPosition;
93                else if(strcmp(keyword,"upwards") == 0) isc >> upwards;
94                else if(strcmp(keyword,"Material") == 0)       
95                {
96                        if(nVirtualWorldMaterials == materialArraySize)
97                        {
98                                materialArraySize += 4;
99                                Material** largerArray = new Material*[materialArraySize];
100                                for(int d=0;d<nVirtualWorldMaterials;d++)
101                                        largerArray[d] = virtualWorldMaterials[d];
102                                delete virtualWorldMaterials;
103                                virtualWorldMaterials = largerArray;
104                        }
105                        virtualWorldMaterials[nVirtualWorldMaterials] =  new Material(isc);
106                        nVirtualWorldMaterials++;
107                }
108/*              else if(strcmp(keyword,"HDRIMaterial") == 0)   
109                {
110                        if(nVirtualWorldMaterials == materialArraySize)
111                        {
112                                materialArraySize += 4;
113                                Material** largerArray = new Material*[materialArraySize];
114                                for(int d=0;d<nVirtualWorldMaterials;d++)
115                                        largerArray[d] = virtualWorldMaterials[d];
116                                delete virtualWorldMaterials;
117                                virtualWorldMaterials = largerArray;
118                        }
119                        virtualWorldMaterials[nVirtualWorldMaterials] =  new HDRIMaterial(isc);
120                        nVirtualWorldMaterials++;
121                }*/
122                else if(strcmp(keyword,"Sphere") == 0) 
123                {
124                        if(nVirtualWorldObjects == objectArraySize)
125                        {
126                                objectArraySize += 8;
127                                Intersectable** largerArray = new Intersectable*[objectArraySize];
128                                for(int d=0;d<nVirtualWorldObjects;d++)
129                                        largerArray[d] = virtualWorldObjects[d];
130                                delete virtualWorldObjects;
131                                virtualWorldObjects = largerArray;
132                        }
133                        virtualWorldObjects[nVirtualWorldObjects] =  new Sphere(isc, virtualWorldMaterials, nVirtualWorldMaterials);
134                        nVirtualWorldObjects++;
135                }
136                else if(strcmp(keyword,"Cylinder") == 0)       
137                {
138                        if(nVirtualWorldObjects == objectArraySize)
139                        {
140                                objectArraySize += 8;
141                                Intersectable** largerArray = new Intersectable*[objectArraySize];
142                                for(int d=0;d<nVirtualWorldObjects;d++)
143                                        largerArray[d] = virtualWorldObjects[d];
144                                delete virtualWorldObjects;
145                                virtualWorldObjects = largerArray;
146                        }
147                        virtualWorldObjects[nVirtualWorldObjects] =  new Cylinder(isc, virtualWorldMaterials, nVirtualWorldMaterials);
148                        nVirtualWorldObjects++;
149                }
150                else if(strcmp(keyword,"PlaneXAligned") == 0)   
151                {
152                        if(nVirtualWorldObjects == objectArraySize)
153                        {
154                                objectArraySize += 8;
155                                Intersectable** largerArray = new Intersectable*[objectArraySize];
156                                for(int d=0;d<nVirtualWorldObjects;d++)
157                                        largerArray[d] = virtualWorldObjects[d];
158                                delete virtualWorldObjects;
159                                virtualWorldObjects = largerArray;
160                        }
161                        virtualWorldObjects[nVirtualWorldObjects] =  new PlaneXAligned(isc, virtualWorldMaterials, nVirtualWorldMaterials);
162                        nVirtualWorldObjects++;
163                }
164                else if(strcmp(keyword,"PlaneYAligned") == 0)   
165                {
166                        if(nVirtualWorldObjects == objectArraySize)
167                        {
168                                objectArraySize += 8;
169                                Intersectable** largerArray = new Intersectable*[objectArraySize];
170                                for(int d=0;d<nVirtualWorldObjects;d++)
171                                        largerArray[d] = virtualWorldObjects[d];
172                                delete virtualWorldObjects;
173                                virtualWorldObjects = largerArray;
174                        }
175                        virtualWorldObjects[nVirtualWorldObjects] =  new PlaneYAligned(isc, virtualWorldMaterials, nVirtualWorldMaterials);
176                        nVirtualWorldObjects++;
177                }
178                else if(strcmp(keyword,"PlaneZAligned") == 0)   
179                {
180                        if(nVirtualWorldObjects == objectArraySize)
181                        {
182                                objectArraySize += 8;
183                                Intersectable** largerArray = new Intersectable*[objectArraySize];
184                                for(int d=0;d<nVirtualWorldObjects;d++)
185                                        largerArray[d] = virtualWorldObjects[d];
186                                delete virtualWorldObjects;
187                                virtualWorldObjects = largerArray;
188                        }
189                        virtualWorldObjects[nVirtualWorldObjects] =  new PlaneZAligned(isc, virtualWorldMaterials, nVirtualWorldMaterials);
190                        nVirtualWorldObjects++;
191                }
192                else if(strcmp(keyword,"TriangleMesh") == 0)   
193                {
194                        if(nVirtualWorldObjects == objectArraySize)
195                        {
196                                objectArraySize += 8;
197                                Intersectable** largerArray = new Intersectable*[objectArraySize];
198                                for(int d=0;d<nVirtualWorldObjects;d++)
199                                        largerArray[d] = virtualWorldObjects[d];
200                                delete virtualWorldObjects;
201                                virtualWorldObjects = largerArray;
202                        }
203                        virtualWorldObjects[nVirtualWorldObjects] =  new TriangleMesh(isc, virtualWorldMaterials, nVirtualWorldMaterials);
204                        nVirtualWorldObjects++;
205                }
206                else if(strcmp(keyword,"Transformed") == 0)     
207                {
208                        if(nVirtualWorldObjects == objectArraySize)
209                        {
210                                objectArraySize += 8;
211                                Intersectable** largerArray = new Intersectable*[objectArraySize];
212                                for(int d=0;d<nVirtualWorldObjects;d++)
213                                        largerArray[d] = virtualWorldObjects[d];
214                                delete virtualWorldObjects;
215                                virtualWorldObjects = largerArray;
216                        }
217                        virtualWorldObjects[nVirtualWorldObjects] =  new Transformed(isc, virtualWorldMaterials, nVirtualWorldMaterials);
218                        nVirtualWorldObjects++;
219                }
220                else if(strcmp(keyword,"EnvironmentCube") == 0)
221                        createEnvironmentMap(isc);
222                else if(strcmp(keyword,"SkyscraperArray") == 0)
223                {
224                        Material* skymat1; Material* skymat2; Material* skymat3; Material* skymat4;
225                        char ky[200];
226                        isc >> ky;
227                        for(int i=0; i < nVirtualWorldMaterials; i++)
228                        {
229                                skymat1 = virtualWorldMaterials[i];
230                                if(strcmp(ky, skymat1->getName()) == 0) break;
231                        }
232                        isc >> ky;
233                        for(int i=0; i < nVirtualWorldMaterials; i++)
234                        {
235                                skymat2 = virtualWorldMaterials[i];
236                                if(strcmp(ky, skymat2->getName()) == 0) break;
237                        }
238                        isc >> ky;
239                        for(int i=0; i < nVirtualWorldMaterials; i++)
240                        {
241                                skymat3 = virtualWorldMaterials[i];
242                                if(strcmp(ky, skymat3->getName()) == 0) break;
243                        }
244                        isc >> ky;
245                        for(int i=0; i < nVirtualWorldMaterials; i++)
246                        {
247                                skymat4 = virtualWorldMaterials[i];
248                                if(strcmp(ky, skymat4->getName()) == 0) break;
249                        }
250                        int rows, cols;
251                        float edge, street, minHeight, maxHeight;
252                        isc >> rows >> cols;
253                        {
254                                objectArraySize += rows * cols * 6;
255                                Intersectable** largerArray = new Intersectable*[objectArraySize];
256                                for(int d=0;d<nVirtualWorldObjects;d++)
257                                        largerArray[d] = virtualWorldObjects[d];
258                                delete virtualWorldObjects;
259                                virtualWorldObjects = largerArray;
260                        }
261                        isc >> edge >> street >> minHeight >> maxHeight;
262                        for(int r=0; r < rows; r++)
263                                for(int c=0; c < cols; c++)
264                                {
265                                        Material* skymat;
266                                        float marand = (float)rand() / (float)RAND_MAX;
267                                        if(marand < 0.25f)
268                                                skymat = skymat1;
269                                        else if(marand < 0.5f)
270                                                skymat = skymat2;
271                                        else if(marand < 0.75f)
272                                                skymat = skymat3;
273                                        else
274                                                skymat = skymat4;
275                                        float xMin = r * (edge + street);
276                                        float xMax = xMin + edge;
277                                        float yMin = c * (edge + street);
278                                        float yMax = yMin + edge;
279                                        float height = minHeight + (maxHeight - minHeight) * (float)rand() / (float)RAND_MAX;
280                                        PlaneXAligned* p = new PlaneXAligned(xMin, false, skymat);
281                                        p->yMin = yMin; p->yMax = yMax;
282                                        p->zMin = 0.0f; p->zMax = height;
283                                        p->bbox.minPoint.x = p->bbox.maxPoint.x = xMin;
284                                        p->bbox.maxPoint.y = yMax;
285                                        p->bbox.maxPoint.z = height;
286                                        p->bbox.minPoint.y = yMin;
287                                        p->bbox.minPoint.z = 0.0f;
288                                        virtualWorldObjects[nVirtualWorldObjects++] = p;
289                                        p = new PlaneXAligned(xMax, true, skymat);
290                                        p->yMin = yMin; p->yMax = yMax;
291                                        p->zMin = 0.0f; p->zMax = height;
292                                        p->bbox.minPoint.x = p->bbox.maxPoint.x = xMax;
293                                        p->bbox.maxPoint.y = yMax;
294                                        p->bbox.maxPoint.z = height;
295                                        p->bbox.minPoint.y = yMin;
296                                        p->bbox.minPoint.z = 0.0f;
297                                        virtualWorldObjects[nVirtualWorldObjects++] = p;
298                                        PlaneYAligned* py = new PlaneYAligned(yMin, false, skymat);
299                                        py->xMin = xMin; py->xMax = xMax;
300                                        py->zMin = 0.0f; py->zMax = height;
301                                        py->bbox.minPoint.y = py->bbox.maxPoint.y = yMin;
302                                        py->bbox.maxPoint.x = xMax;
303                                        py->bbox.maxPoint.z = height;
304                                        py->bbox.minPoint.x = xMin;
305                                        py->bbox.minPoint.z = 0.0f;
306                                        virtualWorldObjects[nVirtualWorldObjects++] = py;
307                                        py = new PlaneYAligned(yMax, true, skymat);
308                                        py->xMin = xMin; py->xMax = xMax;
309                                        py->zMin = 0.0f; py->zMax = height;
310                                        py->bbox.minPoint.y = py->bbox.maxPoint.y = yMax;
311                                        py->bbox.maxPoint.x = xMax;
312                                        py->bbox.maxPoint.z = height;
313                                        py->bbox.minPoint.x = xMin;
314                                        py->bbox.minPoint.z = 0.0f;
315                                        virtualWorldObjects[nVirtualWorldObjects++] = py;
316                                        PlaneZAligned* pz = new PlaneZAligned(0.0f, false, skymat);
317                                        pz->xMin = xMin; pz->xMax = xMax;
318                                        pz->yMin = yMin; pz->yMax = yMax;
319                                        pz->bbox.minPoint.z = pz->bbox.maxPoint.z = 0.0;
320                                        pz->bbox.maxPoint.x = xMax;
321                                        pz->bbox.maxPoint.y = yMax;
322                                        pz->bbox.minPoint.x = xMin;
323                                        pz->bbox.minPoint.y = yMin;
324                                        virtualWorldObjects[nVirtualWorldObjects++] = pz;
325                                        pz = new PlaneZAligned(height, true, skymat);
326                                        pz->xMin = xMin; pz->xMax = xMax;
327                                        pz->yMin = yMin; pz->yMax = yMax;
328                                        pz->bbox.minPoint.z = pz->bbox.maxPoint.z = height;
329                                        pz->bbox.maxPoint.x = xMax;
330                                        pz->bbox.maxPoint.y = yMax;
331                                        pz->bbox.minPoint.x = xMin;
332                                        pz->bbox.minPoint.y = yMin;
333                                        virtualWorldObjects[nVirtualWorldObjects++] = pz;
334
335                                }
336                }
337        }while(strcmp(keyword,"end") != 0);
338
339        nVirtualWorldLights = 0;
340        for(int iLightCounter=0;iLightCounter < nVirtualWorldObjects;iLightCounter++)
341                if(virtualWorldObjects[iLightCounter]->getMaterial()->isEmissive())
342                        nVirtualWorldLights++;
343
344        virtualWorldLights = new Light*[nVirtualWorldLights];
345
346        int iLightPlacer = 0;
347        virtualWorldSummedLightLuminance = 0.0f;
348
349        for(int iLightMaker=0;iLightMaker < nVirtualWorldObjects;iLightMaker++)
350                if(virtualWorldObjects[iLightMaker]->getMaterial()->isEmissive())
351                {
352                        virtualWorldLights[iLightPlacer] = virtualWorldObjects[iLightMaker]->makeLight();
353                        virtualWorldSummedLightLuminance += virtualWorldLights[iLightPlacer]->getLuminance();
354                        iLightPlacer++;
355                }
356
357        kdtree = new KDTree(virtualWorldObjects, nVirtualWorldObjects);
358}
359
360void World::obliterate()
361{
362        if(virtualWorldObjects)
363                delete virtualWorldObjects;
364        if(virtualWorldVertices)
365                delete virtualWorldVertices;
366        if(virtualWorldLights)
367                delete virtualWorldLights;
368}
369
370/*
371        nVirtualWorldLights = 4;
372        virtualWorldLights = new Light[4];
373        nVirtualWorldVertices = 81;
374        virtualWorldVertices = new Vector[nVirtualWorldVertices];
375        float b = 1.0f / sqrtf(2.0f);
376        virtualWorldLights[0] = Light(Vector(10.0f, 0.0f, 14.0f), Vector(110000.0f, 110000.0f, 110000.0f), Vector(b, 0.0f, -b));
377        virtualWorldLights[1] = Light(Vector(-10.0f, 0.0f, 14.0f), Vector(110000.0f, 110000.0f, 110000.0f), Vector(-b, 0.0f, -b));
378        virtualWorldLights[2] = Light(Vector(0.0f, 10.0f, 14.0f), Vector(110000.0f, 110000.0f, 110000.0f), Vector(0.0f, b, -b));
379        virtualWorldLights[3] = Light(Vector(0.0f, -10.0f, 14.0f), Vector(110000.0f, 110000.0f, 110000.0f), Vector(0.0f, -b, -b));
380
381        virtualWorldSummedLightLuminance = virtualWorldLights[0].getLuminance()
382                +
383                virtualWorldLights[1].getLuminance()
384                +
385                virtualWorldLights[2].getLuminance()
386                +
387                virtualWorldLights[3].getLuminance()
388                ;
389
390        Material* tmat = new Material(Vector(0.6f, 0.6f, 0.1f), Vector(0.3f, 0.3f, 0.3f), 3.0f);
391//      Material* glass = new Material(Vector(0.1f, 0.5f, 0.1f), Vector(0.15f, 0.15f, 0.15f), 3.0f);
392//      glass->makeRefractiveAndIdeal(0.95f, Vector(0.7f, 0.6f, 0.5f), Vector(0.25f, 0.2f, 0.15f));
393//      Material* woodmat = new WoodMaterial();
394
395        nVirtualWorldObjects = 7;
396        virtualWorldObjects = new Intersectable*[19];
397        TriangleMesh* pot = new TriangleMesh(isc, tmat);
398//      TriangleMesh* not = new TriangleMesh(isc, &Material::YELLOWPLASTIC);
399        Transformed* trs;
400        trs = new Transformed(pot);
401        virtualWorldObjects[6] = trs;
402//dragon:
403//              trs->scale(0.08f);
404//              trs->rotateY(3.14f);
405//              trs->rotateX(1.55f);
406//              trs->rotateY(0.3f);
407//              trs->translate(Vector(0.0f, -16.5f, 0.0f));
408
409//      trs = new Transformed(not);
410//      virtualWorldObjects[6] = trs;
411                trs->scale(2.9f);
412//              trs->rotateZ(1.55f);
413//              trs->translate(Vector(0.0f, -7.0f, 10.0f));
414
415//              trs->translate(Vector(y%3 * 10.0f - 10.0f, (y/3) * 10.0f - 10.0f, 0.0f));
416
417
418        virtualWorldObjects[0] = new PlaneZAligned(-15.0f, true, &Material::DIFFUSEORANGE);
419        virtualWorldObjects[1] = new PlaneZAligned(50.0f, false, &Material::DIFFUSEWHITE);
420        virtualWorldObjects[2] = new PlaneXAligned(-15.0f, true, &Material::DIFFUSELIGHTBLUE);
421        virtualWorldObjects[3] = new PlaneXAligned(15.0f, false, &Material::DIFFUSEGREEN);
422        virtualWorldObjects[4] = new PlaneYAligned(-15.0f, true, &Material::DIFFUSEYELLOW);
423        virtualWorldObjects[5] = new PlaneYAligned(15.0f, false, &Material::DIFFUSEORANGE);
424//      virtualWorldObjects[6] = new Cylinder(Vector(-11.0f, 0.0f, -28.0f), 15.0f, 35.0f, -25.0f, &Material::DIFFUSEWHITE);
425//      virtualWorldObjects[7] = new Sphere(Vector(3.3f, 2.8f, 5.0f), 2.0f, glass);
426
427//      virtualWorldObjects[8] = new Cylinder(Vector(-15.0f, 0.0f, 10.0f), 2.5f, 15.0f, -15.0f, &Material::DIFFUSEWHITE);
428//      virtualWorldObjects[9] = new Cylinder(Vector(-15.0f, 0.0f, 0.0f), 2.5f, 15.0f, -15.0f, &Material::DIFFUSEWHITE);
429//      virtualWorldObjects[10] = new Cylinder(Vector(-15.0f, 0.0f, -10.0f), 2.5f, 15.0f, -15.0f, &Material::DIFFUSEWHITE);
430//      virtualWorldObjects[11] = new Cylinder(Vector(-10.0f, 0.0f, -15.0f), 2.5f, 15.0f, -15.0f, &Material::DIFFUSEWHITE);
431//      virtualWorldObjects[12] = new Cylinder(Vector(0.0f, 0.0f, -15.0f), 2.5f, 15.0f, -15.0f, &Material::DIFFUSEWHITE);
432//      virtualWorldObjects[13] = new Cylinder(Vector(15.0f, 0.0f, 10.0f), 2.5f, 15.0f, -15.0f, &Material::DIFFUSEWHITE);
433//      virtualWorldObjects[14] = new Cylinder(Vector(15.0f, 0.0f, 0.0f), 2.5f, 15.0f, -15.0f, &Material::DIFFUSEWHITE);
434//      virtualWorldObjects[15] = new Cylinder(Vector(15.0f, 0.0f, -10.0f), 2.5f, 15.0f, -15.0f, &Material::DIFFUSEWHITE);
435//      virtualWorldObjects[16] = new Cylinder(Vector(10.0f, 0.0f, -15.0f), 2.5f, 15.0f, -15.0f, &Material::DIFFUSEWHITE);
436//      virtualWorldObjects[17] = new Sphere(Vector(10.0f, -12.99f, -3.0f), 2.0f, glass);
437//      virtualWorldObjects[18] = new Sphere(Vector(-10.0f, -12.99f, 5.0f), 2.0f, glass);
438
439//      virtualWorldObjects[0] = new Sphere(Vector(0.0f, 1.0f, 0.0f), 2.0f, &Material::DIFFUSEWHITE);
440
441*/
442
443void World::createEnvironmentMap(std::istream& isc)
444{
445        int division = 1;
446        const Material* material = &Material::DIFFUSEORANGE;
447        Vector centre(0.0f, 0.0f, 0.0f);
448        float radius = 10000.0f;
449        char key[200];
450        do
451        {
452                isc >> key;
453                if(strcmp(key,"radius") == 0)   isc >> radius;
454                else if(strcmp(key,"centre")==0)        isc >> centre;
455                else if(strcmp(key,"division")==0)      isc >> division;
456                else if(strcmp(key,"material") == 0)
457                {
458                        isc >> key;
459                        for(int i=0; i < nVirtualWorldMaterials; i++)
460                        {
461                                material = virtualWorldMaterials[i];
462                                if(strcmp(key, material->getName()) == 0) break;
463                        }
464                }
465        }
466        while(strcmp(key,"end")!=0);
467
468        {
469                objectArraySize += division * division * 6;
470                Intersectable** largerArray = new Intersectable*[objectArraySize];
471                for(int d=0;d<nVirtualWorldObjects;d++)
472                        largerArray[d] = virtualWorldObjects[d];
473                delete virtualWorldObjects;
474                virtualWorldObjects = largerArray;
475        }
476
477        int q,w;
478        for(q=0; q<division; q++)
479        {
480                for(w=0; w<division; w++)
481                {
482                        PlaneXAligned* p =      new PlaneXAligned(-radius, true, material);
483                        p->yMin = (2.0 * radius / division) * q - radius;
484                        p->yMax = p->yMin + 2.0 * radius / division;
485                        p->zMin = (2.0 * radius / division) * w - radius;
486                        p->zMax = p->zMin + 2.0 * radius / division;
487                        p->bbox.minPoint.x = p->bbox.maxPoint.x = -radius;
488                        p->bbox.minPoint.y = p->yMin;
489                        p->bbox.maxPoint.y = p->yMax;
490                        p->bbox.minPoint.z = p->zMin;
491                        p->bbox.maxPoint.z = p->zMax;
492                        virtualWorldObjects[nVirtualWorldObjects] = p;
493                        nVirtualWorldObjects++;
494                }
495        }
496        for(q=0; q<division; q++)
497        {
498                for(w=0; w<division; w++)
499                {
500                        PlaneXAligned* p =      new PlaneXAligned(radius, false, material);
501                        p->yMin = (2.0 * radius / division) * q - radius;
502                        p->yMax = p->yMin + 2.0 * radius / division;
503                        p->zMin = (2.0 * radius / division) * w - radius;
504                        p->zMax = p->zMin + 2.0 * radius / division;
505                        p->bbox.minPoint.x = p->bbox.maxPoint.x = radius;
506                        p->bbox.minPoint.y = p->yMin;
507                        p->bbox.maxPoint.y = p->yMax;
508                        p->bbox.minPoint.z = p->zMin;
509                        p->bbox.maxPoint.z = p->zMax;
510                        virtualWorldObjects[nVirtualWorldObjects] = p;
511                        nVirtualWorldObjects++;
512                }
513        }
514        for(q=0; q<division; q++)
515        {
516                for(w=0; w<division; w++)
517                {
518                        PlaneYAligned* p =      new PlaneYAligned(-radius, true, material);
519                        p->xMin = (2.0 * radius / division) * q - radius;
520                        p->xMax = p->xMin + 2.0 * radius / division;
521                        p->zMin = (2.0 * radius / division) * w - radius;
522                        p->zMax = p->zMin + 2.0 * radius / division;
523                        p->bbox.minPoint.y = p->bbox.maxPoint.y = -radius;
524                        p->bbox.minPoint.x = p->xMin;
525                        p->bbox.maxPoint.x = p->xMax;
526                        p->bbox.minPoint.z = p->zMin;
527                        p->bbox.maxPoint.z = p->zMax;
528                        virtualWorldObjects[nVirtualWorldObjects] = p;
529                        nVirtualWorldObjects++;
530                }
531        }
532        for(q=0; q<division; q++)
533        {
534                for(w=0; w<division; w++)
535                {
536                        PlaneYAligned* p =      new PlaneYAligned(radius, false, material);
537                        p->xMin = (2.0 * radius / division) * q - radius;
538                        p->xMax = p->xMin + 2.0 * radius / division;
539                        p->zMin = (2.0 * radius / division) * w - radius;
540                        p->zMax = p->zMin + 2.0 * radius / division;
541                        p->bbox.minPoint.y = p->bbox.maxPoint.y = radius;
542                        p->bbox.minPoint.x = p->xMin;
543                        p->bbox.maxPoint.x = p->xMax;
544                        p->bbox.minPoint.z = p->zMin;
545                        p->bbox.maxPoint.z = p->zMax;
546                        virtualWorldObjects[nVirtualWorldObjects] = p;
547                        nVirtualWorldObjects++;
548                }
549        }
550        for(q=0; q<division; q++)
551        {
552                for(w=0; w<division; w++)
553                {
554                        PlaneZAligned* p =      new PlaneZAligned(-radius, true, material);
555                        p->yMin = (2.0 * radius / division) * q - radius;
556                        p->yMax = p->yMin + 2.0 * radius / division;
557                        p->xMin = (2.0 * radius / division) * w - radius;
558                        p->xMax = p->xMin + 2.0 * radius / division;
559                        p->bbox.minPoint.z = p->bbox.maxPoint.z = -radius;
560                        p->bbox.minPoint.y = p->yMin;
561                        p->bbox.maxPoint.y = p->yMax;
562                        p->bbox.minPoint.x = p->xMin;
563                        p->bbox.maxPoint.x = p->xMax;
564                        virtualWorldObjects[nVirtualWorldObjects] = p;
565                        nVirtualWorldObjects++;
566                }
567        }
568        for(q=0; q<division; q++)
569        {
570                for(w=0; w<division; w++)
571                {
572                        PlaneZAligned* p =      new PlaneZAligned(radius, false, material);
573                        p->yMin = (2.0 * radius / division) * q - radius;
574                        p->yMax = p->yMin + 2.0 * radius / division;
575                        p->xMin = (2.0 * radius / division) * w - radius;
576                        p->xMax = p->xMin + 2.0 * radius / division;
577                        p->bbox.minPoint.z = p->bbox.maxPoint.z = radius;
578                        p->bbox.minPoint.y = p->yMin;
579                        p->bbox.maxPoint.y = p->yMax;
580                        p->bbox.minPoint.x = p->xMin;
581                        p->bbox.maxPoint.x = p->xMax;
582                        virtualWorldObjects[nVirtualWorldObjects] = p;
583                        nVirtualWorldObjects++;
584                }
585        }
586}
Note: See TracBrowser for help on using the repository browser.