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

Function AddProcLightning

Descent3/procedurals.cpp:407–436  ·  view source on GitHub ↗

Draws lightning into a bitmap

Source from the content-addressed store, hash-verified

405}
406// Draws lightning into a bitmap
407void AddProcLightning(int x1, int y1, int x2, int y2, uint8_t color, static_proc_element *proc) {
408 float dx = x2 - x1;
409 float dy = y2 - y1;
410
411 float mag = sqrt((dx * dx) + (dy * dy));
412 if (mag < 1)
413 return;
414 int num_segments = mag / 8;
415 dx /= mag;
416 dy /= mag;
417 float cur_x = x1;
418 float cur_y = y1;
419 float rot_x = dy;
420 float rot_y = dx;
421 float from_x = cur_x;
422 float from_y = cur_y;
423 for (int i = 0; i < num_segments; i++, cur_x += (dx * 8), cur_y += (dy * 8)) {
424 float to_x = cur_x + (dx * 8);
425 float to_y = cur_y + (dy * 8);
426 if (i != num_segments - 1) {
427 to_x += (rot_x) * ((1 + proc->speed) * (((prand() % 200) - 100.0) / 18.0));
428 to_y += (rot_y) * ((1 + proc->speed) * (((prand() % 200) - 100.0) / 18.0));
429 }
430
431 DrawProceduralLine(from_x, from_y, to_x, to_y, color);
432
433 from_x = to_x;
434 from_y = to_y;
435 }
436}
437// link the procedural into the list for its texture
438void ProcElementLink(int index, int texnum) {
439 dynamic_proc_element *proc = &DynamicProcElements[index];

Callers 2

AddProcSphereLightningFunction · 0.85
EvaluateFireProceduralFunction · 0.85

Calls 2

prandFunction · 0.85
DrawProceduralLineFunction · 0.85

Tested by

no test coverage detected