Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Simple Geometry
[Geometry]


Material Access

MaterialPtr osg::getDefaultMaterial (void)
MaterialPtr osg::getDefaultUnlitMaterial (void)

Construction functions

NodePtr osg::makePlane (Real32 xsize, Real32 ysize, UInt16 hor, UInt16 vert)
GeometryPtr osg::makePlaneGeo (Real32 xsize, Real32 ysize, UInt16 hor, UInt16 vert)
NodePtr osg::makeCone (Real32 height, Real32 botradius, UInt16 sides, bool doSide, bool doBottom)
GeometryPtr osg::makeConeGeo (Real32 height, Real32 botradius, UInt16 sides, bool doSide, bool doBottom)
NodePtr osg::makeCylinder (Real32 height, Real32 radius, UInt16 sides, bool doSide, bool doTop, bool doBottom)
GeometryPtr osg::makeCylinderGeo (Real32 height, Real32 radius, UInt16 sides, bool doSide, bool doTop, bool doBottom)
NodePtr osg::makeConicalFrustum (Real32 height, Real32 topradius, Real32 botradius, UInt16 sides, bool doSide, bool doTop, bool doBottom)
GeometryPtr osg::makeConicalFrustumGeo (Real32 height, Real32 topradius, Real32 botradius, UInt16 sides, bool doSide, bool doTop, bool doBottom)
NodePtr osg::makeTorus (Real32 innerRadius, Real32 outerRadius, UInt16 sides, UInt16 rings)
GeometryPtr osg::makeTorusGeo (Real32 innerRadius, Real32 outerRadius, UInt16 sides, UInt16 rings)
NodePtr osg::makeSphere (UInt16 depth, Real32 radius)
GeometryPtr osg::makeSphereGeo (UInt16 depth, Real32 radius)
NodePtr osg::makeLatLongSphere (UInt16 latres, UInt16 longres, Real32 radius)
GeometryPtr osg::makeLatLongSphereGeo (UInt16 latres, UInt16 longres, Real32 radius)
NodePtr osg::makeBox (Real32 xsize, Real32 ysize, Real32 zsize, UInt16 hor, UInt16 vert, UInt16 depth)
GeometryPtr osg::makeBoxGeo (Real32 xsize, Real32 ysize, Real32 zsize, UInt16 hor, UInt16 vert, UInt16 depth)

Functions

GeoPositions3fPtr osg::makeGeoPositions3fPtr (UInt32 uiSize)
 some workaround functions for Windows problems

Variables

static SimpleMaterialPtr _defaultMaterial
static SimpleMaterialPtr _defaultUnlitMaterial

Detailed Description

SimpleGeometry combines a number of functions to create some specialized geometry very easily. See Simple Geometry for a description.

Function Documentation

*MaterialPtr osg::getDefaultMaterial void   ) 
 

Access the default Material for Simple Geometry. Also useful whenever an arbitrary material is needed.

Definition at line 71 of file OSGSimpleGeometry.cpp.

References osg::addRefCP(), osg::beginEditCP(), osg::endEditCP(), and osg::NullFC.

Referenced by osg::MaterialDrawable::drawActionHandler(), osg::makeBoxGeo(), osg::makeConicalFrustumGeo(), osg::makeLatLongSphereGeo(), osg::makePlaneGeo(), osg::makeSphereGeo(), osg::makeTorusGeo(), osg::MaterialDrawable::renderActionHandler(), and osg::VRMLWriteAction::writeMaterial().

00072 {
00073     if(_defaultMaterial == NullFC)
00074     {
00075         _defaultMaterial = SimpleMaterial::create();
00076 
00077         beginEditCP(_defaultMaterial);
00078         _defaultMaterial->setDiffuse(Color3f(.7,.7,.5));
00079         _defaultMaterial->setAmbient(Color3f(0.1,0.1,0.1));
00080         _defaultMaterial->setSpecular(Color3f(1,1,1));
00081         _defaultMaterial->setShininess(20);
00082         endEditCP  (_defaultMaterial);
00083 
00084         addRefCP(_defaultMaterial);
00085     }
00086     
00087     return _defaultMaterial;
00088 }

MaterialPtr osg::getDefaultUnlitMaterial void   ) 
 

Access the default unlit Material. Useful whenever an arbitrary unlit material is needed.

Definition at line 99 of file OSGSimpleGeometry.cpp.

References osg::addRefCP(), osg::beginEditCP(), osg::endEditCP(), and osg::NullFC.

Referenced by VolumeDrawWrapper::drop().

00100 {
00101     if(_defaultUnlitMaterial == NullFC)
00102     {
00103         _defaultUnlitMaterial = SimpleMaterial::create();
00104 
00105         beginEditCP(_defaultUnlitMaterial);
00106         _defaultUnlitMaterial->setDiffuse(Color3f(1,1,.5));
00107         _defaultUnlitMaterial->setLit(false);
00108         endEditCP  (_defaultUnlitMaterial);
00109 
00110         addRefCP(_defaultUnlitMaterial);
00111     }
00112     
00113     return _defaultUnlitMaterial;
00114 }

NodePtr osg::makePlane Real32  xsize,
Real32  ysize,
UInt16  hor,
UInt16  vert
 

