2 #include <Main/fg_props.hxx>
3 #include <Cockpit/panel.hxx>
4 #include <Cockpit/panel_io.hxx>
5 #include "panelnode.hxx"
7 FGPanelNode::FGPanelNode(SGPropertyNode* props)
9 // Make an FGPanel object. But *don't* call init() or bind() on
10 // it -- those methods touch static state.
11 _panel = fgReadPanel(props->getStringValue("path"));
13 // Read out the pixel-space info
14 _xmax = _panel->getWidth();
15 _ymax = _panel->getHeight();
17 // And the corner points
18 SGPropertyNode* pt = props->getChild("bottom-left");
19 _bottomLeft[0] = pt->getFloatValue("x-m");
20 _bottomLeft[1] = pt->getFloatValue("y-m");
21 _bottomLeft[2] = pt->getFloatValue("z-m");
23 pt = props->getChild("top-left");
24 _topLeft[0] = pt->getFloatValue("x-m");
25 _topLeft[1] = pt->getFloatValue("y-m");
26 _topLeft[2] = pt->getFloatValue("z-m");
28 pt = props->getChild("bottom-right");
29 _bottomRight[0] = pt->getFloatValue("x-m");
30 _bottomRight[1] = pt->getFloatValue("y-m");
31 _bottomRight[2] = pt->getFloatValue("z-m");
33 // Now generate out transformation matrix. For shorthand, use
34 // "a", "b", and "c" as our corners and "m" as the matrix. The
35 // vector u goes from a to b, v from a to c, and w is a
36 // perpendicular cross product.
37 float *a = _bottomLeft, *b = _bottomRight, *c = _topLeft, *m = _xform;
38 float u[3], v[3], w[3];
40 for(i=0; i<3; i++) u[i] = b[i] - a[i]; // U = B - A
41 for(i=0; i<3; i++) v[i] = c[i] - a[i]; // V = C - A
43 w[0] = u[1]*v[2] - v[1]*u[2]; // W = U x V
44 w[1] = u[2]*v[0] - v[2]*u[0];
45 w[2] = u[0]*v[1] - v[0]*u[1];
47 // Now generate a trivial basis transformation matrix. If we want
48 // to map the three unit vectors to three arbitrary vectors U, V,
49 // and W, then those just become the columns of the 3x3 matrix.
50 m[0] = u[0]; m[4] = v[0]; m[8] = w[0]; m[12] = a[0]; // |Ux Vx Wx|
51 m[1] = u[1]; m[5] = v[1]; m[9] = w[1]; m[13] = a[1]; // m = |Uy Vy Wy|
52 m[2] = u[2]; m[6] = v[2]; m[10] = w[2]; m[14] = a[2]; // |Uz Vz Wz|
53 m[3] = 0; m[7] = 0; m[11] = 0; m[15] = 1;
55 // The above matrix maps the unit (!) square to the panel
56 // rectangle. Postmultiply scaling factors that match the
57 // pixel-space size of the panel.
63 // Now plib initialization. The bounding sphere is defined nicely
64 // by our corner points:
65 float cx = (b[0]+c[0])/2;
66 float cy = (b[1]+c[1])/2;
67 float cz = (b[2]+c[2])/2;
68 float r = sqrt((cx-a[0])*(cx-a[0]) +
71 bsphere.setCenter(cx, cy, cz);
75 FGPanelNode::~FGPanelNode()
80 void FGPanelNode::draw()
82 // What's the difference?
86 void FGPanelNode::draw_geometry()
88 glMatrixMode(GL_MODELVIEW);
90 glMultMatrixf(_xform);
95 void FGPanelNode::die()
97 SG_LOG(SG_ALL,SG_ALERT,"Unimplemented function called on FGPanelNode");