CloudyDay
 All Classes Functions Variables Enumerations
CloudCreatorWang.h
1 #pragma once
2 #include "cloudgenerator.h"
3 #include <osg/BoundingBox>
4 #include <vector>
5 #include <iostream>
6 #include <string>
7 
8 namespace osgCloudyDay
9 {
13  class TraverseMesh : public osg::NodeVisitor
14 {
15 public:
19  TraverseMesh() : NodeVisitor( NodeVisitor::TRAVERSE_ALL_CHILDREN )
20  {
21  // ----------------------------------------------------------------------
22  //
23  // Default Public Class Constructor
24  //
25  // ----------------------------------------------------------------------
26  m_transformMatrix.makeIdentity();
27  }
28 
32  virtual ~TraverseMesh() {}
33 
38  virtual void apply( osg::Geode &geode )
39  {
40  // -------------------------------------------
41  //
42  // Handle nodes of the type osg::Geode
43  //
44  // -------------------------------------------
45 
46  //
47  // update bounding box for each drawable
48  //
49  for( unsigned int i = 0; i < geode.getNumDrawables(); ++i )
50  {
51 
52  osg::BoundingBox bbox;
53  bbox.expandBy( geode.getDrawable( i )->getBound());
54 
55 
56  //
57  // transform corners by current matrix
58  //
59  osg::BoundingBox bboxTrans;
60 
61  std::cout << "center: " << bbox.center().x() << " " << bbox.center().y() << " " << bbox.center().z() << std::endl;
62  std::cout << "min: " << bbox.xMin() << " " << bbox.yMin() << " " << bbox.zMin() << std::endl;
63  std::cout << "max: " << bbox.xMax() << " " << bbox.yMax() << " " << bbox.zMax() << std::endl;
64  for( unsigned int i = 0; i < 8; ++i )
65  {
66  osg::Vec3 xvec = bbox.corner( i ) * m_transformMatrix;
67  bboxTrans.expandBy( xvec );
68  }
69 
70  std::cout << "bboxTrans: " << bboxTrans.center().x() << " " << bboxTrans.center().y() << " " << bboxTrans.center().z() << std::endl;
71  m_boundingBox.push_back(bboxTrans);
72  }
73 
74  //
75  // update the overall bounding box size
76  //
77  //m_boundingBox.expandBy( bboxTrans );
78 
79  //
80  // continue traversing through the graph
81  //
82  traverse( geode );
83 
84  } // ::apply(osg::Geode &geode)
85 
89  virtual void apply( osg::MatrixTransform &node )
90  {
91  // ---------------------------------------------------------
92  //
93  // Handle nodes of the type osg::MatrixTransform
94  //
95  // ---------------------------------------------------------
96  std::cout << "TRANSFORM NODE" << std::endl;
97  m_transformMatrix *= node.getMatrix();
98 
99  //
100  // continue traversing through the graph
101  //
102  traverse( node );
103 
104  } // ::apply(osg::MatrixTransform &node)
105 
109  virtual void apply( osg::Billboard &node )
110  {
111  // -----------------------------------------------
112  //
113  // Handle nodes of the type osg::Billboard
114  //
115  // -----------------------------------------------
116 
117  //
118  // important to handle billboard so that its size will
119  // not affect the geode size continue traversing the graph
120  //
121  traverse( node );
122  } // ::apply(osg::MatrixTransform &node)
123 
124 
125  //
126  // return teh bounding box
127  //
128  std::vector<osg::BoundingBox> &getBoundBox() { return m_boundingBox; }
129 
130 protected :
131  std::vector<osg::BoundingBox> m_boundingBox; // the overall resultant bounding box
132  osg::Matrix m_transformMatrix; // the current transform matrix
133 
134 }; // class CcalculateBoundingBox
135 
140  {
141  public:
149  CloudCreatorWang(std::string path, osg::Vec3 middlepos, int type, osg::Vec4 color);
153  ~CloudCreatorWang(void);
154 
155  protected:
159  void Initialize();
160 
161  osg::Vec3 m_middlepos;
162 
163  int m_type;
164  std::string m_path;
165  };
166 }