MakePlane creates a plane in the x/y plane. It spans the [-xsize /2,xsize /2]x [-ysize /2,ysize/2] area and is subdivided into hor * vert quads.

Definition at line 124 of file OSGSimpleGeometry.cpp.

References osg::beginEditCP(), osg::endEditCP(), osg::makePlaneGeo(), and osg::NullFC.

Referenced by osg::DisplayCalibration::createCMViewports().

00125 {
00126     GeometryPtr pGeo = makePlaneGeo(xsize, ysize, hor, vert);
00127  
00128     if(pGeo == NullFC)
00129     {
00130         return NullFC;
00131     }
00132     
00133     NodePtr node = Node::create();
00134 
00135     beginEditCP  (node);
00136     node->setCore(pGeo);
00137     endEditCP    (node);
00138 
00139     return node;
00140 }

*GeometryPtr osg::makePlaneGeo Real32  xsize,
Real32  ysize,
UInt16  hor,
UInt16  vert
 

Create the Geometry Core for used by osg::makePlane.

Definition at line 146 of file OSGSimpleGeometry.cpp.

References osg::beginEditCP(), osg::endEditCP(), osg::getDefaultMaterial(), osg::NullFC, p, and SWARNING.

Referenced by osg::makePlane().

00148 {
00149     if(! hor || ! vert)
00150     {
00151         SWARNING << "makePlane: illegal parameters hor=" << hor << ", vert="
00152                  << vert << std::endl;
00153         return NullFC;
00154     }
00155     
00156     GeoPositions3fPtr    pnts  = GeoPositions3f::create();
00157     GeoNormals3fPtr      norms = GeoNormals3f::create();
00158     GeoTexCoords2fPtr    tex   = GeoTexCoords2f::create();
00159     GeoIndicesUI32Ptr    index = GeoIndicesUI32::create();   
00160     GeoPLengthsUI32Ptr   lens  = GeoPLengthsUI32::create();  
00161     GeoPTypesUI8Ptr      types = GeoPTypesUI8::create();     
00162     
00163     UInt16 x,y;
00164     Real32 xstep,ystep;
00165     xstep=xsize / hor;
00166     ystep=ysize / vert;
00167 
00168     // calc the vertices
00169 
00170     GeoPositions3f::StoredFieldType  * p  = pnts->getFieldPtr();
00171     GeoNormals3f::StoredFieldType    * n  = norms->getFieldPtr();
00172     GeoTexCoords2f::StoredFieldType  * tx = tex->getFieldPtr();
00173 
00174     beginEditCP(pnts);
00175     beginEditCP(norms);
00176     beginEditCP(tex);
00177     
00178     for(y = 0; y <= vert; y++)
00179     {
00180         for(x = 0; x <= hor; x++)
00181         {
00182             p->push_back(Pnt3f(x * xstep - xsize / 2, y * ystep - ysize / 2, 0));
00183             n->push_back(Vec3f(0, 0, 1));
00184             tx->push_back(Vec2f(x / (Real32) hor, y / (Real32) vert));
00185         }
00186     }
00187 
00188     endEditCP(pnts);
00189     endEditCP(norms);
00190     endEditCP(tex);
00191 
00192     // create the faces
00193     
00194     GeoIndicesUI32::StoredFieldType    * i = index->getFieldPtr();
00195     GeoPLengthsUI32::StoredFieldType   * l = lens->getFieldPtr();
00196     GeoPTypesUI8::StoredFieldType      * t = types->getFieldPtr();
00197 
00198     beginEditCP(index);
00199     beginEditCP(lens);
00200     beginEditCP(types);
00201 
00202     for(y = 0; y < vert; y++)
00203     {
00204         t->push_back(GL_TRIANGLE_STRIP);
00205         l->push_back(2 * (hor + 1));
00206         
00207         for(x = 0; x <= hor; x++)
00208         {
00209             i->push_back((y + 1) * (hor + 1) + x);
00210             i->push_back( y      * (hor + 1) + x);
00211         }
00212     }
00213 
00214     endEditCP(index);
00215     endEditCP(lens);
00216     endEditCP(types);
00217     
00218     // create the geometry
00219     
00220     GeometryPtr geo = Geometry::create();
00221 
00222     beginEditCP(geo);
00223     geo->setMaterial(getDefaultMaterial());
00224     geo->setPositions(pnts);
00225     geo->setNormals(norms);
00226     geo->setTexCoords(tex);
00227     geo->setIndices(index);
00228     geo->getIndexMapping().push_back(Geometry::MapPosition | 
00229                                     Geometry::MapNormal   |
00230                                     Geometry::MapTexCoords);
00231     geo->setTypes(types);
00232     geo->setLengths(lens);
00233     endEditCP(geo);
00234     
00235     return geo;
00236 }

NodePtr osg::makeCone Real32  height,
Real32  botradius,
UInt16  sides,
bool  doSide,
bool  doBottom
 

MakeCone creates a cone. It's center sits in the origin of the x/z plane. It's radius is radius and the base is subdivided into sides parts.

Each part of the cone (bottom cap, sides) can be enabled or disabled.

Definition at line 246 of file OSGSimpleGeometry.cpp.

References osg::makeConicalFrustum().

