Clone of Bael'Zharon's Respite @ https://github.com/boardwalk/bzr

TriangleFan.cpp 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Bael'Zharon's Respite
  3. * Copyright (C) 2014 Daniel Skorupski
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #include "TriangleFan.h"
  19. #include "BinReader.h"
  20. // enum StipplingType
  21. enum StipplingType
  22. {
  23. kNoStippling = 0,
  24. kPositiveStippling = 1,
  25. kNegativeStippling = 2,
  26. kBothStippling = 3,
  27. kNoPosUVs = 4,
  28. kNoNegUVs = 8,
  29. };
  30. // enum SidesType
  31. enum SidesType
  32. {
  33. kSingle = 0,
  34. kDouble = 1,
  35. kBoth = 2
  36. };
  37. void read(BinReader& reader, TriangleFan& trifan)
  38. {
  39. uint8_t numIndices = reader.readByte();
  40. trifan.indices.resize(numIndices);
  41. trifan.stipplingType = reader.readByte();
  42. assert(trifan.stipplingType == kNoStippling || trifan.stipplingType == kPositiveStippling || trifan.stipplingType == kNoPosUVs);
  43. uint32_t sidesType = reader.readInt();
  44. assert(sidesType == kSingle || sidesType == kDouble || sidesType == kBoth);
  45. trifan.surfaceIndex = reader.readShort();
  46. /*negSurface*/ reader.readShort();
  47. for(TriangleFan::Index& index : trifan.indices)
  48. {
  49. index.vertexIndex = reader.readShort();
  50. }
  51. if(trifan.stipplingType != kNoPosUVs)
  52. {
  53. for(TriangleFan::Index& index : trifan.indices)
  54. {
  55. index.texCoordIndex = reader.readByte();
  56. }
  57. }
  58. if(sidesType == kBoth)
  59. {
  60. for(uint8_t i = 0; i < numIndices; i++)
  61. {
  62. reader.readByte();
  63. }
  64. }
  65. }