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
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
19 * @file SkyRenderableInstanceGroup.cpp
21 * Implementation of class SkyRenderableInstanceGroup, an instance that groups
26 # include <simgear_config.h>
35 #include "SkyRenderableInstanceGroup.hpp"
36 #include "SkySceneManager.hpp"
39 //------------------------------------------------------------------------------
40 // Function : SkyRenderableInstanceGroup::SkyRenderableInstanceGroup
42 //------------------------------------------------------------------------------
44 * @fn SkyRenderableInstanceGroup::SkyRenderableInstanceGroup()
47 SkyRenderableInstanceGroup::SkyRenderableInstanceGroup()
48 : SkyRenderableInstance(),
54 //------------------------------------------------------------------------------
55 // Function : SkyRenderableInstanceGroup::~SkyRenderableInstanceGroup
57 //------------------------------------------------------------------------------
59 * @fn SkyRenderableInstanceGroup::~SkyRenderableInstanceGroup()
62 SkyRenderableInstanceGroup::~SkyRenderableInstanceGroup()
67 //------------------------------------------------------------------------------
68 // Function : SkyRenderableInstanceGroup::Update
70 //------------------------------------------------------------------------------
72 * @fn SkyRenderableInstanceGroup::Update(const Camera &cam)
73 * @brief Processes any per frame updates the instance requires.
75 * This method simply calls the SkyRenderableInstance::Update() method of each of
78 SKYRESULT SkyRenderableInstanceGroup::Update(const Camera &cam)
81 for (ii = _opaqueSubInstances.begin(); ii != _opaqueSubInstances.end(); ++ii)
83 FAIL_RETURN((*ii)->Update(cam));
85 for (ii = _transparentSubInstances.begin(); ii != _transparentSubInstances.end(); ++ii)
87 FAIL_RETURN((*ii)->Update(cam));
90 SkySceneManager::SortInstances(_transparentSubInstances, cam.Orig);
95 //------------------------------------------------------------------------------
96 // Function : SkyRenderableInstanceGroup::Display
98 //------------------------------------------------------------------------------
100 * @fn SkyRenderableInstanceGroup::Display()
101 * @brief Displays all sub-instances of this instance.
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.
106 SKYRESULT SkyRenderableInstanceGroup::Display()
108 // Get and set the world space transformation
110 GetModelToWorldTransform(mat);
112 glMatrixMode(GL_MODELVIEW);
114 glMultMatrixf(mat.M);
118 for (ii = _opaqueSubInstances.begin(); ii != _opaqueSubInstances.end(); ++ii)
120 FAIL_RETURN((*ii)->Display());
123 for (ii = _transparentSubInstances.begin(); ii != _transparentSubInstances.end(); ++ii)
125 FAIL_RETURN((*ii)->Display());
128 _pObjectSpaceBV->Display();
130 glMatrixMode(GL_MODELVIEW);
137 //------------------------------------------------------------------------------
138 // Function : SkyRenderableInstanceGroup::ViewFrustumCull
140 //------------------------------------------------------------------------------
142 * @fn SkyRenderableInstanceGroup::ViewFrustumCull(const Camera& cam)
143 * @brief @todo <WRITE BRIEF SkyRenderableInstanceGroup::ViewFrustumCull DOCUMENTATION>
145 * @todo <WRITE EXTENDED SkyRenderableInstanceGroup::ViewFrustumCull FUNCTION DOCUMENTATION>
147 bool SkyRenderableInstanceGroup::ViewFrustumCull(const Camera& cam)
150 GetModelToWorldTransform(xform);
151 _bCulled = (_pObjectSpaceBV == NULL) ? false : _pObjectSpaceBV->ViewFrustumCull(cam, xform);
156 //------------------------------------------------------------------------------
157 // Function : SkyRenderableInstanceGroup::AddSubInstance
159 //------------------------------------------------------------------------------
161 * @fn SkyRenderableInstanceGroup::AddSubInstance(SkyRenderableInstance *pInstance, bool bTransparent)
162 * @brief Adds a sub-instance to the group.
164 void SkyRenderableInstanceGroup::AddSubInstance(SkyRenderableInstance *pInstance, bool bTransparent)
167 _opaqueSubInstances.push_back(pInstance);
169 _transparentSubInstances.push_back(pInstance);
171 // update the bounds...
173 pInstance->GetModelToWorldTransform(xform);
175 SkyMinMaxBox *pBV = pInstance->GetBoundingVolume();
178 Vec3f min = pInstance->GetBoundingVolume()->GetMin();
179 Vec3f max = pInstance->GetBoundingVolume()->GetMax();
181 if (!_pObjectSpaceBV)
182 _pObjectSpaceBV = new SkyMinMaxBox;
184 _pObjectSpaceBV->AddPoint(xform * min);
185 _pObjectSpaceBV->AddPoint(xform * max);