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
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 SkyRenderableInstanceGeneric.cpp
21 * A basic implementation of SkyRenderableInstance
25 #include "SkyUtil.hpp"
26 #include "SkyRenderable.hpp"
27 #include "SkyMinMaxBox.hpp"
28 #include "SkyRenderableInstanceGeneric.hpp"
30 //------------------------------------------------------------------------------
31 // Function : SkyRenderableInstanceGeneric::SkyRenderableInstanceGeneric
33 //------------------------------------------------------------------------------
35 * @fn SkyRenderableInstanceGeneric::SkyRenderableInstanceGeneric(SkyRenderable *object)
36 * @brief Constructor, store the renderable and set the position to identity
38 SkyRenderableInstanceGeneric::SkyRenderableInstanceGeneric(SkyRenderable *pObject)
39 : SkyRenderableInstance(),
42 _pBV = pObject->CopyBoundingVolume();
45 //------------------------------------------------------------------------------
46 // Function : SkyRenderableInstanceGeneric::SkyRenderableInstanceGeneric
48 //------------------------------------------------------------------------------
50 * @fn SkyRenderableInstanceGeneric::SkyRenderableInstanceGeneric(SkyRenderable *object, const Vec3f &position, const Mat33f &rotation, const float scale)
51 * @brief Constructor, stores the instance information given
53 SkyRenderableInstanceGeneric::SkyRenderableInstanceGeneric(SkyRenderable *pObject,
54 const Vec3f &position,
55 const Mat33f &rotation,
57 : SkyRenderableInstance(position, rotation, scale),
60 _pBV = pObject->CopyBoundingVolume();
63 //------------------------------------------------------------------------------
64 // Function : SkyRenderableInstanceGeneric::~SkyRenderableInstanceGeneric
66 //------------------------------------------------------------------------------
68 * @fn SkyRenderableInstanceGeneric::~SkyRenderableInstanceGeneric()
71 SkyRenderableInstanceGeneric::~SkyRenderableInstanceGeneric()
78 //------------------------------------------------------------------------------
79 // Function : SkyRenderableInstanceGeneric::SetRenderable
81 //------------------------------------------------------------------------------
83 * @fn SkyRenderableInstanceGeneric::SetRenderable(SkyRenderable *pRenderable)
84 * @brief Set the renderable for this instance.
86 void SkyRenderableInstanceGeneric::SetRenderable(SkyRenderable *pRenderable)
90 _pBV = pRenderable->CopyBoundingVolume();
94 //------------------------------------------------------------------------------
95 // Function : SkyRenderableInstanceGeneric::Display
97 //------------------------------------------------------------------------------
99 * @fn SkyRenderableInstanceGeneric::Display()
100 * @brief Displays the instance by calling the renderable's display function
102 SKYRESULT SkyRenderableInstanceGeneric::Display()
104 // Get and set the world space transformation
106 GetModelToWorldTransform(mat);
108 glMatrixMode(GL_MODELVIEW);
110 glMultMatrixf(mat.M);
112 //FAIL_RETURN_MSG(_pObj->Display(*(GLVU::GetCurrent()->GetCurrentCam()), this),
113 // "SkyRenderableInstanceGeneric:Display(), error returned from object's display");
115 glMatrixMode(GL_MODELVIEW);
122 //------------------------------------------------------------------------------
123 // Function : SkyRenderableInstanceGeneric::ViewFrustumCull
125 //------------------------------------------------------------------------------
127 * @fn SkyRenderableInstanceGeneric::ViewFrustumCull(const Camera &cam)
128 * @brief View frustum cull the object given its world position
130 bool SkyRenderableInstanceGeneric::ViewFrustumCull(const Camera &cam)
133 GetModelToWorldTransform(xform);
134 _bCulled = (_pBV == NULL) ? false : _pBV->ViewFrustumCull(cam, xform);