00251 {
00252     return makeConicalFrustum(height, 
00253                               0, 
00254                               botradius, 
00255                               sides, 
00256                               doSide, 
00257                               false, 
00258                               doBottom);
00259 }

GeometryPtr osg::makeConeGeo Real32  height,
Real32  botradius,
UInt16  sides,
bool  doSide,
bool  doBottom
 

Create the Geometry Core for used by osg::makeCone.

Definition at line 265 of file OSGSimpleGeometry.cpp.

References osg::makeConicalFrustumGeo().

Referenced by osg::VRMLGeometryObjectDesc::endNode().

00270 {
00271     return makeConicalFrustumGeo(height, 
00272                                  0, 
00273                                  botradius, 
00274                                  sides, 
00275                                  doSide, 
00276                                  false, 
00277                                  doBottom);
00278 }

NodePtr osg::makeCylinder Real32  height,
Real32  radius,
UInt16  sides,
bool  doSide,
bool  doTop,
bool  doBottom
 

MakeCylinder creates a cylinder. It's center sits in the origin of the x/z plane. It's radius is radius and the base is subdivided into sides parts.

Each part of the cylinder (top cap, bottom cap, sides) can be enabled or disabled.

Definition at line 290 of file OSGSimpleGeometry.cpp.

References osg::makeConicalFrustum().

00296 {
00297     return makeConicalFrustum(height, 
00298                               radius, 
00299                               radius, 
00300                               sides, 
00301                               doSide, 
00302                               doTop, 
00303                               doBottom);
00304 }

GeometryPtr osg::makeCylinderGeo Real32  height,
Real32  radius,
UInt16  sides,
bool  doSide,
bool  doTop,
bool  doBottom
 

Create the Geometry Core for used by osg::makeCylinder.

Definition at line 310 of file OSGSimpleGeometry.cpp.

References osg::makeConicalFrustumGeo().

Referenced by osg::VRMLGeometryObjectDesc::endNode().

00316 {
00317     return makeConicalFrustumGeo(height, 
00318                                  radius, 
00319                                  radius, 
00320                                  sides, 
00321                                  doSide, 
00322                                  doTop, 
00323                                  doBottom);
00324 }

NodePtr osg::makeConicalFrustum Real32  height,
Real32  topradius,
Real32  botradius,
UInt16  sides,
bool  doSide,
bool  doTop,
bool  doBottom
 

MakeConicalFrustum creates a conical frustum. It's center sits in the origin of the x/z plane. It's height is height and the base is subdivided into sides parts. The top radius is topradius, the bottom radius botradius.

Each part of the frustum (top cap, bottom cap, sides) can be enabled or disabled. Caps forradius 0 are automatically disabled.

Definition at line 338 of file OSGSimpleGeometry.cpp.

References osg::beginEditCP(), osg::endEditCP(), osg::makeConicalFrustumGeo(), and osg::NullFC.

Referenced by osg::makeCone(), and osg::makeCylinder().

00345 {
00346     GeometryPtr pGeo = makeConicalFrustumGeo(height, 
00347                                              topradius, 
00348                                              botradius,
00349                                              sides, 
00350                                              doSide, 
00351                                              doTop, 
00352                                              doBottom);
00353 
00354     if(pGeo == NullFC)
00355     {
00356         return NullFC;
00357     }
00358     
00359     NodePtr node = Node::create();
00360 
00361     beginEditCP  (node);
00362     node->setCore(pGeo);
00363     endEditCP    (node);
00364 
00365     return node;
00366 }

GeometryPtr osg::makeConicalFrustumGeo Real32  height,
Real32  topradius,
Real32  botradius,
UInt16  sides,
bool  doSide,
bool  doTop,
bool  doBottom
 

Create the Geometry Core for used by osg::makeConicalFrustum.

Definition at line 372 of file OSGSimpleGeometry.cpp.

References osg::beginEditCP(), osg::endEditCP(), osg::getDefaultMaterial(), osg::NullFC, osg::osgcos(), osg::osgsin(), osg::osgsqrt(), p, osg::Pi, and SWARNING.

Referenced by osg::makeConeGeo(), osg::makeConicalFrustum(), and osg::makeCylinderGeo().

