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

Function DeformTerrain

Descent3/terrain.cpp:461–531  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

459
460void UpdateSingleTerrainLightmap(int which);
461void DeformTerrain(vector *pos, int depth, float size) {
462 int startx, startz, endx, endz;
463 int changed[4] = {0, 0, 0, 0};
464 vector local_pos = *pos;
465
466 startx = (pos->x / TERRAIN_SIZE) - (size / TERRAIN_SIZE);
467 startz = (pos->z / TERRAIN_SIZE) - (size / TERRAIN_SIZE);
468 endx = (pos->x / TERRAIN_SIZE) + (size / TERRAIN_SIZE);
469 endz = (pos->z / TERRAIN_SIZE) + (size / TERRAIN_SIZE);
470
471 startx = std::max(0, startx);
472 startz = std::max(0, startz);
473 endx = std::min(TERRAIN_WIDTH - 1, endx);
474 endz = std::min(TERRAIN_DEPTH - 1, endz);
475
476 int i, t;
477
478 vector cur_vec;
479 vector up_vec = {0, 1, 0};
480
481 local_pos.y = 0;
482
483 cur_vec.x = startx * TERRAIN_SIZE;
484 cur_vec.y = 0;
485 cur_vec.z = startz * TERRAIN_SIZE;
486
487 float max_dist = vm_VectorDistanceQuick(&local_pos, &cur_vec);
488
489 for (i = startz; i <= endz; i++, cur_vec.z += TERRAIN_SIZE) {
490 cur_vec.x = startx * TERRAIN_SIZE;
491 for (t = startx; t <= endx; t++, cur_vec.x += TERRAIN_SIZE) {
492 terrain_segment *tseg = &Terrain_seg[i * TERRAIN_WIDTH + t];
493
494 if ((up_vec * TerrainNormals[MAX_TERRAIN_LOD - 1][i * TERRAIN_WIDTH + t].normal1) < .5)
495 continue; // not flat enough
496 if ((up_vec * TerrainNormals[MAX_TERRAIN_LOD - 1][i * TERRAIN_WIDTH + t].normal2) < .5)
497 continue; // not flat enough
498
499 float dist = 1.0 - (vm_VectorDistanceQuick(&local_pos, &cur_vec) / max_dist);
500
501 int height_change = -(dist * (float)depth);
502 int light_change = height_change * 2;
503
504 DeformTerrainPoint(t, i, height_change);
505
506 tseg->r = std::max(0, tseg->r + light_change);
507 tseg->g = std::max(0, tseg->g + light_change);
508 tseg->b = std::max(0, tseg->b + light_change);
509
510 int which = ((i / 128) * 2) + (t / 128);
511 changed[which] = 1;
512 }
513 }
514
515 int div = (1 << (MAX_TERRAIN_LOD - 1));
516
517 startx /= div;
518 startz /= div;

Callers 1

collide_weapon_and_wallFunction · 0.85

Calls 4

DeformTerrainPointFunction · 0.85
GenerateSingleLODDeltaFunction · 0.85
vm_VectorDistanceQuickFunction · 0.50

Tested by

no test coverage detected