要创建一个几何图形,先得知道其数据大小,以申请合适的内存.
1 bool YfCalculateGeometryBufferSize 2 ( 3 YeGraphType graphType, 4 Yuint slices, 5 Yuint stacks, 6 OUT Yuint& numVertices, // 顶点数目 7 OUT Yuint& numTriangles, // 三角形数目 8 OUT Yuint& numLines // 线段数目 9 ) 10 { 11 switch (graphType) 12 { 13 case YE_GRAPH_PLANE: 14 { 15 if (slices < 2 || stacks < 2) 16 { 17 return false; 18 } 19 numVertices = slices * stacks; 20 numTriangles = (slices - 1) * (stacks - 1) * 2; 21 numLines = slices * (stacks - 1) +(slices - 1) * stacks; 22 } 23 break; 24 25 case YE_GRAPH_BOX: 26 { 27 numVertices = 8; 28 numTriangles = 12; 29 numLines = 12; 30 } 31 break; 32 33 case YE_GRAPH_SPHERE: 34 { 35 if (slices < 2 || stacks < 3) 36 { 37 return false; 38 } 39 numVertices = slices * (stacks - 2) + 2; 40 numTriangles = slices * (stacks - 2) * 2; 41 numLines = slices * (stacks - 2) + slices * (stacks - 1); 42 } 43 break; 44 45 case YE_GRAPH_DRUM: 46 { 47 if (slices < 2 || stacks < 3) 48 { 49 return false; 50 } 51 numVertices = slices * stacks + 2; 52 numTriangles = slices * stacks * 2; 53 numLines = slices * stacks + slices * (stacks + 1); 54 } 55 break; 56 57 case YE_GRAPH_HEMISPHERE: 58 { 59 if (slices < 2 || stacks < 3) 60 { 61 return false; 62 } 63 numVertices = slices * (stacks - 1) + 1; 64 numTriangles = slices * (stacks - 2) * 2 + slices; 65 numLines = slices * (stacks - 1) * 2; 66 } 67 break; 68 69 case YE_GRAPH_CONE: 70 { 71 if (slices < 2) 72 { 73 return false; 74 } 75 numVertices = slices + 2; 76 numTriangles = slices * 2; 77 numLines = slices * 2; 78 } 79 break; 80 81 case YE_GRAPH_CYLINDER: 82 { 83 if (slices < 2) 84 { 85 return false; 86 } 87 numVertices = slices * 2 + 2; 88 numTriangles = slices * 4; 89 numLines = slices * 5; 90 } 91 break; 92 93 case YE_GRAPH_CAPSULE: 94 { 95 Yuint halfStacks = stacks / 2; 96 if (slices < 2 || halfStacks < 2) 97 { 98 return false; 99 } 100 numVertices = slices * (halfStacks - 1) * 2 + 2; 101 numTriangles = slices * (halfStacks - 1) * 4; 102 numLines = slices * (halfStacks - 1) * 2 + slices * (2 * halfStacks - 1); 103 } 104 break; 105 106 case YE_GRAPH_PYRAMID: 107 { 108 numVertices = 5; 109 numTriangles = 6; 110 numLines = 8; 111 } 112 break; 113 114 case YE_GRAPH_ROUND: 115 { 116 if (slices < 3) 117 { 118 return false; 119 } 120 numVertices = slices + 1; 121 numTriangles = slices; 122 numLines = slices; 123 } 124 break; 125 126 case YE_GRAPH_RING: 127 { 128 if (slices < 2 || stacks < 3) 129 { 130 return false; 131 } 132 numVertices = slices * stacks; 133 numTriangles = slices * stacks * 2; 134 numLines = slices * stacks * 2; 135 } 136 break; 137 138 case YE_GRAPH_PIPE: 139 { 140 if (slices < 2) 141 { 142 return false; 143 } 144 numVertices = slices * 4; 145 numTriangles = slices * 8; 146 numLines = slices * 8; 147 } 148 break; 149 150 case YE_GRAPH_WEDGE: 151 { 152 numVertices = 6; 153 numTriangles = 8; 154 numLines = 9; 155 } 156 break; 157 158 case YE_GRAPH_FAN: 159 { 160 if (slices < 2) 161 { 162 return false; 163 } 164 numVertices = (slices + 1) * 2; 165 numTriangles = slices * 4; 166 numLines = slices + (slices-1) * 2 + 5; 167 } 168 break; 169 170 case YE_GRAPH_ARC: 171 { 172 if (slices < 2 || stacks < 3) 173 { 174 return false; 175 } 176 numVertices = slices * (stacks - 1) + 1; 177 numTriangles = slices * (stacks - 2) * 2 + slices; 178 numLines = slices * (stacks - 1) * 2; 179 } 180 break; 181 182 case YE_GRAPH_GEARWHEEL: 183 { 184 if (slices < 3) 185 { 186 return false; 187 } 188 numVertices = (slices*2) * 2 + 2; 189 numTriangles = slices * 8; 190 numLines = (slices*2) * 5; 191 } 192 break; 193 194 case YE_GRAPH_STAR: 195 { 196 if (slices < 3) 197 { 198 return false; 199 } 200 numVertices = (slices*2) + 2; 201 numTriangles = slices * 4; 202 numLines = slices * 5; 203 } 204 break; 205 206 case YE_GRAPH_SPIRE: 207 { 208 if (stacks < 1 || slices < 3) 209 { 210 return false; 211 } 212 numVertices = 2 + stacks * 2; 213 numTriangles = stacks * 2; 214 numLines = 1 + stacks * 3; 215 } 216 break; 217 218 case YE_GRAPH_STAIRS: 219 { 220 if (stacks < 1) 221 { 222 return false; 223 } 224 numVertices = 2 + stacks * 4; 225 numTriangles = stacks * 8; 226 numLines = 1 + stacks * 8; 227 } 228 break; 229 230 case YE_GRAPH_SPIRAL_STAIRS: 231 { 232 if (stacks < 1) 233 { 234 return false; 235 } 236 numVertices = 2 + stacks * 4; 237 numTriangles = stacks * 8; 238 numLines = 1 + stacks * 8; 239 } 240 break; 241 242 default: 243 { 244 numVertices = 0; 245 numTriangles = 0; 246 numLines = 0; 247 return false; 248 } 249 break; 250 } 251 252 return true; 253 }