00379 {
00380     if(height <= 0 || topradius < 0 || botradius < 0 || sides < 3)
00381     {
00382         SWARNING << "makeConicalFrustum: illegal parameters height=" << height 
00383                  << ", topradius=" << topradius 
00384                  << ", botradius=" << botradius 
00385                  << ", sides=" << sides 
00386                  << std::endl;
00387         return NullFC;
00388     }
00389     
00390     GeoPositions3fPtr   pnts  = GeoPositions3f::create();
00391     GeoNormals3fPtr     norms = GeoNormals3f::create();
00392     GeoTexCoords2fPtr   tex   = GeoTexCoords2f::create();
00393     GeoIndicesUI32Ptr   index = GeoIndicesUI32::create();   
00394     GeoPLengthsUI32Ptr  lens  = GeoPLengthsUI32::create();  
00395     GeoPTypesUI8Ptr     types = GeoPTypesUI8::create();     
00396     
00397     Int16  j;
00398     Real32 delta = 2.f * Pi / sides;
00399     Real32 beta, x, z;
00400     Real32 incl = (botradius - topradius) / height;
00401     Real32 nlen = 1.f / osgsqrt(1 + incl * incl);
00402     
00403     // vertices
00404 
00405     GeoPositions3f::StoredFieldType     * p  = pnts->getFieldPtr();
00406     GeoNormals3f::StoredFieldType       * n  = norms->getFieldPtr();
00407     GeoTexCoords2f::StoredFieldType     * tx = tex->getFieldPtr();
00408 
00409     // faces
00410     
00411     GeoIndicesUI32::StoredFieldType     * i  = index->getFieldPtr();
00412     GeoPLengthsUI32::StoredFieldType    * l  = lens->getFieldPtr();
00413     GeoPTypesUI8::StoredFieldType       * t  = types->getFieldPtr();
00414 
00415     // 
00416     
00417     beginEditCP(pnts);
00418     beginEditCP(norms);
00419     beginEditCP(tex);
00420 
00421     beginEditCP(index);
00422     beginEditCP(lens);
00423     beginEditCP(types);
00424     
00425     if(doSide)
00426     {
00427         UInt32 baseindex = p->size();
00428         
00429         for(j = 0; j <= sides; j++)
00430         {
00431             beta = j * delta;
00432             x    =  osgsin(beta);
00433             z    = -osgcos(beta);         
00434 
00435             p->push_back(Pnt3f(x * topradius, height/2, z * topradius));
00436             n->push_back(Vec3f(x/nlen, incl/nlen, z/nlen));
00437             tx->push_back(Vec2f(j / (Real32) sides, 1));
00438         }
00439         
00440         for(j = 0; j <= sides; j++)
00441         {
00442             beta = j * delta;
00443             x    =  osgsin(beta);
00444             z    = -osgcos(beta);         
00445 
00446             p->push_back(Pnt3f(x * botradius, -height/2, z * botradius));
00447             n->push_back(Vec3f(x/nlen, incl/nlen, z/nlen));
00448             tx->push_back(Vec2f(j / (Real32) sides, 0));
00449         }
00450 
00451         t->push_back(GL_TRIANGLE_STRIP);
00452         l->push_back(2 * (sides + 1));
00453 
00454         for(j = 0; j <= sides; j++) 
00455         {
00456                 i->push_back(baseindex + sides + 1 + j);
00457                 i->push_back(baseindex + j);
00458         }
00459     }
00460     
00461     if(doTop && topradius > 0)
00462     {
00463         UInt32 baseindex = p->size();
00464         
00465         // need to duplicate the points fornow, as we don't have multi-index geo yet
00466         
00467         for(j = sides - 1; j >= 0; j--)
00468         {
00469             beta = j * delta;
00470             x    =  topradius * osgsin(beta);
00471             z    = -topradius * osgcos(beta);        
00472 
00473             p->push_back(Pnt3f(x, height/2, z));
00474             n->push_back(Vec3f(0, 1, 0));
00475             tx->push_back(Vec2f(x / topradius / 2 + .5f, z / topradius / 2 + .5f));
00476         }
00477 
00478         t->push_back(GL_POLYGON);
00479         l->push_back(sides);
00480 
00481         for(j = 0; j < sides; j++) 
00482         {
00483             i->push_back(baseindex + j);
00484         }
00485     }
00486     
00487     if(doBottom && botradius > 0 )
00488     {
00489         UInt32 baseindex = p->size();
00490         
00491         // need to duplicate the points fornow, as we don't have multi-index geo yet
00492         
00493         for(j = sides - 1; j >= 0; j--)
00494         {
00495             beta = j * delta;
00496             x    =  botradius * osgsin(beta);
00497             z    = -botradius * osgcos(beta);      
00498 
00499             p->push_back(Pnt3f(x, -height/2, z));
00500             n->push_back(Vec3f(0, -1, 0));
00501             tx->push_back(Vec2f(x / botradius / 2 + .5f, z / botradius / 2 + .5f));
00502         }
00503 
00504         t->push_back(GL_POLYGON);
00505         l->push_back(sides);
00506 
00507         for(j = 0; j < sides; j++) 
00508         {
00509             i->push_back(baseindex + sides - 1 - j);
00510         }
00511     }
00512     
00513     endEditCP(pnts);
00514     endEditCP(norms);
00515     endEditCP(tex);
00516     
00517     endEditCP(index);
00518     endEditCP(lens);
00519     endEditCP(types);
00520 
00521     // create the geometry
00522     
00523     GeometryPtr geo = Geometry::create();
00524 
00525     beginEditCP(geo);
00526     geo->setMaterial(getDefaultMaterial());
00527     geo->setPositions(pnts);
00528     geo->setNormals(norms);
00529     geo->getIndexMapping().push_back(Geometry::MapPosition | 
00530                                     Geometry::MapNormal   |
00531                                     Geometry::MapTexCoords);
00532     geo->setTexCoords(tex);
00533     geo->setIndices(index);
00534     geo->setTypes(types);
00535     geo->setLengths(lens);
00536     endEditCP(geo);
00537 
00538     return geo;
00539 }

NodePtr osg::makeTorus Real32  innerRadius,
Real32  outerRadius,
UInt16  sides,
UInt16  rings
 

MakeTorus creates a torus in the x/y plane. Sides are the number of subdivisions forthe inner radius, rings forthe outer.

