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.

voxelinfo.cpp 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * =====================================================================================
  3. *
  4. * Filename: voxelinfo.cpp
  5. *
  6. * Description: Voxelinfo source file
  7. *
  8. * Version: 1.0
  9. * Created: 04/06/2014 01:30:10 PM
  10. * Revision: none
  11. * Compiler: gcc
  12. *
  13. * Author: YOUR NAME (),
  14. * Organization:
  15. *
  16. * =====================================================================================
  17. */
  18. #include "voxelinfo.h"
  19. #include "world.h"
  20. namespace vtk {
  21. void VoxelInfo::pushTexCoordFromWorldCoords(std::vector<float>& data, const glm::ivec3& pos, const Face3D& face, const Corner2D& corner) {
  22. pushTexCoordFromVoxelID(data, linkedWorld->getVoxelType(pos), face, corner);
  23. }
  24. void VoxelInfo::pushTexCoordFromVoxelID(std::vector<float>& data, const unsigned& id, const Face3D& face, const Corner2D& corner) {
  25. auto coord = getTexCoordFromID(id, face, corner);
  26. data.push_back(coord.first);
  27. data.push_back(coord.second);
  28. data.push_back(getTexIndexFromID(id, face));
  29. }
  30. float VoxelInfo::getTexIndexFromID(const unsigned& id, const Face3D& face) {
  31. if (voxelDataMap.find(id) == voxelDataMap.end()) return 0.0f;
  32. return voxelDataMap[id].faceTextureIndices[face];
  33. }
  34. std::pair<float, float> VoxelInfo::getTexCoordFromID(const unsigned& id, const Face3D& face, const Corner2D& corner) {
  35. if (voxelDataMap.find(id) == voxelDataMap.end()) return std::make_pair(0.0f, 0.0f);
  36. Orientation2D orient = voxelDataMap[id].faceOrientation[face];
  37. switch (orient) {
  38. case Orientation2D::UP:
  39. switch (corner) {
  40. case Corner2D::TOPLEFT:
  41. return std::make_pair(0.0f, 1.0f);
  42. break;
  43. case Corner2D::TOPRIGHT:
  44. return std::make_pair(1.0f, 1.0f);
  45. break;
  46. case Corner2D::BOTTOMLEFT:
  47. return std::make_pair(0.0f, 0.0f);
  48. break;
  49. case Corner2D::BOTTOMRIGHT:
  50. return std::make_pair(1.0f, 0.0f);
  51. break;
  52. }
  53. break;
  54. case Orientation2D::DOWN:
  55. switch (corner) {
  56. case Corner2D::TOPLEFT:
  57. return std::make_pair(0.0f, 0.0f);
  58. break;
  59. case Corner2D::TOPRIGHT:
  60. return std::make_pair(1.0f, 0.0f);
  61. break;
  62. case Corner2D::BOTTOMLEFT:
  63. return std::make_pair(0.0f, 1.0f);
  64. break;
  65. case Corner2D::BOTTOMRIGHT:
  66. return std::make_pair(1.0f, 1.0f);
  67. break;
  68. }
  69. break;
  70. case Orientation2D::LEFT:
  71. switch (corner) {
  72. case Corner2D::TOPLEFT:
  73. return std::make_pair(0.0f, 1.0f);
  74. break;
  75. case Corner2D::TOPRIGHT:
  76. return std::make_pair(1.0f, 1.0f);
  77. break;
  78. case Corner2D::BOTTOMLEFT:
  79. return std::make_pair(0.0f, 0.0f);
  80. break;
  81. case Corner2D::BOTTOMRIGHT:
  82. return std::make_pair(1.0f, 0.0f);
  83. break;
  84. }
  85. break;
  86. case Orientation2D::RIGHT:
  87. switch (corner) {
  88. case Corner2D::TOPLEFT:
  89. return std::make_pair(0.0f, 1.0f);
  90. break;
  91. case Corner2D::TOPRIGHT:
  92. return std::make_pair(1.0f, 1.0f);
  93. break;
  94. case Corner2D::BOTTOMLEFT:
  95. return std::make_pair(0.0f, 0.0f);
  96. break;
  97. case Corner2D::BOTTOMRIGHT:
  98. return std::make_pair(1.0f, 0.0f);
  99. break;
  100. }
  101. break;
  102. }
  103. return std::make_pair(0.0f, 0.0f);
  104. }
  105. unsigned VoxelInfo::getTextureIndex(const unsigned int &id, const FaceDirection &face) {
  106. return voxelDataMap[id].faceTextures[face];
  107. }
  108. void VoxelInfo::setTextureIndex(const unsigned int &id, const FaceDirection &face, const unsigned int &index) {
  109. voxelDataMap[id].faceTextures[face] = index;
  110. }
  111. void VoxelInfo::setAllTextureIndexes(const unsigned int &id, const unsigned int &index) {
  112. auto& textures = voxelDataMap[id].faceTextures;
  113. textures[FaceDirection::TOP] = index;
  114. textures[FaceDirection::BOTTOM] = index;
  115. textures[FaceDirection::NORTH] = index;
  116. textures[FaceDirection::SOUTH] = index;
  117. textures[FaceDirection::EAST] = index;
  118. textures[FaceDirection::WEST] = index;
  119. }
  120. void VoxelInfo::setTextureData(const unsigned& id, const Face3D& face, const Orientation2D& orientation, const float& textureIndex) {
  121. voxelDataMap[id].faceOrientation[face] = orientation;
  122. voxelDataMap[id].faceTextureIndices[face] = textureIndex;
  123. }
  124. void VoxelInfo::setTransparent(const unsigned& id, const bool& transparent) {
  125. voxelDataMap[id].transparent = transparent;
  126. }
  127. bool VoxelInfo::isTransparent(const unsigned& id) {
  128. return voxelDataMap[id].transparent;
  129. }
  130. }