Voilà, pour mon besoin personnel, j'ai codé une classe qui renvoie un buffer contenant une sphere basé sur un icosaèdre.
Pour l'itération, il faut savoir qu'elle doit être entre 0 et 5 compris. L'itération 0 rend une sphère à 20 triangles et chaque itération multiplie par 4 le nombre de triangles pour arriver à 20480 pour une itération de 5.
Les buffers étant limités à 65536 vertices et les triangles étant tous séparés (3 vertices par triangles, pour des raisons de texturing et manipulations), il est impossible d'aller au-dessus de 5 itérations.
Maintenant, si quelqu'un à des suggestions d'améliorations, qu'il n'hésite pas! Je modifierais le code dès que possible.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | #ifndef SPHEREICOSA_H #define SPHEREICOSA_H #include "irrTypes.h" #include "vector3d.h" #include "aabbox3d.h" #include "CMeshBuffer.h" #include "SMaterial.h" class SphereIcosa { public: SphereIcosa(irr::video::SMaterial material, irr::f32 rayon=1, irr::u8 iterations=0); SphereIcosa(irr::f32 rayon=1, irr::u8 iterations=0); virtual ~SphereIcosa(); bool createNewSphere(irr::f32 rayon=1, irr::u8 iterations=0); irr::scene::SMeshBuffer* getBufferCopy(); irr::video::SMaterial& getMaterial(); void setMaterial(irr::video::SMaterial material); irr::core::aabbox3df& getBoundingBox(); protected: irr::f32 Rayon; irr::u8 NbIterations; irr::scene::SMeshBuffer* Buffer; irr::core::aabbox3df BoundingBox; void createBoundingBox(); private: }; #endif // SPHEREICOSA_H |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | #include "SphereIcosa.h" SphereIcosa::SphereIcosa(irr::video::SMaterial material, irr::f32 rayon, irr::u8 iterations) : Rayon(rayon), NbIterations(iterations) { /// initialisation du buffer Buffer = new irr::scene::SMeshBuffer(); Buffer->Material = material; /// créé la sphère createNewSphere(rayon, iterations); } SphereIcosa::SphereIcosa(irr::f32 rayon, irr::u8 iterations) : Rayon(rayon), NbIterations(iterations) { /// créé la sphère createNewSphere(rayon, iterations); } SphereIcosa::~SphereIcosa() { /// libère la mémoire if(Buffer) delete Buffer; } bool SphereIcosa::createNewSphere(irr::f32 rayon, irr::u8 iterations) { /// si le nb de vertex dépasse la limite on retourne if( iterations > 5 ) return false; /// array contenant les vertices irr::core::array<irr::core::vector3df> listevertex; /// calcul des termes de base irr::core::vector3df normalise(1, ((1+irr::core::squareroot(5.f))/2), 0); normalise.setLength(rayon); irr::f32 terme1 = normalise.X; irr::f32 terme2 = normalise.Y; /// calcul des 4 points du plan : XY listevertex.push_back( irr::core::vector3df(-terme1,-terme2,0) ); listevertex.push_back( irr::core::vector3df(-terme1,terme2,0) ); listevertex.push_back( irr::core::vector3df(terme1,terme2,0) ); listevertex.push_back( irr::core::vector3df(terme1,-terme2,0) ); /// calcul des 4 points du plan : YZ listevertex.push_back( irr::core::vector3df(0,-terme1,-terme2) ); listevertex.push_back( irr::core::vector3df(0,terme1,-terme2) ); listevertex.push_back( irr::core::vector3df(0,terme1,terme2) ); listevertex.push_back( irr::core::vector3df(0,-terme1,terme2) ); /// calcul des 4 points du plan : XZ listevertex.push_back( irr::core::vector3df(-terme2,0,-terme1) ); listevertex.push_back( irr::core::vector3df(-terme2,0,terme1) ); listevertex.push_back( irr::core::vector3df(terme2,0,terme1) ); listevertex.push_back( irr::core::vector3df(terme2,0,-terme1) ); /// mise dans le buffer dans la forme première Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[0], irr::core::vector3df(0), irr::video::SColor(255,000,255,000), irr::core::vector2df(0,0)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[3], irr::core::vector3df(0), irr::video::SColor(255,000,255,000), irr::core::vector2df(0,1)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[7], irr::core::vector3df(0), irr::video::SColor(255,000,255,000), irr::core::vector2df(0.5,0.5)) ); Buffer->Indices.push_back( 0 ); Buffer->Indices.push_back( 1 ); Buffer->Indices.push_back( 2 ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[3], irr::core::vector3df(0), irr::video::SColor(255,000,255,000), irr::core::vector2df(0,0)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[0], irr::core::vector3df(0), irr::video::SColor(255,000,255,000), irr::core::vector2df(0,1)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[4], irr::core::vector3df(0), irr::video::SColor(255,000,255,000), irr::core::vector2df(0.5,0.5)) ); Buffer->Indices.push_back( 3 ); Buffer->Indices.push_back( 4 ); Buffer->Indices.push_back( 5 ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[2], irr::core::vector3df(0), irr::video::SColor(255,000,255,000), irr::core::vector2df(0,0)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[1], irr::core::vector3df(0), irr::video::SColor(255,000,255,000), irr::core::vector2df(0,1)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[6], irr::core::vector3df(0), irr::video::SColor(255,000,255,000), irr::core::vector2df(0.5,0.5)) ); Buffer->Indices.push_back( 6 ); Buffer->Indices.push_back( 7 ); Buffer->Indices.push_back( 8 ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[1], irr::core::vector3df(0), irr::video::SColor(255,000,255,000), irr::core::vector2df(0,0)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[2], irr::core::vector3df(0), irr::video::SColor(255,000,255,000), irr::core::vector2df(0,1)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[5], irr::core::vector3df(0), irr::video::SColor(255,000,255,000), irr::core::vector2df(0.5,0.5)) ); Buffer->Indices.push_back( 9 ); Buffer->Indices.push_back( 10 ); Buffer->Indices.push_back( 11 ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[4], irr::core::vector3df(0), irr::video::SColor(255,000,000,255), irr::core::vector2df(0,0)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[5], irr::core::vector3df(0), irr::video::SColor(255,000,000,255), irr::core::vector2df(0,1)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[11], irr::core::vector3df(0), irr::video::SColor(255,000,000,255), irr::core::vector2df(0.5,0.5)) ); Buffer->Indices.push_back( 12 ); Buffer->Indices.push_back( 13 ); Buffer->Indices.push_back( 14 ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[5], irr::core::vector3df(0), irr::video::SColor(255,000,000,255), irr::core::vector2df(0,0)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[4], irr::core::vector3df(0), irr::video::SColor(255,000,000,255), irr::core::vector2df(0,1)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[8], irr::core::vector3df(0), irr::video::SColor(255,000,000,255), irr::core::vector2df(0.5,0.5)) ); Buffer->Indices.push_back( 15 ); Buffer->Indices.push_back( 16 ); Buffer->Indices.push_back( 17 ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[7], irr::core::vector3df(0), irr::video::SColor(255,000,000,255), irr::core::vector2df(0,0)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[6], irr::core::vector3df(0), irr::video::SColor(255,000,000,255), irr::core::vector2df(0,1)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[9], irr::core::vector3df(0), irr::video::SColor(255,000,000,255), irr::core::vector2df(0.5,0.5)) ); Buffer->Indices.push_back( 18 ); Buffer->Indices.push_back( 19 ); Buffer->Indices.push_back( 20 ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[6], irr::core::vector3df(0), irr::video::SColor(255,000,000,255), irr::core::vector2df(0,0)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[7], irr::core::vector3df(0), irr::video::SColor(255,000,000,255), irr::core::vector2df(0,1)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[10], irr::core::vector3df(0), irr::video::SColor(255,000,000,255), irr::core::vector2df(0.5,0.5)) ); Buffer->Indices.push_back( 21 ); Buffer->Indices.push_back( 22 ); Buffer->Indices.push_back( 23 ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[9], irr::core::vector3df(0), irr::video::SColor(255,255,000,000), irr::core::vector2df(0,0)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[8], irr::core::vector3df(0), irr::video::SColor(255,255,000,000), irr::core::vector2df(0,1)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[0], irr::core::vector3df(0), irr::video::SColor(255,255,000,000), irr::core::vector2df(0.5,0.5)) ); Buffer->Indices.push_back( 24 ); Buffer->Indices.push_back( 25 ); Buffer->Indices.push_back( 26 ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[8], irr::core::vector3df(0), irr::video::SColor(255,255,000,000), irr::core::vector2df(0,0)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[9], irr::core::vector3df(0), irr::video::SColor(255,255,000,000), irr::core::vector2df(0,1)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[1], irr::core::vector3df(0), irr::video::SColor(255,255,000,000), irr::core::vector2df(0.5,0.5)) ); Buffer->Indices.push_back( 27 ); Buffer->Indices.push_back( 28 ); Buffer->Indices.push_back( 29 ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[10], irr::core::vector3df(0), irr::video::SColor(255,255,000,000), irr::core::vector2df(0,0)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[11], irr::core::vector3df(0), irr::video::SColor(255,255,000,000), irr::core::vector2df(0,1)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[2], irr::core::vector3df(0), irr::video::SColor(255,255,000,000), irr::core::vector2df(0.5,0.5)) ); Buffer->Indices.push_back( 30 ); Buffer->Indices.push_back( 31 ); Buffer->Indices.push_back( 32 ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[11], irr::core::vector3df(0), irr::video::SColor(255,255,000,000), irr::core::vector2df(0,0)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[10], irr::core::vector3df(0), irr::video::SColor(255,255,000,000), irr::core::vector2df(0,1)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[3], irr::core::vector3df(0), irr::video::SColor(255,255,000,000), irr::core::vector2df(0.5,0.5)) ); Buffer->Indices.push_back( 33 ); Buffer->Indices.push_back( 34 ); Buffer->Indices.push_back( 35 ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[0], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0,0)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[8], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0,1)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[4], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0.5,0.5)) ); Buffer->Indices.push_back( 36 ); Buffer->Indices.push_back( 37 ); Buffer->Indices.push_back( 38 ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[0], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0,0)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[7], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0,1)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[9], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0.5,0.5)) ); Buffer->Indices.push_back( 39 ); Buffer->Indices.push_back( 40 ); Buffer->Indices.push_back( 41 ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[1], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0,0)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[5], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0,1)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[8], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0.5,0.5)) ); Buffer->Indices.push_back( 42 ); Buffer->Indices.push_back( 43 ); Buffer->Indices.push_back( 44 ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[1], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0,0)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[9], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0,1)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[6], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0.5,0.5)) ); Buffer->Indices.push_back( 45 ); Buffer->Indices.push_back( 46 ); Buffer->Indices.push_back( 47 ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[2], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0,0)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[6], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0,1)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[10], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0.5,0.5)) ); Buffer->Indices.push_back( 48 ); Buffer->Indices.push_back( 49 ); Buffer->Indices.push_back( 50 ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[2], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0,0)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[11], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0,1)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[5], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0.5,0.5)) ); Buffer->Indices.push_back( 51 ); Buffer->Indices.push_back( 52 ); Buffer->Indices.push_back( 53 ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[3], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0,0)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[10], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0,1)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[7], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0.5,0.5)) ); Buffer->Indices.push_back( 54 ); Buffer->Indices.push_back( 55 ); Buffer->Indices.push_back( 56 ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[3], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0,0)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[4], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0,1)) ); Buffer->Vertices.push_back( irr::video::S3DVertex( listevertex[11], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0.5,0.5)) ); Buffer->Indices.push_back( 57 ); Buffer->Indices.push_back( 58 ); Buffer->Indices.push_back( 59 ); for(irr::s32 nbIterations=0; nbIterations < iterations; ++nbIterations ) { /// variables irr::core::array<irr::video::S3DVertex> newVertices; irr::core::array<irr::u16> newIndices; /// créations des couleurs irr::video::SColor color1(255,255,000,000); irr::video::SColor color2(255,000,255,000); irr::video::SColor color3(255,000,000,255); irr::video::SColor color4(255,255,255,000); /// pour chaque triangles on en créé 4 nouveaux par subdivisions for(irr::s32 a=0; a < (irr::s32)Buffer->Indices.size(); a+=3) { /// on enregistre l'index irr::s32 index = (int)newVertices.size(); /// on enregistre les 3 points existant irr::core::vector3df A( Buffer->Vertices[Buffer->Indices[a]].Pos ); irr::core::vector3df B( Buffer->Vertices[Buffer->Indices[a+1]].Pos ); irr::core::vector3df C( Buffer->Vertices[Buffer->Indices[a+2]].Pos ); /// on calcule les 3 nouveaux points irr::core::vector3df D( irr::core::line3df(A, B).getMiddle().setLength(rayon) ); irr::core::vector3df E( irr::core::line3df(B, C).getMiddle().setLength(rayon) ); irr::core::vector3df F( irr::core::line3df(C, A).getMiddle().setLength(rayon) ); /// on insère les 4 nouveaux triangles /// ADF newVertices.push_back( irr::video::S3DVertex( A, irr::core::vector3df(0), color1, irr::core::vector2df(0,0)) ); newVertices.push_back( irr::video::S3DVertex( D, irr::core::vector3df(0), color1, irr::core::vector2df(0,1)) ); newVertices.push_back( irr::video::S3DVertex( F, irr::core::vector3df(0), color1, irr::core::vector2df(0.5,0.5)) ); newIndices.push_back( index ); newIndices.push_back( index+1 ); newIndices.push_back( index+2 ); /// DBE newVertices.push_back( irr::video::S3DVertex( D, irr::core::vector3df(0), color2, irr::core::vector2df(0,0)) ); newVertices.push_back( irr::video::S3DVertex( B, irr::core::vector3df(0), color2, irr::core::vector2df(0,1)) ); newVertices.push_back( irr::video::S3DVertex( E, irr::core::vector3df(0), color2, irr::core::vector2df(0.5,0.5)) ); newIndices.push_back( index+3 ); newIndices.push_back( index+4 ); newIndices.push_back( index+5 ); /// FDE newVertices.push_back( irr::video::S3DVertex( F, irr::core::vector3df(0), color3, irr::core::vector2df(0,0)) ); newVertices.push_back( irr::video::S3DVertex( D, irr::core::vector3df(0), color3, irr::core::vector2df(0,1)) ); newVertices.push_back( irr::video::S3DVertex( E, irr::core::vector3df(0), color3, irr::core::vector2df(0.5,0.5)) ); newIndices.push_back( index+6 ); newIndices.push_back( index+7 ); newIndices.push_back( index+8 ); /// FEC newVertices.push_back( irr::video::S3DVertex( F, irr::core::vector3df(0), color4, irr::core::vector2df(0,0)) ); newVertices.push_back( irr::video::S3DVertex( E, irr::core::vector3df(0), color4, irr::core::vector2df(0,1)) ); newVertices.push_back( irr::video::S3DVertex( C, irr::core::vector3df(0), color4, irr::core::vector2df(0.5,0.5)) ); newIndices.push_back( index+9 ); newIndices.push_back( index+10 ); newIndices.push_back( index+11 ); } Buffer->Vertices = newVertices; Buffer->Indices = newIndices; } /// on mets à jour les paramètres de création de la sphere Rayon = rayon; NbIterations = iterations; /// on met à jour la Bounding Box createBoundingBox(); /// tout s'est bien passé on quitte return true; } irr::scene::SMeshBuffer* SphereIcosa::getBufferCopy() { irr::scene::SMeshBuffer* tmp = new irr::scene::SMeshBuffer(); tmp->Material = Buffer->Material; tmp->Vertices = Buffer->Vertices; tmp->Indices = Buffer->Indices; return tmp; } irr::video::SMaterial& SphereIcosa::getMaterial() { return Buffer->Material; } void SphereIcosa::setMaterial(irr::video::SMaterial material) { Buffer->Material = material; } irr::core::aabbox3df& SphereIcosa::getBoundingBox() { return BoundingBox; } void SphereIcosa::createBoundingBox() { BoundingBox = irr::core::aabbox3df( irr::core::vector3df(-Rayon), irr::core::vector3df(Rayon) ); } |
1 2 3 4 5 6 | SMaterial blanc; blanc.Lighting = false; SphereIcosa sphere(blanc, 1000, 5); SMeshBuffer* SphereBuffer = sphere.getBufferCopy(); // à mettre entre beginscene et endscene Driver->drawMeshBuffer( SphereBuffer ); |
Hors ligne
Voici une autre classe qui elle utilise des index 32 bits. Ceux-ci ne sont pas compatibles avec toutes les cartes graphiques. Niveau perfs 245fps pour une itération 8 soit 1 311 000 triangles sur une GTX590 avec VBO activé.
Par contre pour ma part je ne dépasse pas l'itération 8 car la 9ème plante (environ 5 000 000 de triangles).
Ce n'est pas vraiment génant de ne pouvoir monter que jusqu'à 1 311 000 triagles.^^
// fichier : SphereIcosaUnlimited.h #ifndef SPHEREICOSAUNLIMITED_H #define SPHEREICOSAUNLIMITED_H #include "irrTypes.h" #include "vector3d.h" #include "aabbox3d.h" #include "CDynamicMeshBuffer.h" #include "SMaterial.h" class SphereIcosaUnlimited { public: SphereIcosaUnlimited(irr::video::SMaterial material, irr::f32 rayon=1, irr::u16 iterations=0); SphereIcosaUnlimited(irr::f32 rayon=1, irr::u16 iterations=0); virtual ~SphereIcosaUnlimited(); bool createNewSphere(irr::f32 rayon=1, irr::u16 iterations=0); irr::scene::CDynamicMeshBuffer* getBuffer(); irr::video::SMaterial& getMaterial(); void setMaterial(irr::video::SMaterial material); irr::core::aabbox3df& getBoundingBox(); void setUseVBO(irr::scene::E_HARDWARE_MAPPING vbo=irr::scene::EHM_NEVER); protected: irr::f32 Rayon; irr::u8 NbIterations; irr::scene::CDynamicMeshBuffer* Buffer; irr::core::aabbox3df BoundingBox; void createBoundingBox(); private: }; #endif // SPHEREICOSAUNLIMITED_H
// fichier SphereIcosaUnlimited.cpp #include "SphereIcosaUnlimited.h" SphereIcosaUnlimited::SphereIcosaUnlimited(irr::video::SMaterial material, irr::f32 rayon, irr::u16 iterations) : Rayon(rayon), NbIterations(iterations) { /// initialisation du buffer Buffer = new irr::scene::CDynamicMeshBuffer(irr::video::EVT_STANDARD, irr::video::EIT_32BIT); Buffer->Material = material; /// créé la sphère createNewSphere(rayon, iterations); } SphereIcosaUnlimited::SphereIcosaUnlimited(irr::f32 rayon, irr::u16 iterations) : Rayon(rayon), NbIterations(iterations) { /// créé la sphère createNewSphere(rayon, iterations); } SphereIcosaUnlimited::~SphereIcosaUnlimited() { /// libère la mémoire } bool SphereIcosaUnlimited::createNewSphere(irr::f32 rayon, irr::u16 iterations) { /// array contenant les vertices irr::core::array<irr::core::vector3df> listevertex; /// calcul des termes de base irr::core::vector3df normalise(1, ((1+irr::core::squareroot(5.f))/2), 0); normalise.setLength(rayon); irr::f32 terme1 = normalise.X; irr::f32 terme2 = normalise.Y; /// calcul des 4 points du plan : XY listevertex.push_back( irr::core::vector3df(-terme1,-terme2,0) ); listevertex.push_back( irr::core::vector3df(-terme1,terme2,0) ); listevertex.push_back( irr::core::vector3df(terme1,terme2,0) ); listevertex.push_back( irr::core::vector3df(terme1,-terme2,0) ); /// calcul des 4 points du plan : YZ listevertex.push_back( irr::core::vector3df(0,-terme1,-terme2) ); listevertex.push_back( irr::core::vector3df(0,terme1,-terme2) ); listevertex.push_back( irr::core::vector3df(0,terme1,terme2) ); listevertex.push_back( irr::core::vector3df(0,-terme1,terme2) ); /// calcul des 4 points du plan : XZ listevertex.push_back( irr::core::vector3df(-terme2,0,-terme1) ); listevertex.push_back( irr::core::vector3df(-terme2,0,terme1) ); listevertex.push_back( irr::core::vector3df(terme2,0,terme1) ); listevertex.push_back( irr::core::vector3df(terme2,0,-terme1) ); /// mise dans le buffer dans la forme première Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[0], irr::core::vector3df(0), irr::video::SColor(255,000,255,000), irr::core::vector2df(0,0)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[3], irr::core::vector3df(0), irr::video::SColor(255,000,255,000), irr::core::vector2df(0,1)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[7], irr::core::vector3df(0), irr::video::SColor(255,000,255,000), irr::core::vector2df(0.5,0.5)) ); Buffer->getIndexBuffer().push_back( 0 ); Buffer->getIndexBuffer().push_back( 1 ); Buffer->getIndexBuffer().push_back( 2 ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[3], irr::core::vector3df(0), irr::video::SColor(255,000,255,000), irr::core::vector2df(0,0)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[0], irr::core::vector3df(0), irr::video::SColor(255,000,255,000), irr::core::vector2df(0,1)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[4], irr::core::vector3df(0), irr::video::SColor(255,000,255,000), irr::core::vector2df(0.5,0.5)) ); Buffer->getIndexBuffer().push_back( 3 ); Buffer->getIndexBuffer().push_back( 4 ); Buffer->getIndexBuffer().push_back( 5 ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[2], irr::core::vector3df(0), irr::video::SColor(255,000,255,000), irr::core::vector2df(0,0)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[1], irr::core::vector3df(0), irr::video::SColor(255,000,255,000), irr::core::vector2df(0,1)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[6], irr::core::vector3df(0), irr::video::SColor(255,000,255,000), irr::core::vector2df(0.5,0.5)) ); Buffer->getIndexBuffer().push_back( 6 ); Buffer->getIndexBuffer().push_back( 7 ); Buffer->getIndexBuffer().push_back( 8 ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[1], irr::core::vector3df(0), irr::video::SColor(255,000,255,000), irr::core::vector2df(0,0)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[2], irr::core::vector3df(0), irr::video::SColor(255,000,255,000), irr::core::vector2df(0,1)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[5], irr::core::vector3df(0), irr::video::SColor(255,000,255,000), irr::core::vector2df(0.5,0.5)) ); Buffer->getIndexBuffer().push_back( 9 ); Buffer->getIndexBuffer().push_back( 10 ); Buffer->getIndexBuffer().push_back( 11 ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[4], irr::core::vector3df(0), irr::video::SColor(255,000,000,255), irr::core::vector2df(0,0)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[5], irr::core::vector3df(0), irr::video::SColor(255,000,000,255), irr::core::vector2df(0,1)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[11], irr::core::vector3df(0), irr::video::SColor(255,000,000,255), irr::core::vector2df(0.5,0.5)) ); Buffer->getIndexBuffer().push_back( 12 ); Buffer->getIndexBuffer().push_back( 13 ); Buffer->getIndexBuffer().push_back( 14 ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[5], irr::core::vector3df(0), irr::video::SColor(255,000,000,255), irr::core::vector2df(0,0)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[4], irr::core::vector3df(0), irr::video::SColor(255,000,000,255), irr::core::vector2df(0,1)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[8], irr::core::vector3df(0), irr::video::SColor(255,000,000,255), irr::core::vector2df(0.5,0.5)) ); Buffer->getIndexBuffer().push_back( 15 ); Buffer->getIndexBuffer().push_back( 16 ); Buffer->getIndexBuffer().push_back( 17 ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[7], irr::core::vector3df(0), irr::video::SColor(255,000,000,255), irr::core::vector2df(0,0)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[6], irr::core::vector3df(0), irr::video::SColor(255,000,000,255), irr::core::vector2df(0,1)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[9], irr::core::vector3df(0), irr::video::SColor(255,000,000,255), irr::core::vector2df(0.5,0.5)) ); Buffer->getIndexBuffer().push_back( 18 ); Buffer->getIndexBuffer().push_back( 19 ); Buffer->getIndexBuffer().push_back( 20 ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[6], irr::core::vector3df(0), irr::video::SColor(255,000,000,255), irr::core::vector2df(0,0)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[7], irr::core::vector3df(0), irr::video::SColor(255,000,000,255), irr::core::vector2df(0,1)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[10], irr::core::vector3df(0), irr::video::SColor(255,000,000,255), irr::core::vector2df(0.5,0.5)) ); Buffer->getIndexBuffer().push_back( 21 ); Buffer->getIndexBuffer().push_back( 22 ); Buffer->getIndexBuffer().push_back( 23 ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[9], irr::core::vector3df(0), irr::video::SColor(255,255,000,000), irr::core::vector2df(0,0)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[8], irr::core::vector3df(0), irr::video::SColor(255,255,000,000), irr::core::vector2df(0,1)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[0], irr::core::vector3df(0), irr::video::SColor(255,255,000,000), irr::core::vector2df(0.5,0.5)) ); Buffer->getIndexBuffer().push_back( 24 ); Buffer->getIndexBuffer().push_back( 25 ); Buffer->getIndexBuffer().push_back( 26 ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[8], irr::core::vector3df(0), irr::video::SColor(255,255,000,000), irr::core::vector2df(0,0)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[9], irr::core::vector3df(0), irr::video::SColor(255,255,000,000), irr::core::vector2df(0,1)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[1], irr::core::vector3df(0), irr::video::SColor(255,255,000,000), irr::core::vector2df(0.5,0.5)) ); Buffer->getIndexBuffer().push_back( 27 ); Buffer->getIndexBuffer().push_back( 28 ); Buffer->getIndexBuffer().push_back( 29 ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[10], irr::core::vector3df(0), irr::video::SColor(255,255,000,000), irr::core::vector2df(0,0)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[11], irr::core::vector3df(0), irr::video::SColor(255,255,000,000), irr::core::vector2df(0,1)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[2], irr::core::vector3df(0), irr::video::SColor(255,255,000,000), irr::core::vector2df(0.5,0.5)) ); Buffer->getIndexBuffer().push_back( 30 ); Buffer->getIndexBuffer().push_back( 31 ); Buffer->getIndexBuffer().push_back( 32 ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[11], irr::core::vector3df(0), irr::video::SColor(255,255,000,000), irr::core::vector2df(0,0)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[10], irr::core::vector3df(0), irr::video::SColor(255,255,000,000), irr::core::vector2df(0,1)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[3], irr::core::vector3df(0), irr::video::SColor(255,255,000,000), irr::core::vector2df(0.5,0.5)) ); Buffer->getIndexBuffer().push_back( 33 ); Buffer->getIndexBuffer().push_back( 34 ); Buffer->getIndexBuffer().push_back( 35 ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[0], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0,0)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[8], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0,1)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[4], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0.5,0.5)) ); Buffer->getIndexBuffer().push_back( 36 ); Buffer->getIndexBuffer().push_back( 37 ); Buffer->getIndexBuffer().push_back( 38 ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[0], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0,0)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[7], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0,1)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[9], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0.5,0.5)) ); Buffer->getIndexBuffer().push_back( 39 ); Buffer->getIndexBuffer().push_back( 40 ); Buffer->getIndexBuffer().push_back( 41 ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[1], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0,0)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[5], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0,1)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[8], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0.5,0.5)) ); Buffer->getIndexBuffer().push_back( 42 ); Buffer->getIndexBuffer().push_back( 43 ); Buffer->getIndexBuffer().push_back( 44 ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[1], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0,0)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[9], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0,1)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[6], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0.5,0.5)) ); Buffer->getIndexBuffer().push_back( 45 ); Buffer->getIndexBuffer().push_back( 46 ); Buffer->getIndexBuffer().push_back( 47 ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[2], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0,0)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[6], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0,1)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[10], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0.5,0.5)) ); Buffer->getIndexBuffer().push_back( 48 ); Buffer->getIndexBuffer().push_back( 49 ); Buffer->getIndexBuffer().push_back( 50 ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[2], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0,0)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[11], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0,1)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[5], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0.5,0.5)) ); Buffer->getIndexBuffer().push_back( 51 ); Buffer->getIndexBuffer().push_back( 52 ); Buffer->getIndexBuffer().push_back( 53 ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[3], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0,0)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[10], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0,1)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[7], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0.5,0.5)) ); Buffer->getIndexBuffer().push_back( 54 ); Buffer->getIndexBuffer().push_back( 55 ); Buffer->getIndexBuffer().push_back( 56 ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[3], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0,0)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[4], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0,1)) ); Buffer->getVertexBuffer().push_back( irr::video::S3DVertex( listevertex[11], irr::core::vector3df(0), irr::video::SColor(255,200,200,000), irr::core::vector2df(0.5,0.5)) ); Buffer->getIndexBuffer().push_back( 57 ); Buffer->getIndexBuffer().push_back( 58 ); Buffer->getIndexBuffer().push_back( 59 ); for(irr::u16 nbIterations=0; nbIterations < iterations; ++nbIterations ) { /// variables irr::scene::IVertexBuffer* VBuffer = new irr::scene::CVertexBuffer(irr::video::EVT_STANDARD); irr::scene::IIndexBuffer* IBuffer = new irr::scene::CIndexBuffer(irr::video::EIT_32BIT); VBuffer->setHardwareMappingHint( Buffer->getVertexBuffer().getHardwareMappingHint() ); IBuffer->setHardwareMappingHint( Buffer->getIndexBuffer().getHardwareMappingHint() ); /// créations des couleurs irr::video::SColor color1(255,255,000,000); irr::video::SColor color2(255,000,255,000); irr::video::SColor color3(255,000,000,255); irr::video::SColor color4(255,255,255,000); /// pour chaque triangles on en créé 4 nouveaux par subdivisions for(irr::u32 a=0; a < Buffer->getIndexBuffer().size(); a+=3) { /// on enregistre l'index irr::u32 index = VBuffer->size(); /// on enregistre les 3 points existant irr::core::vector3df A( Buffer->getVertexBuffer()[Buffer->getIndexBuffer()[a]].Pos ); irr::core::vector3df B( Buffer->getVertexBuffer()[Buffer->getIndexBuffer()[a+1]].Pos ); irr::core::vector3df C( Buffer->getVertexBuffer()[Buffer->getIndexBuffer()[a+2]].Pos ); /// on calcule les 3 nouveaux points irr::core::vector3df D( irr::core::line3df(A, B).getMiddle().setLength(rayon) ); irr::core::vector3df E( irr::core::line3df(B, C).getMiddle().setLength(rayon) ); irr::core::vector3df F( irr::core::line3df(C, A).getMiddle().setLength(rayon) ); /// on insère les 4 nouveaux triangles /// ADF VBuffer->push_back( irr::video::S3DVertex( A, irr::core::vector3df(0), color1, irr::core::vector2df(0,0)) ); VBuffer->push_back( irr::video::S3DVertex( D, irr::core::vector3df(0), color1, irr::core::vector2df(0,1)) ); VBuffer->push_back( irr::video::S3DVertex( F, irr::core::vector3df(0), color1, irr::core::vector2df(0.5,0.5)) ); IBuffer->push_back( index ); IBuffer->push_back( index+1 ); IBuffer->push_back( index+2 ); /// DBE VBuffer->push_back( irr::video::S3DVertex( D, irr::core::vector3df(0), color2, irr::core::vector2df(0,0)) ); VBuffer->push_back( irr::video::S3DVertex( B, irr::core::vector3df(0), color2, irr::core::vector2df(0,1)) ); VBuffer->push_back( irr::video::S3DVertex( E, irr::core::vector3df(0), color2, irr::core::vector2df(0.5,0.5)) ); IBuffer->push_back( index+3 ); IBuffer->push_back( index+4 ); IBuffer->push_back( index+5 ); /// FDE VBuffer->push_back( irr::video::S3DVertex( F, irr::core::vector3df(0), color3, irr::core::vector2df(0,0)) ); VBuffer->push_back( irr::video::S3DVertex( D, irr::core::vector3df(0), color3, irr::core::vector2df(0,1)) ); VBuffer->push_back( irr::video::S3DVertex( E, irr::core::vector3df(0), color3, irr::core::vector2df(0.5,0.5)) ); IBuffer->push_back( index+6 ); IBuffer->push_back( index+7 ); IBuffer->push_back( index+8 ); /// FEC VBuffer->push_back( irr::video::S3DVertex( F, irr::core::vector3df(0), color4, irr::core::vector2df(0,0)) ); VBuffer->push_back( irr::video::S3DVertex( E, irr::core::vector3df(0), color4, irr::core::vector2df(0,1)) ); VBuffer->push_back( irr::video::S3DVertex( C, irr::core::vector3df(0), color4, irr::core::vector2df(0.5,0.5)) ); IBuffer->push_back( index+9 ); IBuffer->push_back( index+10 ); IBuffer->push_back( index+11 ); } /// on change les buffers Buffer->setVertexBuffer( VBuffer ); Buffer->setIndexBuffer( IBuffer ); } /// on mets à jour les paramètres de création de la sphere Rayon = rayon; NbIterations = iterations; /// on met à jour la Bounding Box createBoundingBox(); /// tout s'est bien passé on quitte return true; } irr::scene::CDynamicMeshBuffer* SphereIcosaUnlimited::getBuffer() { return Buffer; } irr::video::SMaterial& SphereIcosaUnlimited::getMaterial() { return Buffer->Material; } void SphereIcosaUnlimited::setMaterial(irr::video::SMaterial material) { Buffer->Material = material; } irr::core::aabbox3df& SphereIcosaUnlimited::getBoundingBox() { return BoundingBox; } void SphereIcosaUnlimited::setUseVBO(irr::scene::E_HARDWARE_MAPPING vbo) { Buffer->getVertexBuffer().setHardwareMappingHint(vbo); Buffer->getIndexBuffer().setHardwareMappingHint(vbo); } void SphereIcosaUnlimited::createBoundingBox() { BoundingBox = irr::core::aabbox3df( irr::core::vector3df(-Rayon), irr::core::vector3df(Rayon) ); }
Utilisation :
SMaterial blanc;
blanc.Lighting = false;
SphereIcosaUnlimited sphere(blanc, 1000, 8);
sphere.setUseVBO(EHM_STATIC);
CdynamicMeshBuffer* bufferessai32 = sphere.getBuffer();
// à mettre entre beginscene et endscene
Driver->drawMeshBuffer( SphereBuffer );
ATTENTION : Je ne l'ai pas précisé avant mais il faut libérer les buffers car ce n'est pas fait dans la classe.
Hors ligne
Salut,
Tout simplement énorme ton code .
Je n'en aurai probablement pas l'utilité mais je serais curieux de savoir pourquoi tu as besoin de se type de mesh ?
Hors ligne
La particularite de cette sphere est qu'elle est entièrement composée de triangles EQUILATERAUX. Le mesh est donc régulier, ce qui facilite les opérations de déformation du mesh. Par exemple si tu éloigne un vertex du centre de la sphère, tu obtiendras un pic bien arrondi. Avec des quads, il faudrait réagencer leurs diagonales pour qu'elles "suivent" le pic. Si tu n'as pas compris je te ferai un screen pour mieux expliquer.
Hors ligne
Copland :
Salut,
Tout simplement énorme ton code .
je plussoie sur ce point, super ton code
Hors ligne
Merci pour les compliments.^^ Je travaille sur des fonctions de modification du mesh afin de pouvoir extruder, voir même faire un lod. Mais je vais d'abord retravailler la classe , il faudrait que suivant le nombre d'itérations la sphère soit divisée sur plusieurs buffers afin de ne pas limiter le nombre de triangles. Car les buffers 32bits ne sont pas compatibles avec toutes les cartes graphiques.
Sur ce, je repars coder.
Hors ligne
Options | Liens officiels | Caractéristiques | Statistiques | Communauté |
---|---|---|---|---|
Corrections |
|
xhtml 1.0 css 2.1 Propulsé par FluxBB Traduit par FluxBB.fr |
882 membres 1429 sujets 11119 messages |
Dernier membre inscrit: LiseBuisson96 66 invités en ligne Aucun membre connecté RSS Feed |