DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Create A Sphere

12.12.2008
| 438 views |
  • submit to reddit
        
            float lRadius = 0.85f;
            
            cMeshModeler lModeler = new cMeshModeler();
            List<cVector3f> lLine = new Vector<cVector3f>(1);
            lLine.add(new cVector3f(0, 0, -lRadius));
            lModeler.mSetBorderList(lModeler.mCreateNewBorder(lLine));
            
            float lH, lr;
            for (int lAlpha = -80; lAlpha < 90; lAlpha = lAlpha + 10)
            {
                lH = lRadius * (float)Math.sin(lAlpha * Math.PI / 180);
                lr = lRadius * ((float)Math.cos(lAlpha * Math.PI / 180));
                lLine = cMathUtils.mCreateCircle(new cVector3f(0,0,lH), lr, 18);
                lModeler.mSewBorderToPoints(lLine);
            }
            lLine = new Vector<cVector3f>(1);
            lLine.add(new cVector3f(0, 0, lRadius));
            lModeler.mSewBorderToPoints(lLine);
            
            cShapeNode lShape = new cShapeNode(null);
            lModeler.mGetMesh().mInitChildrenNodes();
            lModeler.mGetMesh().mSmoothVerticesNormals(true);
            lShape.mAddSceneGraphChild(lModeler.mGetMesh());
            aSceneGraph.mAddSceneGraphChild(lShape);