Renderer.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include "client/rendering/Renderer.h"
  2. Renderer::Renderer(Shader& shader, MatrixStack<16>& 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.peek().getValues());
  12. return *this;
  13. }
  14. Renderer& Renderer::update(const Vector3& pos, const Quaternion& rotation) {
  15. Vector3 right = rotation * Vector3(1.0f, 0.0f, 0.0f);
  16. Vector3 up = rotation * Vector3(0.0f, 1.0f, 0.0f);
  17. Vector3 back = rotation * Vector3(0.0f, 0.0f, -1.0f);
  18. view.set(0, Vector4(right[0], right[1], right[2], right.dot(-pos)));
  19. view.set(1, Vector4(up[0], up[1], up[2], up.dot(-pos)));
  20. view.set(2, Vector4(back[0], back[1], back[2], back.dot(-pos)));
  21. view.set(3, Vector4(0.0f, 0.0f, 0.0f, 1.0f));
  22. shader.setMatrix("view", view.getValues());
  23. return *this;
  24. }
  25. Renderer& Renderer::scale(float sx, float sy, float sz) {
  26. stack.peek().scale(Vector3(sx, sy, sz));
  27. return *this;
  28. }
  29. Renderer& Renderer::scale(float s) {
  30. stack.peek().scale(s);
  31. return *this;
  32. }
  33. Renderer& Renderer::translate(float tx, float ty, float tz) {
  34. stack.peek().translate(Vector3(tx, ty, tz));
  35. return *this;
  36. }
  37. Renderer& Renderer::translateX(float tx) {
  38. stack.peek().translateX(tx);
  39. return *this;
  40. }
  41. Renderer& Renderer::translateY(float ty) {
  42. stack.peek().translateY(ty);
  43. return *this;
  44. }
  45. Renderer& Renderer::translateZ(float tz) {
  46. stack.peek().translateZ(tz);
  47. return *this;
  48. }
  49. Renderer& Renderer::translateTo(float tx, float ty, float tz) {
  50. stack.peek().translateTo(Vector3(tx, ty, tz));
  51. return *this;
  52. }
  53. Renderer& Renderer::rotateX(float degrees) {
  54. stack.peek().rotateX(degrees);
  55. return *this;
  56. }
  57. Renderer& Renderer::rotateY(float degrees) {
  58. stack.peek().rotateY(degrees);
  59. return *this;
  60. }
  61. Renderer& Renderer::rotateZ(float degrees) {
  62. stack.peek().rotateZ(degrees);
  63. return *this;
  64. }