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

Revision 721, 4.4 KB checked in by igarcia, 19 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
50        std::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        Ogre::Vector2 *vertexs2d;
155        int num_vertexs = 4;
156        //Box box;
157        Ogre::Vector3 min;
158        Ogre::Vector3 max;
159        float num, den;
160        bool type = true;
161
162        Ogre::LogManager::getSingleton().logMessage("\tCreant cluster 2d");
163        axisproj = cluster2d.Create2d (this, 0, true); 
164        Ogre::LogManager::getSingleton().logMessage("\t Imprimint el que hi al del cluster");
165               
166        std::vector<Ogre::Vector2> vector2;
167        vector2 =*cluster2d.GetVector3sVector();
168       
169        for (unsigned int i = 0; i < vector2.size(); i++)
170        {               
171                bound.AddBoundingVector3 (vector2[i].x, vector2[i].y, 0);               
172        }
173       
174        min = bound.GetMinimum();       
175        max = bound.GetMaximum();
176       
177        Ogre::LogManager::getSingleton().logMessage("Caixa Englobant del cluster 2d");
178        bound.Print();
179
180        Ogre::Vector3 aux (-9999,-9999,-9999);
181
182        Ogre::LogManager::getSingleton().logMessage("Axisproj:" + Ogre::StringConverter::toString(axisproj));
183}
184
185//* Return the increment in U (lumel increment in x). For patchs calculation
186Ogre::Vector3 Cluster::GetIncU()
187{
188        return lumel_x_axis;
189}
190
191//* Return the increment in V (lumel increment in x). For patchs calculation
192Ogre::Vector3 Cluster::GetIncV()
193{
194        return lumel_y_axis;
195}
196
197Ogre::Vector3 Cluster::GetOrigin()
198{
199        return lumel_origin;
200}
201
202unsigned int Cluster::ID_CLUSTER = 0;
203
204}
Note: See TracBrowser for help on using the repository browser.