vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
grass_parameters.h
Go to the documentation of this file.
1 #ifndef GRASS_PARAMETERS_H
2 #define GRASS_PARAMETERS_H
3 
4 #include <vrecko/ReaderWriter.h>
5 #include <gl/gl.h>
6 #include <vector>
7 #include <osg/Texture2D>
8 
9 namespace grass
10 {
11 
12  // predeclaration
13  class GrassCullCallback;
14 
15 
16  // holds parameters of the Grass ability.
17  struct GrassAbilityParameters : osg::Referenced
18  {
19  private:
20  // copying of this object is not wanted
22 
23  // returns the half of width of "ideal" grass blade at y-position (bottom: y = 0.0f, top: y = 1.0f)
24  inline float GrassBladeProfile(float y)
25  { return 0.5f * (0.5f + y*y*(9.3f - y*(19.6f - 9.8f*y))); } // :)
26 
27  // creates a set of grassBlades within given context
28  void CreateGrassBlades();
29 
30  // internal method which prepares both statesets
31  void PrepareStateSets();
32 
33  // texture used for texturing blades of grass, far grass, and far soil
34  osg::ref_ptr<osg::Texture2D> bladeTexture, farSoilTexture, farGrassTexture;
35 
36  public:
37  // ensures that grass-blades are prepared
39  {
40  if(grassBlades.size() == 0)
41  CreateGrassBlades();
42  }
43 
44  // only deletes display lists
46  {
47  for(int i = grassBlades.size(); i--; )
48  glDeleteLists(grassBlades[i], 1);
49  }
50 
51  // prepares everything for rendering grass
52  void Init();
53 
54  // only sets default values
56 
57  // use this method to read parameters from xml file
58  bool loadXMLParameters(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *parametersNode);
59 
60  // use this to save parameters
61  XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *saveXMLParameters(XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *);
62 
63  // denstity of the grass (number of blades per unit area)
64  float density;
65 
66  // range of random height, width and bend variance of blades
68 
69  // number of fractions of each grass blade. (low number means noticeably 'broken' blades,
70  // but also a faster rendering) Optimum for good look depends also on bend intensity.
71  // Nearly straight blades don't need to be divided into many pieces, while twisted ones need
72  // a lot of pieces to look well. The minFractions value is applied to the straightest blades
73  // and maxFractions to the most twisted ones. Others between them use adequate mix of those two values.
75 
76  // maximal size of a tringle which is covered with grass. Bigger triangles are divided
77  // first and then covered. This rule should avoid need of drawind huge triangles covered with
78  // grass which is in fact not visible at some far places of the triangle. Every smaller triangle
79  // obtained by dividing bigger ones is a part of sometihng like an oct-tree, so the visibility
80  // of its grass-cover can be determined quite efficiently.
81  float maxArea;
82 
83  // maximal distance from grass blade to draw the grass blade
85 
86  // maximal difference between last LOD and current LOD to recreate a displaylist
88 
89  // one divided by the difference between max and min Visibility
91 
92  // a set of different grassBlades
93  std::vector<GLuint> grassBlades;
94 
95  // two different statesets - one for low detail version of grass,
96  // the other for detailed version of grass.
97  osg::ref_ptr<osg::StateSet> lowDetailGrassStateSet;
98  osg::ref_ptr<osg::StateSet> detailedGrassStateSet;
99 
100  // color used for far blades
101  osg::Vec4 neutralColor;
102 
103  // CullCallback for GrassGeometry
104  osg::ref_ptr<GrassCullCallback> grassCullCallback;
105  };
106 
107 
108 
109 
110 }; // end of namespace grass
111 
112 #endif // GRASS_PARAMETERS_H