1 // panel.cxx -- routines to draw an instrument panel
3 // Written by Friedemann Reinhard, started June 1998.
5 // Major code reorganization by David Megginson, November 1999.
7 // Copyright(C)1998 Friedemann Reinhard-reinhard@theorie2.physik.uni-erlangen.de
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License as
11 // published by the Free Software Foundation; either version 2 of the
12 // License, or (at your option) any later version.
14 // This program is distributed in the hope that it will be useful, but
15 // WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
45 #include <Debug/logstream.hxx>
46 #include <Aircraft/aircraft.hxx>
47 #include <Main/options.hxx>
48 #include <Main/views.hxx>
49 #include <Misc/fgpath.hxx>
50 #include <Objects/texload.h>
53 #include "cockpit.hxx"
58 ////////////////////////////////////////////////////////////////////////
59 // Implementation of FGPanel.
60 ////////////////////////////////////////////////////////////////////////
64 FGPanel* FGPanel::OurPanel = 0;
67 // Constructor (ensures that the panel is a singleton).
68 FGPanel::FGPanel(void) {
73 GLubyte *tex = new GLubyte[262144];
77 FG_LOG( FG_GENERAL, FG_ALERT, "Error: only one Panel allowed" );
83 Xzoom = (float)((float)(current_view.get_winWidth())/1024);
84 Yzoom = (float)((float)(current_view.get_winHeight())/768);
86 airspeedIndicator = new FGAirspeedIndicator(144.375, 166.875);
87 verticalSpeedIndicator = new FGVerticalSpeedIndicator(358, 52);
88 // Each hand of the altimeter is a
89 // separate instrument for now...
90 altimeter = new FGAltimeter(357.5, 167);
91 altimeter2 = new FGAltimeter2(357.5, 167);
92 horizonIndicator = new FGHorizon(251, 166.75);
93 turnCoordinator = new FGTurnCoordinator(143.75, 51.75);
94 rpmIndicator = new FGRPMIndicator(462.5, 133);
97 xglGenTextures(2, panel_tex_id);
98 xglBindTexture(GL_TEXTURE_2D, panel_tex_id[1]);
99 #elif GL_EXT_texture_object
100 xglGenTexturesEXT(2, panel_tex_id);
101 xglBindTextureEXT(GL_TEXTURE_2D, panel_tex_id[1]);
106 xglMatrixMode(GL_PROJECTION);
109 xglViewport(0, 0, 640, 480);
110 xglOrtho(0, 640, 0, 480, 1, -1);
111 xglMatrixMode(GL_MODELVIEW);
114 xglPixelStorei(GL_UNPACK_ALIGNMENT, 4);
115 xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
116 xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
117 xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
118 xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
120 // load in the texture data
122 xglPixelStorei(GL_UNPACK_ROW_LENGTH, 256);
123 FGPath tpath( current_options.get_fg_root() );
124 tpath.append( "Textures/gauges.rgb" );
125 if((img = read_rgb_texture( (char *)tpath.c_str(), &img_width, &img_height ))==NULL){
128 xglPixelStorei(GL_UNPACK_ROW_LENGTH, 256);
129 tpath.set( current_options.get_fg_root() );
130 tpath.append( "Textures/gauges2.rgb" );
131 if((imag = read_rgb_texture( (char *)tpath.c_str(), &imag_width, &imag_height ))==NULL){
134 xglPixelStorei(GL_UNPACK_ROW_LENGTH, 1024);
136 tpath.set( current_options.get_fg_root() );
137 tpath.append( "Textures/Fullone.rgb" );
138 if ((background = read_rgb_texture( (char *)tpath.c_str(), &width, &height ))==NULL ){
141 xglPixelZoom(Xzoom, Yzoom);
142 xglPixelStorei(GL_UNPACK_ALIGNMENT, 1);
143 xglPixelStorei(GL_UNPACK_ROW_LENGTH, 1024);
145 xglPixelZoom(Xzoom, Yzoom);
146 xglPixelStorei(GL_UNPACK_ROW_LENGTH, 256);
147 xglTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, imag);
149 #ifdef GL_VERSION_1_1
150 xglBindTexture(GL_TEXTURE_2D, panel_tex_id[0]);
151 #elif GL_EXT_texture_object
152 xglBindTextureEXT(GL_TEXTURE_2D, panel_tex_id[0]);
156 xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
157 xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
158 xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
159 xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
160 xglTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid *)(img));
162 xglMatrixMode(GL_MODELVIEW);
170 delete airspeedIndicator;
171 delete verticalSpeedIndicator;
174 delete horizonIndicator;
175 delete turnCoordinator;
181 // Reinitialize the panel.
182 void FGPanel::ReInit( int x, int y, int finx, int finy){
186 xglDisable(GL_DEPTH_TEST);
188 Xzoom = (float)((float)(current_view.get_winWidth())/1024);
189 Yzoom = (float)((float)(current_view.get_winHeight())/768);
191 // save the current buffer state
192 xglGetIntegerv(GL_DRAW_BUFFER, &buffer);
194 // and enable both buffers for writing
195 xglDrawBuffer(GL_FRONT_AND_BACK);
197 xglMatrixMode(GL_PROJECTION);
200 xglViewport(0, 0, 640, 480);
201 xglOrtho(0, 640, 0, 480, 1, -1);
202 xglMatrixMode(GL_MODELVIEW);
205 xglPixelStorei(GL_UNPACK_ALIGNMENT, 1);
206 xglPixelZoom(Xzoom, Yzoom);
207 xglPixelStorei(GL_UNPACK_ALIGNMENT, 1);
208 xglPixelStorei(GL_UNPACK_ROW_LENGTH, 1024);
209 xglPixelStorei(GL_UNPACK_SKIP_PIXELS, x);
210 xglPixelStorei(GL_UNPACK_SKIP_ROWS, y);
211 xglRasterPos2i(x, y);
212 xglPixelZoom(Xzoom, Yzoom);
213 xglDrawPixels(finx - x, finy - y, GL_RGB, GL_UNSIGNED_BYTE,
214 (GLvoid *)(background));
216 // restore original buffer state
217 xglDrawBuffer( (GLenum)buffer );
218 xglEnable(GL_DEPTH_TEST);
223 void FGPanel::Update ( void ) {
224 xglMatrixMode(GL_PROJECTION);
227 xglOrtho(0, 640, 0, 480, 10, -10);
228 xglMatrixMode(GL_MODELVIEW);
231 xglDisable(GL_DEPTH_TEST);
232 xglEnable(GL_LIGHTING);
233 xglEnable(GL_TEXTURE_2D);
234 xglDisable(GL_BLEND);
236 xglMatrixMode(GL_MODELVIEW);
240 xglDisable(GL_LIGHTING);
241 airspeedIndicator->Render();
242 verticalSpeedIndicator->Render();
244 altimeter2->Render();
249 turnCoordinator->Render();
250 rpmIndicator->Render();
252 xglEnable(GL_LIGHTING);
254 horizonIndicator->Render();
257 xglDisable(GL_TEXTURE_2D);
259 xglEnable(GL_DEPTH_TEST);
260 xglEnable(GL_LIGHTING);
261 xglDisable(GL_TEXTURE_2D);
262 xglDisable(GL_BLEND);
263 xglMatrixMode(GL_PROJECTION);
265 xglMatrixMode(GL_MODELVIEW);
270 // fgEraseArea - 'Erases' a drawn Polygon by overlaying it with a textured
271 // area. Shall be a method of a panel class once.
272 // This should migrate into FGPanel somehow.
273 void fgEraseArea(GLfloat *array, int NumVerti, GLfloat texXPos, GLfloat texYPos, GLfloat XPos, GLfloat YPos, int Texid, float ScaleFactor){
279 xglEnable(GL_TEXTURE_2D);
280 xglEnable(GL_TEXTURE_GEN_S);
281 xglEnable(GL_TEXTURE_GEN_T);
282 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
283 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
284 xglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
285 xglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
286 xglTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
287 xglMatrixMode(GL_TEXTURE);
290 #ifdef GL_VERSION_1_1
291 xglBindTexture(GL_TEXTURE_2D, FGPanel::OurPanel->panel_tex_id[Texid]);
292 #elif GL_EXT_texture_object
293 xglBindTextureEXT(GL_TEXTURE_2D, FGPanel::OurPanel->panel_tex_id[Texid]);
298 xglMatrixMode(GL_TEXTURE);
300 xglTranslatef(-((float)((XPos/0.625)/256)), -((float)((YPos/0.625)/256)), 0.0);
301 xglTranslatef(texXPos/256 , texYPos/256, 0.0);
302 xglScalef(0.00625, 0.00625, 1.0);
304 xglBegin(GL_POLYGON);
305 for(n=0;n<NumVerti;n += 2){
306 xglVertex2f(array[n] * ScaleFactor, array[n + 1] * ScaleFactor);
311 xglMatrixMode(GL_MODELVIEW);
312 xglPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
313 xglPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
314 xglDisable(GL_TEXTURE_2D);
315 xglDisable(GL_TEXTURE_GEN_S);
316 xglDisable(GL_TEXTURE_GEN_T);
321 ////////////////////////////////////////////////////////////////////////
322 // Implementation of FGHorizon instrument.
323 ////////////////////////////////////////////////////////////////////////
326 FGHorizon::FGHorizon (float inXPos, float inYPos)
334 FGHorizon::~FGHorizon ()
339 void FGHorizon::Render(void){
342 float shifted, alpha, theta;
343 float epsi = 360 / 180;
347 int n1, n2, n, dn, rot, tmp1, tmp2;
350 GLfloat material[] = { 0.714844, 0.265625, 0.056875 ,1.0};
351 GLfloat material2[] = {0.6640625, 0.921875, 0.984375, 1.0};
352 GLfloat material3[] = {0.2, 0.2, 0.2, 1.0};
353 GLfloat material4[] = {0.8, 0.8, 0.8, 1.0};
354 GLfloat material5[] = {0.0, 0.0, 0.0, 1.0};
355 GLfloat direction[] = {0.0, 0.0, 0.0};
356 GLfloat light_position[4];
357 GLfloat light_ambient[] = {0.7, 0.7, 0.7, 1.0};
358 GLfloat light_ambient2[] = {0.7, 0.7, 0.7, 1.0};
359 GLfloat light_diffuse[] = {1.0, 1.0, 1.0, 1.0};
360 GLfloat light_specular[] = {1.0, 1.0, 1.0, 1.0};
362 pitch = get_pitch() * RAD_TO_DEG;
369 roll = get_roll() * RAD_TO_DEG;
371 xglEnable(GL_NORMALIZE);
372 xglEnable(GL_LIGHTING);
373 xglEnable(GL_TEXTURE_2D);
374 xglEnable(GL_LIGHT1);
375 xglDisable(GL_LIGHT2);
376 xglDisable(GL_LIGHT0);
377 xglMatrixMode(GL_MODELVIEW);
379 xglTranslatef(XPos, YPos, 0);
380 xglTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
381 xglMatrixMode(GL_TEXTURE);
384 // computations for the non-textured parts of the AH
386 shifted = -((pitch / 10) * 7.0588235);
388 if(shifted > (bottom - radius)){
389 theta = (180 - (acos((bottom - shifted) / radius)*RAD_TO_DEG));
390 n = (int)(theta / epsi) - 1;
394 rot = (int)(roll / epsi);
399 if(shifted < (-top + radius)){
400 theta = ((acos((-top - shifted) / radius)*RAD_TO_DEG));
401 n = (int)(theta / epsi) + 1;
405 rot = (int)(roll / epsi);
408 if(n1 < 0){ n1 += 180; n2 +=180;}
411 // end of computations
413 light_position[0] = 0.0;
414 light_position[1] = 0.0;
415 light_position[2] = 1.5;
416 light_position[3] = 0.0;
417 xglLightfv(GL_LIGHT1, GL_POSITION, light_position);
418 xglLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);
419 xglLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
420 xglLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);
421 xglLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, direction);
423 #ifdef GL_VERSION_1_1
425 xglBindTexture(GL_TEXTURE_2D, FGPanel::OurPanel->panel_tex_id[1]);
426 #elif GL_EXT_texture_object
428 xglBindTextureEXT(GL_TEXTURE_2D, FGPanel::OurPanel->panel_tex_id[1]);
434 xglTranslatef(0.0, ((pitch / 10) * 0.046875), 0.0);
435 xglTranslatef((texXPos/256), (texYPos/256), 0.0);
436 xglRotatef(-roll, 0.0, 0.0, 1.0);
437 xglScalef(1.7, 1.7, 0.0);
439 // the following loop draws the textured part of the AH
441 xglMaterialf(GL_FRONT, GL_SHININESS, 85.0);
443 xglMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, material4);
444 xglMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, material5);
445 xglMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, material3);
447 xglMatrixMode(GL_MODELVIEW);
448 xglBegin(GL_TRIANGLES);
451 for(i=45; i < 225; i++){
452 xglTexCoord2f(0.0, 0.0);
453 xglNormal3f(0.0, 0.0, 0.6);
454 xglVertex3f(0.0, 0.0, 0.0);
455 xglTexCoord2f(texCoord[i % 180][0], texCoord[i % 180][1]);
456 xglNormal3f(normals[i % 180][0], normals[i % 180][1], 0.6);
457 xglVertex3f(vertices[i % 180][0], vertices[i % 180][1], 0.0);
459 xglTexCoord2f(texCoord[n][0], texCoord[n][1]);
460 xglNormal3f(normals[n][0], normals[n][1], 0.6);
461 xglVertex3f(vertices[n][0], vertices[n][1], 0.0);
466 if((shifted > (bottom - radius)) && (n1 < 1000) && (n1 > 0)){
468 a = sin(theta * DEG_TO_RAD) * sin(theta * DEG_TO_RAD);
469 light_ambient2[0] = a;
470 light_ambient2[1] = a;
471 light_ambient2[2] = a;
473 xglLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient2);
474 xglLightfv(GL_LIGHT1, GL_DIFFUSE, light_ambient2);
475 xglLightfv(GL_LIGHT1, GL_SPECULAR, light_ambient2);
477 xglBegin(GL_TRIANGLES);
479 tmp1 = n1; tmp2 = n2;
481 for(i = tmp1; i < tmp2 + 1; i++){
483 xglNormal3f(0.0, 0.0, 1.5);
484 xglTexCoord2f((56 / 256), (140 / 256));
485 xglVertex3f(((vertices[n1 % 180][0] + vertices[n2 % 180][0]) / 2), ((vertices[n1 % 180][1] + vertices[n2 % 180][1]) / 2), 0.0);
487 xglTexCoord2f((57 / 256), (139 / 256));
488 xglNormal3f(normals[n][0], normals[n][1], normals[n][3]);
489 xglVertex3f(vertices[n][0], vertices[n][1], 0.0);
492 xglTexCoord2f((57 / 256), (139 / 256));
493 xglNormal3f(normals[n][0], normals[n][1], normals[n][3]);
494 xglVertex3f(vertices[n][0], vertices[n][1], 0.0);
499 if((shifted < (-top + radius)) && (n1 < 1000) && (n1 > 0)){
500 a = sin(theta * DEG_TO_RAD) * sin(theta * DEG_TO_RAD);
501 light_ambient2[0] = a;
502 light_ambient2[1] = a;
503 light_ambient2[2] = a;
505 xglLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient2);
506 xglLightfv(GL_LIGHT1, GL_DIFFUSE, light_ambient2);
507 xglLightfv(GL_LIGHT1, GL_SPECULAR, light_ambient2);
508 xglMaterialf(GL_FRONT, GL_SHININESS, a * 85);
509 xglBegin(GL_TRIANGLES);
510 tmp1 = n1; tmp2 = n2;
511 for(i = tmp1; i <= tmp2; i++){
513 xglNormal3f(0.0, 0.0, 1.5);
514 xglTexCoord2f((73 / 256), (237 / 256));
515 xglVertex3f(((vertices[n1 % 180][0] + vertices[n2 % 180][0]) / 2), ((vertices[n1 % 180][1] + vertices[n2 % 180][1]) / 2), 0.0);
517 xglTexCoord2f((73 / 256), (236 / 256));
518 xglNormal3f(normals[n][0], normals[n][1], normals[n][2]);
519 xglVertex3f(vertices[n][0], vertices[n][1], 0.0);
522 xglTexCoord2f((73 / 256), (236 / 256));
523 xglNormal3f(normals[n][0], normals[n][1], normals[n][2]);
524 xglVertex3f(vertices[n][0], vertices[n][1], 0.0);
529 // Now we will have to draw the small triangle indicating the roll value
531 xglDisable(GL_LIGHTING);
532 xglDisable(GL_TEXTURE_2D);
534 xglRotatef(roll, 0.0, 0.0, 1.0);
536 xglBegin(GL_TRIANGLES);
537 xglColor3f(1.0, 1.0, 1.0);
538 xglVertex3f(0.0, radius, 0.0);
539 xglVertex3f(-3.0, (radius - 7.0), 0.0);
540 xglVertex3f(3.0, (radius - 7.0), 0.0);
545 xglBegin(GL_POLYGON);
546 xglColor3f(0.2109375, 0.23046875, 0.203125);
547 xglVertex2f(275.625, 138.0);
548 xglVertex2f(275.625, 148.125);
549 xglVertex2f(258.125, 151.25);
550 xglVertex2f(246.875, 151.25);
551 xglVertex2f(226.875, 147.5);
552 xglVertex2f(226.875, 138.0);
553 xglVertex2f(275.625, 138.0);
558 xglMatrixMode(GL_TEXTURE);
560 xglMatrixMode(GL_PROJECTION);
562 xglDisable(GL_TEXTURE_2D);
563 xglDisable(GL_NORMALIZE);
564 xglDisable(GL_LIGHTING);
565 xglDisable(GL_LIGHT1);
566 xglEnable(GL_LIGHT0);
569 // fgHorizonInit - initialize values for the AH
571 void FGHorizon::Init(void){
579 float step = (360*DEG_TO_RAD)/180;
582 vertices[n][0] = cos(n * step) * radius;
583 vertices[n][1] = sin(n * step) * radius;
584 texCoord[n][0] = (cos(n * step) * radius)/256;
585 texCoord[n][1] = (sin(n * step) * radius)/256;
586 normals[n][0] = cos(n * step) * radius + sin(n * step);
587 normals[n][1] = sin(n * step) * radius + cos(n * step);
594 ////////////////////////////////////////////////////////////////////////
595 // Implementation of FGTurnCoordinator.
596 ////////////////////////////////////////////////////////////////////////
601 GLfloat FGTurnCoordinator::wingArea[] = {
602 -1.25, -28.125, 1.255, -28.125, 1.255, 28.125, -1.25, 28.125 };
604 GLfloat FGTurnCoordinator::elevatorArea[] = {
605 3.0, -10.9375, 4.5, -10.9375, 4.5, 10.9375, 3.0, 10.9375 };
607 GLfloat FGTurnCoordinator::rudderArea[] = {
608 2.0, -0.45, 10.625, -0.45, 10.625, 0.55, 2.0, 0.55};
611 FGTurnCoordinator::FGTurnCoordinator (float inXPos, float inYPos)
618 FGTurnCoordinator::~FGTurnCoordinator ()
623 // fgUpdateTurnCoordinator - draws turn coordinator related stuff
625 void FGTurnCoordinator::Render(void){
628 xglDisable(GL_LIGHTING);
629 xglDisable(GL_BLEND);
630 xglEnable(GL_TEXTURE_2D);
632 alpha = (get_sideslip() / 1.5) * 560;
640 PlaneAlpha = get_roll();
642 xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
643 xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
644 xglTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
646 xglMatrixMode(GL_MODELVIEW);
648 xglTranslatef(BallXPos, BallYPos, 0.0);
649 xglTranslatef(0.75 * sin(alphahist[0] * DEG_TO_RAD) * 31, 0.3 * (39 - (cos(alphahist[0] * DEG_TO_RAD) * 39)), 0.0);
650 fgEraseArea(vertices, 72, BallTexXPos + ((0.75 * sin(alphahist[0] * DEG_TO_RAD) * 31) / 0.625), BallTexYPos + ((0.3 * (39 - (cos(alphahist[0] * DEG_TO_RAD) * 39))) / 0.625), BallXPos + (0.75 * sin(alphahist[0] * DEG_TO_RAD) * 31), BallYPos + (0.3 * (39 - (cos(alphahist[0] * DEG_TO_RAD) * 39))), 1, 1);
651 xglDisable(GL_TEXTURE_2D);
653 xglBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE);
654 xglMatrixMode(GL_MODELVIEW);
656 xglTranslatef(BallXPos, BallYPos, 0.0);
657 xglTranslatef(0.75 * sin(alpha * DEG_TO_RAD) * 31, 0.3 * (39 - (cos(alpha * DEG_TO_RAD) * 39)), 0.0);
658 xglBegin(GL_POLYGON);
659 xglColor3f(0.8, 0.8, 0.8);
663 xglVertex2f(vertices[2 * i], vertices[(2 * i) + 1]);
667 xglDisable(GL_TEXTURE_2D);
668 xglDisable(GL_BLEND);
670 xglMatrixMode(GL_MODELVIEW);
672 xglTranslatef(XPos, YPos, 0.0);
673 xglRotatef(rollhist[0] * RAD_TO_DEG + 90, 0.0, 0.0, 1.0);
675 fgEraseArea(wingArea, 8, PlaneTexXPos, PlaneTexYPos, XPos, YPos, 1, 1);
676 fgEraseArea(elevatorArea, 8, PlaneTexXPos, PlaneTexYPos, XPos, YPos, 1, 1);
677 fgEraseArea(rudderArea, 8, PlaneTexXPos, PlaneTexYPos, XPos, YPos, 1, 1);
680 xglTranslatef(XPos, YPos, 0.0);
681 xglRotatef(-get_roll() * RAD_TO_DEG + 90, 0.0, 0.0, 1.0);
683 xglBegin(GL_POLYGON);
684 xglColor3f(1.0, 1.0, 1.0);
686 xglVertex2f(cos(i * 4 * DEG_TO_RAD) * 5, sin(i * 4 * DEG_TO_RAD) * 5);
690 xglBegin(GL_POLYGON);
691 xglVertex2f(wingArea[0], wingArea[1]);
692 xglVertex2f(wingArea[2], wingArea[3]);
693 xglVertex2f(wingArea[4], wingArea[5]);
694 xglVertex2f(wingArea[6], wingArea[7]);
695 xglVertex2f(wingArea[0], wingArea[1]);
698 xglBegin(GL_POLYGON);
699 xglVertex2f(elevatorArea[0], elevatorArea[1]);
700 xglVertex2f(elevatorArea[2], elevatorArea[3]);
701 xglVertex2f(elevatorArea[4], elevatorArea[5]);
702 xglVertex2f(elevatorArea[6], elevatorArea[7]);
703 xglVertex2f(elevatorArea[0], elevatorArea[1]);
706 xglBegin(GL_POLYGON);
707 xglVertex2f(rudderArea[0], rudderArea[1]);
708 xglVertex2f(rudderArea[2], rudderArea[3]);
709 xglVertex2f(rudderArea[4], rudderArea[5]);
710 xglVertex2f(rudderArea[6], rudderArea[7]);
711 xglVertex2f(rudderArea[0], rudderArea[1]);
715 alphahist[0] = alphahist[1];
716 alphahist[1] = alpha;
717 rollhist[0] = rollhist[1];
718 rollhist[1] = -get_roll();
720 xglDisable(GL_BLEND);
723 void FGTurnCoordinator::Init(void){
726 PlaneTexYPos = 59.75;
734 vertices[2 * n] = cos(10 * n * DEG_TO_RAD) * BallRadius;
735 vertices[(2 * n) + 1] = sin(10 * n * DEG_TO_RAD) * BallRadius;
741 ////////////////////////////////////////////////////////////////////////
742 // Implementation of FGTexInstrument base class.
743 ////////////////////////////////////////////////////////////////////////
745 FGTexInstrument::FGTexInstrument (void)
749 FGTexInstrument::~FGTexInstrument (void)
753 void FGTexInstrument::UpdatePointer(void){
756 glEnableClientState(GL_VERTEX_ARRAY);
757 glVertexPointer(2, GL_FLOAT, 0, vertices);
759 alpha=((((float)(getValue() - (value1))) /
760 (value2 - value1))* (alpha2 - alpha1) + alpha1);
766 xglMatrixMode(GL_MODELVIEW);
769 xglDisable(GL_TEXTURE_2D);
770 xglTranslatef(XPos, YPos, 0);
771 xglRotatef(-alpha, 0.0, 0.0, 1.0);
772 xglColor4f(1.0, 1.0, 1.0, 1.0);
773 glDrawArrays(GL_POLYGON, 0, 10);
776 xglEnable(GL_TEXTURE_2D);
777 glDisableClientState(GL_VERTEX_ARRAY);
780 // CreatePointer - calculate the vertices of a pointer
782 void FGTexInstrument::CreatePointer(void){
789 vertices[1] = length;
790 vertices[2] = -(width/2);
791 vertices[3] = length - ((width/2)/(tan(angle*DEG_TO_RAD/2)));
792 vertices[4] = -(width/2);
793 vertices[5] = cos(asin((width/2)/r))*r;
795 alphastep = (asin((width/2)/r)+asin((width/2)/r))/5;
796 alpha = asin(-(width/2)/r);
800 vertices[(i*2)+6] = sin(alpha)*r;
803 alpha = asin(-(width/2)/r);
807 vertices[(i*2)+7]= cos(alpha)*r;
810 vertices[16] = - vertices[4];
811 vertices[17] = vertices[5];
812 vertices[18] = - vertices[2];
813 vertices[19] = vertices[3];
817 void FGTexInstrument::Init(void){
821 void FGTexInstrument::Render(void){
822 xglEnable(GL_TEXTURE_2D);
824 xglTranslatef(XPos, YPos, 0.0);
825 xglRotatef(-tape[0], 0.0, 0.0, 1.0);
826 fgEraseArea(vertices, 20, (GLfloat)(textureXPos), (GLfloat)(textureYPos), (GLfloat)(XPos), (GLfloat)(YPos), 0, 1);
830 xglDisable(GL_TEXTURE_2D);
835 ////////////////////////////////////////////////////////////////////////
836 // Implementation of FGAirspeedIndicator.
837 ////////////////////////////////////////////////////////////////////////
840 FGAirspeedIndicator::FGAirspeedIndicator (int x, int y)
858 FGAirspeedIndicator::~FGAirspeedIndicator ()
864 FGAirspeedIndicator::getValue () const
871 ////////////////////////////////////////////////////////////////////////
872 // Implementation of FGVerticalSpeedIndicator.
873 ////////////////////////////////////////////////////////////////////////
876 FGVerticalSpeedIndicator::FGVerticalSpeedIndicator (int x, int y)
894 FGVerticalSpeedIndicator::~FGVerticalSpeedIndicator ()
900 FGVerticalSpeedIndicator::getValue () const
902 return get_climb_rate() / 1000.0;
907 ////////////////////////////////////////////////////////////////////////
908 // Implementation of FGAltimeter.
909 ////////////////////////////////////////////////////////////////////////
912 FGAltimeter::FGAltimeter (int x, int y)
930 FGAltimeter::~FGAltimeter ()
936 FGAltimeter::getValue () const
938 return get_altitude();
943 ////////////////////////////////////////////////////////////////////////
944 // Implementation of FGAltimeter2.
945 ////////////////////////////////////////////////////////////////////////
948 FGAltimeter2::FGAltimeter2 (int x, int y)
966 FGAltimeter2::~FGAltimeter2 ()
972 FGAltimeter2::getValue () const
974 return get_altitude();
979 ////////////////////////////////////////////////////////////////////////
980 // Implementation of FGRPMIndicator.
981 ////////////////////////////////////////////////////////////////////////
984 FGRPMIndicator::FGRPMIndicator (int x, int y)
1002 FGRPMIndicator::~FGRPMIndicator ()
1008 FGRPMIndicator::getValue () const
1010 return get_throttleval();