| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | #include <math.h> |
|---|
| 20 | |
|---|
| 21 | #include <osg/Geode> |
|---|
| 22 | #include <osg/Geometry> |
|---|
| 23 | #include <osg/Texture2D> |
|---|
| 24 | #include <osg/TexEnv> |
|---|
| 25 | #include <osg/Depth> |
|---|
| 26 | #include <osg/StateSet> |
|---|
| 27 | |
|---|
| 28 | #include <osgDB/ReadFile> |
|---|
| 29 | |
|---|
| 30 | using namespace osg; |
|---|
| 31 | |
|---|
| 32 | Node *makeBase( void ) |
|---|
| 33 | { |
|---|
| 34 | int i, c; |
|---|
| 35 | float theta; |
|---|
| 36 | float ir = 20.0f; |
|---|
| 37 | |
|---|
| 38 | Vec3Array *coords = new Vec3Array(19); |
|---|
| 39 | Vec2Array *tcoords = new Vec2Array(19); |
|---|
| 40 | Vec4Array *colors = new Vec4Array(1); |
|---|
| 41 | |
|---|
| 42 | (*colors)[0].set(1.0f,1.0f,1.0f,1.0f); |
|---|
| 43 | |
|---|
| 44 | c = 0; |
|---|
| 45 | (*coords)[c].set(0.0f,0.0f,0.0f); |
|---|
| 46 | (*tcoords)[c].set(0.0f,0.0f); |
|---|
| 47 | |
|---|
| 48 | for( i = 0; i <= 18; i++ ) |
|---|
| 49 | { |
|---|
| 50 | theta = osg::DegreesToRadians((float)i * 20.0); |
|---|
| 51 | |
|---|
| 52 | (*coords)[c].set(ir * cosf( theta ), ir * sinf( theta ), 0.0f); |
|---|
| 53 | (*tcoords)[c].set((*coords)[c][0]/36.0f,(*coords)[c][1]/36.0f); |
|---|
| 54 | |
|---|
| 55 | c++; |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | Geometry *geom = new Geometry; |
|---|
| 59 | |
|---|
| 60 | geom->setVertexArray( coords ); |
|---|
| 61 | |
|---|
| 62 | geom->setTexCoordArray( 0, tcoords ); |
|---|
| 63 | |
|---|
| 64 | geom->setColorArray( colors ); |
|---|
| 65 | geom->setColorBinding( Geometry::BIND_OVERALL ); |
|---|
| 66 | |
|---|
| 67 | geom->addPrimitiveSet( new DrawArrays(PrimitiveSet::TRIANGLE_FAN,0,19) ); |
|---|
| 68 | |
|---|
| 69 | Texture2D *tex = new Texture2D; |
|---|
| 70 | |
|---|
| 71 | tex->setImage(osgDB::readImageFile("Images/water.rgb")); |
|---|
| 72 | tex->setWrap( Texture2D::WRAP_S, Texture2D::REPEAT ); |
|---|
| 73 | tex->setWrap( Texture2D::WRAP_T, Texture2D::REPEAT ); |
|---|
| 74 | |
|---|
| 75 | StateSet *dstate = new StateSet; |
|---|
| 76 | dstate->setMode( GL_LIGHTING, StateAttribute::OFF ); |
|---|
| 77 | dstate->setTextureAttributeAndModes(0, tex, StateAttribute::ON ); |
|---|
| 78 | |
|---|
| 79 | dstate->setTextureAttribute(0, new TexEnv ); |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | osg::Depth* depth = new osg::Depth; |
|---|
| 83 | depth->setFunction(osg::Depth::ALWAYS); |
|---|
| 84 | depth->setRange(1.0,1.0); |
|---|
| 85 | dstate->setAttributeAndModes(depth,StateAttribute::ON ); |
|---|
| 86 | |
|---|
| 87 | dstate->setRenderBinDetails(-1,"RenderBin"); |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | geom->setStateSet( dstate ); |
|---|
| 91 | |
|---|
| 92 | Geode *geode = new Geode; |
|---|
| 93 | geode->addDrawable( geom ); |
|---|
| 94 | |
|---|
| 95 | return geode; |
|---|
| 96 | } |
|---|