OpenWalnut  1.5.0dev
WDemoGeometry.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <osg/Geode>
26 #include <osg/ShapeDrawable>
27 
28 #include "core/graphicsEngine/WGEGeodeUtils.h"
29 
30 #include "WDemoGeometry.h"
31 
32 osg::ref_ptr< osg::Node > WDemoGeometry::createSphereGeometry()
33 {
34  // Create some spheres using the OSG functionality. To understand the following code, we would like to refer you to the OpenSceneGraph
35  // documentation.
36 
37  // add a bunch of spheres to a group and return it. Normals are set but no color.
38  osg::ref_ptr< osg::Group > group( new osg::Group );
39 
40  // add 5 spheres with increasing size and add them along the X axis
41  float x = 2.0;
42  for( size_t i = 0; i < 5; ++i )
43  {
44  // Create a sphere.
45  osg::Geode* sphereGeode = new osg::Geode;
46  sphereGeode->addDrawable(
47  new osg::ShapeDrawable(
48  new osg::Sphere(
49  osg::Vec3d( x, 50.0, 2 + i * 3 ), // moving center
50  2 + i * 3 // increasing radius
51  )
52  )
53  );
54 
55  // move the spheres along the X axis a bit each time
56  x += 2 + 2 * i * 3 + 10.0;
57 
58  // Add to group.
59  group->addChild( sphereGeode );
60  }
61  return group;
62 }
63 
64 osg::ref_ptr< osg::Node > WDemoGeometry::createPlaneGeometry()
65 {
66  // Create a nice plane. We use a pre-defined function in OpenWalnut's graphics engine:
67  return wge::genFinitePlane( osg::Vec3( 0.0, 0.0, 0.0 ), // base
68  osg::Vec3( 100.0, 0.0, 0.0 ), // spanning vector a
69  osg::Vec3( 0.0, 100.0, 0.0 ), // spanning vector b
70  WColor( 0.5, 0.5, 0.5, 1.0 ) // a color.
71  );
72 }
73 
osg::ref_ptr< osg::Node > createSphereGeometry()
Create several spheres.
osg::ref_ptr< osg::Node > createPlaneGeometry()
Create a plane.
osg::ref_ptr< osg::Geode > genFinitePlane(double xSize, double ySize, const WPlane &p, const WColor &color=WColor(0.0, 0.7, 0.7, 1.0), bool border=false)
Generates a geode out of a Plane with a fixed size in direction of the vectors which span that plane.