Ported various demos and support classes over to use the new osg::Geometry class
thus removing dependancy on osg::Geoset from most of the OSG, only loaders left to port now.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#include <math.h>
|
||||
|
||||
#include <osg/Geode>
|
||||
#include <osg/GeoSet>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/Texture>
|
||||
#include <osg/TexEnv>
|
||||
#include <osg/Depth>
|
||||
@@ -15,54 +15,39 @@ Node *makeBase( void )
|
||||
{
|
||||
int i, c;
|
||||
float theta;
|
||||
float ir, ori;
|
||||
ir = 0.0;
|
||||
ori = 20.0;
|
||||
float ir = 20.0f;
|
||||
|
||||
Vec3 *coords = new Vec3[38];
|
||||
Vec2 *tcoords = new Vec2[38];
|
||||
Vec4 *colors = new Vec4[1];
|
||||
Vec3Array *coords = new Vec3Array(19);
|
||||
Vec2Array *tcoords = new Vec2Array(19);
|
||||
Vec4Array *colors = new Vec4Array(1);
|
||||
int *lengths = new int[1];
|
||||
|
||||
colors[0][0] = colors[0][1] = colors[0][2] = colors[0][3] = 1;
|
||||
(*colors)[0].set(1.0f,1.0f,1.0f,1.0f);
|
||||
|
||||
c = 0;
|
||||
(*coords)[c].set(0.0f,0.0f,0.0f);
|
||||
(*tcoords)[c].set(0.0f,0.0f);
|
||||
|
||||
for( i = 0; i <= 18; i++ )
|
||||
{
|
||||
theta = osg::DegreesToRadians((float)i * 20.0);
|
||||
|
||||
coords[c][0] = ir * cosf( theta );
|
||||
coords[c][1] = ir * sinf( theta );
|
||||
coords[c][2] = 0.0;
|
||||
tcoords[c][0] = coords[c][0]/36.;
|
||||
tcoords[c][1] = coords[c][1]/36.;
|
||||
|
||||
c++;
|
||||
|
||||
coords[c][0] = ori * cosf( theta );
|
||||
coords[c][1] = ori * sinf( theta );
|
||||
coords[c][2] = 0.0f;
|
||||
|
||||
tcoords[c][0] = coords[c][0]/36.;
|
||||
tcoords[c][1] = coords[c][1]/36.;
|
||||
(*coords)[c].set(ir * cosf( theta ), ir * sinf( theta ), 0.0f);
|
||||
(*tcoords)[c].set((*coords)[c][0]/36.0f,(*coords)[c][1]/36.0f);
|
||||
|
||||
c++;
|
||||
}
|
||||
*lengths = 38;
|
||||
|
||||
GeoSet *gset = new GeoSet;
|
||||
Geometry *geom = new Geometry;
|
||||
|
||||
gset->setCoords( coords );
|
||||
geom->setVertexArray( coords );
|
||||
|
||||
gset->setTextureCoords( tcoords );
|
||||
gset->setTextureBinding( GeoSet::BIND_PERVERTEX );
|
||||
geom->setTexCoordArray( 0, tcoords );
|
||||
|
||||
gset->setColors( colors );
|
||||
gset->setColorBinding( GeoSet::BIND_OVERALL );
|
||||
geom->setColorArray( colors );
|
||||
geom->setColorBinding( Geometry::BIND_OVERALL );
|
||||
|
||||
gset->setPrimType( GeoSet::TRIANGLE_STRIP );
|
||||
gset->setNumPrims( 1 );
|
||||
gset->setPrimLengths( lengths );
|
||||
geom->addPrimitive( new DrawArrays(Primitive::TRIANGLE_FAN,0,19) );
|
||||
|
||||
Texture *tex = new Texture;
|
||||
|
||||
@@ -75,16 +60,6 @@ Node *makeBase( void )
|
||||
dstate->setAttributeAndModes( tex, StateAttribute::ON );
|
||||
|
||||
dstate->setAttribute( new TexEnv );
|
||||
/*
|
||||
pfFog *fog = new pfFog;
|
||||
|
||||
fog->setFogType( PFFOG_PIX_EXP2 );
|
||||
fog->setColor( 0.1, 0.2, 0.2 );
|
||||
fog->setRange( 16.0, 22.0 );
|
||||
|
||||
gstate->setMode( PFSTATE_ENFOG, PF_ON );
|
||||
gstate->setAttr( PFSTATE_FOG, fog );
|
||||
*/
|
||||
|
||||
// clear the depth to the far plane.
|
||||
osg::Depth* depth = new osg::Depth;
|
||||
@@ -95,10 +70,10 @@ Node *makeBase( void )
|
||||
dstate->setRenderBinDetails(-1,"RenderBin");
|
||||
|
||||
|
||||
gset->setStateSet( dstate );
|
||||
geom->setStateSet( dstate );
|
||||
|
||||
Geode *geode = new Geode;
|
||||
geode->addDrawable( gset );
|
||||
geode->addDrawable( geom );
|
||||
|
||||
return geode;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <math.h>
|
||||
|
||||
#include <osg/Geode>
|
||||
#include <osg/GeoSet>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/Texture>
|
||||
#include <osg/TexEnv>
|
||||
#include <osg/Depth>
|
||||
@@ -35,12 +35,13 @@ Node *makeSky( void )
|
||||
float radius = 20.0f;
|
||||
int nlev = sizeof( lev )/sizeof(float);
|
||||
|
||||
Vec3 *coords = new Vec3[19*nlev];
|
||||
Vec4 *colors = new Vec4[19*nlev];
|
||||
Vec2 *tcoords = new Vec2[19*nlev];
|
||||
osg::ushort *idx = new osg::ushort[38* nlev];
|
||||
int *lengths = new int[nlev];
|
||||
Geometry *geom = new Geometry;
|
||||
|
||||
Vec3Array& coords = *(new Vec3Array(19*nlev));
|
||||
Vec4Array& colors = *(new Vec4Array(19*nlev));
|
||||
Vec2Array& tcoords = *(new Vec2Array(19*nlev));
|
||||
|
||||
|
||||
int ci, ii;
|
||||
ii = ci = 0;
|
||||
|
||||
@@ -68,25 +69,35 @@ Node *makeSky( void )
|
||||
tcoords[ci][0] = (float)i/(float)(nlev-1);
|
||||
|
||||
ci++;
|
||||
|
||||
idx[ii++] = ((i+1)*19+j);
|
||||
idx[ii++] = ((i+0)*19+j);
|
||||
}
|
||||
lengths[i] = 38;
|
||||
|
||||
|
||||
}
|
||||
|
||||
GeoSet *gset = new GeoSet;
|
||||
for( i = 0; i < nlev-1; i++ )
|
||||
{
|
||||
for( j = 0; j <= 18; j++ )
|
||||
{
|
||||
|
||||
gset->setCoords( coords, idx );
|
||||
gset->setTextureCoords( tcoords, idx );
|
||||
gset->setTextureBinding( GeoSet::BIND_PERVERTEX );
|
||||
UShortDrawElements* drawElements = new UShortDrawElements(Primitive::TRIANGLE_STRIP);
|
||||
drawElements->reserve(38);
|
||||
|
||||
gset->setColors( colors, idx );
|
||||
gset->setColorBinding( GeoSet::BIND_PERVERTEX );
|
||||
for( j = 0; j <= 18; j++ )
|
||||
{
|
||||
drawElements->push_back((i+1)*19+j);
|
||||
drawElements->push_back((i+0)*19+j);
|
||||
}
|
||||
|
||||
geom->addPrimitive(drawElements);
|
||||
}
|
||||
}
|
||||
|
||||
geom->setVertexArray( &coords );
|
||||
geom->setTexCoordArray( 0, &tcoords );
|
||||
|
||||
geom->setColorArray( &colors );
|
||||
geom->setColorBinding( Geometry::BIND_PER_VERTEX );
|
||||
|
||||
gset->setPrimType( GeoSet::TRIANGLE_STRIP );
|
||||
gset->setNumPrims( nlev - 1 );
|
||||
gset->setPrimLengths( lengths );
|
||||
|
||||
Texture *tex = new Texture;
|
||||
tex->setImage(osgDB::readImageFile("Images/white.rgb"));
|
||||
@@ -107,10 +118,10 @@ Node *makeSky( void )
|
||||
|
||||
dstate->setRenderBinDetails(-2,"RenderBin");
|
||||
|
||||
gset->setStateSet( dstate );
|
||||
geom->setStateSet( dstate );
|
||||
|
||||
Geode *geode = new Geode;
|
||||
geode->addDrawable( gset );
|
||||
geode->addDrawable( geom );
|
||||
|
||||
geode->setName( "Sky" );
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <osg/GL>
|
||||
#include <osg/Group>
|
||||
#include <osg/Geode>
|
||||
#include <osg/GeoSet>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/Texture>
|
||||
#include <osg/TexEnv>
|
||||
#include <osg/StateSet>
|
||||
@@ -44,7 +44,7 @@ static void conv( const Vec3& a, const Matrix& mat, Vec3& b )
|
||||
Node *makeTank( void )
|
||||
{
|
||||
|
||||
Geode *geode1 = new Geode;
|
||||
Geode *geode = new Geode;
|
||||
|
||||
getDatabaseCenterRadius( dbcenter, &dbradius );
|
||||
|
||||
@@ -58,12 +58,16 @@ Node *makeTank( void )
|
||||
1
|
||||
);
|
||||
|
||||
Vec3 *vc = new Vec3[42];
|
||||
Vec2 *tc = new Vec2[42];
|
||||
int *lens = new int[1];
|
||||
int i, c;
|
||||
// 42 required for sodes, 22 for the top.
|
||||
Vec3Array& vc = *(new Vec3Array(42+22));
|
||||
Vec2Array& tc = *(new Vec2Array(42+22));
|
||||
|
||||
c = 0;
|
||||
Geometry *gset = new Geometry;
|
||||
gset->setVertexArray( &vc );
|
||||
gset->setTexCoordArray( 0, &tc );
|
||||
|
||||
// create the sides of the tank.
|
||||
unsigned int i, c = 0;
|
||||
for( i = 0; i <= 360; i += 18 )
|
||||
{
|
||||
float x, y, z;
|
||||
@@ -97,41 +101,13 @@ Node *makeTank( void )
|
||||
tc[c][1] = t;
|
||||
c++;
|
||||
}
|
||||
*lens = 42;
|
||||
|
||||
for( i = 0; i < c; i++ )
|
||||
conv( vc[i], *mat, vc[i] );
|
||||
gset->addPrimitive( new DrawArrays(Primitive::TRIANGLE_STRIP,0,c) );
|
||||
|
||||
GeoSet *gset = new GeoSet;
|
||||
gset->setCoords( vc );
|
||||
// create the top of the tank.
|
||||
|
||||
gset->setTextureCoords( tc );
|
||||
gset->setTextureBinding( GeoSet::BIND_PERVERTEX );
|
||||
int prev_c = c;
|
||||
|
||||
gset->setPrimType( GeoSet::TRIANGLE_STRIP );
|
||||
gset->setNumPrims( 1 );
|
||||
gset->setPrimLengths( lens );
|
||||
|
||||
Texture *tex = new Texture;
|
||||
|
||||
tex->setWrap( Texture::WRAP_S, Texture::REPEAT );
|
||||
tex->setWrap( Texture::WRAP_T, Texture::REPEAT );
|
||||
tex->setImage(osgDB::readImageFile("Images/tank.rgb"));
|
||||
|
||||
StateSet *dstate = new StateSet;
|
||||
dstate->setAttributeAndModes( tex, StateAttribute::ON );
|
||||
dstate->setAttribute( new TexEnv );
|
||||
|
||||
gset->setStateSet( dstate );
|
||||
geode1->addDrawable( gset );
|
||||
|
||||
lens = new int[1];
|
||||
*lens = 22;
|
||||
|
||||
vc = new Vec3[22];
|
||||
tc = new Vec2[22];
|
||||
|
||||
c = 0;
|
||||
vc[c][0] = 0.0f;
|
||||
vc[c][1] = 0.0f;
|
||||
vc[c][2] = 1.0f;
|
||||
@@ -167,26 +143,24 @@ Node *makeTank( void )
|
||||
|
||||
for( i = 0; i < c; i++ )
|
||||
conv( vc[i], *mat, vc[i] );
|
||||
|
||||
gset->addPrimitive(new DrawArrays(Primitive::TRIANGLE_FAN,prev_c,c-prev_c));
|
||||
|
||||
gset = new GeoSet;
|
||||
gset->setCoords( vc );
|
||||
gset->setTextureCoords( tc );
|
||||
gset->setPrimType(GeoSet::TRIANGLE_FAN);
|
||||
gset->setNumPrims( 1 );
|
||||
gset->setPrimLengths( lens );
|
||||
|
||||
|
||||
|
||||
Texture *tex = new Texture;
|
||||
|
||||
tex->setWrap( Texture::WRAP_S, Texture::REPEAT );
|
||||
tex->setWrap( Texture::WRAP_T, Texture::REPEAT );
|
||||
tex->setImage(osgDB::readImageFile("Images/tank.rgb"));
|
||||
|
||||
StateSet *dstate = new StateSet;
|
||||
dstate->setAttributeAndModes( tex, StateAttribute::ON );
|
||||
dstate->setAttribute( new TexEnv );
|
||||
|
||||
gset->setStateSet( dstate );
|
||||
geode->addDrawable( gset );
|
||||
|
||||
Geode *geode2 = new Geode;
|
||||
geode2->addDrawable( gset );
|
||||
|
||||
|
||||
Group *grp = new Group;
|
||||
grp->addChild( geode1 );
|
||||
grp->addChild( geode2 );
|
||||
|
||||
geode1->setName( "Geode 1" );
|
||||
geode2->setName( "Geode 2" );
|
||||
|
||||
return grp;
|
||||
return geode;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// #include <math.h>
|
||||
|
||||
#include <osg/Geode>
|
||||
#include <osg/GeoSet>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/Texture>
|
||||
#include <osg/TexEnv>
|
||||
#include <osg/StateSet>
|
||||
@@ -73,15 +73,11 @@ Node *makeTerrain( void )
|
||||
m = (sizeof( vertex ) /(sizeof( float[3])))/39;
|
||||
n = 39;
|
||||
|
||||
Vec3 *v = new Vec3[m*n];
|
||||
Vec2 *t = new Vec2[m*n];
|
||||
Vec4 *col = new Vec4[1];
|
||||
osg::ushort *cidx = new osg::ushort[1];
|
||||
osg::ushort *idx = new osg::ushort[m*n*2];
|
||||
int *lens = new int[m];
|
||||
|
||||
col[0][0] = col[0][1] = col[0][2] = col[0][3] = 1;
|
||||
*cidx = 0;
|
||||
Vec3Array& v = *(new Vec3Array(m*n));
|
||||
Vec2Array& t = *(new Vec2Array(m*n));
|
||||
Vec4Array& col = *(new Vec4Array(1));
|
||||
|
||||
col[0][0] = col[0][1] = col[0][2] = col[0][3] = 1.0f;
|
||||
|
||||
for( i = 0; i < m * n; i++ )
|
||||
{
|
||||
@@ -93,29 +89,27 @@ Node *makeTerrain( void )
|
||||
t[i][1] = texcoord[i][1];
|
||||
}
|
||||
|
||||
Geometry *geom = new Geometry;
|
||||
|
||||
geom->setVertexArray( &v );
|
||||
geom->setTexCoordArray( 0, &t );
|
||||
|
||||
geom->setColorArray( &col );
|
||||
geom->setColorBinding( Geometry::BIND_OVERALL );
|
||||
|
||||
c = 0;
|
||||
for( i = 0; i < m-2; i++ )
|
||||
{
|
||||
UShortDrawElements* elements = new UShortDrawElements(Primitive::TRIANGLE_STRIP);
|
||||
elements->reserve(39*2);
|
||||
for( j = 0; j < n; j++ )
|
||||
{
|
||||
idx[c++] = (i+0)*n+j;
|
||||
idx[c++] = (i+1)*n+j;
|
||||
elements->push_back((i+0)*n+j);
|
||||
elements->push_back((i+1)*n+j);
|
||||
}
|
||||
lens[i] = 39*2;
|
||||
geom->addPrimitive(elements);
|
||||
}
|
||||
|
||||
GeoSet *gset = new GeoSet;
|
||||
|
||||
gset->setCoords( v, idx );
|
||||
gset->setTextureCoords( t, idx );
|
||||
gset->setTextureBinding( GeoSet::BIND_PERVERTEX );
|
||||
|
||||
gset->setColors( col, cidx );
|
||||
gset->setColorBinding( GeoSet::BIND_OVERALL );
|
||||
|
||||
gset->setPrimType( GeoSet::TRIANGLE_STRIP );
|
||||
gset->setNumPrims( m-2 );
|
||||
gset->setPrimLengths( lens );
|
||||
|
||||
Texture *tex = new Texture;
|
||||
|
||||
@@ -126,12 +120,10 @@ Node *makeTerrain( void )
|
||||
dstate->setAttributeAndModes( tex, StateAttribute::ON );
|
||||
dstate->setAttribute( new TexEnv );
|
||||
|
||||
gset->setStateSet( dstate );
|
||||
geom->setStateSet( dstate );
|
||||
|
||||
Geode *geode = new Geode;
|
||||
geode->addDrawable( gset );
|
||||
|
||||
gset->check();
|
||||
geode->addDrawable( geom );
|
||||
|
||||
return geode;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <osg/Billboard>
|
||||
#include <osg/Group>
|
||||
#include <osg/Geode>
|
||||
#include <osg/GeoSet>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/Texture>
|
||||
#include <osg/TexEnv>
|
||||
#include <osg/Transparency>
|
||||
@@ -144,7 +144,7 @@ trees[] =
|
||||
{ -1, 0, 0, 0, 0, 0 },
|
||||
};
|
||||
|
||||
static GeoSet *makeTree( _tree *tree, StateSet *dstate )
|
||||
static Geometry *makeTree( _tree *tree, StateSet *dstate )
|
||||
{
|
||||
float vv[][3] =
|
||||
{
|
||||
@@ -154,9 +154,9 @@ static GeoSet *makeTree( _tree *tree, StateSet *dstate )
|
||||
{ -tree->w/2.0, 0.0, 2 * tree->h },
|
||||
};
|
||||
|
||||
Vec3 *v = new Vec3[4];
|
||||
Vec2 *t = new Vec2[4];
|
||||
Vec4 *l = new Vec4[1];
|
||||
Vec3Array& v = *(new Vec3Array(4));
|
||||
Vec2Array& t = *(new Vec2Array(4));
|
||||
Vec4Array& l = *(new Vec4Array(1));
|
||||
|
||||
int i;
|
||||
|
||||
@@ -174,22 +174,20 @@ static GeoSet *makeTree( _tree *tree, StateSet *dstate )
|
||||
t[2][0] = 1.0; t[2][1] = 1.0;
|
||||
t[3][0] = 0.0; t[3][1] = 1.0;
|
||||
|
||||
GeoSet *gset = new GeoSet;
|
||||
Geometry *geom = new Geometry;
|
||||
|
||||
gset->setCoords( v );
|
||||
geom->setVertexArray( &v );
|
||||
|
||||
gset->setTextureCoords( t );
|
||||
gset->setTextureBinding( GeoSet::BIND_PERVERTEX );
|
||||
geom->setTexCoordArray( 0, &t );
|
||||
|
||||
gset->setColors( l );
|
||||
gset->setColorBinding( GeoSet::BIND_OVERALL );
|
||||
geom->setColorArray( &l );
|
||||
geom->setColorBinding( Geometry::BIND_OVERALL );
|
||||
|
||||
gset->setPrimType( GeoSet::QUADS );
|
||||
gset->setNumPrims( 1 );
|
||||
geom->addPrimitive( new DrawArrays(Primitive::QUADS,0,4) );
|
||||
|
||||
gset->setStateSet( dstate );
|
||||
geom->setStateSet( dstate );
|
||||
|
||||
return gset;
|
||||
return geom;
|
||||
}
|
||||
|
||||
|
||||
@@ -263,8 +261,8 @@ Node *makeTrees( void )
|
||||
t->x -= 0.3f;
|
||||
float h = Hat(t->x, t->y, t->z );
|
||||
Vec3 pos( t->x, t->y, t->z-h );
|
||||
GeoSet *gset = makeTree( t, dstate );
|
||||
bb->addDrawable( gset, pos );
|
||||
Geometry *geom = makeTree( t, dstate );
|
||||
bb->addDrawable( geom, pos );
|
||||
t++;
|
||||
}
|
||||
group->addChild( bb );
|
||||
|
||||
Reference in New Issue
Block a user