1 /*
2     GL-117
3     Copyright 2001, 2002 Thomas A. Drexl aka heptargon
4 
5     This file is part of GL-117.
6 
7     GL-117 is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11 
12     GL-117 is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16 
17     You should have received a copy of the GNU General Public License
18     along with GL-117; if not, write to the Free Software
19     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 */
21 
22 /* This file includes the cockpit rendering methods. */
23 
24 #ifndef IS_COCKPIT_H
25 
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include "cockpit.h"
29 #include "main.h"
30 #include "pilots.h"
31 #include "mathtab.h"
32 #include "mission.h"
33 #include "gl.h"
34 #include "glland.h"
35 
36 #define TRIANGLE_BLIP 1
37 #define SQUARE_BLIP   2
38 
Cockpit()39 Cockpit::Cockpit ()
40 {
41   flarewarning = 0;
42   chaffwarning = 0;
43 }
44 
45 // Mitchell Perilstein:
drawBlip(int shape,float x,float y,float z,unsigned char r,unsigned char g,unsigned char b)46 void Cockpit::drawBlip(int shape, float x, float y, float z, unsigned char r, unsigned char g, unsigned char b)
47 {
48   float blipsize = 0.02;
49   int alpha = 200;
50   CColor color;
51 
52 //  setColor (&color, alpha); // no need here
53   glColor4ub (r, g, b, alpha);
54   glBegin (GL_QUADS);
55 
56   switch (shape) {
57   case SQUARE_BLIP:
58     glVertex3f (x + blipsize, y + blipsize, z);
59     glVertex3f (x + blipsize, y - blipsize, z);
60     glVertex3f (x - blipsize, y - blipsize, z);
61     glVertex3f (x - blipsize, y + blipsize, z);
62     glVertex3f (x + blipsize, y + blipsize, z);
63     break;
64   case TRIANGLE_BLIP:
65     glVertex3f (x, y + blipsize, z);
66     glVertex3f (x + blipsize, y - blipsize, z);
67     glVertex3f (x - blipsize, y - blipsize, z);
68     glVertex3f (x, y + blipsize, z);
69     break;
70   default:
71     abort();
72   }
73   glEnd ();
74 }
75 
cockpitvertex(float phi,float gamma)76 void Cockpit::cockpitvertex (float phi, float gamma) // cylindrical headup projection
77 {
78   float fpt = -fplayer->theta + 180;
79   float sinfpt = SIN(fpt), cosfpt = COS(fpt);
80   float x = cosfpt * phi + sinfpt * gamma + 180;
81   float y = sinfpt * phi - cosfpt * gamma + 180;
82   glVertex3f (10*SIN(x),10*SIN(y),-10*COS(x)*COS(y));
83 }
84 
setColor(int alpha)85 void Cockpit::setColor (int alpha)
86 {
87   if (fplayer->o == &model_fig) glColor4ub (255, 255, 0, alpha);
88   else if (fplayer->o == &model_figb) glColor4ub (255, 150, 100, alpha);
89   else if (fplayer->o == &model_figc) glColor4ub (200, 200, 100, alpha);
90   else if (fplayer->o == &model_figg) glColor4ub (255, 0, 0, alpha);
91   else if (fplayer->o == &model_figi) glColor4ub (200, 200, 100, alpha);
92   else glColor4ub (100, 100, 255, alpha);
93 }
94 
setColor(CColor * color,int alpha)95 void Cockpit::setColor (CColor *color, int alpha)
96 {
97   if (fplayer->o == &model_fig) color->setColor (255, 255, 0, alpha);
98   else if (fplayer->o == &model_figb) color->setColor (255, 150, 100, alpha);
99   else if (fplayer->o == &model_figc) color->setColor (200, 200, 100, alpha);
100   else if (fplayer->o == &model_figg) color->setColor (255, 0, 0, alpha);
101   else if (fplayer->o == &model_figi) color->setColor (200, 200, 100, alpha);
102   else color->setColor (100, 100, 255, alpha);
103 }
104 
drawCounter()105 void Cockpit::drawCounter ()
106 {
107   int i;
108   char buf [STDSIZE];
109   float xf = 2.8F, yf = -1.0F, zf = -4.0F, yf2 = -1.3F, xfl = 0.4F, yfl = 0.1F;
110 //    glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
111   bool flarewarn = false, chaffwarn = false;
112   for (i = 0; i < maxmissile; i ++)
113     if (missile [i]->active)
114       if (missile [i]->target == fplayer)
115       {
116         if (missile [i]->id <= MISSILE_AIR1)
117           flarewarn = true;
118         else
119           chaffwarn = true;
120       }
121   if (flarewarn && game == GAME_PLAY)
122   {
123     if (flarewarning <= 0)
124     {
125       flarewarning = 10 * timestep;
126       sound->play (SOUND_BEEP2, false);
127     }
128     flarewarning -= dt;
129     if (flarewarning <= 6 * timestep)
130     {
131       glColor3ub (200, 0, 0);
132       glBegin (GL_QUADS);
133       glVertex3f (xf - xfl, yf2 - yfl, zf);
134       glVertex3f (xf + xfl, yf2 - yfl, zf);
135       glVertex3f (xf + xfl, yf2 + yfl, zf);
136       glVertex3f (xf - xfl, yf2 + yfl, zf);
137       glEnd ();
138     }
139   }
140   if (chaffwarn && game == GAME_PLAY)
141   {
142     if (chaffwarning <= 0)
143     {
144       chaffwarning = 10 * timestep;
145       sound->play (SOUND_BEEP1, false);
146     }
147     chaffwarning -= dt;
148     if (chaffwarning <= 6 * timestep)
149     {
150       glColor3ub (0, 0, 200);
151       glBegin (GL_QUADS);
152       glVertex3f (xf - xfl, yf - yfl, zf);
153       glVertex3f (xf + xfl, yf - yfl, zf);
154       glVertex3f (xf + xfl, yf + yfl, zf);
155       glVertex3f (xf - xfl, yf + yfl, zf);
156       glEnd ();
157     }
158   }
159   glLineWidth (LINEWIDTH(1.0F));
160   glColor3ub (255, 0, 0);
161   glBegin (GL_LINE_STRIP);
162   glVertex3f (xf - xfl, yf2 - yfl, zf);
163   glVertex3f (xf + xfl, yf2 - yfl, zf);
164   glVertex3f (xf + xfl, yf2 + yfl, zf);
165   glVertex3f (xf - xfl, yf2 + yfl, zf);
166   glVertex3f (xf - xfl, yf2 - yfl, zf);
167   glEnd ();
168   glColor3ub (0, 100, 255);
169   glBegin (GL_LINE_STRIP);
170   glVertex3f (xf - xfl, yf - yfl, zf);
171   glVertex3f (xf + xfl, yf - yfl, zf);
172   glVertex3f (xf + xfl, yf + yfl, zf);
173   glVertex3f (xf - xfl, yf + yfl, zf);
174   glVertex3f (xf - xfl, yf - yfl, zf);
175   glEnd ();
176   CColor blue (0, 100, 255);
177   CColor red (255, 0, 0);
178   sprintf (buf, "CHAFF: %d", fplayer->chaffs);
179   font1->drawTextCentered (xf*10, (yf-0.05)*10, zf, buf, &blue);
180   sprintf (buf, "FLARE: %d", fplayer->flares);
181   font1->drawTextCentered (xf*10, (yf2-0.05)*10, zf, buf, &red);
182 
183   if (mission->id == MISSION_DEATHMATCH1 || mission->id == MISSION_DEATHMATCH3)
184   {
185     sprintf (buf, "%s: %d", pilots->pilot [pilots->aktpilot]->name, fplayer->fighterkills);
186     font1->drawText (-30.0F, 15.0F, -3.0F, buf, &blue);
187     for (i = 1; i < 8; i ++)
188     {
189       sprintf (buf, "PILOT%d: %d", i, fighter [i]->fighterkills);
190       font1->drawText (-30.0F, 15.0F - i, -3.0F, buf, &red);
191     }
192   }
193   if (mission->id == MISSION_DEATHMATCH2)
194   {
195     for (i = 0; i < 4; i ++)
196     {
197       sprintf (buf, "TEAM%d: %d", i, fighter [i * 2]->fighterkills + fighter [i * 2 + 1]->fighterkills);
198       font1->drawText (-30.0F, 15.0F - i, -3.0F, buf, &red);
199     }
200   }
201 }
202 
203 /*void Cockpit::drawTargeter ()
204 {
205   if (! fplayer->target)
206     return;
207 
208   glMatrixMode (GL_MODELVIEW);
209   glPushMatrix();
210   if (fplayer->target->active)
211   {
212     DynamicObj* target = fplayer->target;
213 
214     float hud_width  = 800.0f; // so x will be from -400.0f to 400.0f
215     float hud_height = 600.0f; //        and y from -300.0f to 300.0f
216     float view_angle = 80.0f / 180.0f * PI; // in radians!
217 
218     float view_matrix [16];
219     glGetFloatv (GL_MODELVIEW_MATRIX, view_matrix);
220 
221     glLoadIdentity ();
222     glMatrixMode (GL_PROJECTION);
223     glLoadIdentity ();
224     gluOrtho2D (-hud_width * 0.5f,  hud_width * 0.5f,
225                 -hud_height * 0.5f, hud_height * 0.5f);
226 
227     CVector3 pos = *target->tl;
228     CVector3 delta = *fplayer->tl;
229     delta.sub (&pos);
230 
231     // multiply Vector by Matrix
232     float* m = view_matrix;
233     float x = m[0] * pos.x + m[4] * pos.y + m[8] * pos.z + m[12];
234     float y = m[1] * pos.x + m[5] * pos.y + m[9] * pos.z + m[13];
235     float z = m[2] * pos.x + m[6] * pos.y + m[10] * pos.z + m[14];
236     pos.x = x; pos.y = y; pos.z = z;
237 
238     float dist = delta.length ();
239 
240     // sorry, but some variables names as good as my english :(
241     float a = sqrt (pos.x * pos.x + pos.y * pos.y);
242     float b = sqrt (dist * dist - a * a);
243     float descale = hud_height * 0.5f / tan (view_angle * 0.5f) / b;
244 
245     gl->enableAlphaBlending ();
246     glTranslatef (pos.x * descale, pos.y * descale, 0.0f);
247     glPushMatrix ();
248 
249       // FIXME: don't sure that this is right:
250       float object_radius = target->zoom;
251 
252       float second_descale = hud_height * 0.5f / tan (view_angle * 0.5f) / (b - object_radius);
253       float radius = object_radius * second_descale + 4.0f;
254 
255       bool full = false;
256       if (static_cast <AIObj*> (fplayer->target)->party != fplayer->party)
257       {
258         if (fplayer->ttf < 0 && fplayer->missiletype != MISSILE_DF1 - MISSILE1)
259         {
260           glColor4ub (255, 255, 0, 255); full = true;
261         }
262         else
263         {
264           glColor4ub (255, (50 * timestep - fplayer->ttf) * 255 / 60 / timestep, 0, 255);
265         }
266       }
267       else
268       {
269         glColor4ub (0, 0, 255, 255);
270       }
271       if (! full)
272       {
273         const float corner_size = 0.5f; // in half's of rect side
274         glBegin (GL_LINE_STRIP);
275         glVertex2f (- radius, radius * (1.0f - corner_size));
276         glVertex2f (- radius, radius);
277         glVertex2f (- radius * (1.0f - corner_size), radius);
278         glEnd ();
279 
280         glBegin (GL_LINE_STRIP);
281         glVertex2f (radius * (1.0f - corner_size), radius);
282         glVertex2f (radius, radius);
283         glVertex2f (radius, radius * (1.0f - corner_size));
284         glEnd ();
285 
286         glBegin (GL_LINE_STRIP);
287         glVertex2f (radius * (1.0f - corner_size), - radius);
288         glVertex2f (radius, - radius);
289         glVertex2f (radius, - radius * (1.0f - corner_size));
290         glEnd ();
291 
292         glBegin (GL_LINE_STRIP);
293         glVertex2f (- radius, - radius * (1.0f - corner_size));
294         glVertex2f (- radius, - radius);
295         glVertex2f (- radius * (1.0f - corner_size), - radius);
296         glEnd ();
297       }
298       else
299       {
300         glBegin (GL_LINE_STRIP);
301         glVertex2f (- radius, - radius);
302         glVertex2f (radius, - radius);
303         glVertex2f (radius, radius);
304         glVertex2f (- radius, radius);
305         glVertex2f (- radius, - radius);
306         glEnd ();
307       }
308     glPopMatrix ();
309     gl->disableAlphaBlending ();
310   }
311   glMatrixMode (GL_MODELVIEW);
312   glPopMatrix();
313 
314   glViewport(0, 0, (GLint) width, (GLint) height);
315 
316   glMatrixMode (GL_PROJECTION);
317   glLoadIdentity ();
318 
319   float v = getView ();
320   if (camera == 50) v = 100000.0;
321   gluPerspective (80.0, (float) width / height, 0.25 * GLOBALSCALE, v * GLOBALSCALE);
322   glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
323 }*/
324 
drawTargeter()325 void Cockpit::drawTargeter ()
326 {
327   if (fplayer->target)
328   if (fplayer->target->active)
329   {
330     DynamicObj *o = fplayer->target;
331     float myphi = fplayer->phi;
332     if (myphi < 0) myphi += 360;
333     float ex1 = cosi [(int) myphi] * o->zoom, ey1 = -sine [(int) myphi] * o->zoom;
334     float ex2 = -ex1, ey2 = -ey1;
335     float ez = o->zoom;
336     gl->enableAlphaBlending ();
337     bool full = false;
338     if (((AIObj *) fplayer->target)->party != fplayer->party)
339     {
340       if (fplayer->ttf <= 0 && fplayer->missiletype != MISSILE_DF1 - MISSILE1)
341       {
342         glColor4ub (255, 255, 0, 255); full = true;
343       }
344       else
345       {
346         glColor4ub (255, (50 * timestep - fplayer->ttf) * 255 / 60 / timestep, 0, 255);
347       }
348     }
349     else
350     {
351       glColor4ub (0, 0, 255, 255);
352     }
353     if (!full)
354     {
355       float dx = (ex2 - ex1) / 4;
356       float dy = (ey2 - ey1) / 4;
357       float dz = ez / 2;
358       glBegin (GL_LINE_STRIP);
359       glVertex3f (o->tl->x + ex1, o->tl->y + ez - dz, o->tl->z + ey1);
360       glVertex3f (o->tl->x + ex1, o->tl->y + ez, o->tl->z + ey1);
361       glVertex3f (o->tl->x + ex1 + dx, o->tl->y + ez, o->tl->z + ey1 + dy);
362       glEnd ();
363       glBegin (GL_LINE_STRIP);
364       glVertex3f (o->tl->x + ex2 - dx, o->tl->y + ez, o->tl->z + ey2 - dy);
365       glVertex3f (o->tl->x + ex2, o->tl->y + ez, o->tl->z + ey2);
366       glVertex3f (o->tl->x + ex2, o->tl->y + ez - dz, o->tl->z + ey2);
367       glEnd ();
368       glBegin (GL_LINE_STRIP);
369       glVertex3f (o->tl->x + ex2, o->tl->y - ez + dz, o->tl->z + ey2);
370       glVertex3f (o->tl->x + ex2, o->tl->y - ez, o->tl->z + ey2);
371       glVertex3f (o->tl->x + ex2 - dx, o->tl->y - ez, o->tl->z + ey2 - dy);
372       glEnd ();
373       glBegin (GL_LINE_STRIP);
374       glVertex3f (o->tl->x + ex1 + dx, o->tl->y - ez, o->tl->z + ey1 + dy);
375       glVertex3f (o->tl->x + ex1, o->tl->y - ez, o->tl->z + ey1);
376       glVertex3f (o->tl->x + ex1, o->tl->y - ez + dz, o->tl->z + ey1);
377       glEnd ();
378     }
379     else
380     {
381       glBegin (GL_LINE_STRIP);
382       glVertex3f (o->tl->x + ex1, o->tl->y + ez, o->tl->z + ey1);
383       glVertex3f (o->tl->x + ex2, o->tl->y + ez, o->tl->z + ey2);
384       glVertex3f (o->tl->x + ex2, o->tl->y - ez, o->tl->z + ey2);
385       glVertex3f (o->tl->x + ex1, o->tl->y - ez, o->tl->z + ey1);
386       glVertex3f (o->tl->x + ex1, o->tl->y + ez, o->tl->z + ey1);
387       glEnd ();
388     }
389     gl->disableAlphaBlending ();
390   }
391 }
392 
drawCross()393 void Cockpit::drawCross ()
394 {
395   glDisable (GL_LIGHTING);
396 
397   gl->enableAlphaBlending ();
398   glEnable (GL_ALPHA_TEST);
399   glAlphaFunc (GL_GEQUAL, 0.1);
400   //  glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
401   if (fplayer->o == &model_fig || fplayer->o == &model_figg)
402   {
403     gl->enableTextures (texcross->textureID);
404   }
405   else
406   {
407     gl->enableTextures (texcross2->textureID);
408   }
409 
410   float xf = 0.1, yf = 0.1, zf = 1.0;
411   setColor (150);
412   glBegin (GL_QUADS);
413   glTexCoord2d (0, 0);
414   glVertex3f (-xf, -yf, -zf);
415   glTexCoord2d (0, 1);
416   glVertex3f (-xf, yf, -zf);
417   glTexCoord2d (1, 1);
418   glVertex3f (xf, yf, -zf);
419   glTexCoord2d (1, 0);
420   glVertex3f (xf, -yf, -zf);
421   glEnd ();
422   glDisable (GL_ALPHA_TEST);
423   glDisable (GL_TEXTURE_2D);
424   gl->disableAlphaBlending ();
425   //  glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
426 }
427 
drawHeading()428 void Cockpit::drawHeading ()
429 {
430   char str [STDSIZE];
431   CColor color;
432   int i = 0;
433   int alpha = 175;
434   setColor (&color, alpha);
435   glDisable (GL_LIGHTING);
436   glLineWidth (LINEWIDTH(2.0F));
437   glDisable (GL_DEPTH_TEST);
438   float xf;
439   float yf = 17.5;
440   float zf = -2.5;
441   float g = 0.5;
442   for (i = 0; i < 360; i += 5)
443   {
444     float p = (float) i - fplayer->phi;
445     if (p < -180) p += 360;
446     if (p > 180) p -= 360;
447     if (p >= -40 && p <= 40)
448     {
449       if ((i - mission->heading) % 90 == 0)
450         g = 0.6;
451       else if (!(i % 10))
452         g = 0.3;
453       else
454         g = 0.1;
455       xf = p / 6.0;
456       gl->enableAlphaBlending ();
457       setColor (alpha);
458       glBegin (GL_LINES);
459       glVertex3f (xf * 0.1, (yf - g) * 0.1, zf);
460       glVertex3f (xf * 0.1, yf * 0.1, zf);
461       glEnd ();
462       if (i == mission->heading)
463         font1->drawText (xf - 0.5, yf - 2.0, zf, "S", &color);
464       else if (i == mission->heading + 90 || i == mission->heading - 270)
465         font1->drawText (xf - 0.5, yf - 2.0, zf, "E", &color);
466       else if (i == mission->heading + 180 || i == mission->heading - 180)
467         font1->drawText (xf - 0.5, yf - 2.0, zf, "N", &color);
468       else if (i == mission->heading + 270 || i == mission->heading - 90)
469         font1->drawText (xf - 0.5, yf - 2.0, zf, "W", &color);
470     }
471   }
472 
473   if (fplayer->target != NULL)
474     if (fplayer->target->active)
475     {
476       float dgamma = fplayer->getAngleH (fplayer->target);
477       float dphi = fplayer->getAngle (fplayer->target);
478       if (fabs (dphi) > 50 || fabs (dgamma) > 50)
479       {
480         if (dphi < -90) dphi = -90;
481         else if (dphi > 90) dphi = 90;
482         float delta = atan (dgamma / dphi) * 180 / PI;
483         if (dphi > 0) delta -= 180;
484         delta += fplayer->theta;
485         float xs = COS(delta) * 3;
486         float ys = -SIN(delta) * 3;
487         float delta1 = delta + 5;
488         float xs1 = COS(delta1) * 2.8;
489         float ys1 = -SIN(delta1) * 2.8;
490         float delta2 = delta - 5;
491         float xs2 = COS(delta2) * 2.8;
492         float ys2 = -SIN(delta2) * 2.8;
493         zf = -4;
494         glBegin (GL_LINE_STRIP);
495         glColor4ub (255, 0, 0, alpha);
496         glVertex3f (xs2, ys2, zf);
497         glVertex3f (xs, ys, zf);
498         glVertex3f (xs1, ys1, zf);
499         glEnd ();
500       }
501     }
502 
503   sprintf (str, "SPEED %d", (int) (fplayer->realspeed / timestep * 80000.0F));
504   font1->drawTextCentered (-8.0, -8.5, -4.0, str, &color);
505 
506   sprintf (str, "AMMO %d", fplayer->ammo);
507   font1->drawTextCentered (8.0, -8.5, -4.0, str, &color);
508 
509   gl->enableAlphaBlending ();
510 
511   float dgamma = fplayer->gamma - (int) fplayer->gamma;
512   float innerx = 5, outerx = 10, widthx = 1;
513   int step = 15;
514 
515   glLineWidth (LINEWIDTH(1.2F));
516 
517   glBegin (GL_LINES);
518   float tmp = fplayer->gamma - 180;
519   cockpitvertex (-innerx,tmp);
520   cockpitvertex (-15,tmp);
521   cockpitvertex (innerx,tmp);
522   cockpitvertex (15,tmp);
523 
524   for (i = -180 + step; i < 0; i += step)
525   {
526     float tmp=int(-i+fplayer->gamma+540)%360-180;
527     tmp += dgamma;
528     cockpitvertex (-innerx,tmp+1);
529     cockpitvertex (-innerx,tmp);
530     cockpitvertex (innerx,tmp+1);
531     cockpitvertex (innerx,tmp);
532     cockpitvertex (-outerx,tmp);
533     cockpitvertex (-innerx,tmp);
534     cockpitvertex (innerx,tmp);
535     cockpitvertex (outerx,tmp);
536   }
537 
538   for (i = step; i < 180; i += step)
539   {
540     float tmp=int(-i+fplayer->gamma+540)%360-180;
541     tmp += dgamma;
542     cockpitvertex (-innerx,tmp+1);
543     cockpitvertex (-innerx,tmp);
544     cockpitvertex (innerx,tmp+1);
545     cockpitvertex (innerx,tmp);
546     cockpitvertex (-outerx,tmp);
547     cockpitvertex (-outerx+widthx,tmp);
548     cockpitvertex (innerx,tmp);
549     cockpitvertex (innerx+widthx,tmp);
550     cockpitvertex (-innerx-widthx,tmp);
551     cockpitvertex (-innerx,tmp);
552     cockpitvertex (outerx-widthx,tmp);
553     cockpitvertex (outerx,tmp);
554   }
555   glEnd ();
556   gl->disableAlphaBlending ();
557 
558   glLineWidth (LINEWIDTH(2.0F));
559 }
560 
drawTargetedElement()561 void Cockpit::drawTargetedElement ()
562 {
563   char str [20];
564   CColor color;
565   CVector3 tl, n;
566   CRotation r;
567   color.setColor (255, 0, 0);
568   color.c [3] = 255;
569   tl.x = -0.35; tl.y = -0.3; tl.z = -0.5;
570   gl->disableAlphaBlending ();
571   glEnable (GL_DEPTH_TEST);
572   if (fplayer->target != NULL)
573     if (fplayer->target->active)
574     {
575       glEnable (GL_LIGHTING);
576       fplayer->target->o->draw (&n, &tl, fplayer->target->rot, 0.05, 0.3, 0);
577       glDisable (GL_LIGHTING);
578       if (((AIObj *) fplayer->target)->party == fplayer->party)
579         color.setColor (0, 0, 255);
580       font1->drawText (-24.0, -23.0, -4.0, fplayer->target->o->name, &color);
581       sprintf (str, "%d", (int) (15.0 * fplayer->distance (fplayer->target)));
582       font1->drawText (-24.0, -25.0, -4.0, str, &color);
583     }
584   glDisable (GL_DEPTH_TEST);
585 }
586 
drawWeapon()587 void Cockpit::drawWeapon ()
588 {
589   char str [20];
590   CColor color;
591   CVector3 tl, n;
592   CRotation r;
593   if (fplayer->missiles [fplayer->missiletype] <= 0)
594     return;
595   color.setColor (255, 0, 0);
596   color.c [3] = 255;
597   tl.x = 0.35; tl.y = -0.3; tl.z = -0.5;
598   gl->disableAlphaBlending ();
599   glEnable (GL_DEPTH_TEST);
600   CModel *missile = NULL;
601   if (fplayer->missiletype == 0) missile = &model_missile1;
602   else if (fplayer->missiletype == 1) missile = &model_missile2;
603   else if (fplayer->missiletype == 2) missile = &model_missile3;
604   else if (fplayer->missiletype == 3) missile = &model_missile4;
605   else if (fplayer->missiletype == 4) missile = &model_missile5;
606   else if (fplayer->missiletype == 5) missile = &model_missile6;
607   else if (fplayer->missiletype == 6) missile = &model_missile7;
608   else if (fplayer->missiletype == 7) missile = &model_missile8;
609   glEnable (GL_LIGHTING);
610   missile->draw (&n, &tl, fplayer->rot, 0.05, 1.0, 0);
611   glDisable (GL_LIGHTING);
612   glDisable (GL_DEPTH_TEST);
613   font1->drawText (16.0, -22.0, -4.0, missile->name, &color);
614   sprintf (str, "N %d", fplayer->missiles [fplayer->missiletype]);
615   font1->drawText (16.0, -24.0, -4.0, str, &color);
616 }
617 
drawRadar()618 void Cockpit::drawRadar ()
619 {
620   int i;
621   float yf = -4.2, zf = -7.0;
622 
623   gl->enableAlphaBlending ();
624   glEnable (GL_ALPHA_TEST);
625   glAlphaFunc (GL_GEQUAL, 0.1);
626   glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
627   setColor (150);
628   float xl, yl;
629   int type;
630   if (fplayer->o == &model_fig || fplayer->o == &model_figg)
631   {
632     gl->enableTextures (texradar2->textureID);
633     xl = 1.4; yl = 1.3;
634     type = 0;
635   }
636   else
637   {
638     gl->enableTextures (texradar1->textureID);
639     xl = 1.3; yl = 1.2;
640     type = 1;
641   }
642   glBegin (GL_QUADS);
643   glTexCoord2d (0, 0);
644   glVertex3f (-xl, yf - yl, zf);
645   glTexCoord2d (0, 1);
646   glVertex3f (-xl, yf + yl, zf);
647   glTexCoord2d (1, 1);
648   glVertex3f (xl, yf + yl, zf);
649   glTexCoord2d (1, 0);
650   glVertex3f (xl, yf - yl, zf);
651   glEnd ();
652   glDisable (GL_ALPHA_TEST);
653   glDisable (GL_TEXTURE_2D);
654   glLineWidth (LINEWIDTH(1.0F));
655   glBegin (GL_LINES);
656   glVertex3f (0, yf - yl * 0.9, zf);
657   glVertex3f (0, yf + yl * 0.9, zf);
658   glVertex3f (-xl * 0.9, yf, zf);
659   glVertex3f (xl * 0.9, yf, zf);
660   glEnd ();
661   int radarzoom = 1;
662   if (fplayer->disttarget < 40) radarzoom = 2;
663   for (i = 0; i < maxfighter; i ++)
664     if (fighter [i] != fplayer && fighter [i]->active)
665     {
666       int aw = fplayer->getAngle (fighter [i]);
667       if (aw < 0) aw += 360;
668       float d = fplayer->distanceXZ (fighter [i]) / 100.0 * radarzoom;
669       float px = -d * sine [aw];
670       float py = yf + d * cosi [aw];
671       if ((type == 0 && d < 1.2) || (type == 1 && px >= -1.2 && px <= 1.2 && py >= yf - 1.1 && py <= yf + 1.1))
672       {
673         if (fighter [i] == fplayer->target)
674         {
675           drawBlip(SQUARE_BLIP, px, py, zf, 255, 200, 0);
676         }
677         else if (fighter [i]->party != fplayer->party)
678         {
679       	  drawBlip(SQUARE_BLIP, px, py, zf, 255, 0, 0);
680         }
681         else
682         {
683       	  drawBlip(SQUARE_BLIP, px, py, zf, 0, 0, 255);
684         }
685       }
686     }
687   for (i = 0; i < maxmissile; i ++)
688   {
689     if (missile [i]->target == fplayer && missile [i]->active)
690     {
691       int aw = fplayer->getAngle (missile [i]);
692       if (aw < 0) aw += 360;
693       float d = fplayer->distance (missile [i]) / 100.0 * radarzoom;
694       float px = -d * sine [aw];
695       float py = yf + d * cosi [aw];
696       if ((type == 0 && d < 1.2) || (type == 1 && px >= -1.2 && px <= 1.2 && py >= yf - 1.1 && py <= yf + 1.1))
697       {
698         drawBlip(TRIANGLE_BLIP, px, py, zf, 255, 255, 255);
699       }
700     }
701   }
702   gl->disableAlphaBlending ();
703 }
704 
drawRelativeHeightBar()705 void Cockpit::drawRelativeHeightBar()
706 {
707   char str [STDSIZE];
708   CColor color;
709   int alpha = 175;
710   setColor (&color, alpha);
711   setColor (alpha);
712   glDisable (GL_LIGHTING);
713   glLineWidth (LINEWIDTH(1.0F));
714   glDisable (GL_DEPTH_TEST);
715   gl->enableAlphaBlending ();
716 
717   float xf = 1.5F, xfl = 0.06F, yf=0.0F, yfl = 0.7F, zf=-4.0F;
718   float px = fplayer->tl->x, py = fplayer->tl->y, pz = fplayer->tl->z;
719   float lh = l->getExactHeight(px, pz);
720   setColor(80); // low alpha for better visibility
721   // add 100.0 to each player_y and land_h to avoid values <= 0.0
722   float rel_height = ((100.0F+py)/(100.0F+lh) * 100.0F) - 100.0F;
723 
724   // turn 0 -> 50.0 range to -0.7 -> 0.7 for drawing, 1.4/50=0.0208
725   float yfv = (rel_height * 0.0208F)-0.7F;
726   // cap max-min values
727   if(yfv >  0.7F) yfv =  0.7F;
728   if(yfv < -0.7F) yfv = -0.7F;
729 
730   glBegin (GL_QUADS);
731   glVertex3f (xf - xfl, yf - yfl, zf);  // fixed
732   glVertex3f (xf + xfl, yf - yfl, zf);  // fixed
733   glVertex3f (xf + xfl, yf + yfv, zf);  // var
734   glVertex3f (xf - xfl, yf + yfv, zf);  // var
735   glEnd ();
736   setColor(alpha);
737 
738   sprintf (str, "RHEIGHT");
739   font1->drawTextCentered (xf*11.0F, (yf-0.85F)*10.0F, zf, str, &color);
740   glEnd();
741   gl->disableAlphaBlending ();
742 }
743 
drawThrustBar()744 void Cockpit::drawThrustBar()
745 {
746   char str [STDSIZE];
747   CColor color;
748   int alpha = 175;
749   setColor (&color, alpha);
750   setColor (alpha);
751   glDisable (GL_LIGHTING);
752   glLineWidth (LINEWIDTH(1.0F));
753   glDisable (GL_DEPTH_TEST);
754   gl->enableAlphaBlending ();
755 
756   setColor(80); // don't block visibility too much
757   float xf = -1.5F, xfl = 0.06F, yf=0.0F, yfl = 0.7F, zf=-4.0F;
758 
759   // turn 0.5 -> 1.0 range to -0.7 -> 0.7 for drawing
760   float yfv = fplayer->thrust / fplayer->maxthrust * 2.8F - 2.1F;
761   // cap max-min values
762   if(yfv >  0.7F) yfv =  0.7F;
763   if(yfv < -0.7F) yfv = -0.7F;
764   glBegin (GL_QUADS);
765   glVertex3f (xf - xfl, yf - yfl, zf);  // fixed
766   glVertex3f (xf + xfl, yf - yfl, zf);  // fixed
767   glVertex3f (xf + xfl, yf + yfv, zf);  // var
768   glVertex3f (xf - xfl, yf + yfv, zf);  // var
769   glEnd ();
770   setColor(alpha);
771   sprintf (str, "THRUST");
772   font1->drawTextCentered (xf*11.0F, (yf-0.85F)*10.0F, zf, str, &color);
773 
774   glEnd();
775   gl->disableAlphaBlending ();
776 }
777 
778 #endif
779 //vim:sw=2 cino=c5,:.4s,=.2s,(0,u0,g0,h2,+2
780