MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / GridTest

Function GridTest

Source/Objects/movementobject.cpp:679–857  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

677}
678
679void GridTest(vec3 pos, BulletWorld* bw, float _leg_sphere_size) {
680 if (grid_cells.empty()) {
681 grid_cells.resize(_grid_size * _grid_size * _grid_size);
682 }
683 int index = 0;
684 for (int i = 0; i < _grid_size; ++i) {
685 for (int j = 0; j < _grid_size; ++j) {
686 for (int k = 0; k < _grid_size; ++k) {
687 vec3 quantized_pos = vec3(floor(pos[0] / cell_size), floor(pos[1] / cell_size), floor(pos[2] / cell_size)) * cell_size;
688 quantized_pos[0] += (i - (_grid_size / 2)) * cell_size;
689 quantized_pos[1] += (j - (_grid_size / 2)) * cell_size;
690 quantized_pos[2] += (k - (_grid_size / 2)) * cell_size;
691 ContactSlideCallback cb;
692 cb.single_sided = false;
693 bw->GetSphereCollisions(quantized_pos, _leg_sphere_size, cb);
694 if (cb.collision_info.contacts.size() == 0) {
695 grid_cells[index].solid = false;
696 } else {
697 grid_cells[index].solid = true;
698 }
699 grid_cells[index].walkable = false;
700 grid_cells[index].boundary = false;
701 ++index;
702 }
703 }
704 }
705
706 for (int i = 0; i < _grid_size; ++i) {
707 for (int j = 0; j < _grid_size; ++j) {
708 for (int k = 0; k < _grid_size; ++k) {
709 if (!grid_cells[GridIndexFromCoord(i, j, k)].solid) {
710 bool next_to_solid = false;
711 if (i != 0 && grid_cells[GridIndexFromCoord(i - 1, j, k)].solid == true) {
712 next_to_solid = true;
713 } else if (i != _grid_size - 1 && grid_cells[GridIndexFromCoord(i + 1, j, k)].solid == true) {
714 next_to_solid = true;
715 } else if (k != 0 && grid_cells[GridIndexFromCoord(i, j, k - 1)].solid == true) {
716 next_to_solid = true;
717 } else if (k != _grid_size - 1 && grid_cells[GridIndexFromCoord(i, j, k + 1)].solid == true) {
718 next_to_solid = true;
719 } else if (j != 0 && grid_cells[GridIndexFromCoord(i, j - 1, k)].solid == true) {
720 next_to_solid = true;
721 } else if (j != _grid_size - 1 && grid_cells[GridIndexFromCoord(i, j + 1, k)].solid == true) {
722 next_to_solid = true;
723 }
724 if (next_to_solid) {
725 grid_cells[GridIndexFromCoord(i, j, k)].boundary = true;
726 vec3 quantized_pos = vec3(floor(pos[0] / cell_size), floor(pos[1] / cell_size), floor(pos[2] / cell_size)) * cell_size;
727 quantized_pos[0] += (i - (_grid_size / 2)) * cell_size;
728 quantized_pos[1] += (j - (_grid_size / 2)) * cell_size;
729 quantized_pos[2] += (k - (_grid_size / 2)) * cell_size;
730 DebugDraw::Instance()->AddWireSphere(quantized_pos, 0.1f, vec4(vec3(0.0f, 1.0f, 0.0f), 0.2f), _delete_on_update);
731 }
732 }
733 }
734 }
735 }
736

Callers

nothing calls this directly

Calls 9

GridIndexFromCoordFunction · 0.85
GetSphereCollisionsMethod · 0.80
AddWireSphereMethod · 0.80
vec3Class · 0.50
floorFunction · 0.50
vec4Class · 0.50
emptyMethod · 0.45
resizeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected