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

Function TerrainCellVisible

Descent3/terrainrender.cpp:2534–2572  ·  view source on GitHub ↗

Puts a 1 in upperleft,lowerright if those triangles are visible

Source from the content-addressed store, hash-verified

2532
2533// Puts a 1 in upperleft,lowerright if those triangles are visible
2534void TerrainCellVisible(int index, int *upper_left, int *lower_right) {
2535 int seg = Terrain_list[index].segment;
2536 int lod = Terrain_list[index].lod;
2537 int simplemul = 1 << ((MAX_TERRAIN_LOD - 1) - lod);
2538 int cx, cz, smul_x, smul_z;
2539
2540 vector tempv;
2541 vector *corner[4];
2542
2543 cx = seg % TERRAIN_WIDTH;
2544 cz = seg / TERRAIN_WIDTH;
2545 if (cx + simplemul == TERRAIN_WIDTH)
2546 smul_x = simplemul - 1;
2547 else
2548 smul_x = simplemul;
2549 if (cz + simplemul == TERRAIN_DEPTH)
2550 smul_z = simplemul - 1;
2551 else
2552 smul_z = simplemul;
2553
2554 // Note - this is upper left and proceeds clockwise
2555 corner[0] = &World_point_buffer[seg + (TERRAIN_WIDTH * smul_z)].p3_vec;
2556 corner[1] = &World_point_buffer[seg + (TERRAIN_WIDTH * smul_z) + smul_x].p3_vec;
2557 corner[2] = &World_point_buffer[seg].p3_vec;
2558 corner[3] = &World_point_buffer[seg + smul_x].p3_vec;
2559
2560 vm_GetPerp(&tempv, corner[0], corner[1], corner[2]);
2561 if ((tempv * *corner[1]) < 0)
2562 *upper_left = 1;
2563 else
2564 *upper_left = 0;
2565
2566 // Now do lower right
2567 vm_GetPerp(&tempv, corner[2], corner[1], corner[3]);
2568 if ((tempv * *corner[1]) < 0)
2569 *lower_right = 1;
2570 else
2571 *lower_right = 0;
2572}
2573
2574void DisplayTerrainList(int cellcount, bool from_automap) {
2575 int total = 0, on, t, i, lod, simplemul;

Callers 1

DisplayTerrainListFunction · 0.85

Calls 1

vm_GetPerpFunction · 0.50

Tested by

no test coverage detected