Definition at line 547 of file OSGSimpleGeometry.cpp.

References osg::beginEditCP(), osg::endEditCP(), osg::makeTorusGeo(), and osg::NullFC.

00549 {
00550     GeometryPtr pGeo = makeTorusGeo(innerRadius, outerRadius, sides, rings);
00551  
00552     if(pGeo == NullFC)
00553     {
00554         return NullFC;
00555     }
00556     
00557     NodePtr node = Node::create();
00558 
00559     beginEditCP  (node);
00560     node->setCore(pGeo);
00561     endEditCP    (node);
00562 
00563     return node;
00564 }

GeometryPtr osg::makeTorusGeo Real32  innerRadius,
Real32  outerRadius,
UInt16  sides,
UInt16  rings
 

Create the Geometry Core for used by osg::makeTorus.

Definition at line 570 of file OSGSimpleGeometry.cpp.

References osg::beginEditCP(), osg::endEditCP(), osg::getDefaultMaterial(), osg::NullFC, osg::osgcos(), osg::osgsin(), p, osg::Pi, and SWARNING.

Referenced by osg::makeTorus().

00572 {
00573     if(innerRadius <= 0 || outerRadius <= 0 || sides < 3 || rings < 3)
00574     {
00575         SWARNING << "makeTorus: illegal parameters innerRadius=" << innerRadius 
00576                  << ", outerRadius=" << outerRadius 
00577                  << ", sides=" << sides 
00578                  << ", rings=" << rings 
00579                  << std::endl;
00580         return NullFC;
00581     }
00582     
00583     GeoPositions3fPtr   pnts  = GeoPositions3f::create();
00584     GeoNormals3fPtr     norms = GeoNormals3f::create();
00585     GeoTexCoords2fPtr   tex   = GeoTexCoords2f::create();
00586     GeoIndicesUI32Ptr   index = GeoIndicesUI32::create();   
00587     GeoPLengthsUI32Ptr  lens  = GeoPLengthsUI32::create();  
00588     GeoPTypesUI8Ptr     types = GeoPTypesUI8::create();     
00589     
00590     UInt16 a, b;
00591     Real32 theta, phi;
00592     Real32 cosTheta, sinTheta;
00593     Real32 ringDelta, sideDelta;
00594 
00595     // calc the vertices
00596 
00597     GeoPositions3f::StoredFieldType   * p  = pnts->getFieldPtr();
00598     GeoNormals3f::StoredFieldType     * n  = norms->getFieldPtr();
00599     GeoTexCoords2f::StoredFieldType   * tx = tex->getFieldPtr();
00600 
00601     beginEditCP(pnts);
00602     beginEditCP(norms);
00603     beginEditCP(tex);
00604     
00605     ringDelta = 2.f * Pi / rings;
00606     sideDelta = 2.f * Pi / sides;
00607 
00608     for(a = 0, theta = 0.0; a <= rings; a++, theta += ringDelta) 
00609     {
00610         cosTheta = osgcos(theta);
00611         sinTheta = osgsin(theta);
00612 
00613         for(b = 0, phi = 0; b <= sides; b++, phi += sideDelta) 
00614         {
00615             GLfloat cosPhi, sinPhi, dist;
00616 
00617             cosPhi = osgcos(phi);
00618             sinPhi = osgsin(phi);
00619             dist   = outerRadius + innerRadius * cosPhi;
00620 
00621             n->push_back(Vec3f(cosTheta * cosPhi, 
00622                               -sinTheta * cosPhi, 
00623                               sinPhi));
00624             p->push_back(Pnt3f(cosTheta * dist, 
00625                               -sinTheta * dist, 
00626                               innerRadius * sinPhi));
00627             tx->push_back(Vec2f(- a / (Real32) rings, b / (Real32)sides));
00628         }
00629     }   
00630 
00631     endEditCP(pnts);
00632     endEditCP(norms);
00633     endEditCP(tex);
00634 
00635     // create the faces
00636     
00637     GeoIndicesUI32::StoredFieldType  * i = index->getFieldPtr();
00638     GeoPLengthsUI32::StoredFieldType * l = lens->getFieldPtr();
00639     GeoPTypesUI8::StoredFieldType    * t = types->getFieldPtr();
00640 
00641     beginEditCP(index);
00642     beginEditCP(lens);
00643     beginEditCP(types);
00644 
00645     for(a = 0; a < sides; a++) 
00646     {
00647         t->push_back(GL_TRIANGLE_STRIP);
00648         l->push_back((rings + 1) * 2);
00649         
00650         for(b = 0; b <= rings; b++)
00651         {
00652             i->push_back(b * (sides+1) + a);
00653             i->push_back(b * (sides+1) + a + 1);
00654         }
00655     }
00656 
00657     endEditCP(index);
00658     endEditCP(lens);
00659     endEditCP(types);
00660 
00661     // create the geometry
00662     
00663     GeometryPtr geo = Geometry::create();
00664 
00665     beginEditCP(geo);
00666     geo->setMaterial(getDefaultMaterial());
00667     geo->setPositions(pnts);
00668     geo->setNormals(norms);
00669     geo->getIndexMapping().push_back(Geometry::MapPosition | 
00670                                     Geometry::MapNormal   |
00671                                     Geometry::MapTexCoords);
00672     geo->setTexCoords(tex);
00673     geo->setIndices(index);
00674     geo->setTypes(types);
00675     geo->setLengths(lens);
00676     endEditCP(geo);
00677     
00678     return geo;
00679 }

