[699] | 1 | |
---|
[721] | 2 | #include <IMGCluster.h> |
---|
| 3 | #include <IMGCluster2d.h> |
---|
[699] | 4 | |
---|
| 5 | namespace IMG { |
---|
| 6 | |
---|
| 7 | Cluster::Cluster(){ |
---|
| 8 | id = Cluster::ID_CLUSTER++; |
---|
| 9 | } |
---|
| 10 | |
---|
[721] | 11 | Cluster::~Cluster() |
---|
| 12 | { |
---|
| 13 | } |
---|
| 14 | |
---|
[731] | 15 | void Cluster::setNormal(Ogre::Vector3* n) |
---|
[721] | 16 | { |
---|
| 17 | normal = *n; |
---|
| 18 | } |
---|
| 19 | |
---|
[731] | 20 | Ogre::Vector3* Cluster::getNormal() |
---|
[721] | 21 | { |
---|
| 22 | return &normal; |
---|
| 23 | } |
---|
| 24 | |
---|
[731] | 25 | BBox* Cluster::getBound() |
---|
[721] | 26 | { |
---|
| 27 | return &bound; |
---|
| 28 | } |
---|
| 29 | |
---|
[731] | 30 | Box2d* Cluster::getBspNodeBound() |
---|
[721] | 31 | { |
---|
| 32 | return &bspnodebound; |
---|
| 33 | } |
---|
| 34 | |
---|
[731] | 35 | void Cluster::setBspNodeBound(Box2d* box) |
---|
[721] | 36 | { |
---|
| 37 | bspnodebound = (*box); |
---|
| 38 | } |
---|
| 39 | |
---|
[731] | 40 | int Cluster::getId() const |
---|
[721] | 41 | { |
---|
| 42 | return id; |
---|
| 43 | } |
---|
| 44 | |
---|
[731] | 45 | void Cluster::setId(int id_) |
---|
[721] | 46 | { |
---|
| 47 | id = id; |
---|
| 48 | } |
---|
| 49 | |
---|
[731] | 50 | std::vector<Ogre::Vector3>* Cluster::getVector3sVector() |
---|
[721] | 51 | { |
---|
| 52 | return &Vector3s_vector; |
---|
| 53 | } |
---|
| 54 | |
---|
[731] | 55 | Ogre::Vector3* Cluster::getVector3sTex() const |
---|
[721] | 56 | { |
---|
| 57 | return Vector3s_triangle_text; |
---|
| 58 | } |
---|
| 59 | |
---|
[731] | 60 | void Cluster::setPlane(Ogre::Vector3* normal, Ogre::Vector3 * point) |
---|
[721] | 61 | { |
---|
| 62 | plane.normal = *normal; |
---|
| 63 | plane.normal = -plane.normal; |
---|
| 64 | plane.d = -normal->dotProduct (*point); |
---|
| 65 | } |
---|
| 66 | |
---|
[731] | 67 | Plane3 * Cluster::getPlane() |
---|
[721] | 68 | { |
---|
| 69 | return &plane; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | Cluster & Cluster::operator =(const Cluster & p) |
---|
| 73 | { |
---|
[699] | 74 | uv = p.uv; |
---|
| 75 | id = p.id; |
---|
| 76 | |
---|
[721] | 77 | //get the lumel_origin becaus if get Inc[0] the value is not correct |
---|
[699] | 78 | lumel_origin = p.lumel_origin; |
---|
| 79 | lumel_x_axis = p.lumel_x_axis; |
---|
| 80 | lumel_y_axis = p.lumel_y_axis; |
---|
[721] | 81 | |
---|
[699] | 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 | |
---|
[721] | 91 | Cluster::Cluster(const Cluster & p) |
---|
| 92 | { |
---|
[699] | 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 | |
---|
[731] | 110 | void Cluster::print() |
---|
[721] | 111 | { |
---|
[751] | 112 | //Ogre::LogManager::getSingleton().logMessage("\n\nCluster: " + Ogre::StringConverter::toString(id) + ", axisproj: " + Ogre::StringConverter::toString(axisproj) + ", order: " + Ogre::StringConverter::toString(order)); |
---|
[721] | 113 | |
---|
[731] | 114 | plane.print(); |
---|
[751] | 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) + ")"); |
---|
[699] | 118 | |
---|
[731] | 119 | bound.print(); |
---|
[699] | 120 | |
---|
[731] | 121 | bspnodebound.print(); |
---|
[699] | 122 | |
---|
[751] | 123 | //Ogre::LogManager::getSingleton().logMessage("Printant els vertexs: "); |
---|
[699] | 124 | } |
---|
| 125 | |
---|
| 126 | //* return the dominant normal axis, for calculate the 2d projection |
---|
[731] | 127 | int Cluster::axisProjected() |
---|
| 128 | { |
---|
| 129 | Ogre::Vector3 *normal = plane.getNormal(); |
---|
[699] | 130 | |
---|
[721] | 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 | } |
---|
[699] | 143 | } |
---|
| 144 | |
---|
[731] | 145 | void Cluster::finish() |
---|
[721] | 146 | { |
---|
[751] | 147 | //Ogre::LogManager::getSingleton().logMessage("\nCluster::Finish()"); |
---|
[731] | 148 | Plane3 *plane = getPlane(); |
---|
| 149 | Ogre::Vector3 normal = *plane->getNormal(); |
---|
| 150 | float distance = plane->getDistance(); |
---|
[699] | 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 | |
---|
[751] | 159 | //Ogre::LogManager::getSingleton().logMessage("\tCreant cluster 2d"); |
---|
[731] | 160 | axisproj = cluster2d.create2d (this, 0, true); |
---|
[751] | 161 | //Ogre::LogManager::getSingleton().logMessage("\t Imprimint el que hi al del cluster"); |
---|
[699] | 162 | |
---|
| 163 | std::vector<Ogre::Vector2> vector2; |
---|
[731] | 164 | vector2 =*cluster2d.getVector3sVector(); |
---|
[699] | 165 | |
---|
| 166 | for (unsigned int i = 0; i < vector2.size(); i++) |
---|
| 167 | { |
---|
[731] | 168 | bound.addBoundingVector3 (vector2[i].x, vector2[i].y, 0); |
---|
[699] | 169 | } |
---|
| 170 | |
---|
[731] | 171 | min = bound.getMinimum(); |
---|
| 172 | max = bound.getMaximum(); |
---|
[699] | 173 | |
---|
[751] | 174 | //Ogre::LogManager::getSingleton().logMessage("Caixa Englobant del cluster 2d"); |
---|
[731] | 175 | bound.print(); |
---|
[721] | 176 | |
---|
[699] | 177 | Ogre::Vector3 aux (-9999,-9999,-9999); |
---|
| 178 | |
---|
[751] | 179 | //Ogre::LogManager::getSingleton().logMessage("Axisproj:" + Ogre::StringConverter::toString(axisproj)); |
---|
[699] | 180 | } |
---|
| 181 | |
---|
| 182 | //* Return the increment in U (lumel increment in x). For patchs calculation |
---|
[731] | 183 | Ogre::Vector3 Cluster::getIncU() |
---|
[721] | 184 | { |
---|
[699] | 185 | return lumel_x_axis; |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | //* Return the increment in V (lumel increment in x). For patchs calculation |
---|
[731] | 189 | Ogre::Vector3 Cluster::getIncV() |
---|
[721] | 190 | { |
---|
[699] | 191 | return lumel_y_axis; |
---|
| 192 | } |
---|
| 193 | |
---|
[731] | 194 | Ogre::Vector3 Cluster::getOrigin() |
---|
[721] | 195 | { |
---|
[699] | 196 | return lumel_origin; |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | unsigned int Cluster::ID_CLUSTER = 0; |
---|
| 200 | |
---|
| 201 | } |
---|