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

Function CreateLightningRodPositions

Descent3/fireball.cpp:2468–2496  ·  view source on GitHub ↗

Creates end points that simulate lightning

Source from the content-addressed store, hash-verified

2466}
2467// Creates end points that simulate lightning
2468void CreateLightningRodPositions(vector *src, vector *dest, vector *world_vecs, int num_segments, float rand_mag,
2469 bool do_flat) {
2470 vector delta_vec = *dest - *src;
2471 matrix mat;
2472
2473 // Setup some interpolants
2474 float mag = vm_GetMagnitudeFast(&delta_vec);
2475 float delta_dist = mag / num_segments;
2476 delta_vec /= mag;
2477 // Create matrix for randomization
2478 vm_VectorToMatrix(&mat, &delta_vec, NULL, NULL);
2479
2480 vector cur_pos = *src;
2481
2482 vector from = cur_pos;
2483 world_vecs[0] = from;
2484 world_vecs[num_segments - 1] = *dest;
2485 // Create the points
2486 for (int i = 1; i < num_segments - 1; i++, cur_pos += (delta_vec * delta_dist)) {
2487 vector to = cur_pos + (delta_vec * delta_dist);
2488 // vector to=world_vecs[i-1]+(delta_vec*delta_dist);
2489 to += mat.rvec * ((((ps_rand() % 200) - 100) / 100.0) * rand_mag);
2490 if (!do_flat)
2491 to += mat.uvec * ((((ps_rand() % 200) - 100) / 100.0) * rand_mag);
2492 ASSERT(i < 50);
2493
2494 world_vecs[i] = to;
2495 }
2496}

Callers 1

DrawVisLightningBoltFunction · 0.85

Calls 3

ps_randFunction · 0.85
vm_GetMagnitudeFastFunction · 0.50
vm_VectorToMatrixFunction · 0.50

Tested by

no test coverage detected