NodePtr osg::makeSphere UInt16  depth,
Real32  radius
 

MakeSphere creates a sphere centered in the origin. It is created by recursive subdivision of an icosahedron, with depth giving the number of subdivisions and radius being the radius.

Definition at line 785 of file OSGSimpleGeometry.cpp.

References osg::beginEditCP(), osg::endEditCP(), osg::makeSphereGeo(), and osg::NullFC.

00786 {   
00787     GeometryPtr pGeo = makeSphereGeo(depth, radius);
00788 
00789     if(pGeo == NullFC)
00790     {
00791         return NullFC;
00792     }
00793 
00794     NodePtr node = Node::create();
00795 
00796     beginEditCP  (node);
00797     node->setCore(pGeo);
00798     endEditCP    (node);    
00799         
00800     return node;
00801 }

GeometryPtr osg::makeSphereGeo UInt16  depth,
Real32  radius
 

Create the Geometry Core for used by osg::makeSphere.

Definition at line 807 of file OSGSimpleGeometry.cpp.

References osg::VectorInterface< ValueTypeT, StorageInterfaceT >::addToZero(), osg::beginEditCP(), osg::endEditCP(), osg::Eps, osg::getDefaultMaterial(), osg::TransformationMatrix< ValueTypeT >::mult(), osg::VectorInterface< ValueTypeT, StorageInterfaceT >::normalize(), osg::osgabs(), osg::osgacos(), osg::osgatan2(), osg::osgpow(), p, osg::Pi, osg::TransformationMatrix< ValueTypeT >::setTransform(), osg::PointInterface< ValueTypeT, StorageInterfaceT >::setValue(), setVecLen(), subdivideTriangle(), X, and Z.

Referenced by osg::makeSphere().

