root/OpenSceneGraph/trunk/examples/osghangglide/base.cpp @ 6941

Revision 6941, 2.8 kB (checked in by robert, 8 years ago)

From Martin Lavery and Robert Osfield, Updated examples to use a variation of the MIT License

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* OpenSceneGraph example, osghangglide.
2*
3*  Permission is hereby granted, free of charge, to any person obtaining a copy
4*  of this software and associated documentation files (the "Software"), to deal
5*  in the Software without restriction, including without limitation the rights
6*  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7*  copies of the Software, and to permit persons to whom the Software is
8*  furnished to do so, subject to the following conditions:
9*
10*  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
11*  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12*  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
13*  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
14*  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
15*  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
16*  THE SOFTWARE.
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
30using namespace osg;
31
32Node *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    // clear the depth to the far plane.
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}
Note: See TracBrowser for help on using the browser.