Renderer.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "client/rendering/Renderer.h"
  2. Renderer::Renderer(Shader& shader, MatrixStack& stack, Matrix& view) : shader(shader), stack(stack), view(view) {
  3. }
  4. void Renderer::pop() {
  5. stack.pop();
  6. }
  7. void Renderer::push() {
  8. stack.push();
  9. }
  10. Renderer& Renderer::update() {
  11. shader.setMatrix("model", stack.get().getValues());
  12. return *this;
  13. }
  14. Renderer& Renderer::update(const Vector3& pos, const Quaternion& rotation) {
  15. Matrix m = rotation.toMatrix();
  16. Vector3 right = m * Vector3(1.0f, 0.0f, 0.0f);
  17. Vector3 up = m * Vector3(0.0f, 1.0f, 0.0f);
  18. Vector3 back = m * Vector3(0.0f, 0.0f, -1.0f);
  19. view.set(0, right[0]);
  20. view.set(1, up[0]);
  21. view.set(2, back[0]);
  22. view.set(4, right[1]);
  23. view.set(5, up[1]);
  24. view.set(6, back[1]);
  25. view.set(8, right[2]);
  26. view.set(9, up[2]);
  27. view.set(10, back[2]);
  28. view.set(12, right.dot(-pos));
  29. view.set(13, up.dot(-pos));
  30. view.set(14, back.dot(-pos));
  31. shader.setMatrix("view", view.getValues());
  32. return *this;
  33. }
  34. Renderer& Renderer::scale(float sx, float sy, float sz) {
  35. stack.get().scale(sx, sy, sz);
  36. return *this;
  37. }
  38. Renderer& Renderer::scale(float s) {
  39. stack.get().scale(s);
  40. return *this;
  41. }
  42. Renderer& Renderer::translate(float tx, float ty, float tz) {
  43. stack.get().translate(tx, ty, tz);
  44. return *this;
  45. }
  46. Renderer& Renderer::translateX(float tx) {
  47. stack.get().translateX(tx);
  48. return *this;
  49. }
  50. Renderer& Renderer::translateY(float ty) {
  51. stack.get().translateY(ty);
  52. return *this;
  53. }
  54. Renderer& Renderer::translateZ(float tz) {
  55. stack.get().translateZ(tz);
  56. return *this;
  57. }
  58. Renderer& Renderer::translateTo(float tx, float ty, float tz) {
  59. stack.get().translateTo(tx, ty, tz);
  60. return *this;
  61. }
  62. Renderer& Renderer::rotateX(float degrees) {
  63. stack.get().rotateX(degrees);
  64. return *this;
  65. }
  66. Renderer& Renderer::rotateY(float degrees) {
  67. stack.get().rotateY(degrees);
  68. return *this;
  69. }
  70. Renderer& Renderer::rotateZ(float degrees) {
  71. stack.get().rotateZ(degrees);
  72. return *this;
  73. }