00808 {
00809     #define X .525731112119133606
00810     #define Z .850650808352039932   
00811 
00812     GeoPositions3fPtr   pnts  = GeoPositions3f::create();
00813     GeoNormals3fPtr     norms = GeoNormals3f::create();
00814     GeoTexCoords2fPtr   tex   = GeoTexCoords2f::create();
00815     GeoIndicesUI32Ptr   index = GeoIndicesUI32::create();   
00816     GeoPLengthsPtr      lens  = GeoPLengthsUI32::create();  
00817     GeoPTypesPtr        types = GeoPTypesUI8::create();     
00818     UInt32              j,z;
00819    
00820     static Vec3f v[12] = {  Vec3f(-X, 0.,  Z),
00821                             Vec3f( X, 0.,  Z),
00822                             Vec3f(-X, 0., -Z),
00823                             Vec3f( X, 0., -Z),
00824                             Vec3f(0.,  Z,  X),
00825                             Vec3f(0.,  Z, -X),
00826                             Vec3f(0., -Z,  X),
00827                             Vec3f(0., -Z, -X),
00828                             Vec3f( Z,  X, 0.),
00829                             Vec3f(-Z,  X, 0.),
00830                             Vec3f( Z, -X, 0.),
00831                             Vec3f(-Z, -X, 0.)  };
00832 
00833     Quaternion q(Vec3f(0,1,0), osgacos(Z));
00834     Matrix mat;
00835 
00836     mat.setTransform(q);
00837 
00838     for (j=0; j<12; j++)
00839         mat.mult(v[j]);
00840                 
00841     Int32 tr[20][3] = { {1,4,0},  {4,9,0},  {4,5,9},  {8,5,4},  {1,8,4},
00842                         {1,10,8}, {10,3,8}, {8,3,5},  {3,2,5},  {3,7,2},
00843                         {3,10,7}, {10,6,7}, {6,11,7}, {6,0,11}, {6,1,0},
00844                         {10,1,6}, {11,0,9}, {2,11,9}, {5,2,9},  {11,2,7} };                  
00845                 
00846     GeoPositions3f::StoredFieldType     * p = pnts->getFieldPtr();
00847     GeoNormals3f::StoredFieldType       * n = norms->getFieldPtr();
00848     GeoTexCoords2f::StoredFieldType    * tx = tex->getFieldPtr();
00849     GeoIndicesUI32::StoredFieldType     * i = index->getFieldPtr();
00850 
00851     beginEditCP(pnts);
00852     beginEditCP(norms);
00853     beginEditCP(tex);
00854     beginEditCP(index);
00855     beginEditCP(lens);
00856     beginEditCP(types);
00857     
00858     // initial sizing to prevent reallocation halfway through
00859     UInt32 estimatedSize = UInt32(osgpow(4.f, (Real32) depth) * 20.f);
00860 
00861     p->reserve (estimatedSize);
00862     n->reserve (estimatedSize);
00863     tx->reserve(estimatedSize);
00864     i->reserve (estimatedSize);
00865     
00866     // add the initial points to the fields     
00867     for (j=0; j<12; j++) 
00868     {
00869         Vec3f pnt = v[j];
00870         Vec3f norm = v[j];
00871         
00872         setVecLen(pnt, radius);
00873         norm.normalize();
00874         
00875         p->push_back(pnt.addToZero());
00876         n->push_back(norm);
00877 
00878         Vec2f texCoord;
00879 
00880         // Theta -> v
00881         texCoord[1] = (Pi - osgacos(norm[1])) / Pi;
00882 
00883         // Phi -> u
00884         Real32 phi = osgatan2(-norm[2], norm[0]);
00885 
00886         if (phi <= -Eps)
00887             phi += (2 * Pi);
00888         phi /= (2 * Pi);
00889 
00890         texCoord[0] = phi;
00891 
00892         tx->push_back(texCoord);
00893     }
00894     
00895     // subdivide the triangles
00896     z=12;
00897     for(j=0; j<20; j++) 
00898     {
00899         subdivideTriangle(tr[j][0], tr[j][1], tr[j][2], 
00900                           depth, p, n, tx, i, z, radius);
00901     }
00902 
00903     types->push_back(GL_TRIANGLES);
00904     lens->push_back(i->size()/2);
00905     
00906     endEditCP(pnts);
00907     endEditCP(norms);
00908     endEditCP(tex);
00909     endEditCP(index);
00910     endEditCP(lens);
00911     endEditCP(types);
00912     
00913     // create the geometry
00914     GeometryPtr geo = Geometry::create();
00915 
00916     beginEditCP(geo);
00917     
00918     geo->setMaterial(getDefaultMaterial());
00919     geo->setPositions(pnts);
00920     geo->setNormals(norms);
00921     geo->getIndexMapping().push_back(Geometry::MapPosition |
00922                                      Geometry::MapNormal);
00923     geo->getIndexMapping().push_back(Geometry::MapTexCoords);
00924     geo->setTexCoords(tex);
00925     geo->setIndices(index);
00926     geo->setTypes(types);
00927     geo->setLengths(lens);
00928 
00929     endEditCP(geo);
00930 
00931     // now check triangles
00932     beginEditCP(geo);
00933 
00934     for (TriangleIterator ti = geo->beginTriangles();
00935                           ti != geo->endTriangles(); ++ti)
00936     {
00937         Vec3f q[3];
00938         q[0] = ti.getNormal(0);
00939         q[1] = ti.getNormal(1);
00940         q[2] = ti.getNormal(2);
00941 
00942         if  ( (osgabs(q[0][2]) <= 0.01 && q[0][0] >= -Eps) ||
00943               (osgabs(q[1][2]) <= 0.01 && q[1][0] >= -Eps) ||
00944               (osgabs(q[2][2]) <= 0.01 && q[2][0] >= -Eps) )
00945         {
00946             for (UInt16 i=0; i<3; i++)
00947             {
00948                 Vec3f norm(q[i]);
00949 
00950                 if (osgabs(norm[2]) <= Eps && norm[0] >= -Eps)
00951                 {
00952                     Real32 theta = (Pi - osgacos(norm[1])) / Pi;
00953                     
00954                     if ( !(q[0][2] < -Eps || q[1][2] < -Eps || q[2][2] < -Eps) )
00955                     {
00956                         Vec2f texCoord(1, theta);
00957 
00958                         if (osgabs(osgabs(norm[1]) - 1) <= Eps)
00959                             texCoord[0] = 0.5;
00960     
00961                         tex->push_back(texCoord);
00962     
00963                         index->setValue( tex->size() - 1, ti.getIndexIndex(i) + 1 );
00964                     }
00965                     else
00966                     {
00967                         Vec2f texCoord(0, theta);
00968 
00969                         if (osgabs(osgabs(norm[1]) - 1) <= Eps)
00970                             texCoord[0] = 0.5;
00971     
00972                         tex->push_back(texCoord);
00973     
00974                         index->setValue( tex->size() - 1, ti.getIndexIndex(i) + 1 );
00975                     }
00976                 }
00977             }
00978         }
00979     }
00980     
00981     endEditCP(geo);
00982 
00983     return geo;
00984 }

NodePtr osg::makeLatLongSphere UInt16  latres,
UInt16  longres,
Real32  radius
 

MakeLatLongSphere creates a sphere in the origin and divided in latitude and longitude. radius is the radius of the sphere, latres and longres are the number of subdivisions along the latitudes and longitudes.

Definition at line 993 of file OSGSimpleGeometry.cpp.

References osg::beginEditCP(), osg::endEditCP(), osg::makeLatLongSphereGeo(), and osg::NullFC.

00994 {
00995     GeometryPtr pGeo = makeLatLongSphereGeo(latres, longres, radius);
00996  
00997     if(pGeo == NullFC)
00998     {
00999         return NullFC;
01000     }
01001     
01002     NodePtr node = Node::create();
01003 
01004     beginEditCP  (node);
01005     node->setCore(pGeo);
01006     endEditCP    (node);
01007 
01008     return node;
01009 }

GeometryPtr osg::makeLatLongSphereGeo UInt16  latres,
UInt16  longres,
Real32  radius
 

Create the Geometry Core for used by osg::makeLatLongSphere.

Definition at line 1015 of file OSGSimpleGeometry.cpp.

