]> git.mxchange.org Git - simgear.git/blob - simgear/scene/sky/clouds3d/SkyRenderableInstanceGeneric.cpp
Tweak lib name.
[simgear.git] / simgear / scene / sky / clouds3d / SkyRenderableInstanceGeneric.cpp
1 //------------------------------------------------------------------------------
2 // File : SkyRenderableInstanceGeneric.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 SkyRenderableInstanceGeneric.cpp
20  * 
21  * A basic implementation of SkyRenderableInstance
22  */
23
24 #include "glvu.hpp"
25 #include "SkyUtil.hpp"
26 #include "SkyRenderable.hpp"
27 #include "SkyMinMaxBox.hpp"
28 #include "SkyRenderableInstanceGeneric.hpp"
29
30 //------------------------------------------------------------------------------
31 // Function               : SkyRenderableInstanceGeneric::SkyRenderableInstanceGeneric
32 // Description      : 
33 //------------------------------------------------------------------------------
34 /**
35  * @fn SkyRenderableInstanceGeneric::SkyRenderableInstanceGeneric(SkyRenderable *object)
36  * @brief Constructor, store the renderable and set the position to identity
37  */ 
38 SkyRenderableInstanceGeneric::SkyRenderableInstanceGeneric(SkyRenderable *pObject)
39 : SkyRenderableInstance(),
40   _pObj(pObject)
41 {
42   _pBV = pObject->CopyBoundingVolume();
43 }
44
45 //------------------------------------------------------------------------------
46 // Function               : SkyRenderableInstanceGeneric::SkyRenderableInstanceGeneric
47 // Description      : 
48 //------------------------------------------------------------------------------
49 /**
50  * @fn SkyRenderableInstanceGeneric::SkyRenderableInstanceGeneric(SkyRenderable *object, const Vec3f &position, const Mat33f &rotation, const float scale)
51  * @brief Constructor, stores the instance information given
52  */ 
53 SkyRenderableInstanceGeneric::SkyRenderableInstanceGeneric(SkyRenderable *pObject, 
54                                                            const Vec3f   &position, 
55                                                            const Mat33f  &rotation, 
56                                                            const float   scale)
57 : SkyRenderableInstance(position, rotation, scale),
58   _pObj(pObject)
59 {
60   _pBV = pObject->CopyBoundingVolume();
61 }
62
63 //------------------------------------------------------------------------------
64 // Function               : SkyRenderableInstanceGeneric::~SkyRenderableInstanceGeneric
65 // Description      : 
66 //------------------------------------------------------------------------------
67 /**
68  * @fn SkyRenderableInstanceGeneric::~SkyRenderableInstanceGeneric()
69  * @brief Destructor
70  */ 
71 SkyRenderableInstanceGeneric::~SkyRenderableInstanceGeneric()
72 {
73   _pObj = NULL;
74   SAFE_DELETE(_pBV);
75 }
76
77
78 //------------------------------------------------------------------------------
79 // Function               : SkyRenderableInstanceGeneric::SetRenderable
80 // Description      : 
81 //------------------------------------------------------------------------------
82 /**
83  * @fn SkyRenderableInstanceGeneric::SetRenderable(SkyRenderable *pRenderable)
84  * @brief Set the renderable for this instance.
85  */ 
86 void SkyRenderableInstanceGeneric::SetRenderable(SkyRenderable *pRenderable) 
87
88   _pObj = pRenderable; 
89   SAFE_DELETE(_pBV);
90   _pBV  = pRenderable->CopyBoundingVolume();
91 }
92
93
94 //------------------------------------------------------------------------------
95 // Function               : SkyRenderableInstanceGeneric::Display
96 // Description      : 
97 //------------------------------------------------------------------------------
98 /**
99  * @fn SkyRenderableInstanceGeneric::Display()
100  * @brief Displays the instance by calling the renderable's display function
101  */ 
102 SKYRESULT SkyRenderableInstanceGeneric::Display()
103 {
104   // Get and set the world space transformation
105   Mat44f mat;
106   GetModelToWorldTransform(mat);
107
108   glMatrixMode(GL_MODELVIEW);
109   glPushMatrix();
110   glMultMatrixf(mat.M);
111  
112   //FAIL_RETURN_MSG(_pObj->Display(*(GLVU::GetCurrent()->GetCurrentCam()), this), 
113     //              "SkyRenderableInstanceGeneric:Display(), error returned from object's display");
114
115   glMatrixMode(GL_MODELVIEW);
116   glPopMatrix();
117
118   return SKYRESULT_OK;
119 }
120
121
122 //------------------------------------------------------------------------------
123 // Function               : SkyRenderableInstanceGeneric::ViewFrustumCull
124 // Description      : 
125 //------------------------------------------------------------------------------
126 /**
127  * @fn SkyRenderableInstanceGeneric::ViewFrustumCull(const Camera &cam)
128  * @brief View frustum cull the object given its world position
129  */ 
130 bool SkyRenderableInstanceGeneric::ViewFrustumCull(const Camera &cam)
131 {
132   Mat44f xform;
133   GetModelToWorldTransform(xform);
134   _bCulled = (_pBV == NULL) ? false : _pBV->ViewFrustumCull(cam, xform);
135   return _bCulled;
136 }