VR-Engage  2.2
Loading...
Searching...
No Matches
clip_viewport.h
Go to the documentation of this file.
1/*! \file clip_viewport.h
2 \brief The ClipViewportBase class.
3
4 \par Copyright Information
5
6 Copyright (c) 2009 The DiSTI Corporation.<br>
7 11486 Corporate Blvd; Suite 190<br>
8 Orlando, Florida 32817<br>
9 USA<br>
10 <br>
11 All rights reserved.<br>
12
13 This Software contains proprietary trade secrets of DiSTI and may not be
14reproduced, in whole or part, in any form, or by any means of electronic,
15mechanical, or otherwise, without the written permission of DiSTI. Said
16permission may be derived through the purchase of applicable DiSTI product
17licenses which detail the distribution rights of this content and any
18Derivative Works based on this or other copyrighted DiSTI Software.
19
20 NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26
27 LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34EXCEED FIVE DOLLARS (US$5.00).
35
36 The aforementioned terms and restrictions are governed by the laws of the
37State of Florida and the United States of America.
38
39*/
40#ifndef CLIP_VIEWPORT_H
41#define CLIP_VIEWPORT_H
42
43#include <GL/glu.h>
44#include "component_base.h"
45#include "component_light_mgr.h"
46
47namespace disti
48{
49
50class ClipViewportBase : public ComponentBase
51{
52
53public:
63
64protected:
65 bool _active[6];
66
67 DisplayObject *_viewportObject;
68
69public:
70 ClipViewportBase() : ComponentBase(), _viewportObject(NULL)
71 {
72 for (int i = 0; i < 6; i++)
73 _active[i] = false;
74 }
75
77 {
78 }
79
80 virtual void Activate(
81 int _1,
82 int _2 = -1,
83 int _3 = -1,
84 int _4 = -1,
85 int _5 = -1,
86 int _6 = -1)
87 {
88 _active[_1] = true;
89 if (_2 != -1) _active[_2] = true;
90 if (_3 != -1) _active[_3] = true;
91 if (_4 != -1) _active[_4] = true;
92 if (_5 != -1) _active[_5] = true;
93 if (_6 != -1) _active[_6] = true;
94 }
95
96 virtual void Deactivate(
97 int _1,
98 int _2 = -1,
99 int _3 = -1,
100 int _4 = -1,
101 int _5 = -1,
102 int _6 = -1)
103 {
104 _active[_1] = false;
105 if (_2 != -1) _active[_2] = false;
106 if (_3 != -1) _active[_3] = false;
107 if (_4 != -1) _active[_4] = false;
108 if (_5 != -1) _active[_5] = false;
109 if (_6 != -1) _active[_6] = false;
110
111 }
112
113 virtual void SetViewport(DisplayObject *obj)
114 {
115 _viewportObject = obj;
116 }
117
118 virtual void Draw()
119 {
120 if (_viewportObject)
122 else
123 ComponentBase::Draw();
124 }
125
126 virtual void DrawInViewport()
127 {
128 if (!_visible || Culled() || (_blinking && BlinkedOff()))
129 return;
130
131 // Setup the viewport variables
132
133 float x,y,z,x1,y1,z1;
134
135 _viewportObject->GetExtents(x,y,z,x1,y1,z1);
136
137 GLdouble eqn[6][4] =
138 {{1.0, 0.0, 0.0, -x}, //E_LEFT
139 {-1.0, 0.0, 0.0, x1}, //E_RIGHT
140 {0.0, -1.0, 0.0, y1}, //E_TOP
141 {0.0, 1.0, 0.0, -y}, //E_BOTTOM
142 {0.0, 0.0, -1.0, z1}, //E_FRONT
143 {0.0, 0.0, 1.0, -z} //E_BACK
144 };
145
146 SetupLighting();
147
148 // The PreDraw way
149
150 bool pushed = ApplyDynamicRotation();
151
152 SaveMatrices(); // Saving a full set.
153
154 if(!_parentDisplayFrame)
155 {
156 // We are the top level for our dll
157 _lightMgr->TopFrameInitialize();
158 }
159
160 _lightMgr->SetupComponentLighting();
161
162 { // Copy/Paste from Group::Draw()
163
164 // Set global variable with current texture index to be used
165 // by child objects that have no texture index
166
167 glColor4ubv(_color.RGBA());
168
169 int i;
170 int maxPlanes;
171 int startPlane;
172 int currPlane;
173
174 glGetIntegerv(GL_MAX_CLIP_PLANES,&maxPlanes);
175
176 for (startPlane = 0; startPlane < maxPlanes; startPlane++)
177 {
178 if (!glIsEnabled( GL_CLIP_PLANE0 + startPlane))
179 {
180 // Found the first non used plane
181 // We will ASSUME the rest are unused
182 break;
183 }
184 }
185
186 currPlane = startPlane - 1;
187
188 for (i = 0; i < 6; i++)
189 {
190 // Turn on our active planes
191 if (_active[i])
192 {
193 currPlane++;
194 glEnable(GL_CLIP_PLANE0 + currPlane);
195 glClipPlane(GL_CLIP_PLANE0 + currPlane,eqn[i]);
196 if (currPlane + 1 >= maxPlanes)
197 {
198#ifdef _DEBUG
199 fprintf(stderr,"Warning: Number of glPlanes exceeded in %s: %d\n",__FILE__,maxPlanes);
200#endif
201 break;
202 }
203 }
204 }
205
206 for (unsigned int j=0; j < _objects.Count(); j++)
207 _objects[j]->Draw();
208
209 // Disable the planes we used
210 for (i = startPlane; i <= currPlane; i++)
211 {
212 glDisable(GL_CLIP_PLANE0 + i);
213 }
214
215 }
216
217 _lightMgr->CleanupComponentLighting();
218
219 if(!_parentDisplayFrame)
220 {
221 _lightMgr->TopFrameRestore();
222 }
223
224 if (pushed)
225 glPopMatrix();
226 }
227
228};
229
230} //namespace disti
231
232#endif
ClipViewportBase()
Definition clip_viewport.h:70
virtual void SetViewport(DisplayObject *obj)
Definition clip_viewport.h:113
virtual void Draw()
Definition clip_viewport.h:118
virtual ~ClipViewportBase()
Definition clip_viewport.h:76
bool _active[6]
Definition clip_viewport.h:65
virtual void Deactivate(int _1, int _2=-1, int _3=-1, int _4=-1, int _5=-1, int _6=-1)
Definition clip_viewport.h:96
virtual void DrawInViewport()
Definition clip_viewport.h:126
E_BoxSideEnum
Definition clip_viewport.h:55
@ E_BOTTOM
Definition clip_viewport.h:59
@ E_LEFT
Definition clip_viewport.h:56
@ E_RIGHT
Definition clip_viewport.h:57
@ E_FRONT
Definition clip_viewport.h:60
@ E_BACK
Definition clip_viewport.h:61
@ E_TOP
Definition clip_viewport.h:58
virtual void Activate(int _1, int _2=-1, int _3=-1, int _4=-1, int _5=-1, int _6=-1)
Definition clip_viewport.h:80
DisplayObject * _viewportObject
Definition clip_viewport.h:67
Definition clip_viewport.h:48