]> git.mxchange.org Git - simgear.git/blob - simgear/scene/sky/clouds3d/SkyRenderableInstanceGroup.cpp
Clouds3D crashes because there is no Light
[simgear.git] / simgear / scene / sky / clouds3d / SkyRenderableInstanceGroup.cpp
1 //------------------------------------------------------------------------------
2 // File : SkyRenderableInstanceGroup.cpp
3 //------------------------------------------------------------------------------
4 // SkyWorks : Copyright 2002 Mark J. Harris and
5 //                                              The University of North Carolina at Chapel Hill
6 //------------------------------------------------------------------------------
7 // Permission to use, copy, modify, distribute and sell this software and its 
8 // documentation for any purpose is hereby granted without fee, provided that 
9 // the above copyright notice appear in all copies and that both that copyright 
10 // notice and this permission notice appear in supporting documentation. 
11 // Binaries may be compiled with this software without any royalties or 
12 // restrictions. 
13 //
14 // The author(s) and The University of North Carolina at Chapel Hill make no 
15 // representations about the suitability of this software for any purpose. 
16 // It is provided "as is" without express or 
17 // implied warranty.
18 /**
19  * @file SkyRenderableInstanceGroup.cpp
20  * 
21  * Implementation of class SkyRenderableInstanceGroup, an instance that groups
22  * other instances.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 #  include <simgear_config.h>
27 #endif
28
29 #ifdef HAVE_WINDOWS_H
30 #  include <windows.h>
31 #endif
32
33 #include <GL/gl.h>
34
35 #include "SkyRenderableInstanceGroup.hpp"
36 #include "SkySceneManager.hpp"
37
38
39 //------------------------------------------------------------------------------
40 // Function               : SkyRenderableInstanceGroup::SkyRenderableInstanceGroup
41 // Description      : 
42 //------------------------------------------------------------------------------
43 /**
44  * @fn SkyRenderableInstanceGroup::SkyRenderableInstanceGroup()
45  * @brief Constructor.
46  */ 
47 SkyRenderableInstanceGroup::SkyRenderableInstanceGroup()
48 : SkyRenderableInstance(),
49   _pObjectSpaceBV(NULL) 
50 {
51 }
52
53
54 //------------------------------------------------------------------------------
55 // Function               : SkyRenderableInstanceGroup::~SkyRenderableInstanceGroup
56 // Description      : 
57 //------------------------------------------------------------------------------
58 /**
59  * @fn SkyRenderableInstanceGroup::~SkyRenderableInstanceGroup()
60  * @brief Destructor.
61  */ 
62 SkyRenderableInstanceGroup::~SkyRenderableInstanceGroup()
63 {
64 }
65
66
67 //------------------------------------------------------------------------------
68 // Function               : SkyRenderableInstanceGroup::Update
69 // Description      : 
70 //------------------------------------------------------------------------------
71 /**
72  * @fn SkyRenderableInstanceGroup::Update(const Camera &cam)
73  * @brief Processes any per frame updates the instance requires.
74  * 
75  * This method simply calls the SkyRenderableInstance::Update() method of each of
76  * its sub-instances.
77  */ 
78 SKYRESULT SkyRenderableInstanceGroup::Update(const Camera &cam)
79 {
80   InstanceIterator ii;
81   for (ii = _opaqueSubInstances.begin(); ii != _opaqueSubInstances.end(); ++ii)
82   {
83     FAIL_RETURN((*ii)->Update(cam));
84   }
85   for (ii = _transparentSubInstances.begin(); ii != _transparentSubInstances.end(); ++ii)
86   {
87     FAIL_RETURN((*ii)->Update(cam));
88   }
89
90   SkySceneManager::SortInstances(_transparentSubInstances, cam.Orig);
91   return SKYRESULT_OK;
92 }
93
94
95 //------------------------------------------------------------------------------
96 // Function               : SkyRenderableInstanceGroup::Display
97 // Description      : 
98 //------------------------------------------------------------------------------
99 /**
100  * @fn SkyRenderableInstanceGroup::Display()
101  * @brief Displays all sub-instances of this instance.
102  * 
103  * The object-to-world transform of this instance group will be applied to all sub-instances before
104  * their own object-to-world transforms are applied.
105  */ 
106 SKYRESULT SkyRenderableInstanceGroup::Display()
107 {
108   // Get and set the world space transformation
109   Mat44f mat;
110   GetModelToWorldTransform(mat);
111
112   glMatrixMode(GL_MODELVIEW);
113   glPushMatrix();
114   glMultMatrixf(mat.M);
115
116   InstanceIterator ii;
117   /***
118   for (ii = _opaqueSubInstances.begin(); ii != _opaqueSubInstances.end(); ++ii)
119   {
120     FAIL_RETURN((*ii)->Display());
121   }
122
123   for (ii = _transparentSubInstances.begin(); ii != _transparentSubInstances.end(); ++ii)
124   {
125     FAIL_RETURN((*ii)->Display());
126   }
127 ***/
128   _pObjectSpaceBV->Display();
129
130   glMatrixMode(GL_MODELVIEW);
131   glPopMatrix();
132
133   return SKYRESULT_OK;
134 }
135
136
137 //------------------------------------------------------------------------------
138 // Function               : SkyRenderableInstanceGroup::ViewFrustumCull
139 // Description      : 
140 //------------------------------------------------------------------------------
141 /**
142  * @fn SkyRenderableInstanceGroup::ViewFrustumCull(const Camera& cam)
143  * @brief @todo <WRITE BRIEF SkyRenderableInstanceGroup::ViewFrustumCull DOCUMENTATION>
144  * 
145  * @todo <WRITE EXTENDED SkyRenderableInstanceGroup::ViewFrustumCull FUNCTION DOCUMENTATION>
146  */ 
147 bool SkyRenderableInstanceGroup::ViewFrustumCull(const Camera& cam)
148 {
149   Mat44f xform;
150   GetModelToWorldTransform(xform);
151   _bCulled = (_pObjectSpaceBV == NULL) ? false : _pObjectSpaceBV->ViewFrustumCull(cam, xform);
152   return _bCulled;
153 }
154
155
156 //------------------------------------------------------------------------------
157 // Function               : SkyRenderableInstanceGroup::AddSubInstance
158 // Description      : 
159 //------------------------------------------------------------------------------
160 /**
161  * @fn SkyRenderableInstanceGroup::AddSubInstance(SkyRenderableInstance *pInstance, bool bTransparent)
162  * @brief Adds a sub-instance to the group.
163  */ 
164 void SkyRenderableInstanceGroup::AddSubInstance(SkyRenderableInstance *pInstance, bool bTransparent)
165 {
166   if (!bTransparent)
167     _opaqueSubInstances.push_back(pInstance);
168   else
169     _transparentSubInstances.push_back(pInstance);
170
171   // update the bounds...
172   Mat44f xform;
173   pInstance->GetModelToWorldTransform(xform);
174
175   SkyMinMaxBox *pBV = pInstance->GetBoundingVolume();
176   if (pBV)
177   {
178     Vec3f min = pInstance->GetBoundingVolume()->GetMin();
179     Vec3f max = pInstance->GetBoundingVolume()->GetMax();
180
181     if (!_pObjectSpaceBV)
182       _pObjectSpaceBV = new SkyMinMaxBox;
183
184     _pObjectSpaceBV->AddPoint(xform * min);
185     _pObjectSpaceBV->AddPoint(xform * max);
186   } 
187 }