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