5 #include <Main/fg_props.hxx>
6 #include <Cockpit/panel.hxx>
7 #include <Cockpit/panel_io.hxx>
9 #include "panelnode.hxx"
11 FGPanelNode::FGPanelNode(SGPropertyNode* props)
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"));
17 // Read out the pixel-space info
18 _xmax = _panel->getWidth();
19 _ymax = _panel->getHeight();
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");
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");
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");
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];
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
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];
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;
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.
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]) +
75 bsphere.setCenter(cx, cy, cz);
79 FGPanelNode::~FGPanelNode()
84 void FGPanelNode::draw()
86 // What's the difference?
90 void FGPanelNode::draw_geometry()
92 glMatrixMode(GL_MODELVIEW);
94 glMultMatrixf(_xform);
99 void FGPanelNode::die()
101 SG_LOG(SG_ALL,SG_ALERT,"Unimplemented function called on FGPanelNode");