Renderer.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 Vector& pos, const Quaternion& rotation) {
  15. Matrix m = rotation.toMatrix();
  16. Vector right(1.0f, 0.0f, 0.0f);
  17. Vector up(0.0f, 1.0f, 0.0f);
  18. Vector back(0.0f, 0.0f, -1.0f);
  19. right.mul(m);
  20. up.mul(m);
  21. back.mul(m);
  22. view.set(0, right.getX());
  23. view.set(1, up.getX());
  24. view.set(2, back.getX());
  25. view.set(4, right.getY());
  26. view.set(5, up.getY());
  27. view.set(6, back.getY());
  28. view.set(8, right.getZ());
  29. view.set(9, up.getZ());
  30. view.set(10, back.getZ());
  31. view.set(12, right.dotInverse(pos));
  32. view.set(13, up.dotInverse(pos));
  33. view.set(14, back.dotInverse(pos));
  34. shader.setMatrix("view", view.getValues());
  35. return *this;
  36. }
  37. Renderer& Renderer::scale(float sx, float sy, float sz) {
  38. stack.get().scale(sx, sy, sz);
  39. return *this;
  40. }
  41. Renderer& Renderer::scale(float s) {
  42. stack.get().scale(s);
  43. return *this;
  44. }
  45. Renderer& Renderer::translate(float tx, float ty, float tz) {
  46. stack.get().translate(tx, ty, tz);
  47. return *this;
  48. }
  49. Renderer& Renderer::translateX(float tx) {
  50. stack.get().translateX(tx);
  51. return *this;
  52. }
  53. Renderer& Renderer::translateY(float ty) {
  54. stack.get().translateY(ty);
  55. return *this;
  56. }
  57. Renderer& Renderer::translateZ(float tz) {
  58. stack.get().translateZ(tz);
  59. return *this;
  60. }
  61. Renderer& Renderer::translateTo(float tx, float ty, float tz) {
  62. stack.get().translateTo(tx, ty, tz);
  63. return *this;
  64. }
  65. Renderer& Renderer::rotateX(float degrees) {
  66. stack.get().rotateX(degrees);
  67. return *this;
  68. }
  69. Renderer& Renderer::rotateY(float degrees) {
  70. stack.get().rotateY(degrees);
  71. return *this;
  72. }
  73. Renderer& Renderer::rotateZ(float degrees) {
  74. stack.get().rotateZ(degrees);
  75. return *this;
  76. }