]> git.mxchange.org Git - flightgear.git/blob - src/Model/panelnode.cxx
Change FGSteam into a proper subsystem rather than a collection of
[flightgear.git] / src / Model / panelnode.cxx
1 #ifdef HAVE_CONFIG_H
2 #  include <config.h>
3 #endif
4
5 #include <Main/fg_props.hxx>
6 #include <Cockpit/panel.hxx>
7 #include <Cockpit/panel_io.hxx>
8 #include <GL/gl.h>
9 #include "panelnode.hxx"
10
11 FGPanelNode::FGPanelNode(SGPropertyNode* props)
12 {
13     // Make an FGPanel object.  But *don't* call init() or bind() on
14     // it -- those methods touch static state.
15     _panel = fgReadPanel(props->getStringValue("path"));
16
17     // Read out the pixel-space info
18     _xmax = _panel->getWidth();
19     _ymax = _panel->getHeight();
20
21     // And the corner points
22     SGPropertyNode* pt = props->getChild("bottom-left");
23     _bottomLeft[0] = pt->getFloatValue("x-m");
24     _bottomLeft[1] = pt->getFloatValue("y-m");
25     _bottomLeft[2] = pt->getFloatValue("z-m");
26
27     pt = props->getChild("top-left");
28     _topLeft[0] = pt->getFloatValue("x-m");
29     _topLeft[1] = pt->getFloatValue("y-m");
30     _topLeft[2] = pt->getFloatValue("z-m");
31
32     pt = props->getChild("bottom-right");
33     _bottomRight[0] = pt->getFloatValue("x-m");
34     _bottomRight[1] = pt->getFloatValue("y-m");
35     _bottomRight[2] = pt->getFloatValue("z-m");
36
37     // Now generate out transformation matrix.  For shorthand, use
38     // "a", "b", and "c" as our corners and "m" as the matrix. The
39     // vector u goes from a to b, v from a to c, and w is a
40     // perpendicular cross product.
41     float *a = _bottomLeft, *b = _bottomRight, *c = _topLeft, *m = _xform;
42     float u[3], v[3], w[3];
43     int i;
44     for(i=0; i<3; i++) u[i] = b[i] - a[i]; // U = B - A
45     for(i=0; i<3; i++) v[i] = c[i] - a[i]; // V = C - A
46
47     w[0] = u[1]*v[2] - v[1]*u[2];          // W = U x V
48     w[1] = u[2]*v[0] - v[2]*u[0];
49     w[2] = u[0]*v[1] - v[0]*u[1];
50
51     // Now generate a trivial basis transformation matrix.  If we want
52     // to map the three unit vectors to three arbitrary vectors U, V,
53     // and W, then those just become the columns of the 3x3 matrix.
54     m[0] = u[0]; m[4] = v[0]; m[8]  = w[0]; m[12] = a[0]; //     |Ux Vx Wx|
55     m[1] = u[1]; m[5] = v[1]; m[9]  = w[1]; m[13] = a[1]; // m = |Uy Vy Wy|
56     m[2] = u[2]; m[6] = v[2]; m[10] = w[2]; m[14] = a[2]; //     |Uz Vz Wz|
57     m[3] = 0;    m[7] = 0;    m[11] = 0;    m[15] = 1;
58
59     // The above matrix maps the unit (!) square to the panel
60     // rectangle.  Postmultiply scaling factors that match the
61     // pixel-space size of the panel.
62     for(i=0; i<4; i++) {
63         m[0+i] *= 1.0/_xmax;
64         m[4+i] *= 1.0/_ymax;
65     }
66
67     // Now plib initialization.  The bounding sphere is defined nicely
68     // by our corner points:
69     float cx = (b[0]+c[0])/2;
70     float cy = (b[1]+c[1])/2;
71     float cz = (b[2]+c[2])/2;
72     float r = sqrt((cx-a[0])*(cx-a[0]) +
73                    (cy-a[1])*(cy-a[1]) +
74                    (cz-a[2])*(cz-a[2]));
75     bsphere.setCenter(cx, cy, cz);
76     bsphere.setRadius(r);
77 }
78
79 FGPanelNode::~FGPanelNode()
80 {
81     delete _panel;
82 }
83
84 void FGPanelNode::draw()
85 {
86     // What's the difference?
87     draw_geometry();
88 }
89
90 void FGPanelNode::draw_geometry()
91 {
92     glMatrixMode(GL_MODELVIEW);
93     glPushMatrix();
94     glMultMatrixf(_xform);
95     _panel->draw();
96     glPopMatrix();
97 }
98
99 void FGPanelNode::die()
100 {
101     SG_LOG(SG_ALL,SG_ALERT,"Unimplemented function called on FGPanelNode");
102     *(int*)0=0;
103 }
104