| 1354 | } |
| 1355 | |
| 1356 | void GFXDrawUtil::drawCylinder( const GFXStateBlockDesc &desc, const Point3F &basePnt, const Point3F &tipPnt, F32 radius, const ColorI &color ) |
| 1357 | { |
| 1358 | VectorF uvec = tipPnt - basePnt; |
| 1359 | F32 height = uvec.len(); |
| 1360 | uvec.normalize(); |
| 1361 | MatrixF mat( true ); |
| 1362 | MathUtils::getMatrixFromUpVector( uvec, &mat ); |
| 1363 | mat.setPosition(basePnt); |
| 1364 | |
| 1365 | Point3F scale( radius, radius, height * 2 ); |
| 1366 | mat.scale(scale); |
| 1367 | GFXTransformSaver saver; |
| 1368 | |
| 1369 | mDevice->pushWorldMatrix(); |
| 1370 | mDevice->multWorld(mat); |
| 1371 | |
| 1372 | S32 numPoints = sizeof(circlePoints) / sizeof(Point2F); |
| 1373 | GFXVertexBufferHandle<GFXVertexPCT> verts(mDevice, numPoints *4 + 2, GFXBufferTypeVolatile); |
| 1374 | verts.lock(); |
| 1375 | F32 sign = -1.f; |
| 1376 | S32 indexDown = 0; //counting down from numPoints |
| 1377 | S32 indexUp = 0; //counting up from 0 |
| 1378 | S32 index = 0; //circlePoints index for caps |
| 1379 | |
| 1380 | for (S32 i = 0; i < numPoints + 1; i++) |
| 1381 | { |
| 1382 | //Top/Bottom cap |
| 1383 | if (i != numPoints) |
| 1384 | { |
| 1385 | if (sign < 0) |
| 1386 | index = indexDown; |
| 1387 | else |
| 1388 | index = indexUp; |
| 1389 | |
| 1390 | verts[i].point = Point3F(circlePoints[index].x, circlePoints[index].y, 0); |
| 1391 | verts[i].color = color; |
| 1392 | verts[i + numPoints].point = Point3F(circlePoints[index].x, circlePoints[index].y, 0.5f); |
| 1393 | verts[i + numPoints].color = color; |
| 1394 | |
| 1395 | if (sign < 0) |
| 1396 | indexUp += 1; |
| 1397 | else |
| 1398 | indexDown = numPoints - indexUp; |
| 1399 | |
| 1400 | // invert sign |
| 1401 | sign *= -1.0f; |
| 1402 | } |
| 1403 | |
| 1404 | //cylinder |
| 1405 | S32 imod = i % numPoints; |
| 1406 | S32 vertindex = 2 * i + (numPoints * 2); |
| 1407 | verts[vertindex].point = Point3F(circlePoints[imod].x, circlePoints[imod].y, 0); |
| 1408 | verts[vertindex].color = color; |
| 1409 | verts[vertindex + 1].point = Point3F(circlePoints[imod].x, circlePoints[imod].y, 0.5f); |
| 1410 | verts[vertindex + 1].color = color; |
| 1411 | } |
| 1412 | |
| 1413 | verts.unlock(); |
no test coverage detected