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.

voxelutils.h 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * =====================================================================================
  3. *
  4. * Filename: voxelutils.h
  5. *
  6. * Description: Positioning and stuff.
  7. *
  8. * Version: 1.0
  9. * Created: 04/03/2014 07:27:40 PM
  10. * Revision: none
  11. * Compiler: gcc
  12. *
  13. * Author: YOUR NAME (),
  14. * Organization:
  15. *
  16. * =====================================================================================
  17. */
  18. #pragma once
  19. #include <tuple>
  20. #include <glm/glm.hpp>
  21. namespace vtk {
  22. enum class FaceDirection {
  23. TOP = 0,
  24. BOTTOM = 1,
  25. NORTH = 2,
  26. SOUTH = 3,
  27. EAST = 4,
  28. WEST = 5
  29. };
  30. typedef std::tuple<unsigned, unsigned, unsigned> uPos; //used for voxel positions
  31. struct uPosHash : public std::unary_function<uPos, std::size_t> {
  32. std::size_t operator()(const uPos& k) const {
  33. return std::get<0>(k) ^ std::get<1>(k) ^ std::get<2>(k);
  34. }
  35. };
  36. struct uPosEqual : public std::binary_function<uPos, uPos, bool> {
  37. bool operator()(const uPos& a, const uPos& b) const {
  38. return (std::get<0>(a) == std::get<0>(b) &&
  39. std::get<1>(a) == std::get<1>(b) &&
  40. std::get<2>(a) == std::get<2>(b));
  41. }
  42. };
  43. typedef std::tuple<int, int, int> iPos; //used for chunk positions
  44. struct iPosHash : public std::unary_function<iPos, std::size_t> {
  45. std::size_t operator()(const iPos& k) const {
  46. return std::get<0>(k) ^ std::get<1>(k) ^ std::get<2>(k);
  47. }
  48. };
  49. struct iPosEqual : public std::binary_function<iPos, iPos, bool> {
  50. bool operator()(const iPos& a, const iPos& b) const {
  51. return (std::get<0>(a) == std::get<0>(b) &&
  52. std::get<1>(a) == std::get<1>(b) &&
  53. std::get<2>(a) == std::get<2>(b));
  54. }
  55. };
  56. // basic hash function for glm::ivec3
  57. struct ivec3Hash : public std::unary_function<iPos, std::size_t> {
  58. std::size_t operator()(const glm::ivec3& k) const {
  59. std::size_t seed = 3;
  60. for(int i = 0; i < 3; ++i) {
  61. seed ^= k[i] + 0x9e3779b9 + (seed << 6) + (seed >> 2);
  62. }
  63. return seed;
  64. }
  65. };
  66. /*
  67. struct ivec3Equal : public std::binary_function<iPos, iPos, bool> {
  68. bool operator()(const iPos& a, const iPos& b) const {
  69. return (std::get<0>(a) == std::get<0>(b) &&
  70. std::get<1>(a) == std::get<1>(b) &&
  71. std::get<2>(a) == std::get<2>(b));
  72. }
  73. };
  74. */
  75. }