]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/HUD/HUD.cxx
Restructure GUI code, isolate PLIB in source files, to ease future refactoring and...
[flightgear.git] / src / Instrumentation / HUD / HUD.cxx
1 // HUD.cxx -- Head Up Display
2 //
3 // Written by Michele America, started September 1997.
4 //
5 // Copyright (C) 1997  Michele F. America  [micheleamerica#geocities:com]
6 // Copyright (C) 2006  Melchior FRANZ  [mfranz#aon:at]
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21
22 #include <simgear/compiler.h>
23 #include <simgear/structure/exception.hxx>
24
25 #include <string>
26 #include <fstream>
27
28 #ifdef HAVE_CONFIG_H
29 #  include <config.h>
30 #endif
31
32 #include <simgear/constants.h>
33 #include <simgear/misc/sg_path.hxx>
34 #include <simgear/props/props_io.hxx>
35 #include <osg/GLU>
36
37 #include <plib/fnt.h>
38
39 #include <Main/globals.hxx>
40 #include <Main/viewmgr.hxx>
41 #include <Main/viewer.hxx>
42 #include <GUI/FGFontCache.hxx>
43
44 #include "HUD.hxx"
45
46 using std::endl;
47 using std::ifstream;
48
49 static float clamp(float f)
50 {
51     return f < 0.0f ? 0.0f : f > 1.0f ? 1.0f : f;
52 }
53
54
55 HUD::HUD() :
56     _path(fgGetNode("/sim/hud/path[1]", "Huds/default.xml")),
57     _current(fgGetNode("/sim/hud/current-color", true)),
58     _visibility(fgGetNode("/sim/hud/visibility[1]", true)),
59     _3DenabledN(fgGetNode("/sim/hud/enable3d[1]", true)),
60     _antialiasing(fgGetNode("/sim/hud/color/antialiased", true)),
61     _transparency(fgGetNode("/sim/hud/color/transparent", true)),
62     _red(fgGetNode("/sim/hud/color/red", true)),
63     _green(fgGetNode("/sim/hud/color/green", true)),
64     _blue(fgGetNode("/sim/hud/color/blue", true)),
65     _alpha(fgGetNode("/sim/hud/color/alpha", true)),
66     _alpha_clamp(fgGetNode("/sim/hud/color/alpha-clamp", true)),
67     _brightness(fgGetNode("/sim/hud/color/brightness", true)),
68     _visible(false),
69     _antialiased(false),
70     _transparent(false),
71     _a(0.67),                                                                   // FIXME better names
72     _cl(0.01),
73     //
74     _scr_widthN(fgGetNode("/sim/startup/xsize", true)),
75     _scr_heightN(fgGetNode("/sim/startup/ysize", true)),
76     _unitsN(fgGetNode("/sim/startup/units", true)),
77     _timer(0.0),
78     //
79     _font_renderer(new fntRenderer()),
80     _font(0),
81     _font_size(0.0),
82     _style(0),
83     _listener_active(false),
84     _clip_box(0)
85 {
86     SG_LOG(SG_COCKPIT, SG_INFO, "Initializing HUD Instrument");
87
88     _path->addChangeListener(this);
89     _visibility->addChangeListener(this);
90     _3DenabledN->addChangeListener(this);
91     _antialiasing->addChangeListener(this);
92     _transparency->addChangeListener(this);
93     _red->addChangeListener(this);
94     _green->addChangeListener(this);
95     _blue->addChangeListener(this);
96     _alpha->addChangeListener(this);
97     _alpha_clamp->addChangeListener(this);
98     _brightness->addChangeListener(this);
99     _current->addChangeListener(this);
100     _scr_widthN->addChangeListener(this);
101     _scr_heightN->addChangeListener(this);
102     _unitsN->addChangeListener(this, true);
103 }
104
105
106 HUD::~HUD()
107 {
108     _path->removeChangeListener(this);
109     _visibility->removeChangeListener(this);
110     _3DenabledN->removeChangeListener(this);
111     _antialiasing->removeChangeListener(this);
112     _transparency->removeChangeListener(this);
113     _red->removeChangeListener(this);
114     _green->removeChangeListener(this);
115     _blue->removeChangeListener(this);
116     _alpha->removeChangeListener(this);
117     _alpha_clamp->removeChangeListener(this);
118     _brightness->removeChangeListener(this);
119     _current->removeChangeListener(this);
120     _scr_widthN->removeChangeListener(this);
121     _scr_heightN->removeChangeListener(this);
122     _unitsN->removeChangeListener(this);
123     delete _font_renderer;
124     
125     deinit();
126 }
127
128
129 void HUD::init()
130 {
131     const char* fontName = 0;
132     _font_cache = globals->get_fontcache();
133     if (!_font) {
134         fontName = fgGetString("/sim/hud/font/name", "Helvetica.txf");
135         _font = _font_cache->getTexFont(fontName);
136     }
137     if (!_font)
138         throw sg_io_exception("/sim/hud/font/name is not a texture font",
139                               sg_location(fontName));
140
141     _font_size = fgGetFloat("/sim/hud/font/size", 8);
142     _font_renderer->setFont(_font);
143     _font_renderer->setPointSize(_font_size);
144     _text_list.setFont(_font_renderer);
145
146     currentColorChanged();
147     
148     _path->fireValueChanged();
149 }
150
151 void HUD::deinit()
152 {
153   deque<Item *>::const_iterator it, end = _items.end();
154     for (it = _items.begin(); it != end; ++it)
155         delete *it;
156     end = _ladders.end();
157     for (it = _ladders.begin(); it != end; ++it)
158         delete *it;
159         
160   _items.clear();
161   _ladders.clear();
162   
163   delete _clip_box;
164   _clip_box = NULL;
165 }
166
167 void HUD::reinit()
168 {
169     deinit();
170     _path->fireValueChanged();
171 }
172
173 void HUD::update(double dt)
174 {
175     _timer += dt;
176 }
177
178
179 void HUD::draw(osg::State&)
180 {
181     if (!isVisible())
182         return;
183
184     if (!_items.size() && !_ladders.size())
185         return;
186
187     if (is3D()) {
188         draw3D();
189         return;
190     }
191
192     const float normal_aspect = 640.0f / 480.0f;
193     // note: aspect_ratio is Y/X
194     float current_aspect = 1.0f / globals->get_current_view()->get_aspect_ratio();
195     if (current_aspect > normal_aspect) {
196         float aspect_adjust = current_aspect / normal_aspect;
197         float adjust = 320.0f * aspect_adjust - 320.0f;
198         draw2D(-adjust, 0.0f, 640.0f + adjust, 480.0f);
199
200     } else {
201         float aspect_adjust = normal_aspect / current_aspect;
202         float adjust = 240.0f * aspect_adjust - 240.0f;
203         draw2D(0.0f, -adjust, 640.0f, 480.0f + adjust);
204     }
205
206     glViewport(0, 0, _scr_width, _scr_height);
207 }
208
209
210 void HUD::draw3D()
211 {
212     using namespace osg;
213     FGViewer* view = globals->get_current_view();
214
215     // Standard fgfs projection, with essentially meaningless clip
216     // planes (we'll map the whole HUD plane to z=-1)
217     glMatrixMode(GL_PROJECTION);
218     glPushMatrix();
219     Matrixf proj
220         = Matrixf::perspective(view->get_v_fov(), 1/view->get_aspect_ratio(),
221                                0.1, 10);
222     glLoadMatrix(proj.ptr());
223
224     glMatrixMode(GL_MODELVIEW);
225     glPushMatrix();
226
227     // Standard fgfs view direction computation
228     Vec3f lookat;
229     lookat[0] = -sin(SG_DEGREES_TO_RADIANS * view->getHeadingOffset_deg());
230     lookat[1] = tan(SG_DEGREES_TO_RADIANS * view->getPitchOffset_deg());
231     lookat[2] = -cos(SG_DEGREES_TO_RADIANS * view->getHeadingOffset_deg());
232     if (fabs(lookat[1]) > 9999)
233         lookat[1] = 9999; // FPU sanity
234     Matrixf mv = Matrixf::lookAt(Vec3f(0.0, 0.0, 0.0), lookat,
235                                  Vec3f(0.0, 1.0, 0.0));
236     glLoadMatrix(mv.ptr());
237
238     // Map the -1:1 square to a 55.0x41.25 degree wide patch at z=1.
239     // This is the default fgfs field of view, which the HUD files are
240     // written to assume.
241     float dx = 0.52056705; // tan(55/2)
242     float dy = dx * 0.75;  // assumes 4:3 aspect ratio
243     float m[16];
244     m[0] = dx, m[4] =  0, m[ 8] = 0, m[12] = 0;
245     m[1] =  0, m[5] = dy, m[ 9] = 0, m[13] = 0;
246     m[2] =  0, m[6] =  0, m[10] = 1, m[14] = 0;
247     m[3] =  0, m[7] =  0, m[11] = 0, m[15] = 1;
248     glMultMatrixf(m);
249
250     // Convert the 640x480 "HUD standard" coordinate space to a square
251     // about the origin in the range [-1:1] at depth of -1
252     glScalef(1.0 / 320, 1.0 / 240, 1);
253     glTranslatef(-320, -240, -1);
254
255     common_draw();
256
257     glMatrixMode(GL_PROJECTION);
258     glPopMatrix();
259     glMatrixMode(GL_MODELVIEW);
260     glPopMatrix();
261 }
262
263
264 void HUD::draw2D(GLfloat x_start, GLfloat y_start, GLfloat x_end, GLfloat y_end)
265 {
266     using namespace osg;
267     glMatrixMode(GL_PROJECTION);
268     glPushMatrix();
269     Matrixf proj = Matrixf::ortho2D(x_start, x_end, y_start, y_end);
270     glLoadMatrix(proj.ptr());
271
272     glMatrixMode(GL_MODELVIEW);
273     glPushMatrix();
274     glLoadIdentity();
275
276     common_draw();
277
278     glMatrixMode(GL_PROJECTION);
279     glPopMatrix();
280     glMatrixMode(GL_MODELVIEW);
281     glPopMatrix();
282 }
283
284
285 void HUD::common_draw()
286 {
287     _text_list.erase();
288     _line_list.erase();
289     _stipple_line_list.erase();
290
291     glDisable(GL_DEPTH_TEST);
292     glDisable(GL_LIGHTING);
293
294     glEnable(GL_BLEND);
295     if (isTransparent())
296         glBlendFunc(GL_SRC_ALPHA, GL_ONE);
297     else
298         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
299
300     if (isAntialiased()) {
301         glEnable(GL_LINE_SMOOTH);
302         glAlphaFunc(GL_GREATER, alphaClamp());
303         glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
304         //glLineWidth(1.5);
305     } else {
306         //glLineWidth(1.0);
307     }
308
309     setColor();
310     _clip_box->set();
311
312     deque<Item *>::const_iterator it, end = _items.end();
313     for (it = _items.begin(); it != end; ++it)
314         if ((*it)->isEnabled())
315             (*it)->draw();
316
317     _text_list.draw();
318     _line_list.draw();
319
320     if (_stipple_line_list.size()) {
321         glEnable(GL_LINE_STIPPLE);
322         glLineStipple(1, 0x00FF);
323         _stipple_line_list.draw();
324         glDisable(GL_LINE_STIPPLE);
325     }
326
327     // ladders last, as they can have their own clip planes
328     end = _ladders.end();
329     for (it = _ladders.begin(); it != end; ++it)
330         if ((*it)->isEnabled())
331             (*it)->draw();
332
333     _clip_box->unset();
334
335     if (isAntialiased()) {
336         glDisable(GL_ALPHA_TEST);
337         glDisable(GL_LINE_SMOOTH);
338         //glLineWidth(1.0);
339     }
340
341     if (isTransparent())
342         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
343
344     glEnable(GL_DEPTH_TEST);
345     glEnable(GL_LIGHTING);
346 }
347
348
349 int HUD::load(const char *file, float x, float y, int level, const string& indent)
350 {
351     const sgDebugPriority TREE = SG_INFO;
352     const int MAXNEST = 10;
353
354     SGPath path(globals->resolve_maybe_aircraft_path(file));
355     if (path.isNull())
356     {
357         SG_LOG(SG_INPUT, SG_ALERT, "HUD: Cannot find configuration file '" << file << "'.");
358         return 0x2;
359     }
360
361     if (!level) {
362         SG_LOG(SG_INPUT, TREE, endl << "load " << file);
363         _items.erase(_items.begin(), _items.end());
364         _ladders.erase(_ladders.begin(), _ladders.end());
365     } else if (level > MAXNEST) {
366         SG_LOG(SG_INPUT, SG_ALERT, "HUD: files nested more than " << MAXNEST << " levels");
367         return 0x1;
368     } else if (!file || !file[0]) {
369         SG_LOG(SG_INPUT, SG_ALERT, "HUD: invalid filename ");
370         return 0x2;
371     }
372
373     int ret = 0;
374     ifstream input(path.c_str());
375     if (!input.good()) {
376         SG_LOG(SG_INPUT, SG_ALERT, "HUD: Cannot read configuration from '" << path.c_str() << "'");
377         return 0x4;
378     }
379
380     SGPropertyNode root;
381     try {
382         readProperties(input, &root);
383     } catch (const sg_exception &e) {
384         input.close();
385         guiErrorMessage("HUD: Error ", e);
386         return 0x8;
387     }
388
389     delete _clip_box;
390     _clip_box = new ClipBox(fgGetNode("/sim/hud/clipping"), x, y);
391
392     for (int i = 0; i < root.nChildren(); i++) {
393         SGPropertyNode *n = root.getChild(i);
394         const char *d = n->getStringValue("name", 0);
395         string desc;
396         if (d)
397             desc = string(": \"") + d + '"';
398
399         const char *name = n->getName();
400         if (!strcmp(name, "name")) {
401             continue;
402
403         } else if (!strcmp(name, "enable3d")) {
404             // set in the tree so that valueChanged() picks it up
405             _3DenabledN->setBoolValue(n->getBoolValue());
406             continue;
407
408         } else if (!strcmp(name, "import")) {
409             const char *fn = n->getStringValue("path", "");
410             float xoffs = n->getFloatValue("x-offset", 0.0f);
411             float yoffs = n->getFloatValue("y-offset", 0.0f);
412
413             SG_LOG(SG_INPUT, TREE, indent << "|__import " << fn << desc);
414
415             string ind = indent + string(i + 1 < root.nChildren() ? "|    " : "     ");
416             ret |= load(fn, x + xoffs, y + yoffs, level + 1, ind);
417             continue;
418         }
419
420         SG_LOG(SG_INPUT, TREE, indent << "|__" << name << desc);
421
422         Item *item;
423         if (!strcmp(name, "label")) {
424             item = static_cast<Item *>(new Label(this, n, x, y));
425         } else if (!strcmp(name, "gauge")) {
426             item = static_cast<Item *>(new Gauge(this, n, x, y));
427         } else if (!strcmp(name, "tape")) {
428             item = static_cast<Item *>(new Tape(this, n, x, y));
429         } else if (!strcmp(name, "dial")) {
430             item = static_cast<Item *>(new Dial(this, n, x, y));
431         } else if (!strcmp(name, "turn-bank-indicator")) {
432             item = static_cast<Item *>(new TurnBankIndicator(this, n, x, y));
433         } else if (!strcmp(name, "ladder")) {
434             item = static_cast<Item *>(new Ladder(this, n, x, y));
435             _ladders.insert(_ladders.begin(), item);
436             continue;
437         } else if (!strcmp(name, "runway")) {
438             item = static_cast<Item *>(new Runway(this, n, x, y));
439         } else if (!strcmp(name, "aiming-reticle")) {
440             item = static_cast<Item *>(new AimingReticle(this, n, x, y));
441         } else {
442             SG_LOG(SG_INPUT, TREE, indent << "      \\...unsupported!");
443             continue;
444         }
445         _items.insert(_items.begin(), item);
446     }
447     input.close();
448     SG_LOG(SG_INPUT, TREE, indent);
449     return ret;
450 }
451
452
453 void HUD::valueChanged(SGPropertyNode *node)
454 {
455     if (_listener_active)
456         return;
457     _listener_active = true;
458     if (!strcmp(node->getName(), "path"))
459         load(fgGetString("/sim/hud/path[1]", "Huds/default.xml"));
460
461     if (!strcmp(node->getName(), "current-color")) {
462         currentColorChanged();
463     }
464     
465     _scr_width = _scr_widthN->getIntValue();
466     _scr_height = _scr_heightN->getIntValue();
467
468     _visible = _visibility->getBoolValue();
469     _3Denabled = _3DenabledN->getBoolValue();
470     _transparent = _transparency->getBoolValue();
471     _antialiased = _antialiasing->getBoolValue();
472     float brt = _brightness->getFloatValue();
473     _r = clamp(brt * _red->getFloatValue());
474     _g = clamp(brt * _green->getFloatValue());
475     _b = clamp(brt * _blue->getFloatValue());
476     _a = clamp(_alpha->getFloatValue());
477     _cl = clamp(_alpha_clamp->getFloatValue());
478
479     _units = strcmp(_unitsN->getStringValue(), "feet") ? METER : FEET;
480     _listener_active = false;
481 }
482
483 void HUD::currentColorChanged()
484 {
485   SGPropertyNode *n = fgGetNode("/sim/hud/palette", true);
486   int index = _current->getIntValue();
487   if (index < 0) {
488     index = 0;
489   }
490   
491   n = n->getChild("color", index, false);
492   if (!n) {
493     return;
494   }
495   
496   if (n->hasValue("red"))
497       _red->setFloatValue(n->getFloatValue("red", 1.0));
498   if (n->hasValue("green"))
499       _green->setFloatValue(n->getFloatValue("green", 1.0));
500   if (n->hasValue("blue"))
501       _blue->setFloatValue(n->getFloatValue("blue", 1.0));
502   if (n->hasValue("alpha"))
503       _alpha->setFloatValue(n->getFloatValue("alpha", 0.67));
504   if (n->hasValue("alpha-clamp"))
505       _alpha_clamp->setFloatValue(n->getFloatValue("alpha-clamp", 0.01));
506   if (n->hasValue("brightness"))
507       _brightness->setFloatValue(n->getFloatValue("brightness", 0.75));
508   if (n->hasValue("antialiased"))
509       _antialiasing->setBoolValue(n->getBoolValue("antialiased", false));
510   if (n->hasValue("transparent"))
511       _transparency->setBoolValue(n->getBoolValue("transparent", false));
512 }
513
514 void HUD::setColor() const
515 {
516     if (_antialiased)
517         glColor4f(_r, _g, _b, _a);
518     else
519         glColor3f(_r, _g, _b);
520 }
521
522
523 void HUD::textAlign(fntRenderer *rend, const char *s, int align,
524         float *x, float *y, float *l, float *r, float *b, float *t)
525 {
526     fntFont *font = rend->getFont();
527     float gap = font->getGap();
528     float left, right, bot, top;
529     font->getBBox(s, rend->getPointSize(), rend->getSlant(), &left, &right, &bot, &top);
530
531     if (align & HUD::HCENTER)
532         *x -= left - gap + (right - left - gap) / 2.0;
533     else if (align & HUD::RIGHT)
534         *x -= right;
535     else if (align & HUD::LEFT)
536         *x -= left;
537
538     if (align & HUD::VCENTER)
539         *y -= bot + (top - bot) / 2.0;
540     else if (align & HUD::TOP)
541         *y -= top;
542     else if (align & HUD::BOTTOM)
543         *y -= bot;
544
545     *l = *x + left;
546     *r = *x + right;
547     *b = *y + bot;
548     *t = *y + top;
549 }
550
551
552
553
554 // HUDText -- text container for TextList vector
555
556
557 HUDText::HUDText(fntRenderer *fnt, float x, float y, const char *s, int align, int d) :
558     _fnt(fnt),
559     _x(x),
560     _y(y),
561     _digits(d)
562 {
563     strncpy(_msg, s, BUFSIZE);
564     if (!align || !s[0])
565         return;
566     float ign;
567     HUD::textAlign(fnt, s, align, &_x, &_y, &ign, &ign, &ign, &ign);
568 }
569
570
571 void HUDText::draw()
572 {
573     if (!_digits) { // show all digits in same size
574         _fnt->start2f(_x, _y);
575         _fnt->puts(_msg);
576         return;
577     }
578
579     // FIXME
580     // this code is changed to display Numbers with big/small digits
581     // according to MIL Standards for example Altitude above 10000 ft
582     // is shown as 10ooo.
583
584     int c = 0, i = 0;
585     char *t = _msg;
586     int p = 4;
587
588     if (t[0] == '-') {
589         //if negative value then increase the c and p values
590         //for '-' sign.
591         c++; // was moved to the comment. Unintentionally?   TODO
592         p++;
593     }
594     char *tmp = _msg;
595     while (tmp[i] != '\0') {
596         if ((tmp[i] >= '0') && (tmp[i] <= '9'))
597             c++;
598         i++;
599     }
600
601     float orig_size = _fnt->getPointSize();
602     if (c > p) {
603         _fnt->setPointSize(orig_size * 0.8);
604         int p1 = c - 3;
605         char *tmp1 = _msg + p1;
606         int p2 = p1 * 8;
607
608         _fnt->start2f(_x + p2, _y);
609         _fnt->puts(tmp1);
610
611         _fnt->setPointSize(orig_size * 1.2);
612         char tmp2[BUFSIZE];
613         strncpy(tmp2, _msg, p1);
614         tmp2[p1] = '\0';
615
616         _fnt->start2f(_x, _y);
617         _fnt->puts(tmp2);
618     } else {
619         _fnt->setPointSize(orig_size * 1.2);
620         _fnt->start2f(_x, _y);
621         _fnt->puts(tmp);
622     }
623     _fnt->setPointSize(orig_size);
624 }
625
626
627 void TextList::align(const char *s, int align, float *x, float *y,
628         float *l, float *r, float *b, float *t) const
629 {
630     HUD::textAlign(_font, s, align, x, y, l, r, b, t);
631 }
632
633
634 void TextList::draw()
635 {
636     assert(_font);
637
638     // FIXME
639     glPushAttrib(GL_COLOR_BUFFER_BIT);
640     glEnable(GL_BLEND);
641
642     _font->begin();
643     vector<HUDText>::iterator it, end = _list.end();
644     for (it = _list.begin(); it != end; ++it)
645         it->draw();
646     _font->end();
647
648     glDisable(GL_TEXTURE_2D);
649     glPopAttrib();
650 }
651
652
653 ClipBox::ClipBox(const SGPropertyNode *n, float xoffset, float yoffset) :
654     _active(false),
655     _xoffs(xoffset),
656     _yoffs(yoffset)
657 {
658     if (!n)
659         return;
660
661     // const_cast is necessary because ATM there's no matching getChild(const ...)
662     // prototype and getNode(const ..., <bool>) is wrongly interpreted as
663     // getNode(const ..., <int>)
664     _top_node = (const_cast<SGPropertyNode *>(n))->getChild("top", 0, true);
665     _bot_node = (const_cast<SGPropertyNode *>(n))->getChild("bottom", 0, true);
666     _left_node = (const_cast<SGPropertyNode *>(n))->getChild("left", 0, true);
667     _right_node = (const_cast<SGPropertyNode *>(n))->getChild("right", 0, true);
668
669     _left[0] = 1.0, _left[1] = _left[2] = 0.0;
670     _right[0] = -1.0, _right[1] = _right[2] = 0.0;
671     _top[0] = 0.0, _top[1] = -1.0, _top[2] = 0.0;
672     _bot[0] = 0.0, _bot[1] = 1.0, _bot[2] = 0.0;
673     _active = true;
674 }
675
676
677 void ClipBox::set()
678 {
679     if (!_active)
680         return;
681
682     _left[3] = -_left_node->getDoubleValue() - _xoffs;
683     _right[3] = _right_node->getDoubleValue() + _xoffs;
684     _bot[3] = -_bot_node->getDoubleValue() - _yoffs;
685     _top[3] = _top_node->getDoubleValue() + _yoffs;
686
687     glClipPlane(GL_CLIP_PLANE0, _top);
688     glEnable(GL_CLIP_PLANE0);
689     glClipPlane(GL_CLIP_PLANE1, _bot);
690     glEnable(GL_CLIP_PLANE1);
691     glClipPlane(GL_CLIP_PLANE2, _left);
692     glEnable(GL_CLIP_PLANE2);
693     glClipPlane(GL_CLIP_PLANE3, _right);
694     glEnable(GL_CLIP_PLANE3);
695 }
696
697
698 void ClipBox::unset()
699 {
700     if (_active) {
701         glDisable(GL_CLIP_PLANE0);
702         glDisable(GL_CLIP_PLANE1);
703         glDisable(GL_CLIP_PLANE2);
704         glDisable(GL_CLIP_PLANE3);
705     }
706 }