source: GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/IMGCluster.cpp @ 699

Revision 699, 13.7 KB checked in by igarcia, 18 years ago (diff)
Line 
1
2#include "IMGCluster.h"
3#include "IMGCluster2d.h"
4
5namespace IMG {
6
7Cluster::Cluster(){
8        id = Cluster::ID_CLUSTER++;
9        bound = new BBox;
10        bspnodebound = NULL;
11        //CreateVector3s();
12}
13
14Cluster & Cluster::operator =(const Cluster & p) {
15        //      printf("\nConstructor d'assignació de cluster");
16        // GametoolsError -- Isma 17/08/2005
17        //vertexs = p.vertexs;
18        //vertexs_vector = p.vertexs_vector;
19        //vertexs_triangle_text = p.vertexs_triangle_text;
20        uv = p.uv;
21        id = p.id;
22
23        //get the lumel_origin becaus if get Inc[0] the value is not correct   
24       
25        lumel_origin = p.lumel_origin;
26        lumel_x_axis = p.lumel_x_axis;
27        lumel_y_axis = p.lumel_y_axis;
28       
29        //patchlistid = p.patchlistid;
30        //plane = p.plane;
31       
32        axisproj = p.axisproj;
33        order = p.order;
34        triangle2d_text = p.triangle2d_text;
35        bound = p.bound;
36        normal = p.normal;
37        bspnodebound = p.bspnodebound;
38        return *this;
39}
40
41Cluster::Cluster(const Cluster & p){
42        ///printf("\nConstructor per copia de cluster");
43        // GametoolsError -- Isma 17/08/2005
44        //vertexs = p.vertexs;
45        //vertexs_triangle_text = p.vertexs_triangle_text;
46        //vertexs_vector = p.vertexs_vector;
47        //printf("\nnombre de vertexs origens: %d", p.vertexs_vector.size());
48        //printf("\nnombre de vertexs copiats: %d", vertexs_vector.size());
49        uv = p.uv;
50        id = p.id;
51       
52        //get the lumel_origin becaus if get Inc[0] the value is not correct   
53       
54        lumel_origin = p.lumel_origin;
55        lumel_x_axis = p.lumel_x_axis;
56        lumel_y_axis = p.lumel_y_axis;
57       
58        //patchlistid = p.patchlistid;
59        //plane = p.plane;
60       
61        axisproj = p.axisproj;
62        order = p.order;
63        triangle2d_text = p.triangle2d_text;
64        bound = p.bound;
65        normal = p.normal;
66        bspnodebound = p.bspnodebound;
67       
68        //trianglelistid = p.trianglelistid;
69       
70}
71
72// Gametools -- Isma 17/08/2005
73//void Cluster::Insert (Triangle *t)
74//{
75//      int axis = t->AxisProjected();
76//     
77//      //printf("\nAxis: %d", axis);
78//      //t->Print();
79//      Vector3 *v = t->GetVector3s();
80//      //std::vector<Vector3> v = *t->GetVector3sVector();
81//     
82//      for (int i = 0; i < 3; i++)
83//      {
84//              //printf("\ntriangle a transformar : (%.4f, %.4f, %.4f)", v[i].x, v[i].y, v[i].z);
85//             
86//              vertexs_vector.push_back (v[i]);
87//              //bound->AddBoundingVector3 (v[i].x, v[i].y, v[i].z);
88//              /*
89//              switch (axis)
90//              {
91//                      case 0: bound->AddBoundingVector3 (v[i].z, v[i].y, 0);break;
92//                      case 1: bound->AddBoundingVector3 (v[i].x, v[i].z, 0);break;
93//                      case 2: bound->AddBoundingVector3 (v[i].x, v[i].y, 0);break;   
94//              }
95//              */
96//      }
97//     
98//      plane = *t->GetPlane();
99//}
100
101void Cluster::Print() {
102        printf("\n\nCluster: %d, axisproj: %d, order: %d", id, axisproj, order);
103        //Vector3 *normal = plane.GetNormal();
104        //printf("\nPlane: (%.4f, %.4f, %.4f)", normal->x, normal->y, normal->z);
105        plane.Print();
106        printf("\nOrigin (%.4f, %.4f, %.4f) \n", lumel_origin.x, lumel_origin.y, lumel_origin.z);
107                //printf("Inc U (%.4f, %.4f, %.4f) \n", Inc[1].x, Inc[1].y, Inc[1].z);
108        printf("Inc U (%.4f, %.4f, %.4f) \n", lumel_x_axis.x, lumel_x_axis.y, lumel_x_axis.z);
109        printf("Inc V (%.4f, %.4f, %.4f) ", lumel_y_axis.x, lumel_y_axis.y, lumel_y_axis.z);
110       
111        if (bound) bound->Print();
112        if (bspnodebound) bspnodebound->Print();
113       
114       
115        /*
116        printf("\nIndex de triangles del cluster: %d -->", trianglelistid.GetSize());
117        for (register int i = 0; i < trianglelistid.GetSize(); i++)
118        {
119                printf(" %d", trianglelistid.Get(i));
120        }
121        */
122       
123        printf("Printant els vertexs: ");
124       
125        //for (int i = 0; i < 4; i++)
126        //      printf("\nVector3s %d del cluster: (%.4f, %.4f, %.4f)", i, vertexs[i].x, vertexs[i].y, vertexs[i].z);
127        // Gametools -- Isma 17/08/2005
128        //for (int i = 0; i < vertexs_vector.size(); i++)
129        //      printf("\nVector3s %d del cluster: (%.4f, %.4f, %.4f)", i, vertexs_vector[i].x, vertexs_vector[i].y, vertexs_vector[i].z);
130
131        //printf("\nVector3s del cluster: ");
132        //for (int i = 0; i < 4; i++)
133        //{
134        //              printf("\nVector3s %d: (%.4f, %.4f, %.4f)", i, vertexs_triangle_text[i].x, vertexs_triangle_text[i].y, vertexs_triangle_text[i].z);
135        //}     
136       
137        /*
138        printf("\nCoordenades de texture dels vertes: %d -->", vertexs_vector.size());
139       
140        for (int i = 0 ; i < vertexs_vector.size(); i++)
141        {
142                Vector3 vec= vertexs_triangle_text[i];
143               
144                printf("  (%.4f, %.4f)", vec.x, vec.y);
145        }       
146        */     
147}
148
149//* return the dominant normal axis, for calculate the 2d projection
150int Cluster::AxisProjected() {
151       
152        Ogre::Vector3 *normal = plane.GetNormal();
153       
154        if (Ogre::Math::Abs(normal->x) >= Ogre::Math::Abs(normal->y) && Ogre::Math::Abs(normal->x) >= Ogre::Math::Abs(normal->z))       return (0);             
155        if (Ogre::Math::Abs(normal->y) >= Ogre::Math::Abs(normal->x) && Ogre::Math::Abs(normal->y) >= Ogre::Math::Abs(normal->z))       return (1);
156        else                                                                            return (2);
157}
158
159// Gametools -- Isma 17/08/2005
160//bool CreatePatches(bool dinamic = false);
161// Gametools -- Isma 17/08/2005
162//Listid *GetPatchList() { return &patchlistid;}
163//Listid *GetTriangleList(){ return &trianglelistid; }
164// Gametools -- Isma 17/08/2005
165//int GetIdPatch (unsigned int i)
166//{
167//      if (i > patchlistid.GetSize()) return -1;
168//     
169//      return patchlistid.Get(i);
170//}
171// Gametools -- Isma 17/08/2005
172//int GetIdTriangle  (unsigned int i)
173//{
174//      if (i > trianglelistid.GetSize()) return -1;
175//     
176//      return trianglelistid.Get(i);
177//}
178void Cluster::Finish() {
179        printf("\nCluster::Finish()");
180        Plane3 *plane = GetPlane();
181        Ogre::Vector3 normal = *plane->GetNormal();
182        float distance = plane->GetDistance();
183        Ogre::Vector3 corner;
184        Cluster2d cluster2d;           
185        Ogre::Vector3 vertexfinal[3];
186        Ogre::Vector2 *vertexs2d;
187        int num_vertexs = 4;
188        //Box box;
189        Ogre::Vector3 min;
190        Ogre::Vector3 max;
191        float num, den;
192        bool type = true;
193
194        printf("\n\tCreant cluster 2d");
195        axisproj = cluster2d.Create2d (this, 0, true); 
196        printf("\n\t Imprimint el que hi al del cluster");
197               
198        //this->Print();
199        //printf("\n\t Imprimint el que hi ha del cluster2d");
200        //cluster2d.Print();
201               
202        //Vector3 *v = GetVector3s();
203        //vertexs2d = cluster2d.GetVector3s();
204        std::vector<Ogre::Vector2> vector2;
205        vector2 =*cluster2d.GetVector3sVector();
206       
207               
208        // Gametools -- Isma 17/08/2005
209        //if (ObscuranceRayTracing::Config::Debug)
210        //{
211        //      this->Print();
212        //      //poly2d->Print();
213        //      cluster2d.Print();
214        //}
215               
216       
217        bound = new BBox;
218        for (unsigned int i = 0; i < vector2.size(); i++)
219        {               
220                bound->AddBoundingVector3 (vector2[i].x, vector2[i].y, 0);             
221        }
222       
223        min = bound->GetMinimum();     
224        max = bound->GetMaximum();
225        //if (ObscuranceRayTracing::Config::Debug)
226        {
227                printf("\nCaixa Englobant del cluster 2d\n");
228                bound->Print();
229        }
230        //-----
231
232        // Gametools -- Isma 17/08/2005
233        //if (ObscuranceRayTracing::Config::Debug)
234        //      printf("\nAxisproject: %d\n", axisproj);
235       
236        // Gametools -- Isma 17/08/2005
237        //vertexs_triangle_text = new Vector3[num_vertexs];
238       
239       
240        Ogre::Vector3 aux (-9999,-9999,-9999);
241        //reconstruim a 3d el polygon englobant del polygon original a partir del pla
242       
243        printf("\nAxisproj: %d", axisproj);
244        // Gametools -- Isma 17/08/2005
245        /*
246        switch(axisproj)
247        {
248                case 0:
249
250                        {
251
252                                vertexs_triangle_text[0].z = min.x;
253                                vertexs_triangle_text[0].y = min.y;
254                                vertexs_triangle_text[0].x = - (normal.y * min.y + normal.z * min.x + distance) / normal.x;
255                               
256                                vertexs_triangle_text[1].z = max.x;
257                                vertexs_triangle_text[1].y = min.y;
258                                vertexs_triangle_text[1].x = - (normal.y * min.y + normal.z * max.x + distance) / normal.x;
259                               
260                                vertexs_triangle_text[2].z = min.x;
261                                vertexs_triangle_text[2].y = max.y;
262                                vertexs_triangle_text[2].x = - (normal.y * max.y + normal.z * min.x + distance) / normal.x;
263
264                                vertexs_triangle_text[3].z = max.x;
265                                vertexs_triangle_text[3].y = max.y;
266                                vertexs_triangle_text[3].x = - (normal.y * max.y + normal.z * max.x + distance) / normal.x;
267                       
268                        }
269                        break;
270                case 1:
271                        {
272                               
273                               
274                                vertexs_triangle_text[0].x = min.x;
275                                vertexs_triangle_text[0].z = min.y;
276                                vertexs_triangle_text[0].y = - (normal.x * min.x + normal.z * min.y + distance) / normal.y;
277                               
278                                vertexs_triangle_text[1].x = max.x;
279                                vertexs_triangle_text[1].z = min.y;
280                                vertexs_triangle_text[1].y = - (normal.x * max.x + normal.z * min.y + distance) / normal.y;
281                                               
282                                vertexs_triangle_text[3].x = max.x;
283                                vertexs_triangle_text[3].z = max.y;
284                                vertexs_triangle_text[3].y = - (normal.x * max.x + normal.z * max.y + distance) / normal.y;
285
286                                vertexs_triangle_text[2].x = min.x;
287                                vertexs_triangle_text[2].z = max.y;
288                                vertexs_triangle_text[2].y = - (normal.x * min.x + normal.z * max.y + distance) / normal.y;
289                               
290
291                               
292                        }
293                        break;
294                case 2:
295
296                        {                               
297                               
298                                vertexs_triangle_text[0].x = min.x;
299                                vertexs_triangle_text[0].y = min.y;
300                                vertexs_triangle_text[0].z = - (normal.x * min.x + normal.y * min.y + distance) / normal.z;
301                               
302                                vertexs_triangle_text[1].x = max.x;
303                                vertexs_triangle_text[1].y = min.y;
304                                vertexs_triangle_text[1].z = - (normal.x * max.x + normal.y * min.y + distance) / normal.z;
305                               
306                                vertexs_triangle_text[3].x = max.x;
307                                vertexs_triangle_text[3].y = max.y;
308                                vertexs_triangle_text[3].z = - (normal.x * max.x + normal.y * max.y + distance) / normal.z;
309                               
310                                vertexs_triangle_text[2].x = min.x;
311                                vertexs_triangle_text[2].y = max.y;
312                                vertexs_triangle_text[2].z =  -(normal.x * min.x + normal.y * max.y + distance) / normal.z;
313                        }
314                        break; 
315        }
316        */
317       
318        //triangle2d_text = new Cluster2d;
319        //triangle2d_text->Create2d (this, 1, true);
320       
321        Ogre::Vector3 v01_, v10_;
322       
323        printf("\nvertexs del cluster \n");
324
325        // Gametools -- Isma 17/08/2005
326        //for (int i = 0; i< 4; i++)
327        //      printf("%d - (%.4f, %.4f, %.4f)\n", i, vertexs_triangle_text[i].x, vertexs_triangle_text[i].y, vertexs_triangle_text[i].z);
328               
329        // Gametools -- Isma 17/08/2005
330        //v01_ = vertexs_triangle_text[1] - vertexs_triangle_text[0];
331        //v10_ = vertexs_triangle_text[2] - vertexs_triangle_text[0];
332       
333        // Gametools -- Isma 17/08/2005
334        //lumel_origin = vertexs_triangle_text[0];
335        //lumel_x_axis = Vector3 (v01_.x / ObscuranceRayTracing::Config::MapHeight , v01_.y / ObscuranceRayTracing::Config::MapHeight, v01_.z / ObscuranceRayTracing::Config::MapHeight);
336        //lumel_y_axis = Vector3 (v10_.x / ObscuranceRayTracing::Config::MapWidth, v10_.y / ObscuranceRayTracing::Config::MapWidth, v10_.z / ObscuranceRayTracing::Config::MapWidth);
337       
338        // Gametools -- Isma 17/08/2005
339        //if (ObscuranceRayTracing::Config::Debug)
340        //{
341        //      printf("Increment cada cop: (%.4f, %.4f, %.4f)\n", lumel_origin.x, lumel_origin.y, lumel_origin.z);                     
342        //      printf("Increment cada cop:  (%.4f, %.4f, %.4f)\n", lumel_x_axis.x, lumel_x_axis.y, lumel_x_axis.z);   
343        //      printf("Increment cada cop:  (%.4f, %.4f, %.4f)\n", lumel_y_axis.x, lumel_y_axis.y, lumel_y_axis.z);   
344        //}
345        /*
346
347        Vector3 finalx, finaly, final;
348         
349        finalx.x = lumel_origin.x + lumel_x_axis.x * ObscuranceRayTracing::Config::MapWidth;
350        finalx.y = lumel_origin.y + lumel_x_axis.y * ObscuranceRayTracing::Config::MapWidth;
351        finalx.z = lumel_origin.z + lumel_x_axis.z * ObscuranceRayTracing::Config::MapWidth;
352         
353        finaly.x = lumel_origin.x + lumel_y_axis.x * ObscuranceRayTracing::Config::MapHeight;
354        finaly.y = lumel_origin.y + lumel_y_axis.y * ObscuranceRayTracing::Config::MapHeight;
355        finaly.z = lumel_origin.z + lumel_y_axis.z * ObscuranceRayTracing::Config::MapHeight;
356               
357        final.x = lumel_origin.x + lumel_x_axis.x * ObscuranceRayTracing::Config::MapWidth + lumel_y_axis.x * ObscuranceRayTracing::Config::MapHeight;
358        final.y = lumel_origin.y + lumel_x_axis.y * ObscuranceRayTracing::Config::MapWidth + lumel_y_axis.y * ObscuranceRayTracing::Config::MapHeight;
359        final.z = lumel_origin.z + lumel_x_axis.z * ObscuranceRayTracing::Config::MapWidth + lumel_y_axis.z * ObscuranceRayTracing::Config::MapHeight;
360       
361        vertexs = new Vector3s[4];
362        vertexs[0] = lumel_origin;
363        vertexs[1] = finalx;
364        vertexs[2] = finaly;
365        vertexs[3] = final;
366        */     
367        /*
368        switch (axisproj)
369        {
370                case 0:
371                        order = ORDER_6; break;
372                case 1:
373                        order = ORDER_2; break;
374                case 2:
375                        order = ORDER_0; break;
376        }
377        //order = 1;
378        if (ObscuranceRayTracing::Config::Debug) printf("\nOrder del triangle: %d", order);
379        */
380}
381
382//* Return the increment in U (lumel increment in x). For patchs calculation
383Ogre::Vector3 Cluster::GetIncU() {
384 
385        return lumel_x_axis;
386}
387
388//* Return the increment in V (lumel increment in x). For patchs calculation
389Ogre::Vector3 Cluster::GetIncV() {
390 
391        return lumel_y_axis;
392
393}
394
395//Vector3 GetOrigin() const { if (Inc) return Inc[0]; }
396
397//* Return the origin. For patchs calculation
398Ogre::Vector3 Cluster::GetOrigin() {
399 
400        return lumel_origin;
401       
402}
403
404//
405//      void CreateVector3s()
406//      {
407//             
408//              //Vector3s = new Vector3[4];
409//              //Vector3s_triangle_text = new Vector3[4];
410//      }
411//     
412bool Cluster::PointIn(Ogre::Vector3 & point) {
413       
414        register unsigned int i = 0;
415        //Polygon2d poly2d;
416        Ogre::Vector2 point2d;
417        Ogre::Vector2 * vertexs2d;
418        Ogre::Vector3 v1, vp;
419       
420        //printf("\ndins pointin cluster");
421       
422        // Gametools -- Isma 17/08/2005
423        //if (ObscuranceRayTracing::Config::Debug) printf("\nPointin\n");
424       
425        //int axis = poly2d.CreatePoly2d (this);
426       
427        //poly2d.Print();
428        //poly2d->Print();
429       
430        // GametoolsError -- Isma 17/08/2005
431        //point2d = point2d.ProjectVector33d (point, axisproj);
432        //if (bound->intersects ( &Vector3 (point2d.x, point2d.y, 0))) return true;
433       
434        return false;
435        //point2d.Print();
436       
437        //if (poly2d_text) return poly2d_text->PointIn(point2d);
438        /*             
439        poly2d_text->Print();
440       
441       
442       
443        //vertexs2d = poly2d.GetVector3s();
444        //vertexs2d = poly2d->GetVector3s();
445        poly2d_text->GetVector3s();
446       
447        //checks if clockwise orientation
448        /**
449        v1 = vertexs[i+1] - vertexs[i];         
450        vp.x = point2d.x - vertexs[i].x;
451        vp.y = point2d.y - vertexs[i].y;
452       
453        if ((v1.x * vp.y - vp.x * v1.y) < 0)
454        **/
455        /*
456        for (; i < 3; i++)
457        {
458                v1.x = vertexs2d[i+1].x - vertexs2d[i].x;               
459                v1.y = vertexs2d[i+1].y - vertexs2d[i].y;               
460               
461                vp.x = point2d.x - vertexs2d[i].x;
462                vp.y = point2d.y - vertexs2d[i].y;
463                v1.Print();
464                vp.Print();
465                printf("\nValor del determinant: %f", (v1.x * vp.y - vp.x * v1.y));
466                if ((v1.x * vp.y - vp.x * v1.y) > 0) return false;
467               
468        }
469        printf("\nEl punt està dins\n");
470       
471        return true;*/
472}
473
474unsigned int Cluster::ID_CLUSTER = 0;
475
476// Gametools -- Isma 17/08/2005
477//Listid patchlistid;
478//Listid trianglelistid;
479int Cluster::CalcPatch(Ogre::Vector3 & point) {
480        return 0;
481}
482
483Cluster::~Cluster() {
484}
485
486
487}
Note: See TracBrowser for help on using the repository browser.