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 "SkyRenderableInstanceGroup.hpp"
27 #include "SkySceneManager.hpp"
30 //------------------------------------------------------------------------------
31 // Function : SkyRenderableInstanceGroup::SkyRenderableInstanceGroup
33 //------------------------------------------------------------------------------
35 * @fn SkyRenderableInstanceGroup::SkyRenderableInstanceGroup()
38 SkyRenderableInstanceGroup::SkyRenderableInstanceGroup()
39 : SkyRenderableInstance(),
45 //------------------------------------------------------------------------------
46 // Function : SkyRenderableInstanceGroup::~SkyRenderableInstanceGroup
48 //------------------------------------------------------------------------------
50 * @fn SkyRenderableInstanceGroup::~SkyRenderableInstanceGroup()
53 SkyRenderableInstanceGroup::~SkyRenderableInstanceGroup()
58 //------------------------------------------------------------------------------
59 // Function : SkyRenderableInstanceGroup::Update
61 //------------------------------------------------------------------------------
63 * @fn SkyRenderableInstanceGroup::Update(const Camera &cam)
64 * @brief Processes any per frame updates the instance requires.
66 * This method simply calls the SkyRenderableInstance::Update() method of each of
69 SKYRESULT SkyRenderableInstanceGroup::Update(const Camera &cam)
72 for (ii = _opaqueSubInstances.begin(); ii != _opaqueSubInstances.end(); ++ii)
74 FAIL_RETURN((*ii)->Update(cam));
76 for (ii = _transparentSubInstances.begin(); ii != _transparentSubInstances.end(); ++ii)
78 FAIL_RETURN((*ii)->Update(cam));
81 SkySceneManager::SortInstances(_transparentSubInstances, cam.Orig);
86 //------------------------------------------------------------------------------
87 // Function : SkyRenderableInstanceGroup::Display
89 //------------------------------------------------------------------------------
91 * @fn SkyRenderableInstanceGroup::Display()
92 * @brief Displays all sub-instances of this instance.
94 * The object-to-world transform of this instance group will be applied to all sub-instances before
95 * their own object-to-world transforms are applied.
97 SKYRESULT SkyRenderableInstanceGroup::Display()
99 // Get and set the world space transformation
101 GetModelToWorldTransform(mat);
103 glMatrixMode(GL_MODELVIEW);
105 glMultMatrixf(mat.M);
109 for (ii = _opaqueSubInstances.begin(); ii != _opaqueSubInstances.end(); ++ii)
111 FAIL_RETURN((*ii)->Display());
114 for (ii = _transparentSubInstances.begin(); ii != _transparentSubInstances.end(); ++ii)
116 FAIL_RETURN((*ii)->Display());
119 _pObjectSpaceBV->Display();
121 glMatrixMode(GL_MODELVIEW);
128 //------------------------------------------------------------------------------
129 // Function : SkyRenderableInstanceGroup::ViewFrustumCull
131 //------------------------------------------------------------------------------
133 * @fn SkyRenderableInstanceGroup::ViewFrustumCull(const Camera& cam)
134 * @brief @todo <WRITE BRIEF SkyRenderableInstanceGroup::ViewFrustumCull DOCUMENTATION>
136 * @todo <WRITE EXTENDED SkyRenderableInstanceGroup::ViewFrustumCull FUNCTION DOCUMENTATION>
138 bool SkyRenderableInstanceGroup::ViewFrustumCull(const Camera& cam)
141 GetModelToWorldTransform(xform);
142 _bCulled = (_pObjectSpaceBV == NULL) ? false : _pObjectSpaceBV->ViewFrustumCull(cam, xform);
147 //------------------------------------------------------------------------------
148 // Function : SkyRenderableInstanceGroup::AddSubInstance
150 //------------------------------------------------------------------------------
152 * @fn SkyRenderableInstanceGroup::AddSubInstance(SkyRenderableInstance *pInstance, bool bTransparent)
153 * @brief Adds a sub-instance to the group.
155 void SkyRenderableInstanceGroup::AddSubInstance(SkyRenderableInstance *pInstance, bool bTransparent)
158 _opaqueSubInstances.push_back(pInstance);
160 _transparentSubInstances.push_back(pInstance);
162 // update the bounds...
164 pInstance->GetModelToWorldTransform(xform);
166 SkyMinMaxBox *pBV = pInstance->GetBoundingVolume();
169 Vec3f min = pInstance->GetBoundingVolume()->GetMin();
170 Vec3f max = pInstance->GetBoundingVolume()->GetMax();
172 if (!_pObjectSpaceBV)
173 _pObjectSpaceBV = new SkyMinMaxBox;
175 _pObjectSpaceBV->AddPoint(xform * min);
176 _pObjectSpaceBV->AddPoint(xform * max);