💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.8 KiB

  1. /*
  2. * Copyright (C) 2020 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef ANTKEEPER_MARCHING_CUBES_HPP
  20. #define ANTKEEPER_MARCHING_CUBES_HPP
  21. #include <cstdint>
  22. /**
  23. * Contains functions and constants related to the Marching Cubes (MC) algorithm.
  24. */
  25. namespace mc {
  26. /**
  27. * Uses the marching cubes algorithm to polygonize a single cell.
  28. *
  29. * @param[out] vertices Array which can hold at least 12 vertices (36 floats).
  30. * @param[out] vertex_count Number of generated vertices.
  31. * @param[out] triangles Array which can hold 5 at least triangles (15 ints).
  32. * @param[out] triangle_count Number of generated triangles. The maximum number triangles generated for a single cell is 5.
  33. */
  34. void polygonize(float* vertices, std::uint_fast8_t* vertex_count, std::int_fast8_t* triangles, std::uint_fast8_t* triangle_count, const float* corners, const float* distances);
  35. /**
  36. * Vertices of a unit cube.
  37. */
  38. constexpr float unit_cube[8][3] =
  39. {
  40. {0, 0, 0},
  41. {1, 0, 0},
  42. {1, 1, 0},
  43. {0, 1, 0},
  44. {0, 0, 1},
  45. {1, 0, 1},
  46. {1, 1, 1},
  47. {0, 1, 1}
  48. };
  49. } // namespace mc
  50. #endif // ANTKEEPER_MARCHING_CUBES_HPP