Open Source Tomb Raider Engine
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.

StaticMesh.cpp 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*!
  2. * \file src/StaticMesh.cpp
  3. * \brief Static Model Meshes
  4. *
  5. * \author xythobuz
  6. */
  7. #include "global.h"
  8. #include "Game.h"
  9. #include "Render.h"
  10. #include "TextureManager.h"
  11. #include "World.h"
  12. #include "utils/pixel.h"
  13. #include "StaticMesh.h"
  14. TexturedTriangle::TexturedTriangle(int i[3], float s[6], int tex, unsigned short trans) {
  15. index[0] = i[0];
  16. index[1] = i[1];
  17. index[2] = i[2];
  18. st[0] = s[0];
  19. st[1] = s[1];
  20. st[2] = s[2];
  21. st[3] = s[3];
  22. st[4] = s[4];
  23. st[5] = s[5];
  24. texture = tex;
  25. transparency = trans;
  26. }
  27. void TexturedTriangle::display(float* vertices, float* colors, float* normals) {
  28. /*
  29. assert(vertices != nullptr);
  30. if ((Render::getMode() != RenderMode::Wireframe)
  31. && (Render::getMode() != RenderMode::Solid)) {
  32. getTextureManager().bindTextureId(texture);
  33. }
  34. glBegin(GL_TRIANGLES);
  35. switch (Render::getMode()) {
  36. case RenderMode::Solid:
  37. //case RenderMode::VertexLight:
  38. if (colors != nullptr) {
  39. glColor3fv(colors + index[0]);
  40. glTexCoord2fv(st);
  41. glVertex3fv(vertices + (index[0] * 3));
  42. glColor3fv(colors + index[1]);
  43. glTexCoord2fv(st + 2);
  44. glVertex3fv(vertices + (index[1] * 3));
  45. glColor3fv(colors + index[2]);
  46. glTexCoord2fv(st + 4);
  47. glVertex3fv(vertices + (index[2] * 3));
  48. } else if (normals != nullptr) {
  49. glNormal3fv(normals + (index[0] * 3));
  50. glTexCoord2fv(st);
  51. glVertex3fv(vertices + (index[0] * 3));
  52. glNormal3fv(normals + (index[1] * 3));
  53. glTexCoord2fv(st + 2);
  54. glVertex3fv(vertices + (index[1] * 3));
  55. glNormal3fv(normals + (index[2] * 3));
  56. glTexCoord2fv(st + 4);
  57. glVertex3fv(vertices + (index[2] * 3));
  58. } else {
  59. glTexCoord2fv(st);
  60. glVertex3fv(vertices + (index[0] * 3));
  61. glTexCoord2fv(st + 2);
  62. glVertex3fv(vertices + (index[1] * 3));
  63. glTexCoord2fv(st + 4);
  64. glVertex3fv(vertices + (index[2] * 3));
  65. }
  66. break;
  67. case RenderMode::Wireframe:
  68. glVertex3fv(vertices + (index[0] * 3));
  69. glVertex3fv(vertices + (index[1] * 3));
  70. glVertex3fv(vertices + (index[2] * 3));
  71. break;
  72. default:
  73. glTexCoord2fv(st);
  74. glVertex3fv(vertices + (index[0] * 3));
  75. glTexCoord2fv(st + 2);
  76. glVertex3fv(vertices + (index[1] * 3));
  77. glTexCoord2fv(st + 4);
  78. glVertex3fv(vertices + (index[2] * 3));
  79. }
  80. glEnd();
  81. */
  82. }
  83. // ----------------------------------------------------------------------------
  84. StaticMesh::StaticMesh(int i, int m) : id(i), mesh(m) {
  85. vertices = colors = normals = nullptr;
  86. }
  87. StaticMesh::~StaticMesh() {
  88. while (!triangles.empty()) {
  89. delete triangles.back();
  90. triangles.pop_back();
  91. }
  92. delete [] vertices;
  93. delete [] normals;
  94. delete [] colors;
  95. }
  96. void StaticMesh::display() {
  97. /*
  98. if ((id != -1) && (mesh != -1)) {
  99. getWorld().getMesh(mesh).drawSolid();
  100. return;
  101. }
  102. if (!dontshow) {
  103. //! \fixme Duh, vis tests need to be put back
  104. //if (!isVisible(center, radius, bbox))
  105. // return;
  106. //! \fixme 'AMBIENT' -- Mongoose 2002.01.08
  107. glColor3ubv(WHITE);
  108. if (Render::getMode() == RenderMode::Wireframe)
  109. glColor3ubv(WHITE);
  110. getTextureManager().bindTextureId(TEXTURE_WHITE, TextureManager::TextureStorage::SYSTEM);
  111. for (unsigned int i = 0; i < triangles.size(); i++)
  112. triangles.at(i)->display(vertices, colors, normals);
  113. }
  114. */
  115. }
  116. float StaticMesh::getRadius() {
  117. assert((id == -1) && (mesh == -1));
  118. return radius;
  119. }