| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * $Logfile: /DescentIII/main/gauges.cpp $ |
| 21 | * $Revision: 47 $ |
| 22 | * $Date: 4/19/00 5:13p $ |
| 23 | * $Author: Matt $ |
| 24 | * |
| 25 | * Gauge rendering |
| 26 | * |
| 27 | * $Log: /DescentIII/main/gauges.cpp $ |
| 28 | * |
| 29 | * 47 4/19/00 5:13p Matt |
| 30 | * From Duane for 1.4 |
| 31 | * Added checks, asserts, and fixes for bad return values |
| 32 | * Removed Mac OpenGL hack |
| 33 | * |
| 34 | * 46 10/21/99 6:37p Matt |
| 35 | * Mac merge |
| 36 | * This change is mostly setting & clearing the variable |
| 37 | * use_opengl_1555_format around some blocks of code. Duane says this |
| 38 | * won't affect the Windows version. (BTW, I think it would have been |
| 39 | * cleaner to use a rend_set() function to do this.) |
| 40 | * |
| 41 | * 45 4/24/99 10:38p Samir |
| 42 | * cleaned up hud text problems in 'small mode' |
| 43 | * |
| 44 | * 44 4/20/99 11:47a Samir |
| 45 | * shrinking hud fixes. |
| 46 | * |
| 47 | * 43 3/04/99 8:07p Samir |
| 48 | * render gauge text at correct scale. |
| 49 | * |
| 50 | * 42 1/31/99 7:26p Matt |
| 51 | * Renamed a bunch of functions to have HUD capitalized |
| 52 | * |
| 53 | * 41 10/23/98 12:52p Samir |
| 54 | * fixed bug in secondary monitors, projecting wrong point. |
| 55 | * |
| 56 | * 40 10/20/98 12:42p Matt |
| 57 | * Made the small views work on the cockpit. |
| 58 | * |
| 59 | * 39 10/13/98 12:56p Matt |
| 60 | * Finished (hopefully) with the ammo system. Added support for napalm |
| 61 | * fuel. |
| 62 | * |
| 63 | * 38 8/25/98 7:07p Samir |
| 64 | * display ammo in primary monitor. |
| 65 | * |
| 66 | * 37 8/25/98 12:22p Jason |
| 67 | * more changes for cockpits |
| 68 | * |
| 69 | * 36 8/24/98 3:25p Samir |
| 70 | * took out reordering. |
| 71 | * |
| 72 | * 35 8/24/98 3:04p Samir |
| 73 | * added reordering of monitor verts. |
| 74 | * |
| 75 | * 34 6/24/98 7:37p Samir |
| 76 | * fixed energy/shield gauges (must still do invulnerability!) |
| 77 | * |
| 78 | * 33 6/16/98 10:38a Jeff |
| 79 | * localization, strings pulled out to stringtable.h and d3.str |
| 80 | * |
| 81 | * 32 5/26/98 5:05p Samir |
| 82 | * shield frames now contained in hud structure and share common graphics |
| 83 | * between gauges and hud. |
| 84 | * |
| 85 | * 31 5/25/98 8:30p Samir |
| 86 | * fixed bug when weapon gauges drawn in multiplayer. |
| 87 | * |
| 88 | * 30 5/25/98 6:38p Matt |
| 89 | * Added needed include. |
| 90 | * |
| 91 | * 29 5/22/98 6:26p Samir |
| 92 | * moved text over a bit on left monitor. |
| 93 | * |
| 94 | * 28 5/18/98 4:52p Samir |
| 95 | * fixed hud image for weapons. |
| 96 | * |
| 97 | * 27 5/15/98 5:36p Samir |
| 98 | * use correct font scale for lores screens. |
| 99 | * |
| 100 | * 26 5/05/98 6:28p Samir |
| 101 | * gauges should render properly when cockpit is resized. |
| 102 | * |
| 103 | * 25 4/24/98 8:03a Samir |
| 104 | * draw weapon names using short names, and pass alpha array to |
| 105 | * drawgaugemonitor. |
| 106 | * |
| 107 | * 24 3/27/98 11:59a Samir |
| 108 | * moved weapon hud text from hud to weapon monitor gauges. |
| 109 | * |
| 110 | * 23 3/22/98 5:03p Samir |
| 111 | * updated cockpit. |
| 112 | * |
| 113 | * 22 3/20/98 8:23p Samir |
| 114 | * Started implementing images. |
| 115 | * |
| 116 | * 21 3/18/98 6:24p Samir |
| 117 | * Implemented monitor system. |
| 118 | * |
| 119 | * 20 3/17/98 2:40p Samir |
| 120 | * reorg of cockpit/gauges and hud systems. |
| 121 | * |
| 122 | * 19 3/16/98 3:30p Samir |
| 123 | * incremental checkin. |
| 124 | * |
| 125 | * 18 2/17/98 3:46p Matt |
| 126 | * Revamped weapon system and got sounds for spray and fusion weapons |
| 127 | * working. Still need to implements getting continuous & cutoff sounds |
| 128 | * from player ship. |
| 129 | * |
| 130 | * 17 2/11/98 4:54p Jeff |
| 131 | * Moved the inventory into the Player struct |
| 132 | * |
| 133 | * 16 2/09/98 4:58p Jeff |
| 134 | * Connected inventory to hud |
| 135 | * |
| 136 | * 15 2/03/98 12:13p Samir |
| 137 | * Font shadowing support in grtext. |
| 138 | * |
| 139 | * 14 1/28/98 1:11p Jason |
| 140 | * took shields field out of Player struct |
| 141 | * |
| 142 | * 13 1/26/98 2:38p Samir |
| 143 | * Assert alpha is opaque for hud font. |
| 144 | * |
| 145 | * 12 1/23/98 12:07p Jason |
| 146 | * made framerate display toggleable |
| 147 | * |
| 148 | * 11 1/12/98 5:40p Samir |
| 149 | * Gauges placed differently. |
| 150 | * |
| 151 | * 10 1/12/98 5:23p Samir |
| 152 | * Use new hud font for gauges. |
| 153 | * |
| 154 | * 9 12/29/97 5:47p Samir |
| 155 | * Uses new text system and took out references to Game_viewport. |
| 156 | * |
| 157 | * 8 11/16/97 6:55p Samir |
| 158 | * Initiated 'init' flag for gauge structure. |
| 159 | * |
| 160 | * 7 11/14/97 5:29p Samir |
| 161 | * Now we pass four world coordinates of the 4 vertex monitor to a gauge |
| 162 | * rendering function. |
| 163 | * |
| 164 | * 6 11/11/97 1:25p Samir |
| 165 | * Added modified flag to tGauge and cleaned up gauge renderering a |
| 166 | * little. |
| 167 | * |
| 168 | * 5 11/04/97 6:23p Samir |
| 169 | * New Gauge interface. |
| 170 | * |
| 171 | * 4 10/29/97 12:33p Samir |
| 172 | * Framework for RenderHudGauges |
| 173 | * |
| 174 | * 3 10/28/97 6:36p Samir |
| 175 | * Gauge system for text controls functioning. |
| 176 | * |
| 177 | * 2 10/28/97 12:47p Samir |
| 178 | * Gauges are drawn once per frame from GameLoop to a call to gauges.cpp |
| 179 | * |
| 180 | * 1 10/28/97 12:27p Samir |
| 181 | * Initial revision |
| 182 | * |
| 183 | * $NoKeywords: $ |
| 184 | */ |
| 185 | |
| 186 | #include "gauges.h" |
| 187 | #include "gamefont.h" |
| 188 | #include "hud.h" |
| 189 | #include "game.h" |
| 190 | #include "renderer.h" |
| 191 | #include "render.h" |
| 192 | #include "player.h" |
| 193 | #include "polymodel.h" |
| 194 | #include "gametexture.h" |
| 195 | #include "bitmap.h" |
| 196 | #include "vclip.h" |
| 197 | #include "Inventory.h" |
| 198 | #include "cockpit.h" |
| 199 | #include "player.h" |
| 200 | #include "ship.h" |
| 201 | #include "3d.h" |
| 202 | #include "weapon.h" |
| 203 | #include "stringtable.h" |
| 204 | |
| 205 | ////////////////////////////////////////////////////////////////////////////// |
| 206 | |
| 207 | struct tGauge { |
| 208 | poly_model *cockpit; // cockpit model of gauge |
| 209 | bsp_info *monitor; // monitor in cockpit. |
| 210 | int first_vert; |
| 211 | bool functional; // is this gauge working? |
| 212 | bool just_init; // gauge just initialized? |
| 213 | uint16_t mask; // mask of stat for gauge |
| 214 | int state; // gauge dependent state data. |
| 215 | union { // data for gauge. |
| 216 | int i; |
| 217 | float f; |
| 218 | } data; |
| 219 | g3Point pts[4]; // points of monitor in view coordinates. (may be cached from last frame) |
| 220 | }; |
| 221 | |
| 222 | // which monitors correspond to what faces on the cockpit model. |
| 223 | #define PRIMARY_MONITOR SOF_MONITOR1 |
| 224 | #define SHIP_MONITOR SOF_MONITOR2 |
| 225 | #define SECONDARY_MONITOR SOF_MONITOR3 |
| 226 | #define ENERGY1_MONITOR SOF_MONITOR4 |
| 227 | #define ENERGY2_MONITOR SOF_MONITOR5 |
| 228 | #define SHIELD_MONITOR SOF_MONITOR6 |
| 229 | #define AFTERBURN_MONITOR SOF_MONITOR7 |
| 230 | |
| 231 | // Hack vars for turning off the monitors |
| 232 | bool Disable_primary_monitor = 0, Disable_secondary_monitor = 0; |
| 233 | |
| 234 | ////////////////////////////////////////////////////////////////////////////// |
| 235 | |
| 236 | // Available gauges to be rendered. |
| 237 | static tStatMask Gauge_mask; |
| 238 | |
| 239 | // sets for next frame which gauges have been modified. |
| 240 | static tStatMask Gauge_mask_modified; |
| 241 | |
| 242 | // sets for next frame the functional state of each gauge (on/off). |
| 243 | static tGauge Gauge_list[NUM_GAUGES]; |
| 244 | |
| 245 | // position of cockpit |
| 246 | static vector *Render_gauge_pos; |
| 247 | |
| 248 | // matrix of cockpit |
| 249 | static matrix *Render_gauge_matrix; |
| 250 | |
| 251 | // normalized times of cockpit |
| 252 | static float *Render_normalized_times; |
| 253 | |
| 254 | // if gauges are moving in cockpit. |
| 255 | static bool Render_gauge_moving; // gauge is moving, but temporarily off. |
| 256 | static bool Render_gauge_reset; // set this if gauges will be moving, but are still active |
| 257 | |
| 258 | // TODO: MTS: function not found |
| 259 | // loads all shield bitmaps into memory |
| 260 | static void FreeShieldFrames(); |
| 261 | |
| 262 | // TODO: MTS: function not found |
| 263 | // loads all ship bitmaps into memory |
| 264 | static void FreeShipFrames(); |
| 265 | |
| 266 | // projects monitor coordinates to screen coordinates |
| 267 | static void RotateMonitorPosition(tGauge *gauge); |
| 268 | |
| 269 | // TODO: MTS: function not found |
| 270 | // renders the current inventory item name at the x,y position |
| 271 | static void InventoryRenderGauge(int x, int y); |
| 272 | |
| 273 | // renders the primary monitor gauge |
| 274 | static void RenderPrimaryMonitor(tGauge *gauge, bool modified); |
| 275 | |
| 276 | // renders the secondary monitor gauge |
| 277 | static void RenderSecondaryMonitor(tGauge *gauge, bool modified); |
| 278 | |
| 279 | // renders the shield gauge monitor |
| 280 | static void RenderShieldMonitor(tGauge *gauge, bool modified); |
| 281 | |
| 282 | // renders the ship gauge monitor |
| 283 | static void RenderShipMonitor(tGauge *gauge, bool modified); |
| 284 | |
| 285 | // renders the ship gauge monitor |
| 286 | static void RenderEnergyMonitor(tGauge *gauge, int orient, bool modified); |
| 287 | |
| 288 | // renders the ship gauge monitor |
| 289 | static void RenderAfterburnMonitor(tGauge *gauge, bool modified); |
| 290 | |
| 291 | // renders a monitor style quad |
| 292 | static void DrawGaugeMonitor(g3Point *pts, int bm, float brightness, float *alphas); |
| 293 | |
| 294 | // renders a square texture onto the screen. |
| 295 | static void DrawGaugeQuad(g3Point *pts, int bm, float u0, float v0, float u1, float v1, uint8_t alpha, bool saturate); |
| 296 | |
| 297 | // renders a square texture onto the screen. |
| 298 | static void DrawGaugeQuad(g3Point *pts, int bm, uint8_t alpha = 255, bool saturate = false); |
| 299 | |
| 300 | // renders a flat poly onto the screen with given color |
| 301 | static void DrawGaugeQuadFlat(g3Point *pts, float r, float g, float b, uint8_t alpha); |
| 302 | |
| 303 | // renders a flat poly onto the screen with 4 colors (for each vertex) |
| 304 | static void DrawGaugeQuadFlat(g3Point *pts, float *r, float *g, float *b, uint8_t alpha); |
| 305 | |
| 306 | // correctly orders monitor vertices based off of UVs |
| 307 | static int GetFirstVert(bsp_info *sm); |
| 308 | |
| 309 | // tells what gauge index is the gauge stat item. |
| 310 | static inline int GAUGE_INDEX(tStatMask mask) { |
| 311 | int i; |
| 312 | |
| 313 | for (i = 0; i < NUM_GAUGES; i++) |
| 314 | if (Gauge_list[i].mask == mask) |
| 315 | return i; |
| 316 | |
| 317 | return -1; |
| 318 | } |
| 319 | |
| 320 | ////////////////////////////////////////////////////////////////////////////// |
| 321 | // Initialization routines |
| 322 | |
| 323 | // initializes cockpit gauges |
| 324 | void InitGauges(uint16_t gauge_mask) { |
| 325 | Gauge_mask = gauge_mask; |
| 326 | Gauge_mask_modified = Gauge_mask; |
| 327 | int gauge = 0; |
| 328 | |
| 329 | for (int i = 0; i < NUM_GAUGES; i++) { |
| 330 | uint16_t mask = Gauge_mask & (1 << i); |
| 331 | |
| 332 | if (mask == STAT_SHIELDS) { |
| 333 | Gauge_list[gauge].monitor = CockpitGetMonitorSubmodel(SHIELD_MONITOR); |
| 334 | } |
| 335 | if (mask == STAT_PRIMARYLOAD) |
| 336 | Gauge_list[gauge].monitor = CockpitGetMonitorSubmodel(PRIMARY_MONITOR); |
| 337 | else if (mask == STAT_SECONDARYLOAD) |
| 338 | Gauge_list[gauge].monitor = CockpitGetMonitorSubmodel(SECONDARY_MONITOR); |
| 339 | else if (mask == STAT_SHIP) { |
| 340 | Gauge_list[gauge].monitor = CockpitGetMonitorSubmodel(SHIP_MONITOR); |
| 341 | } else if (mask == STAT_ENERGY) { |
| 342 | // initialize two gauges. one for left, and one for right energy monitor. |
| 343 | Gauge_list[gauge].monitor = CockpitGetMonitorSubmodel(ENERGY1_MONITOR); |
| 344 | Gauge_list[gauge].functional = false; |
| 345 | Gauge_list[gauge].state = 0; |
| 346 | Gauge_list[gauge].cockpit = CockpitGetPolyModel(); |
| 347 | Gauge_list[gauge].just_init = true; |
| 348 | Gauge_list[gauge].mask = mask; |
| 349 | Gauge_list[gauge].first_vert = GetFirstVert(Gauge_list[gauge].monitor); |
| 350 | gauge++; |
| 351 | Gauge_list[gauge].monitor = CockpitGetMonitorSubmodel(ENERGY2_MONITOR); |
| 352 | } else if (mask == STAT_AFTERBURN) { |
| 353 | Gauge_list[gauge].monitor = CockpitGetMonitorSubmodel(AFTERBURN_MONITOR); |
| 354 | } |
| 355 | |
| 356 | if (mask) { |
| 357 | Gauge_list[gauge].functional = false; |
| 358 | Gauge_list[gauge].state = 0; |
| 359 | Gauge_list[gauge].cockpit = CockpitGetPolyModel(); |
| 360 | Gauge_list[gauge].just_init = true; |
| 361 | Gauge_list[gauge].mask = mask; |
| 362 | Gauge_list[gauge].first_vert = GetFirstVert(Gauge_list[gauge].monitor); |
| 363 | |
| 364 | gauge++; |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | // deinitializes cockpit gauges |
| 370 | void CloseGauges() { |
| 371 | for (int i = 0; i < NUM_GAUGES; i++) { |
| 372 | uint16_t mask = Gauge_mask & (1 << i); |
| 373 | Gauge_list[i].monitor = NULL; |
| 374 | } |
| 375 | Gauge_mask = 0; |
| 376 | Gauge_mask_modified = 0; |
| 377 | } |
| 378 | |
| 379 | // renders gauges |
| 380 | void RenderGauges(vector *cockpit_pos, matrix *cockpit_mat, float *normalized_time, bool moving, bool reset) { |
| 381 | tGauge *gauge; |
| 382 | float font_aspect_x; |
| 383 | float font_aspect_y; |
| 384 | |
| 385 | Render_gauge_pos = cockpit_pos; |
| 386 | Render_gauge_matrix = cockpit_mat; |
| 387 | Render_normalized_times = normalized_time; |
| 388 | Render_gauge_moving = moving; |
| 389 | Render_gauge_reset = reset; |
| 390 | |
| 391 | grtext_Reset(); |
| 392 | grtext_SetFont(HUD_FONT); |
| 393 | // for lores screens, we use different fonts, so DONT SCALE. |
| 394 | font_aspect_x = (float)Game_window_w / Max_window_w; |
| 395 | font_aspect_y = (float)Game_window_h / Max_window_h; |
| 396 | |
| 397 | if (font_aspect_x <= 0.60) { |
| 398 | grtext_SetFontScale(0.60f); |
| 399 | } else if (font_aspect_x <= 0.80) { |
| 400 | grtext_SetFontScale(0.80f); |
| 401 | } else { |
| 402 | grtext_SetFontScale(1.0f); |
| 403 | } |
| 404 | |
| 405 | if (Gauge_mask & STAT_PRIMARYLOAD) { |
| 406 | ASSERT(GAUGE_INDEX(STAT_PRIMARYLOAD) != -1); |
| 407 | gauge = &Gauge_list[GAUGE_INDEX(STAT_PRIMARYLOAD)]; |
| 408 | if (gauge->monitor) { |
| 409 | RotateMonitorPosition(gauge); |
| 410 | RenderPrimaryMonitor(gauge, (Gauge_mask_modified & STAT_PRIMARYLOAD) ? true : false); |
| 411 | } |
| 412 | gauge->just_init = false; |
| 413 | } |
| 414 | if (Gauge_mask & STAT_SECONDARYLOAD) { |
| 415 | ASSERT(GAUGE_INDEX(STAT_SECONDARYLOAD) != -1); |
| 416 | gauge = &Gauge_list[GAUGE_INDEX(STAT_SECONDARYLOAD)]; |
| 417 | if (gauge->monitor) { |
| 418 | RotateMonitorPosition(gauge); |
| 419 | RenderSecondaryMonitor(gauge, (Gauge_mask_modified & STAT_SECONDARYLOAD) ? true : false); |
| 420 | } |
| 421 | gauge->just_init = false; |
| 422 | } |
| 423 | if (Gauge_mask & STAT_SHIELDS) { |
| 424 | ASSERT(GAUGE_INDEX(STAT_SHIELDS) != -1); |
| 425 | gauge = &Gauge_list[GAUGE_INDEX(STAT_SHIELDS)]; |
| 426 | if (gauge->monitor) { |
| 427 | RotateMonitorPosition(gauge); |
| 428 | RenderShieldMonitor(gauge, (Gauge_mask_modified & STAT_SHIELDS) ? true : false); |
| 429 | } |
| 430 | gauge->just_init = false; |
| 431 | } |
| 432 | if (Gauge_mask & STAT_SHIP) { |
| 433 | ASSERT(GAUGE_INDEX(STAT_SHIP) != -1); |
| 434 | gauge = &Gauge_list[GAUGE_INDEX(STAT_SHIP)]; |
| 435 | if (gauge->monitor) { |
| 436 | RotateMonitorPosition(gauge); |
| 437 | RenderShipMonitor(gauge, (Gauge_mask_modified & STAT_SHIP) ? true : false); |
| 438 | } |
| 439 | gauge->just_init = false; |
| 440 | } |
| 441 | if (Gauge_mask & STAT_ENERGY) { |
| 442 | ASSERT(GAUGE_INDEX(STAT_ENERGY) != -1); |
| 443 | gauge = &Gauge_list[GAUGE_INDEX(STAT_ENERGY)]; |
| 444 | if (gauge->monitor) { |
| 445 | RotateMonitorPosition(gauge); |
| 446 | RenderEnergyMonitor(gauge, 0, (Gauge_mask_modified & STAT_ENERGY) ? true : false); |
| 447 | } |
| 448 | gauge->just_init = false; |
| 449 | gauge = &Gauge_list[GAUGE_INDEX(STAT_ENERGY) + 1]; |
| 450 | if (gauge->monitor) { |
| 451 | RotateMonitorPosition(gauge); |
| 452 | RenderEnergyMonitor(gauge, 1, (Gauge_mask_modified & STAT_ENERGY) ? true : false); |
| 453 | } |
| 454 | gauge->just_init = false; |
| 455 | } |
| 456 | if (Gauge_mask & STAT_AFTERBURN) { |
| 457 | ASSERT(GAUGE_INDEX(STAT_AFTERBURN) != -1); |
| 458 | gauge = &Gauge_list[GAUGE_INDEX(STAT_AFTERBURN)]; |
| 459 | if (gauge->monitor) { |
| 460 | RotateMonitorPosition(gauge); |
| 461 | RenderAfterburnMonitor(gauge, (Gauge_mask_modified & STAT_ENERGY) ? true : false); |
| 462 | } |
| 463 | gauge->just_init = false; |
| 464 | } |
| 465 | |
| 466 | // render all text |
| 467 | grtext_Flush(); |
| 468 | |
| 469 | Gauge_mask_modified = 0; |
| 470 | } |
| 471 | |
| 472 | // flags certain gauges to be modified next frame. |
| 473 | void FlagGaugesModified(tStatMask mask_modified) { Gauge_mask_modified |= mask_modified; } |
| 474 | |
| 475 | // sets whether the gauges are functional |
| 476 | void FlagGaugesFunctional(tStatMask mask) { |
| 477 | uint16_t i = 0x8000, j = NUM_GAUGES; |
| 478 | |
| 479 | while (i) { |
| 480 | if (mask & i) |
| 481 | Gauge_list[j - 1].functional = true; |
| 482 | i = i >> 1; |
| 483 | j--; |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | // sets whether the gauges are functional |
| 488 | void FlagGaugesNonfunctional(tStatMask mask) { |
| 489 | uint16_t i = 0x8000, j = NUM_GAUGES; |
| 490 | |
| 491 | while (i) { |
| 492 | if (mask & i) |
| 493 | Gauge_list[j - 1].functional = false; |
| 494 | i = i >> 1; |
| 495 | j--; |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | // renders the primary monitor gauge |
| 500 | // this will normally render the primary weapon currently selected |
| 501 | // can render another view though. |
| 502 | // renders the primary monitor gauge |
| 503 | |
| 504 | static inline int get_weapon_hud_image(int player, int type) { |
| 505 | player_weapon *pw = &Players[player].weapon[type]; |
| 506 | weapon *wpn = GetWeaponFromIndex(player, pw->index); |
| 507 | |
| 508 | return (wpn ? wpn->hud_image_handle : BAD_BITMAP_HANDLE); |
| 509 | } |
| 510 | |
| 511 | void RenderPrimaryMonitor(tGauge *gauge, bool modified) { |
| 512 | if (Disable_primary_monitor) |
| 513 | return; |
| 514 | |
| 515 | if (gauge->functional) { |
| 516 | float alphas[4]; |
| 517 | alphas[0] = 1.0f; |
| 518 | alphas[1] = 1.0f; |
| 519 | alphas[2] = 1.0f; |
| 520 | alphas[3] = 1.0f; |
| 521 | |
| 522 | int hud_image = get_weapon_hud_image(Player_num, PW_PRIMARY); |
| 523 | |
| 524 | DrawGaugeMonitor(gauge->pts, hud_image, 0.5f, alphas); |
| 525 | |
| 526 | if (!Render_gauge_moving) { |
| 527 | int x1, y; |
| 528 | int index = Players[Player_num].weapon[PW_PRIMARY].index; |
| 529 | ship *ship = &Ships[Players[Player_num].ship_index]; |
| 530 | otype_wb_info *wb = &ship->static_wb[index]; |
| 531 | |
| 532 | gauge->pts[0].p3_flags &= (~PF_PROJECTED); |
| 533 | g3_ProjectPoint(&gauge->pts[0]); |
| 534 | x1 = gauge->pts[0].p3_sx; |
| 535 | y = gauge->pts[0].p3_sy; |
| 536 | |
| 537 | grtext_SetFlags(0); |
| 538 | grtext_SetFancyColor(GR_RGB(0, 180, 0), GR_RGB(0, 180, 0), GR_RGB(0, 180, 0), GR_RGB(0, 180, 0)); |
| 539 | grtext_Printf(x1 + HUD_X(30), y + HUD_Y(10), "%s", TXT(Static_weapon_ckpt_names[index][0])); |
| 540 | grtext_SetFlags(GRTEXTFLAG_SATURATE); |
| 541 | grtext_Printf(x1 + HUD_X(30), y + HUD_Y(10), "%s", TXT(Static_weapon_ckpt_names[index][0])); |
| 542 | |
| 543 | if (strlen(TXT(Static_weapon_ckpt_names[Players[Player_num].weapon[PW_PRIMARY].index][1]))) { |
| 544 | grtext_SetFlags(0); |
| 545 | grtext_Printf(x1 + HUD_X(35), y + HUD_Y(20), "%s", TXT(Static_weapon_ckpt_names[index][1])); |
| 546 | grtext_SetFlags(GRTEXTFLAG_SATURATE); |
| 547 | grtext_Printf(x1 + HUD_X(35), y + HUD_Y(20), "%s", TXT(Static_weapon_ckpt_names[index][1])); |
| 548 | y = y + HUD_Y(10); |
| 549 | } |
| 550 | |
| 551 | if (wb && wb->ammo_usage) { |
| 552 | int ammo = Players[Player_num].weapon_ammo[index]; |
| 553 | grtext_SetFlags(0); |
| 554 | if (ship->fire_flags[index] & SFF_TENTHS) { |
| 555 | grtext_Printf(x1 + HUD_X(40), y + HUD_Y(20), "%d.%d", ammo / 10, ammo % 10); |
| 556 | grtext_SetFlags(GRTEXTFLAG_SATURATE); |
| 557 | grtext_Printf(x1 + HUD_X(40), y + HUD_Y(20), "%d.%d", ammo / 10, ammo % 10); |
| 558 | } else { |
| 559 | grtext_Printf(x1 + HUD_X(40), y + HUD_Y(20), "%d", ammo); |
| 560 | grtext_SetFlags(GRTEXTFLAG_SATURATE); |
| 561 | grtext_Printf(x1 + HUD_X(40), y + HUD_Y(20), "%d", ammo); |
| 562 | } |
| 563 | } |
| 564 | } |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | // renders the secondary monitor gauge |
| 569 | void RenderSecondaryMonitor(tGauge *gauge, bool modified) { |
| 570 | if (Disable_secondary_monitor) |
| 571 | return; |
| 572 | |
| 573 | if (gauge->functional) { |
| 574 | float alphas[4]; |
| 575 | |
| 576 | alphas[0] = 1.0f; |
| 577 | alphas[1] = 1.0f; |
| 578 | alphas[2] = 1.0f; |
| 579 | alphas[3] = 1.0f; |
| 580 | |
| 581 | int hud_image = get_weapon_hud_image(Player_num, PW_SECONDARY); |
| 582 | |
| 583 | DrawGaugeMonitor(gauge->pts, hud_image, 0.5f, alphas); |
| 584 | |
| 585 | if (!Render_gauge_moving) { |
| 586 | int x1, y; |
| 587 | |
| 588 | gauge->pts[0].p3_flags &= (~PF_PROJECTED); |
| 589 | g3_ProjectPoint(&gauge->pts[0]); |
| 590 | x1 = gauge->pts[0].p3_sx; |
| 591 | y = gauge->pts[0].p3_sy; |
| 592 | |
| 593 | grtext_SetFancyColor(GR_RGB(0, 180, 0), GR_RGB(0, 180, 0), GR_RGB(0, 180, 0), GR_RGB(0, 180, 0)); |
| 594 | grtext_SetFlags(0); |
| 595 | grtext_Printf(x1 + HUD_X(5), y + HUD_Y(10), "%s", |
| 596 | TXT(Static_weapon_ckpt_names[Players[Player_num].weapon[PW_SECONDARY].index][0])); |
| 597 | grtext_SetFlags(GRTEXTFLAG_SATURATE); |
| 598 | grtext_Printf(x1 + HUD_X(5), y + HUD_Y(10), "%s", |
| 599 | TXT(Static_weapon_ckpt_names[Players[Player_num].weapon[PW_SECONDARY].index][0])); |
| 600 | if (strlen(TXT(Static_weapon_ckpt_names[Players[Player_num].weapon[PW_SECONDARY].index][1]))) { |
| 601 | grtext_SetFlags(0); |
| 602 | grtext_Printf(x1 + HUD_X(5), y + HUD_Y(20), "%s", |
| 603 | TXT(Static_weapon_ckpt_names[Players[Player_num].weapon[PW_SECONDARY].index][1])); |
| 604 | grtext_SetFlags(GRTEXTFLAG_SATURATE); |
| 605 | grtext_Printf(x1 + HUD_X(5), y + HUD_Y(20), "%s", |
| 606 | TXT(Static_weapon_ckpt_names[Players[Player_num].weapon[PW_SECONDARY].index][1])); |
| 607 | y = y + HUD_Y(10); |
| 608 | } |
| 609 | grtext_SetFlags(0); |
| 610 | grtext_Printf(x1 + HUD_X(15), y + HUD_Y(20), "%d", |
| 611 | Players[Player_num].weapon_ammo[Players[Player_num].weapon[PW_SECONDARY].index]); |
| 612 | grtext_SetFlags(GRTEXTFLAG_SATURATE); |
| 613 | grtext_Printf(x1 + HUD_X(15), y + HUD_Y(20), "%d", |
| 614 | Players[Player_num].weapon_ammo[Players[Player_num].weapon[PW_SECONDARY].index]); |
| 615 | } |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | // renders the shield gauge monitor |
| 620 | void RenderShieldMonitor(tGauge *gauge, bool modified) { |
| 621 | float alpha_mod = (Objects[Players[Player_num].objnum].shields) / (float)INITIAL_SHIELDS; |
| 622 | |
| 623 | if (alpha_mod > 1.0f) |
| 624 | alpha_mod = 1.0f; |
| 625 | |
| 626 | int img = (int)ceil((1.0f - alpha_mod - 0.1f) * NUM_SHIELD_GAUGE_FRAMES); |
| 627 | if (img < NUM_SHIELD_GAUGE_FRAMES) { |
| 628 | if (img < 0) |
| 629 | img = 0; |
| 630 | img = HUD_resources.shield_bmp[img]; |
| 631 | |
| 632 | if (gauge->functional) |
| 633 | DrawGaugeQuad(gauge->pts, img, 255); |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | // renders the ship gauge monitor |
| 638 | void RenderEnergyMonitor(tGauge *gauge, int orient, bool modified) { |
| 639 | if (gauge->functional) { |
| 640 | float img_h = bm_h(HUD_resources.energy_bmp, 0); |
| 641 | float normalized_energy = (float)Players[Player_num].energy / (float)INITIAL_ENERGY; |
| 642 | g3Point used_pts[4], left_pts[4]; |
| 643 | float img_energy_h; |
| 644 | float hgt_scalar; |
| 645 | int i; |
| 646 | |
| 647 | if (normalized_energy > 1.0f) |
| 648 | normalized_energy = 1.0f; |
| 649 | |
| 650 | img_energy_h = (normalized_energy * img_h); |
| 651 | |
| 652 | for (i = 0; i < 4; i++) { |
| 653 | used_pts[i] = gauge->pts[i]; |
| 654 | left_pts[i] = gauge->pts[i]; |
| 655 | } |
| 656 | |
| 657 | // draw energy gauge, showing how much energy below 100% you have. draw energy spent faded. |
| 658 | hgt_scalar = img_energy_h / img_h; |
| 659 | used_pts[3].p3_vec = used_pts[3].p3_vec - (used_pts[3].p3_vec - used_pts[0].p3_vec) * hgt_scalar; |
| 660 | used_pts[2].p3_vec = used_pts[2].p3_vec - (used_pts[2].p3_vec - used_pts[1].p3_vec) * hgt_scalar; |
| 661 | used_pts[3].p3_vecPreRot = |
| 662 | used_pts[3].p3_vecPreRot - (used_pts[3].p3_vecPreRot - used_pts[0].p3_vecPreRot) * hgt_scalar; |
| 663 | used_pts[2].p3_vecPreRot = |
| 664 | used_pts[2].p3_vecPreRot - (used_pts[2].p3_vecPreRot - used_pts[1].p3_vecPreRot) * hgt_scalar; |
| 665 | |
| 666 | if (!orient) |
| 667 | DrawGaugeQuad(used_pts, HUD_resources.energy_bmp, 0, 0, 1, 1.0f - normalized_energy, 64, 0); |
| 668 | else |
| 669 | DrawGaugeQuad(used_pts, HUD_resources.energy_bmp, 1, 0, 0, 1.0f - normalized_energy, 64, 0); |
| 670 | |
| 671 | left_pts[0].p3_vec = left_pts[0].p3_vec + (left_pts[3].p3_vec - left_pts[0].p3_vec) * (1.0f - hgt_scalar); |
| 672 | left_pts[1].p3_vec = left_pts[1].p3_vec + (left_pts[2].p3_vec - left_pts[1].p3_vec) * (1.0f - hgt_scalar); |
| 673 | left_pts[0].p3_vecPreRot = |
| 674 | left_pts[0].p3_vecPreRot + (left_pts[3].p3_vecPreRot - left_pts[0].p3_vecPreRot) * (1.0f - hgt_scalar); |
| 675 | left_pts[1].p3_vecPreRot = |
| 676 | left_pts[1].p3_vecPreRot + (left_pts[2].p3_vecPreRot - left_pts[1].p3_vecPreRot) * (1.0f - hgt_scalar); |
| 677 | |
| 678 | if (!orient) |
| 679 | DrawGaugeQuad(left_pts, HUD_resources.energy_bmp, 0, 1.0f - normalized_energy, 1, 1, 255, 0); |
| 680 | else |
| 681 | DrawGaugeQuad(left_pts, HUD_resources.energy_bmp, 1, 1.0f - normalized_energy, 0, 1, 255, 0); |
| 682 | } |
| 683 | } |
| 684 | |
| 685 | // renders the ship gauge monitor |
| 686 | void RenderAfterburnMonitor(tGauge *gauge, bool modified) { |
| 687 | g3Point used_pts[4], left_pts[4]; |
| 688 | |
| 689 | if (gauge->functional) { |
| 690 | float img_w = bm_w(HUD_resources.afterburn_bmp, 0); |
| 691 | float val = (Players[Player_num].afterburn_time_left / AFTERBURN_TIME); |
| 692 | float img_burn_w = (val * img_w); |
| 693 | float w_scalar; |
| 694 | int i; |
| 695 | |
| 696 | for (i = 0; i < 4; i++) { |
| 697 | used_pts[i] = gauge->pts[i]; |
| 698 | left_pts[i] = gauge->pts[i]; |
| 699 | } |
| 700 | |
| 701 | // draw energy gauge, |
| 702 | // showing how much energy below 100% you have. draw energy spent faded. |
| 703 | w_scalar = img_burn_w / img_w; |
| 704 | |
| 705 | used_pts[3].p3_vec = used_pts[3].p3_vec + (used_pts[2].p3_vec - used_pts[3].p3_vec) * w_scalar; |
| 706 | used_pts[0].p3_vec = used_pts[0].p3_vec + (used_pts[1].p3_vec - used_pts[0].p3_vec) * w_scalar; |
| 707 | used_pts[3].p3_vecPreRot = |
| 708 | used_pts[3].p3_vecPreRot + (used_pts[2].p3_vecPreRot - used_pts[3].p3_vecPreRot) * w_scalar; |
| 709 | used_pts[0].p3_vecPreRot = |
| 710 | used_pts[0].p3_vecPreRot + (used_pts[1].p3_vecPreRot - used_pts[0].p3_vecPreRot) * w_scalar; |
| 711 | DrawGaugeQuad(used_pts, HUD_resources.afterburn_bmp, val, 0, 1, 1, 64, 0); |
| 712 | |
| 713 | left_pts[1].p3_vec = left_pts[1].p3_vec - (left_pts[1].p3_vec - left_pts[0].p3_vec) * (1.0f - w_scalar); |
| 714 | left_pts[2].p3_vec = left_pts[2].p3_vec - (left_pts[2].p3_vec - left_pts[3].p3_vec) * (1.0f - w_scalar); |
| 715 | left_pts[1].p3_vecPreRot = |
| 716 | left_pts[1].p3_vecPreRot - (left_pts[1].p3_vecPreRot - left_pts[0].p3_vecPreRot) * (1.0f - w_scalar); |
| 717 | left_pts[2].p3_vecPreRot = |
| 718 | left_pts[2].p3_vecPreRot - (left_pts[2].p3_vecPreRot - left_pts[3].p3_vecPreRot) * (1.0f - w_scalar); |
| 719 | DrawGaugeQuad(left_pts, HUD_resources.afterburn_bmp, 0, 0, val, 1, 255, 0); |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | // renders the ship gauge monitor |
| 724 | #define GAUGE_INVSHIPRING_DELTA 0.06f |
| 725 | void RenderShipMonitor(tGauge *gauge, bool modified) { |
| 726 | if (!gauge->functional) |
| 727 | return; |
| 728 | |
| 729 | uint8_t alpha = 255; |
| 730 | if (Objects[Players[Player_num].objnum].effect_info->type_flags & EF_CLOAKED) { |
| 731 | float time_frame = Objects[Players[Player_num].objnum].effect_info->cloak_time; |
| 732 | if (time_frame < HUD_CLOAKEND_TIME) { |
| 733 | alpha = 128 - 127 * FixCos(65536.0f * (time_frame - (int)time_frame)); |
| 734 | } else { |
| 735 | alpha = 0; |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | DrawGaugeQuad(gauge->pts, HUD_resources.ship_bmp, alpha); |
| 740 | DrawGaugeQuad(gauge->pts, HUD_resources.ship_bmp, alpha, true); |
| 741 | |
| 742 | if (Players[Player_num].flags & PLAYER_FLAGS_INVULNERABLE) { |
| 743 | // get to the view matrix so we have direction vectors to move along |
| 744 | matrix view_matrix; |
| 745 | g3_GetUnscaledMatrix(&view_matrix); |
| 746 | |
| 747 | float inv_time_frame = (Gametime - (int)Gametime); |
| 748 | float inv_alpha = (uint8_t)(255 * (1.0f - (inv_time_frame / 2.0f))); |
| 749 | g3Point invpts[4]; |
| 750 | int i; |
| 751 | |
| 752 | // do invulnerability animation. |
| 753 | for (i = 0; i < 4; i++) { |
| 754 | invpts[i] = gauge->pts[i]; |
| 755 | } |
| 756 | |
| 757 | float amount = (inv_time_frame * GAUGE_INVSHIPRING_DELTA); |
| 758 | invpts[0].p3_x -= amount; |
| 759 | invpts[0].p3_y += amount; |
| 760 | invpts[1].p3_x += amount; |
| 761 | invpts[1].p3_y += amount; |
| 762 | invpts[2].p3_x += amount; |
| 763 | invpts[2].p3_y -= amount; |
| 764 | invpts[3].p3_x -= amount; |
| 765 | invpts[3].p3_y -= amount; |
| 766 | |
| 767 | invpts[0].p3_vecPreRot = invpts[0].p3_vecPreRot - (view_matrix.rvec * amount) + (view_matrix.uvec * amount); |
| 768 | invpts[1].p3_vecPreRot = invpts[1].p3_vecPreRot + (view_matrix.rvec * amount) + (view_matrix.uvec * amount); |
| 769 | invpts[2].p3_vecPreRot = invpts[2].p3_vecPreRot + (view_matrix.rvec * amount) - (view_matrix.uvec * amount); |
| 770 | invpts[3].p3_vecPreRot = invpts[3].p3_vecPreRot - (view_matrix.rvec * amount) - (view_matrix.uvec * amount); |
| 771 | |
| 772 | DrawGaugeQuad(invpts, HUD_resources.invpulse_bmp, inv_alpha); |
| 773 | DrawGaugeQuad(invpts, HUD_resources.invpulse_bmp, inv_alpha, true); |
| 774 | } |
| 775 | } |
| 776 | |
| 777 | // projects monitor coordinates to screen coordinates |
| 778 | void RotateMonitorPosition(tGauge *gauge) { |
| 779 | ASSERT(gauge->monitor); |
| 780 | ASSERT(gauge->monitor->num_faces == 1); |
| 781 | int subnum = gauge->monitor - gauge->cockpit->submodel; |
| 782 | |
| 783 | if (gauge->monitor->faces[0].nverts != 4) |
| 784 | Int3(); |
| 785 | |
| 786 | for (int j = 0; j < gauge->monitor->faces[0].nverts; j++) { |
| 787 | // saved the view coordinates of the monitor if the gauge is moving and/or was just initialized. |
| 788 | // if gauge is not moving, then just use these saved points and make sure to mark them as NOT PROJECTED. |
| 789 | vector vpt; |
| 790 | vector vert; |
| 791 | vpt = gauge->monitor->verts[gauge->monitor->faces[0].vertnums[(gauge->first_vert + j) % 4]]; |
| 792 | // JEFFNOTE: Since we are using hardware transforms, we want to update the points all the time |
| 793 | // if (Render_gauge_moving || gauge->just_init || Render_gauge_reset) |
| 794 | { |
| 795 | GetPolyModelPointInWorld(&vert, gauge->cockpit, Render_gauge_pos, Render_gauge_matrix, subnum, |
| 796 | Render_normalized_times, &vpt); |
| 797 | g3_RotatePoint(&gauge->pts[j], &vert); |
| 798 | } |
| 799 | } |
| 800 | } |
| 801 | |
| 802 | ////////////////////////////////////////////////////////////////////////////// |
| 803 | // Graphic primatives for hud |
| 804 | |
| 805 | // renders a monitor style quad |
| 806 | void DrawGaugeMonitor(g3Point *pts, int bm, float brightness, float *alphas) { |
| 807 | g3Point *pntlist[4]; |
| 808 | g3Point pnts[4]; |
| 809 | |
| 810 | if (bm == -1) |
| 811 | bm = BAD_BITMAP_HANDLE; |
| 812 | |
| 813 | for (int i = 0; i < 4; i++) { |
| 814 | pnts[i] = pts[i]; |
| 815 | pnts[i].p3_flags = PF_UV | PF_RGBA | (pts[i].p3_flags & PF_ORIGPOINT); |
| 816 | pntlist[i] = &pnts[i]; |
| 817 | } |
| 818 | |
| 819 | pnts[0].p3_u = 0; |
| 820 | pnts[0].p3_v = 0; |
| 821 | pnts[0].p3_a = alphas[0]; |
| 822 | |
| 823 | pnts[1].p3_u = 1; |
| 824 | pnts[1].p3_v = 0; |
| 825 | pnts[1].p3_a = alphas[1]; |
| 826 | |
| 827 | pnts[2].p3_u = 1; |
| 828 | pnts[2].p3_v = 1; |
| 829 | pnts[2].p3_a = alphas[2]; |
| 830 | |
| 831 | pnts[3].p3_u = 0; |
| 832 | pnts[3].p3_v = 1; |
| 833 | pnts[3].p3_a = alphas[3]; |
| 834 | |
| 835 | rend_SetZBufferState(0); |
| 836 | rend_SetTextureType(TT_LINEAR); |
| 837 | rend_SetLighting(LS_NONE); |
| 838 | rend_SetAlphaValue(brightness * 255); |
| 839 | |
| 840 | rend_SetAlphaType(AT_CONSTANT_VERTEX); |
| 841 | |
| 842 | g3_DrawPoly(4, pntlist, bm); |
| 843 | } |
| 844 | |
| 845 | // renders a square texture onto the screen. |
| 846 | void DrawGaugeQuad(g3Point *pts, int bm, uint8_t alpha, bool saturate) { |
| 847 | DrawGaugeQuad(pts, bm, 0, 0, 1, 1, alpha, saturate); |
| 848 | } |
| 849 | |
| 850 | // renders a square texture onto the screen. |
| 851 | void DrawGaugeQuad(g3Point *pts, int bm, float u0, float v0, float u1, float v1, uint8_t alpha, bool saturate) { |
| 852 | g3Point *pntlist[4]; |
| 853 | g3Point pnts[4]; |
| 854 | |
| 855 | if (bm == -1) |
| 856 | bm = BAD_BITMAP_HANDLE; |
| 857 | |
| 858 | for (int i = 0; i < 4; i++) { |
| 859 | pnts[i] = pts[i]; |
| 860 | pnts[i].p3_flags = PF_UV | (pts[i].p3_flags & PF_ORIGPOINT); |
| 861 | pntlist[i] = &pnts[i]; |
| 862 | } |
| 863 | |
| 864 | pnts[0].p3_u = u0; |
| 865 | pnts[0].p3_v = v0; |
| 866 | |
| 867 | pnts[1].p3_u = u1; |
| 868 | pnts[1].p3_v = v0; |
| 869 | |
| 870 | pnts[2].p3_u = u1; |
| 871 | pnts[2].p3_v = v1; |
| 872 | |
| 873 | pnts[3].p3_u = u0; |
| 874 | pnts[3].p3_v = v1; |
| 875 | |
| 876 | rend_SetZBufferState(0); |
| 877 | rend_SetTextureType(TT_LINEAR); |
| 878 | rend_SetLighting(LS_NONE); |
| 879 | rend_SetAlphaValue(alpha); |
| 880 | |
| 881 | if (!saturate) |
| 882 | rend_SetAlphaType(AT_CONSTANT_TEXTURE); |
| 883 | else |
| 884 | rend_SetAlphaType(AT_SATURATE_TEXTURE); |
| 885 | |
| 886 | g3_DrawPoly(4, pntlist, bm); |
| 887 | } |
| 888 | |
| 889 | // renders a flat poly onto the screen with given color |
| 890 | void DrawGaugeQuadFlat(g3Point *pts, float r, float g, float b, uint8_t alpha) { |
| 891 | float ar[4] = {r, r, r, r}, ag[4] = {g, g, g, g}, ab[4] = {b, b, b, b}; |
| 892 | |
| 893 | DrawGaugeQuadFlat(pts, ar, ag, ab, alpha); |
| 894 | } |
| 895 | |
| 896 | // renders a flat poly onto the screen with 4 colors (for each vertex) |
| 897 | void DrawGaugeQuadFlat(g3Point *pts, float *r, float *g, float *b, uint8_t alpha) { |
| 898 | g3Point *pntlist[4]; |
| 899 | g3Point pnts[4]; |
| 900 | |
| 901 | for (int i = 0; i < 4; i++) { |
| 902 | pnts[i] = pts[i]; |
| 903 | pnts[i].p3_flags = PF_RGBA | (pts[i].p3_flags & PF_ORIGPOINT); |
| 904 | pntlist[i] = &pnts[i]; |
| 905 | } |
| 906 | |
| 907 | pnts[0].p3_r = r[0]; |
| 908 | pnts[0].p3_g = g[0]; |
| 909 | pnts[0].p3_b = b[0]; |
| 910 | |
| 911 | pnts[1].p3_r = r[1]; |
| 912 | pnts[1].p3_g = g[1]; |
| 913 | pnts[1].p3_b = b[1]; |
| 914 | |
| 915 | pnts[2].p3_r = r[2]; |
| 916 | pnts[2].p3_g = g[2]; |
| 917 | pnts[2].p3_b = b[2]; |
| 918 | |
| 919 | pnts[3].p3_r = r[3]; |
| 920 | pnts[3].p3_g = g[3]; |
| 921 | pnts[3].p3_b = b[3]; |
| 922 | |
| 923 | rend_SetZBufferState(0); |
| 924 | rend_SetLighting(LS_GOURAUD); |
| 925 | rend_SetTextureType(TT_FLAT); |
| 926 | rend_SetColorModel(CM_RGB); |
| 927 | rend_SetAlphaType(AT_CONSTANT); |
| 928 | rend_SetAlphaValue(alpha); |
| 929 | |
| 930 | g3_DrawPoly(4, pntlist, 0); |
| 931 | } |
| 932 | |
| 933 | // Returns the vertex index that corresponds to the upper-left vertex |
| 934 | int GetFirstVert(bsp_info *sm) { |
| 935 | ASSERT(sm->num_faces == 1 && sm->faces[0].nverts == 4); |
| 936 | int i; |
| 937 | polyface *face = &sm->faces[0]; |
| 938 | int first_vert = -1; |
| 939 | |
| 940 | for (i = 0; i < 4 && first_vert == -1; i++) { |
| 941 | if (sm->alpha[face->vertnums[i]] < .5) |
| 942 | first_vert = i; |
| 943 | } |
| 944 | |
| 945 | if (first_vert < 0) |
| 946 | first_vert = 0; // If no alpha info, just set to first vertex |
| 947 | |
| 948 | return first_vert; |
| 949 | } |
| 950 | |
| 951 | // Returns the coordinates of the specified cockpit monitor |
| 952 | // Parameter: window - 0 means primary monitor, 1 means secondary |
| 953 | // x0,y0,x1,y1 - these are filled in with the coordinates of the montiro |
| 954 | // Returns: true if got coords, false if the monitor was animating |
| 955 | bool GetCockpitWindowCoords(int window, int *left, int *top, int *right, int *bot) { |
| 956 | if (Render_gauge_moving) |
| 957 | return 0; |
| 958 | |
| 959 | tGauge *gauge; |
| 960 | |
| 961 | gauge = &Gauge_list[GAUGE_INDEX(window ? STAT_SECONDARYLOAD : STAT_PRIMARYLOAD)]; |
| 962 | |
| 963 | if (gauge->monitor) { |
| 964 | |
| 965 | #define HUD_RENDER_ZOOM 0.56f |
| 966 | |
| 967 | StartFrame(false); |
| 968 | g3_StartFrame(&Viewer_object->pos, &Viewer_object->orient, HUD_RENDER_ZOOM); |
| 969 | |
| 970 | for (int i = 0; i < 2; i++) { |
| 971 | gauge->pts[i * 2].p3_flags &= (~PF_PROJECTED); |
| 972 | g3_ProjectPoint(&gauge->pts[i * 2]); |
| 973 | } |
| 974 | |
| 975 | *left = gauge->pts[0].p3_sx; |
| 976 | *top = gauge->pts[0].p3_sy; |
| 977 | *right = gauge->pts[2].p3_sx + 2; |
| 978 | *bot = gauge->pts[2].p3_sy + 2; |
| 979 | |
| 980 | g3_EndFrame(); |
| 981 | EndFrame(); |
| 982 | |
| 983 | return 1; |
| 984 | } |
| 985 | |
| 986 | return 0; |
| 987 | } |