Open Source Tomb Raider Engine
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Sprite.cpp 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*!
  2. * \file src/Sprite.cpp
  3. * \brief World Sprite
  4. *
  5. * \author xythobuz
  6. */
  7. #include "global.h"
  8. #include "Camera.h"
  9. #include "Render.h"
  10. #include "TextureManager.h"
  11. #include "World.h"
  12. #include "Sprite.h"
  13. const static float scale = 4.0f;
  14. const static float texelScale = 256.0f;
  15. const static int texelOffset = 2;
  16. Sprite::Sprite(int tile, int x, int y, int width, int height) : texture(tile) {
  17. width >>= 8;
  18. height >>= 8;
  19. int width2 = (int)(width * scale);
  20. int height2 = (int)(height * scale);
  21. std::vector<glm::vec2> uv;
  22. uv.emplace_back(float(x + texelOffset) / texelScale, float(y + height) / texelScale);
  23. uv.emplace_back(float(x + texelOffset) / texelScale, float(y + texelOffset) / texelScale);
  24. uv.emplace_back(float(x + width) / texelScale, float(y + texelOffset) / texelScale);
  25. uv.emplace_back(float(x + width) / texelScale, float(y + height) / texelScale);
  26. uv.emplace_back(uv.at(0));
  27. uv.emplace_back(uv.at(2));
  28. std::vector<glm::vec3> vert;
  29. vert.emplace_back(float(-width2) / 2.0f, 0.0f, 0.0f);
  30. vert.emplace_back(float(-width2) / 2.0f, float(-height2), 0.0f);
  31. vert.emplace_back(float(width2) / 2.0f, float(-height2), 0.0f);
  32. vert.emplace_back(float(width2) / 2.0f, 0.0f, 0.0f);
  33. vert.emplace_back(vert.at(0));
  34. vert.emplace_back(vert.at(2));
  35. vertices.bufferData(vert);
  36. uvs.bufferData(uv);
  37. }
  38. void Sprite::display(glm::mat4 MVP) {
  39. Shader::drawGL(vertices, uvs, texture, MVP);
  40. }
  41. // ----------------------------------------------------------------------------
  42. void SpriteSequence::display(glm::mat4 MVP, int index) {
  43. assert(index >= 0);
  44. assert(index < length);
  45. getWorld().getSprite(start + index).display(MVP);
  46. }