void GFXDrawUtil::drawSphere( const GFXStateBlockDesc &desc, F32 radius, const Point3F &pos, const ColorI &color, bool drawTop, bool drawBottom, const MatrixF *xfm ) { MatrixF mat; if ( xfm ) mat = *xfm; else mat = MatrixF::Identity; mat.scale(Point3F(radius,radius,radius)); mat.setPosition(pos); GFX->pushWorldMatrix(); GFX->multWorld(mat); const SphereMesh::TriangleMesh * sphereMesh = gSphere.getMesh(2); S32 numPoly = sphereMesh->numPoly; S32 totalPoly = 0; GFXVertexBufferHandle<GFXVertexPC> verts(mDevice, numPoly*3, GFXBufferTypeVolatile); verts.lock(); S32 vertexIndex = 0; for (S32 i=0; i<numPoly; i++) { if (!drawBottom) { if (sphereMesh->poly[i].pnt[0].z < -0.01f || sphereMesh->poly[i].pnt[1].z < -0.01f || sphereMesh->poly[i].pnt[2].z < -0.01f) continue; } if (!drawTop) { if (sphereMesh->poly[i].pnt[0].z > 0.01f || sphereMesh->poly[i].pnt[1].z > 0.01f || sphereMesh->poly[i].pnt[2].z > 0.01f) continue; } totalPoly++; verts[vertexIndex].point = sphereMesh->poly[i].pnt[0]; verts[vertexIndex].color = color; vertexIndex++; verts[vertexIndex].point = sphereMesh->poly[i].pnt[1]; verts[vertexIndex].color = color; vertexIndex++; verts[vertexIndex].point = sphereMesh->poly[i].pnt[2]; verts[vertexIndex].color = color; vertexIndex++; } verts.unlock(); mDevice->setStateBlockByDesc( desc ); mDevice->setVertexBuffer( verts ); mDevice->setupGenericShaders(); mDevice->drawPrimitive( GFXTriangleList, 0, totalPoly ); GFX->popWorldMatrix(); }
GFXVertexBufferHandle<AdvancedLightManager::LightVertex> AdvancedLightManager::getSphereMesh(U32 &outNumPrimitives, GFXPrimitiveBuffer *&outPrimitives) { static SphereMesh sSphereMesh; if( mSphereGeometry.isNull() ) { const SphereMesh::TriangleMesh * sphereMesh = sSphereMesh.getMesh(3); S32 numPoly = sphereMesh->numPoly; mSpherePrimitiveCount = 0; mSphereGeometry.set(GFX, numPoly*3, GFXBufferTypeStatic); mSphereGeometry.lock(); S32 vertexIndex = 0; for (S32 i=0; i<numPoly; i++) { mSpherePrimitiveCount++; mSphereGeometry[vertexIndex].point = sphereMesh->poly[i].pnt[0]; mSphereGeometry[vertexIndex].color = ColorI::WHITE; vertexIndex++; mSphereGeometry[vertexIndex].point = sphereMesh->poly[i].pnt[1]; mSphereGeometry[vertexIndex].color = ColorI::WHITE; vertexIndex++; mSphereGeometry[vertexIndex].point = sphereMesh->poly[i].pnt[2]; mSphereGeometry[vertexIndex].color = ColorI::WHITE; vertexIndex++; } mSphereGeometry.unlock(); } outNumPrimitives = mSpherePrimitiveCount; outPrimitives = NULL; // For now return mSphereGeometry; }