OSGSimpleGeometry.cpp File Reference

#include <stdlib.h>
#include <stdio.h>
#include "OSGConfig.h"
#include <OSGLog.h>
#include <OSGQuaternion.h>
#include <OSGSimpleMaterial.h>
#include <OSGTriangleIterator.h>
#include "OSGSimpleGeometry.h"

Go to the source code of this file.

Namespaces

namespace  osg

Functions

Real32 setVecLen (Vec3f &vec, Real32 length)
Real32 calcTexS (Vec3f &n, Real32 theta)
void addPoint (Pnt3f v, UInt32 index, Real32 radius, GeoPositions3f::StoredFieldType *p, GeoNormals3f::StoredFieldType *n, GeoTexCoords2f::StoredFieldType *tx)
void subdivideTriangle (UInt32 i1, UInt32 i2, UInt32 i3, Int32 depth, GeoPositions3f::StoredFieldType *p, GeoNormals3f::StoredFieldType *n, GeoTexCoords2f::StoredFieldType *tx, GeoIndicesUI32::StoredFieldType *i, UInt32 &z, Real32 radius)
GeoPositions3fPtr osg::makeGeoPositions3fPtr (UInt32 uiSize)
 some workaround functions for Windows problems
GeoIndicesUI32Ptr osg::makeGeoIndicesUI32Ptr (UInt32 uiSize)
GeoPLengthsPtr osg::makeGeoPLengthsPtr (UInt32 uiSize)
GeoPTypesPtr osg::makeGeoPTypesPtr (UInt32 uiSize)
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)

Variables

static SimpleMaterialPtr _defaultMaterial
static SimpleMaterialPtr _defaultUnlitMaterial


Function Documentation

Real32 setVecLen ( Vec3f vec,
Real32  length 
)

Definition at line 683 of file OSGSimpleGeometry.cpp.

References osg::VectorInterface< ValueTypeT, StorageInterfaceT >::length().

Referenced by osg::makeSphereGeo().

00684 {
00685     Real32 len = vec.length();
00686     if(len == 0.0) 
00687     {
00688         len = 1;
00689     } 
00690     else 
00691     {
00692         len = length / len;
00693     }
00694     vec *= len;
00695     
00696     return length;
00697 }

Real32 calcTexS ( Vec3f n,
Real32  theta 
)

Definition at line 699 of file OSGSimpleGeometry.cpp.

References osg::Eps, and osg::osgatan2().

Referenced by addPoint(), and osg::makeSphereGeo().

00700 {
00701     const Real32 TwoPi  = 6.283185307179586;
00702     const Real32 HalfPi = 1.570796326794897;
00703     
00704     Real32 phi = osgatan2(-n[2], n[0]) - HalfPi;
00705 
00706     if (phi <= -Eps)
00707         phi += TwoPi;
00708     phi /= TwoPi;
00709     
00710     return phi;
00711 }

void addPoint ( Pnt3f  v,
UInt32  index,
Real32  radius,
GeoPositions3f::StoredFieldType *  p,
GeoNormals3f::StoredFieldType *  n,
GeoTexCoords2f::StoredFieldType *  tx 
)

Definition at line 713 of file OSGSimpleGeometry.cpp.

References calcTexS(), osg::VectorInterface< ValueTypeT, StorageInterfaceT >::normalize(), osg::osgacos(), and osg::Pi.

Referenced by subdivideTriangle().

00717 {
00718     Vec3f norm(v[0], v[1], v[2]);
00719 
00720     norm.normalize();
00721     n->push_back(norm);
00722 
00723     Pnt3f pnt(radius * norm);
00724     p->push_back(pnt);
00725 
00726     Vec2f texCoord;
00727 
00728     // Theta -> v
00729     texCoord[1] = (Pi - osgacos(norm[1])) / Pi;
00730 
00731     // Phi -> u
00732     texCoord[0] = calcTexS(norm, texCoord[1]);
00733 
00734     tx->push_back(texCoord);
00735 }

void subdivideTriangle ( UInt32  i1,
UInt32  i2,
UInt32  i3,
Int32  depth,
GeoPositions3f::StoredFieldType *  p,
GeoNormals3f::StoredFieldType *  n,
GeoTexCoords2f::StoredFieldType *  tx,
GeoIndicesUI32::StoredFieldType *  i,
UInt32 &  z,
Real32  radius 
)

Definition at line 737 of file OSGSimpleGeometry.cpp.

References addPoint().

Referenced by osg::makeSphereGeo().

00746 {   
00747     if (depth == 0) 
00748     {
00749         i->push_back(i1);
00750         i->push_back(i1);
00751         i->push_back(i2);
00752         i->push_back(i2);
00753         i->push_back(i3);
00754         i->push_back(i3);
00755                             
00756         return;         
00757     }
00758 
00759     Pnt3f v1 = (*p)[i1],
00760           v2 = (*p)[i2],
00761           v3 = (*p)[i3];
00762     Pnt3f v12, v23, v31;
00763 
00764     v12 = v1 + (v2 - v1) * .5f;
00765     v23 = v2 + (v3 - v2) * .5f;
00766     v31 = v3 + (v1 - v3) * .5f;
00767     
00768     v12 /= 2.0f;
00769     v23 /= 2.0f;
00770     v31 /= 2.0f;
00771     
00772     UInt32 i12 = z++, i23 = z++, i31 = z++;
00773 
00774     addPoint(v12,i12,radius,p,n,tx);
00775     addPoint(v23,i23,radius,p,n,tx);
00776     addPoint(v31,i31,radius,p,n,tx);
00777     
00778     subdivideTriangle( i1, i12, i31, depth - 1, p,n,tx,i, z, radius);
00779     subdivideTriangle( i2, i23, i12, depth - 1, p,n,tx,i, z, radius);
00780     subdivideTriangle( i3, i31, i23, depth - 1, p,n,tx,i, z, radius);
00781     subdivideTriangle(i12, i23, i31, depth - 1, p,n,tx,i, z, radius);
00782 }


Generated on Mon Mar 17 12:02:44 2008 for OpenSG by  doxygen 1.5.5