- Timestamp:
- 03/31/06 17:29:32 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/IMGCluster.cpp
r699 r721 1 1 2 #include "IMGCluster.h"3 #include "IMGCluster2d.h"2 #include <IMGCluster.h> 3 #include <IMGCluster2d.h> 4 4 5 5 namespace IMG { … … 7 7 Cluster::Cluster(){ 8 8 id = Cluster::ID_CLUSTER++; 9 bound = new BBox; 10 bspnodebound = NULL; 11 //CreateVector3s(); 12 } 13 14 Cluster & 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; 9 } 10 11 Cluster::~Cluster() 12 { 13 } 14 15 void Cluster::SetNormal(Ogre::Vector3* n) 16 { 17 normal = *n; 18 } 19 20 Ogre::Vector3* Cluster::GetNormal() 21 { 22 return &normal; 23 } 24 25 BBox* Cluster::GetBound() 26 { 27 return &bound; 28 } 29 30 Box2d* Cluster::GetBspNodeBound() 31 { 32 return &bspnodebound; 33 } 34 35 void Cluster::SetBspNodeBound(Box2d* box) 36 { 37 bspnodebound = (*box); 38 } 39 40 int Cluster::GetId() const 41 { 42 return id; 43 } 44 45 void Cluster::SetId(int id_) 46 { 47 id = id; 48 } 49 50 std::vector<Ogre::Vector3>* Cluster::GetVector3sVector() 51 { 52 return &Vector3s_vector; 53 } 54 55 Ogre::Vector3* Cluster::GetVector3sTex() const 56 { 57 return Vector3s_triangle_text; 58 } 59 60 void 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 67 Plane3 * Cluster::GetPlane() 68 { 69 return &plane; 70 } 71 72 Cluster & Cluster::operator =(const Cluster & p) 73 { 20 74 uv = p.uv; 21 75 id = p.id; 22 76 23 //get the lumel_origin becaus if get Inc[0] the value is not correct 24 77 //get the lumel_origin becaus if get Inc[0] the value is not correct 25 78 lumel_origin = p.lumel_origin; 26 79 lumel_x_axis = p.lumel_x_axis; 27 80 lumel_y_axis = p.lumel_y_axis; 28 29 //patchlistid = p.patchlistid; 30 //plane = p.plane; 31 81 32 82 axisproj = p.axisproj; 33 83 order = p.order; … … 39 89 } 40 90 41 Cluster::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()); 91 Cluster::Cluster(const Cluster & p) 92 { 49 93 uv = p.uv; 50 94 id = p.id; … … 55 99 lumel_x_axis = p.lumel_x_axis; 56 100 lumel_y_axis = p.lumel_y_axis; 57 58 //patchlistid = p.patchlistid;59 //plane = p.plane;60 101 61 102 axisproj = p.axisproj; … … 65 106 normal = p.normal; 66 107 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 101 void 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); 108 } 109 110 void 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 105 114 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 */ 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: "); 147 124 } 148 125 … … 152 129 Ogre::Vector3 *normal = plane.GetNormal(); 153 130 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 //} 178 void Cluster::Finish() { 179 printf("\nCluster::Finish()"); 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 145 void Cluster::Finish() 146 { 147 Ogre::LogManager::getSingleton().logMessage("\nCluster::Finish()"); 180 148 Plane3 *plane = GetPlane(); 181 149 Ogre::Vector3 normal = *plane->GetNormal(); … … 192 160 bool type = true; 193 161 194 printf("\n\tCreant cluster 2d");162 Ogre::LogManager::getSingleton().logMessage("\tCreant cluster 2d"); 195 163 axisproj = cluster2d.Create2d (this, 0, true); 196 printf("\n\t Imprimint el que hi al del cluster");164 Ogre::LogManager::getSingleton().logMessage("\t Imprimint el que hi al del cluster"); 197 165 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 166 std::vector<Ogre::Vector2> vector2; 205 167 vector2 =*cluster2d.GetVector3sVector(); 206 168 207 208 // Gametools -- Isma 17/08/2005209 //if (ObscuranceRayTracing::Config::Debug)210 //{211 // this->Print();212 // //poly2d->Print();213 // cluster2d.Print();214 //}215 216 217 bound = new BBox;218 169 for (unsigned int i = 0; i < vector2.size(); i++) 219 170 { 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 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 240 180 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 */ 181 182 Ogre::LogManager::getSingleton().logMessage("Axisproj:" + Ogre::StringConverter::toString(axisproj)); 380 183 } 381 184 382 185 //* Return the increment in U (lumel increment in x). For patchs calculation 383 Ogre::Vector3 Cluster::GetIncU() {384 186 Ogre::Vector3 Cluster::GetIncU() 187 { 385 188 return lumel_x_axis; 386 189 } 387 190 388 191 //* Return the increment in V (lumel increment in x). For patchs calculation 389 Ogre::Vector3 Cluster::GetIncV() {390 192 Ogre::Vector3 Cluster::GetIncV() 193 { 391 194 return lumel_y_axis; 392 393 } 394 395 //Vector3 GetOrigin() const { if (Inc) return Inc[0]; } 396 397 //* Return the origin. For patchs calculation 398 Ogre::Vector3 Cluster::GetOrigin() { 399 195 } 196 197 Ogre::Vector3 Cluster::GetOrigin() 198 { 400 199 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 //412 bool 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/2005423 //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/2005431 //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 orientation448 /**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 200 } 473 201 474 202 unsigned int Cluster::ID_CLUSTER = 0; 475 203 476 // Gametools -- Isma 17/08/2005 477 //Listid patchlistid; 478 //Listid trianglelistid; 479 int Cluster::CalcPatch(Ogre::Vector3 & point) { 480 return 0; 481 } 482 483 Cluster::~Cluster() { 484 } 485 486 487 } 204 }
Note: See TracChangeset
for help on using the changeset viewer.