References osg::beginEditCP(), osg::endEditCP(), osg::getDefaultMaterial(), osg::NullFC, osg::osgcos(), osg::osgsin(), p, osg::Pi, and SWARNING.

Referenced by osg::VRMLGeometryObjectDesc::endNode(), and osg::makeLatLongSphere().

01017 {
01018     if(radius <= 0 || latres < 4 || longres < 4)
01019     {
01020         SWARNING << "makeLatLongSphere: illegal parameters "
01021                  << "latres=" << latres 
01022                  << ", longres=" << longres 
01023                  << ", radius=" << radius 
01024                  << std::endl;
01025         return NullFC;
01026     }
01027     
01028     GeoPositions3fPtr   pnts  = GeoPositions3f::create();
01029     GeoNormals3fPtr     norms = GeoNormals3f::create();
01030     GeoTexCoords2fPtr   tex   = GeoTexCoords2f::create();
01031     GeoIndicesUI32Ptr   index = GeoIndicesUI32::create();   
01032     GeoPLengthsUI32Ptr  lens  = GeoPLengthsUI32::create();  
01033     GeoPTypesUI8Ptr     types = GeoPTypesUI8::create();     
01034     
01035     UInt16 a, b;
01036     Real32 theta, phi;
01037     Real32 cosTheta, sinTheta;
01038     Real32 latDelta, longDelta;
01039 
01040     // calc the vertices
01041 
01042     GeoPositions3f::StoredFieldType   * p  = pnts->getFieldPtr();
01043     GeoNormals3f::StoredFieldType     * n  = norms->getFieldPtr();
01044     GeoTexCoords2f::StoredFieldType   * tx = tex->getFieldPtr();
01045 
01046     beginEditCP(pnts);
01047     beginEditCP(norms);
01048     beginEditCP(tex);
01049     
01050     latDelta  =       Pi / latres;
01051     longDelta = 2.f * Pi / longres;
01052 
01053     for(a = 0, theta = -Pi / 2; a <= latres; a++, theta += latDelta) 
01054     {
01055         cosTheta = osgcos(theta);
01056         sinTheta = osgsin(theta);
01057 
01058         for(b = 0, phi = -Pi; b <= longres; b++, phi += longDelta) 
01059         {
01060             GLfloat cosPhi, sinPhi;
01061 
01062             cosPhi = osgcos(phi);
01063             sinPhi = osgsin(phi);
01064  
01065             n->push_back(Vec3f( cosTheta * sinPhi, 
01066                                sinTheta,
01067                                cosTheta * cosPhi));
01068             p->push_back(Pnt3f( cosTheta * sinPhi * radius, 
01069                                sinTheta          * radius, 
01070                                cosTheta * cosPhi * radius));
01071             tx->push_back(Vec2f(b / (Real32)longres, 
01072                                a / (Real32)latres));
01073         }
01074     }   
01075 
01076     endEditCP(pnts);
01077     endEditCP(norms);
01078     endEditCP(tex);
01079 
01080     // create the faces
01081     
01082     GeoIndicesUI32::StoredFieldType  * i = index->getFieldPtr();
01083     GeoPLengthsUI32::StoredFieldType * l = lens->getFieldPtr();
01084     GeoPTypesUI8::StoredFieldType    * t = types->getFieldPtr();
01085 
01086     beginEditCP(index);
01087     beginEditCP(lens);
01088     beginEditCP(types);
01089 
01090     for(a = 0; a < longres; a++) 
01091     {
01092         t->push_back(GL_TRIANGLE_STRIP);
01093         l->push_back((latres + 1) * 2);
01094         
01095         for(b = 0; b <= latres; b++)
01096         {
01097             i->push_back(b * (longres+1) + a);
01098             i->push_back(b * (longres+1) + a + 1);
01099         }
01100     }
01101 
01102     endEditCP(index);
01103     endEditCP(lens);
01104     endEditCP(types);
01105 
01106     // create the geometry
01107     
01108     GeometryPtr geo = Geometry::create();
01109 
01110     beginEditCP(geo);
01111     geo->setMaterial(getDefaultMaterial());
01112     geo->setPositions(pnts);
01113     geo->setNormals(norms);
01114     geo->getIndexMapping().push_back(Geometry::MapPosition | 
01115                                     Geometry::MapNormal   |
01116                                     Geometry::MapTexCoords);
01117     geo->setTexCoords(tex);
01118     geo->setIndices(index);
01119     geo->setTypes(types);
01120     geo->setLengths(lens);
01121     endEditCP(geo);
01122     
01123     return geo;
01124 }

NodePtr osg::makeBox Real32  xsize,
Real32  ysize,
Real32  zsize,
UInt16  hor,
UInt16  vert,
UInt16  depth
 

MakeBox creates a box around the origin. It spans the [-xsize /2,xsize /2]x [-ysize /2,ysize/2]x[-zsize /2,zsize/2] volume and is subdivided into hor * vert * depth quads.

Definition at line 1134 of file OSGSimpleGeometry.cpp.

References osg::beginEditCP(), osg::endEditCP(), osg::makeBoxGeo(), and osg::NullFC.

01136 {
01137     GeometryPtr pGeo = makeBoxGeo(xsize, ysize, zsize, hor, vert, depth);
01138 
01139     if(pGeo == NullFC)