#include "IMGCluster.h" #include "IMGCluster2d.h" namespace IMG { Cluster::Cluster(){ id = Cluster::ID_CLUSTER++; bound = new BBox; bspnodebound = NULL; //CreateVector3s(); } Cluster & Cluster::operator =(const Cluster & p) { // printf("\nConstructor d'assignació de cluster"); // GametoolsError -- Isma 17/08/2005 //vertexs = p.vertexs; //vertexs_vector = p.vertexs_vector; //vertexs_triangle_text = p.vertexs_triangle_text; uv = p.uv; id = p.id; //get the lumel_origin becaus if get Inc[0] the value is not correct lumel_origin = p.lumel_origin; lumel_x_axis = p.lumel_x_axis; lumel_y_axis = p.lumel_y_axis; //patchlistid = p.patchlistid; //plane = p.plane; axisproj = p.axisproj; order = p.order; triangle2d_text = p.triangle2d_text; bound = p.bound; normal = p.normal; bspnodebound = p.bspnodebound; return *this; } Cluster::Cluster(const Cluster & p){ ///printf("\nConstructor per copia de cluster"); // GametoolsError -- Isma 17/08/2005 //vertexs = p.vertexs; //vertexs_triangle_text = p.vertexs_triangle_text; //vertexs_vector = p.vertexs_vector; //printf("\nnombre de vertexs origens: %d", p.vertexs_vector.size()); //printf("\nnombre de vertexs copiats: %d", vertexs_vector.size()); uv = p.uv; id = p.id; //get the lumel_origin becaus if get Inc[0] the value is not correct lumel_origin = p.lumel_origin; lumel_x_axis = p.lumel_x_axis; lumel_y_axis = p.lumel_y_axis; //patchlistid = p.patchlistid; //plane = p.plane; axisproj = p.axisproj; order = p.order; triangle2d_text = p.triangle2d_text; bound = p.bound; normal = p.normal; bspnodebound = p.bspnodebound; //trianglelistid = p.trianglelistid; } // Gametools -- Isma 17/08/2005 //void Cluster::Insert (Triangle *t) //{ // int axis = t->AxisProjected(); // // //printf("\nAxis: %d", axis); // //t->Print(); // Vector3 *v = t->GetVector3s(); // //std::vector v = *t->GetVector3sVector(); // // for (int i = 0; i < 3; i++) // { // //printf("\ntriangle a transformar : (%.4f, %.4f, %.4f)", v[i].x, v[i].y, v[i].z); // // vertexs_vector.push_back (v[i]); // //bound->AddBoundingVector3 (v[i].x, v[i].y, v[i].z); // /* // switch (axis) // { // case 0: bound->AddBoundingVector3 (v[i].z, v[i].y, 0);break; // case 1: bound->AddBoundingVector3 (v[i].x, v[i].z, 0);break; // case 2: bound->AddBoundingVector3 (v[i].x, v[i].y, 0);break; // } // */ // } // // plane = *t->GetPlane(); //} void Cluster::Print() { printf("\n\nCluster: %d, axisproj: %d, order: %d", id, axisproj, order); //Vector3 *normal = plane.GetNormal(); //printf("\nPlane: (%.4f, %.4f, %.4f)", normal->x, normal->y, normal->z); plane.Print(); printf("\nOrigin (%.4f, %.4f, %.4f) \n", lumel_origin.x, lumel_origin.y, lumel_origin.z); //printf("Inc U (%.4f, %.4f, %.4f) \n", Inc[1].x, Inc[1].y, Inc[1].z); printf("Inc U (%.4f, %.4f, %.4f) \n", lumel_x_axis.x, lumel_x_axis.y, lumel_x_axis.z); printf("Inc V (%.4f, %.4f, %.4f) ", lumel_y_axis.x, lumel_y_axis.y, lumel_y_axis.z); if (bound) bound->Print(); if (bspnodebound) bspnodebound->Print(); /* printf("\nIndex de triangles del cluster: %d -->", trianglelistid.GetSize()); for (register int i = 0; i < trianglelistid.GetSize(); i++) { printf(" %d", trianglelistid.Get(i)); } */ printf("Printant els vertexs: "); //for (int i = 0; i < 4; i++) // printf("\nVector3s %d del cluster: (%.4f, %.4f, %.4f)", i, vertexs[i].x, vertexs[i].y, vertexs[i].z); // Gametools -- Isma 17/08/2005 //for (int i = 0; i < vertexs_vector.size(); i++) // printf("\nVector3s %d del cluster: (%.4f, %.4f, %.4f)", i, vertexs_vector[i].x, vertexs_vector[i].y, vertexs_vector[i].z); //printf("\nVector3s del cluster: "); //for (int i = 0; i < 4; i++) //{ // printf("\nVector3s %d: (%.4f, %.4f, %.4f)", i, vertexs_triangle_text[i].x, vertexs_triangle_text[i].y, vertexs_triangle_text[i].z); //} /* printf("\nCoordenades de texture dels vertes: %d -->", vertexs_vector.size()); for (int i = 0 ; i < vertexs_vector.size(); i++) { Vector3 vec= vertexs_triangle_text[i]; printf(" (%.4f, %.4f)", vec.x, vec.y); } */ } //* return the dominant normal axis, for calculate the 2d projection int Cluster::AxisProjected() { Ogre::Vector3 *normal = plane.GetNormal(); if (Ogre::Math::Abs(normal->x) >= Ogre::Math::Abs(normal->y) && Ogre::Math::Abs(normal->x) >= Ogre::Math::Abs(normal->z)) return (0); if (Ogre::Math::Abs(normal->y) >= Ogre::Math::Abs(normal->x) && Ogre::Math::Abs(normal->y) >= Ogre::Math::Abs(normal->z)) return (1); else return (2); } // Gametools -- Isma 17/08/2005 //bool CreatePatches(bool dinamic = false); // Gametools -- Isma 17/08/2005 //Listid *GetPatchList() { return &patchlistid;} //Listid *GetTriangleList(){ return &trianglelistid; } // Gametools -- Isma 17/08/2005 //int GetIdPatch (unsigned int i) //{ // if (i > patchlistid.GetSize()) return -1; // // return patchlistid.Get(i); //} // Gametools -- Isma 17/08/2005 //int GetIdTriangle (unsigned int i) //{ // if (i > trianglelistid.GetSize()) return -1; // // return trianglelistid.Get(i); //} void Cluster::Finish() { printf("\nCluster::Finish()"); Plane3 *plane = GetPlane(); Ogre::Vector3 normal = *plane->GetNormal(); float distance = plane->GetDistance(); Ogre::Vector3 corner; Cluster2d cluster2d; Ogre::Vector3 vertexfinal[3]; Ogre::Vector2 *vertexs2d; int num_vertexs = 4; //Box box; Ogre::Vector3 min; Ogre::Vector3 max; float num, den; bool type = true; printf("\n\tCreant cluster 2d"); axisproj = cluster2d.Create2d (this, 0, true); printf("\n\t Imprimint el que hi al del cluster"); //this->Print(); //printf("\n\t Imprimint el que hi ha del cluster2d"); //cluster2d.Print(); //Vector3 *v = GetVector3s(); //vertexs2d = cluster2d.GetVector3s(); std::vector vector2; vector2 =*cluster2d.GetVector3sVector(); // Gametools -- Isma 17/08/2005 //if (ObscuranceRayTracing::Config::Debug) //{ // this->Print(); // //poly2d->Print(); // cluster2d.Print(); //} bound = new BBox; for (unsigned int i = 0; i < vector2.size(); i++) { bound->AddBoundingVector3 (vector2[i].x, vector2[i].y, 0); } min = bound->GetMinimum(); max = bound->GetMaximum(); //if (ObscuranceRayTracing::Config::Debug) { printf("\nCaixa Englobant del cluster 2d\n"); bound->Print(); } //----- // Gametools -- Isma 17/08/2005 //if (ObscuranceRayTracing::Config::Debug) // printf("\nAxisproject: %d\n", axisproj); // Gametools -- Isma 17/08/2005 //vertexs_triangle_text = new Vector3[num_vertexs]; Ogre::Vector3 aux (-9999,-9999,-9999); //reconstruim a 3d el polygon englobant del polygon original a partir del pla printf("\nAxisproj: %d", axisproj); // Gametools -- Isma 17/08/2005 /* switch(axisproj) { case 0: { vertexs_triangle_text[0].z = min.x; vertexs_triangle_text[0].y = min.y; vertexs_triangle_text[0].x = - (normal.y * min.y + normal.z * min.x + distance) / normal.x; vertexs_triangle_text[1].z = max.x; vertexs_triangle_text[1].y = min.y; vertexs_triangle_text[1].x = - (normal.y * min.y + normal.z * max.x + distance) / normal.x; vertexs_triangle_text[2].z = min.x; vertexs_triangle_text[2].y = max.y; vertexs_triangle_text[2].x = - (normal.y * max.y + normal.z * min.x + distance) / normal.x; vertexs_triangle_text[3].z = max.x; vertexs_triangle_text[3].y = max.y; vertexs_triangle_text[3].x = - (normal.y * max.y + normal.z * max.x + distance) / normal.x; } break; case 1: { vertexs_triangle_text[0].x = min.x; vertexs_triangle_text[0].z = min.y; vertexs_triangle_text[0].y = - (normal.x * min.x + normal.z * min.y + distance) / normal.y; vertexs_triangle_text[1].x = max.x; vertexs_triangle_text[1].z = min.y; vertexs_triangle_text[1].y = - (normal.x * max.x + normal.z * min.y + distance) / normal.y; vertexs_triangle_text[3].x = max.x; vertexs_triangle_text[3].z = max.y; vertexs_triangle_text[3].y = - (normal.x * max.x + normal.z * max.y + distance) / normal.y; vertexs_triangle_text[2].x = min.x; vertexs_triangle_text[2].z = max.y; vertexs_triangle_text[2].y = - (normal.x * min.x + normal.z * max.y + distance) / normal.y; } break; case 2: { vertexs_triangle_text[0].x = min.x; vertexs_triangle_text[0].y = min.y; vertexs_triangle_text[0].z = - (normal.x * min.x + normal.y * min.y + distance) / normal.z; vertexs_triangle_text[1].x = max.x; vertexs_triangle_text[1].y = min.y; vertexs_triangle_text[1].z = - (normal.x * max.x + normal.y * min.y + distance) / normal.z; vertexs_triangle_text[3].x = max.x; vertexs_triangle_text[3].y = max.y; vertexs_triangle_text[3].z = - (normal.x * max.x + normal.y * max.y + distance) / normal.z; vertexs_triangle_text[2].x = min.x; vertexs_triangle_text[2].y = max.y; vertexs_triangle_text[2].z = -(normal.x * min.x + normal.y * max.y + distance) / normal.z; } break; } */ //triangle2d_text = new Cluster2d; //triangle2d_text->Create2d (this, 1, true); Ogre::Vector3 v01_, v10_; printf("\nvertexs del cluster \n"); // Gametools -- Isma 17/08/2005 //for (int i = 0; i< 4; i++) // printf("%d - (%.4f, %.4f, %.4f)\n", i, vertexs_triangle_text[i].x, vertexs_triangle_text[i].y, vertexs_triangle_text[i].z); // Gametools -- Isma 17/08/2005 //v01_ = vertexs_triangle_text[1] - vertexs_triangle_text[0]; //v10_ = vertexs_triangle_text[2] - vertexs_triangle_text[0]; // Gametools -- Isma 17/08/2005 //lumel_origin = vertexs_triangle_text[0]; //lumel_x_axis = Vector3 (v01_.x / ObscuranceRayTracing::Config::MapHeight , v01_.y / ObscuranceRayTracing::Config::MapHeight, v01_.z / ObscuranceRayTracing::Config::MapHeight); //lumel_y_axis = Vector3 (v10_.x / ObscuranceRayTracing::Config::MapWidth, v10_.y / ObscuranceRayTracing::Config::MapWidth, v10_.z / ObscuranceRayTracing::Config::MapWidth); // Gametools -- Isma 17/08/2005 //if (ObscuranceRayTracing::Config::Debug) //{ // printf("Increment cada cop: (%.4f, %.4f, %.4f)\n", lumel_origin.x, lumel_origin.y, lumel_origin.z); // printf("Increment cada cop: (%.4f, %.4f, %.4f)\n", lumel_x_axis.x, lumel_x_axis.y, lumel_x_axis.z); // printf("Increment cada cop: (%.4f, %.4f, %.4f)\n", lumel_y_axis.x, lumel_y_axis.y, lumel_y_axis.z); //} /* Vector3 finalx, finaly, final; finalx.x = lumel_origin.x + lumel_x_axis.x * ObscuranceRayTracing::Config::MapWidth; finalx.y = lumel_origin.y + lumel_x_axis.y * ObscuranceRayTracing::Config::MapWidth; finalx.z = lumel_origin.z + lumel_x_axis.z * ObscuranceRayTracing::Config::MapWidth; finaly.x = lumel_origin.x + lumel_y_axis.x * ObscuranceRayTracing::Config::MapHeight; finaly.y = lumel_origin.y + lumel_y_axis.y * ObscuranceRayTracing::Config::MapHeight; finaly.z = lumel_origin.z + lumel_y_axis.z * ObscuranceRayTracing::Config::MapHeight; final.x = lumel_origin.x + lumel_x_axis.x * ObscuranceRayTracing::Config::MapWidth + lumel_y_axis.x * ObscuranceRayTracing::Config::MapHeight; final.y = lumel_origin.y + lumel_x_axis.y * ObscuranceRayTracing::Config::MapWidth + lumel_y_axis.y * ObscuranceRayTracing::Config::MapHeight; final.z = lumel_origin.z + lumel_x_axis.z * ObscuranceRayTracing::Config::MapWidth + lumel_y_axis.z * ObscuranceRayTracing::Config::MapHeight; vertexs = new Vector3s[4]; vertexs[0] = lumel_origin; vertexs[1] = finalx; vertexs[2] = finaly; vertexs[3] = final; */ /* switch (axisproj) { case 0: order = ORDER_6; break; case 1: order = ORDER_2; break; case 2: order = ORDER_0; break; } //order = 1; if (ObscuranceRayTracing::Config::Debug) printf("\nOrder del triangle: %d", order); */ } //* Return the increment in U (lumel increment in x). For patchs calculation Ogre::Vector3 Cluster::GetIncU() { return lumel_x_axis; } //* Return the increment in V (lumel increment in x). For patchs calculation Ogre::Vector3 Cluster::GetIncV() { return lumel_y_axis; } //Vector3 GetOrigin() const { if (Inc) return Inc[0]; } //* Return the origin. For patchs calculation Ogre::Vector3 Cluster::GetOrigin() { return lumel_origin; } // // void CreateVector3s() // { // // //Vector3s = new Vector3[4]; // //Vector3s_triangle_text = new Vector3[4]; // } // bool Cluster::PointIn(Ogre::Vector3 & point) { register unsigned int i = 0; //Polygon2d poly2d; Ogre::Vector2 point2d; Ogre::Vector2 * vertexs2d; Ogre::Vector3 v1, vp; //printf("\ndins pointin cluster"); // Gametools -- Isma 17/08/2005 //if (ObscuranceRayTracing::Config::Debug) printf("\nPointin\n"); //int axis = poly2d.CreatePoly2d (this); //poly2d.Print(); //poly2d->Print(); // GametoolsError -- Isma 17/08/2005 //point2d = point2d.ProjectVector33d (point, axisproj); //if (bound->intersects ( &Vector3 (point2d.x, point2d.y, 0))) return true; return false; //point2d.Print(); //if (poly2d_text) return poly2d_text->PointIn(point2d); /* poly2d_text->Print(); //vertexs2d = poly2d.GetVector3s(); //vertexs2d = poly2d->GetVector3s(); poly2d_text->GetVector3s(); //checks if clockwise orientation /** v1 = vertexs[i+1] - vertexs[i]; vp.x = point2d.x - vertexs[i].x; vp.y = point2d.y - vertexs[i].y; if ((v1.x * vp.y - vp.x * v1.y) < 0) **/ /* for (; i < 3; i++) { v1.x = vertexs2d[i+1].x - vertexs2d[i].x; v1.y = vertexs2d[i+1].y - vertexs2d[i].y; vp.x = point2d.x - vertexs2d[i].x; vp.y = point2d.y - vertexs2d[i].y; v1.Print(); vp.Print(); printf("\nValor del determinant: %f", (v1.x * vp.y - vp.x * v1.y)); if ((v1.x * vp.y - vp.x * v1.y) > 0) return false; } printf("\nEl punt està dins\n"); return true;*/ } unsigned int Cluster::ID_CLUSTER = 0; // Gametools -- Isma 17/08/2005 //Listid patchlistid; //Listid trianglelistid; int Cluster::CalcPatch(Ogre::Vector3 & point) { return 0; } Cluster::~Cluster() { } }