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

Revision 731, 4.3 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}
10
11Cluster::~Cluster()
12{
13}
14
15void Cluster::setNormal(Ogre::Vector3* n)
16{
17        normal = *n;
18}
19
20Ogre::Vector3* Cluster::getNormal()
21{
22        return &normal;
23}
24
25BBox* Cluster::getBound()
26{
27        return &bound;
28}
29
30Box2d* Cluster::getBspNodeBound()
31{
32        return &bspnodebound;
33}
34
35void Cluster::setBspNodeBound(Box2d* box)
36{
37        bspnodebound = (*box);
38}
39
40int Cluster::getId() const
41{
42        return id;
43}
44
45void Cluster::setId(int id_)
46{
47        id = id;
48}
49
50std::vector<Ogre::Vector3>* Cluster::getVector3sVector()
51{
52        return &Vector3s_vector;
53}
54
55Ogre::Vector3* Cluster::getVector3sTex() const
56{
57        return Vector3s_triangle_text;
58}
59
60void Cluster::setPlane(Ogre::Vector3* normal, Ogre::Vector3 * point)
61{
62    plane.normal = *normal;
63    plane.normal = -plane.normal;
64    plane.d = -normal->dotProduct (*point);             
65}
66
67Plane3 * Cluster::getPlane()
68{
69        return &plane;
70}
71
72Cluster & Cluster::operator =(const Cluster & p)
73{
74        uv = p.uv;
75        id = p.id;
76
77        //get the lumel_origin becaus if get Inc[0] the value is not correct           
78        lumel_origin = p.lumel_origin;
79        lumel_x_axis = p.lumel_x_axis;
80        lumel_y_axis = p.lumel_y_axis;
81               
82        axisproj = p.axisproj;
83        order = p.order;
84        triangle2d_text = p.triangle2d_text;
85        bound = p.bound;
86        normal = p.normal;
87        bspnodebound = p.bspnodebound;
88        return *this;
89}
90
91Cluster::Cluster(const Cluster & p)
92{
93        uv = p.uv;
94        id = p.id;
95       
96        //get the lumel_origin becaus if get Inc[0] the value is not correct   
97       
98        lumel_origin = p.lumel_origin;
99        lumel_x_axis = p.lumel_x_axis;
100        lumel_y_axis = p.lumel_y_axis;
101       
102        axisproj = p.axisproj;
103        order = p.order;
104        triangle2d_text = p.triangle2d_text;
105        bound = p.bound;
106        normal = p.normal;
107        bspnodebound = p.bspnodebound;
108}
109
110void Cluster::print()
111{
112        Ogre::LogManager::getSingleton().logMessage("\n\nCluster: " + Ogre::StringConverter::toString(id) + ", axisproj: " + Ogre::StringConverter::toString(axisproj)  + ", order: " + Ogre::StringConverter::toString(order));
113       
114        plane.print();
115        Ogre::LogManager::getSingleton().logMessage("\nOrigin (" + Ogre::StringConverter::toString(lumel_origin) + ")");
116        Ogre::LogManager::getSingleton().logMessage("Inc U (" + Ogre::StringConverter::toString(lumel_x_axis) + ")");
117        Ogre::LogManager::getSingleton().logMessage("Inc V (" + Ogre::StringConverter::toString(lumel_y_axis.z) + ")");
118       
119        bound.print();
120
121        bspnodebound.print();
122       
123        Ogre::LogManager::getSingleton().logMessage("Printant els vertexs: ");
124}
125
126//* return the dominant normal axis, for calculate the 2d projection
127int Cluster::axisProjected()
128{
129        Ogre::Vector3 *normal = plane.getNormal();
130       
131        if (Ogre::Math::Abs(normal->x) >= Ogre::Math::Abs(normal->y) && Ogre::Math::Abs(normal->x) >= Ogre::Math::Abs(normal->z))
132        {
133                return (0);             
134        }
135        if (Ogre::Math::Abs(normal->y) >= Ogre::Math::Abs(normal->x) && Ogre::Math::Abs(normal->y) >= Ogre::Math::Abs(normal->z))
136        {
137                return (1);
138        }
139        else
140        {
141                return (2);
142        }
143}
144
145void Cluster::finish()
146{
147        Ogre::LogManager::getSingleton().logMessage("\nCluster::Finish()");
148        Plane3 *plane = getPlane();
149        Ogre::Vector3 normal = *plane->getNormal();
150        float distance = plane->getDistance();
151        Ogre::Vector3 corner;
152        Cluster2d cluster2d;           
153        Ogre::Vector3 vertexfinal[3];
154        int num_vertexs = 4;
155        Ogre::Vector3 min;
156        Ogre::Vector3 max;
157        bool type = true;
158
159        Ogre::LogManager::getSingleton().logMessage("\tCreant cluster 2d");
160        axisproj = cluster2d.create2d (this, 0, true); 
161        Ogre::LogManager::getSingleton().logMessage("\t Imprimint el que hi al del cluster");
162               
163        std::vector<Ogre::Vector2> vector2;
164        vector2 =*cluster2d.getVector3sVector();
165       
166        for (unsigned int i = 0; i < vector2.size(); i++)
167        {               
168                bound.addBoundingVector3 (vector2[i].x, vector2[i].y, 0);               
169        }
170       
171        min = bound.getMinimum();       
172        max = bound.getMaximum();
173       
174        Ogre::LogManager::getSingleton().logMessage("Caixa Englobant del cluster 2d");
175        bound.print();
176
177        Ogre::Vector3 aux (-9999,-9999,-9999);
178
179        Ogre::LogManager::getSingleton().logMessage("Axisproj:" + Ogre::StringConverter::toString(axisproj));
180}
181
182//* Return the increment in U (lumel increment in x). For patchs calculation
183Ogre::Vector3 Cluster::getIncU()
184{
185        return lumel_x_axis;
186}
187
188//* Return the increment in V (lumel increment in x). For patchs calculation
189Ogre::Vector3 Cluster::getIncV()
190{
191        return lumel_y_axis;
192}
193
194Ogre::Vector3 Cluster::getOrigin()
195{
196        return lumel_origin;
197}
198
199unsigned int Cluster::ID_CLUSTER = 0;
200
201}
Note: See TracBrowser for help on using the repository browser.