MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / DrawLightning

Function DrawLightning

Descent3/terrainrender.cpp:1491–1552  ·  view source on GitHub ↗

Draws an entire strip of lightning

Source from the content-addressed store, hash-verified

1489 }
1490// Draws an entire strip of lightning
1491void DrawLightning(void) {
1492 angvec player_angs;
1493 matrix mat;
1494 vector froms[50];
1495 int si = 0, level;
1496 int stack_level[50];
1497 int splits[50];
1498 int cur_splits = 0;
1499 int new_heading;
1500 float scalar;
1501 scalar = ((ps_rand() % 1000) - 500) / 500.0;
1502 scalar *= 15000;
1503 vm_ExtractAnglesFromMatrix(&player_angs, &Viewer_object->orient);
1504 new_heading = (player_angs.h + (int)scalar) % 65536;
1505 vm_AnglesToMatrix(&mat, 0, new_heading, 0);
1506 // Put the starting point way up in the air
1507 float ylimit = (-(Viewer_object->pos.y * 2)) + (ps_rand() % 400);
1508 vector cur_from = Viewer_object->pos + (mat.fvec * 4000);
1509 vector new_vec;
1510 cur_from.y += 800.0f;
1511 cur_from.y += (ps_rand() % 100);
1512 // Set some states
1513
1514 rend_SetAlphaType(AT_SATURATE_TEXTURE);
1515 rend_SetAlphaValue(.5 * 255);
1516 rend_SetLighting(LS_NONE);
1517 int bm_handle;
1518
1519 // See if we should drawn an origin bitmap
1520 if (ps_rand() % 3) {
1521 // Pick an origin bitmap
1522 if (ps_rand() % 2)
1523 bm_handle = Fireballs[LIGHTNING_ORIGIN_INDEXA].bm_handle;
1524 else
1525 bm_handle = Fireballs[LIGHTNING_ORIGIN_INDEXB].bm_handle;
1526 // Draw the origin bitmap
1527 int size = 300 + (ps_rand() % 200);
1528 g3_DrawRotatedBitmap(&cur_from, 0, size, (size * bm_h(bm_handle, 0)) / bm_w(bm_handle, 0), bm_handle);
1529 }
1530 PUSH_LIGHTNING_TREE(cur_from, 0, 0)
1531 while (si > 0) {
1532 POP_LIGHTNING_TREE()
1533 ASSERT(level < 50);
1534 float x_adjust = ((ps_rand() % 200) - 100) / 100.0;
1535 float y_adjust = .3 + ((ps_rand() % 100) / 100.0);
1536
1537 new_vec = cur_from;
1538 new_vec += x_adjust * (mat.rvec * 70);
1539 new_vec -= y_adjust * (mat.uvec * 100);
1540 DrawLightningSegment(&cur_from, &new_vec);
1541 if (cur_from.y < ylimit) // We're close to the ground, so just bail!
1542 continue;
1543
1544 if ((ps_rand() % ((level * level * 20) + 8)) == 0 && cur_splits < 2) {
1545 // Make this branch split
1546 PUSH_LIGHTNING_TREE(new_vec, level, cur_splits + 1)
1547 PUSH_LIGHTNING_TREE(new_vec, level, cur_splits + 1)
1548 } else {

Callers 1

DrawSkyFunction · 0.85

Calls 10

ps_randFunction · 0.85
g3_DrawRotatedBitmapFunction · 0.85
bm_hFunction · 0.85
bm_wFunction · 0.85
DrawLightningSegmentFunction · 0.85
vm_AnglesToMatrixFunction · 0.50
rend_SetAlphaTypeFunction · 0.50
rend_SetAlphaValueFunction · 0.50
rend_SetLightingFunction · 0.50

Tested by

no test coverage detected