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

Revision 699, 2.6 KB checked in by igarcia, 18 years ago (diff)
Line 
1
2#include "IMGNodeBsp.h"
3
4namespace IMG {
5
6NodeBsp::NodeBsp(){
7        child[0] = NULL;
8        child[1] = NULL;
9        //bound.StartBoundingBox();
10        bound = NULL;
11        //id= NodeBsp::ID++;
12        id = -1;
13        fit = false;
14}
15
16Box2d * NodeBsp::GetBound() {
17 
18        return bound;   
19}
20
21void NodeBsp::Print() {
22        printf("\nNode : %d, fit: %d", id, fit);
23        if (bound) bound->Print();
24        //if (plane) plane->Print();
25}
26
27//void SetPlane (Plane3 *pla) { plane = pla; }
28//Plane3 * GetPlane () { return plane; }
29NodeBsp * NodeBsp::Insert(int w, int h) {
30        //printf("\nInsert del node: :%d (%d, %d)\n", id, w,  h);
31       
32        if (this->fit == true) return NULL;
33       
34        if (this->child[0] != NULL && this->child[1] != NULL)
35        {
36                NodeBsp * new_node = child[0]->Insert (w, h);
37               
38                if (new_node) return new_node;
39               
40                return child[1]->Insert(w,h);
41        }
42       
43        if (!bound->In (w,h)) {//printf("\nNo hi quep!!!\n");
44                                return NULL; }
45       
46        if (bound->FitPerfect(w,h)){ //printf("\nFit Perfectly: \n");
47                                fit = true;  return this; }
48       
49        child[0] = new NodeBsp;
50        child[1] = new NodeBsp;
51       
52        int dw, dh;
53        Ogre::Vector2 min, max;
54        float width, height;
55       
56        bound->Print();
57        min = bound->GetMinimum();
58        max = bound->GetMaximum();
59       
60        width = max.x - min.x;
61        height = max.y - min.y;
62       
63        //printf("\nwidth: %.4f\n", width);
64        //printf("\nheigth: %.4f\n", height);
65       
66        dw = (int) width - w;
67        dh = (int) height - h;
68       
69        //printf("\n Valor dw: %d\n", dw);
70        //printf("\n Valor dh: %d\n", dh);
71       
72        child[0]->bound = new Box2d;
73        child[1]->bound = new Box2d;
74       
75        if (dw > dh)
76        {       
77                /*
78                child[0]->bound->SetBoundBox(   min.x                   , max.y,
79                                                min.x + width - 1       , min.y);               
80                child[1]->bound->SetBoundBox(   min.x + width           , max.y,
81                                                max.x                   , min.y);                               
82                */
83                child[0]->bound->SetBoundBox(   min.x                   , min.y,
84                                                min.x + w               , max.y);               
85                                                //min.x + w - 1         , max.y);               
86                //child[1]->bound->SetBoundBox( min.x + w + 1           , min.y,
87                child[1]->bound->SetBoundBox(   min.x + w               , min.y,
88                                                max.x                   , max.y);                                                                               
89        }
90        else
91        {               
92                //child[0]->bound->SetBoundBox( min.x                   , max.y,
93                //                              max.x                   , max.y + height - 1);
94                child[0]->bound->SetBoundBox(   min.x                   , max.y - h ,
95                //child[0]->bound->SetBoundBox( min.x                   , max.y - h - 1 ,
96                                                max.x                   , max.y
97                                                );
98                                               
99                //child[1]->bound->SetBoundBox( min.x                   , max.y + height,
100                //                              max.x                   , min.y);
101                child[1]->bound->SetBoundBox(   min.x                   , min.y,
102                                                //max.x                 , max.y - h -1
103                                                max.x                   , max.y - h
104                                                );
105        }
106       
107        //printf("\nImprimint child[0]: \n");
108        //child[0]->Print();
109        //printf("\nImprimint child[1]: \n");
110        //child[1]->Print();
111       
112        return child[0]->Insert (w, h);
113}
114
115unsigned int NodeBsp::ID = 0;
116
117NodeBsp::~NodeBsp() {
118}
119
120
121}
Note: See TracBrowser for help on using the repository browser.