MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / drawSphere

Method drawSphere

Engine/source/gfx/gfxDrawUtil.cpp:657–712  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

655static SphereMesh gSphere;
656
657void GFXDrawUtil::drawSphere( const GFXStateBlockDesc &desc, F32 radius, const Point3F &pos, const ColorI &color, bool drawTop, bool drawBottom, const MatrixF *xfm )
658{
659 MatrixF mat;
660 if ( xfm )
661 mat = *xfm;
662 else
663 mat = MatrixF::Identity;
664
665 mat.scale(Point3F(radius,radius,radius));
666 mat.setPosition(pos);
667 GFX->pushWorldMatrix();
668 GFX->multWorld(mat);
669
670 const SphereMesh::TriangleMesh * sphereMesh = gSphere.getMesh(2);
671 S32 numPoly = sphereMesh->numPoly;
672 S32 totalPoly = 0;
673 GFXVertexBufferHandle<GFXVertexPCT> verts(mDevice, numPoly*3, GFXBufferTypeVolatile);
674 verts.lock();
675 S32 vertexIndex = 0;
676 for (S32 i=0; i<numPoly; i++)
677 {
678 if (!drawBottom)
679 {
680 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)
681 continue;
682 }
683 if (!drawTop)
684 {
685 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)
686 continue;
687 }
688 totalPoly++;
689
690 verts[vertexIndex].point = sphereMesh->poly[i].pnt[0];
691 verts[vertexIndex].color = color;
692 vertexIndex++;
693
694 verts[vertexIndex].point = sphereMesh->poly[i].pnt[1];
695 verts[vertexIndex].color = color;
696 vertexIndex++;
697
698 verts[vertexIndex].point = sphereMesh->poly[i].pnt[2];
699 verts[vertexIndex].color = color;
700 vertexIndex++;
701 }
702 verts.unlock();
703
704 mDevice->setStateBlockByDesc( desc );
705
706 mDevice->setVertexBuffer( verts );
707 mDevice->setupGenericShaders();
708
709 mDevice->drawPrimitive( GFXTriangleList, 0, totalPoly );
710
711 GFX->popWorldMatrix();
712}
713
714//-----------------------------------------------------------------------------

Callers 10

renderSceneMethod · 0.45
renderSceneMethod · 0.45
_renderVizMethod · 0.45
renderObjectMethod · 0.45
_renderDecalSpheresMethod · 0.45
_onRenderVizMethod · 0.45
_renderEmitterInfoMethod · 0.45
DefineEngineMethodFunction · 0.45
renderSceneMethod · 0.45

Calls 13

pushWorldMatrixMethod · 0.80
multWorldMethod · 0.80
setStateBlockByDescMethod · 0.80
setVertexBufferMethod · 0.80
popWorldMatrixMethod · 0.80
Point3FClass · 0.50
scaleMethod · 0.45
setPositionMethod · 0.45
getMeshMethod · 0.45
lockMethod · 0.45
unlockMethod · 0.45
setupGenericShadersMethod · 0.45

Tested by

no test coverage detected