123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- #include "client/rendering/Renderer.h"
- Renderer::Renderer(Shader& shader, MatrixStack& stack, Matrix& view) : shader(shader), stack(stack), view(view) {
- }
- void Renderer::pop() {
- stack.pop();
- }
- void Renderer::push() {
- stack.push();
- }
- Renderer& Renderer::update() {
- shader.setMatrix("model", stack.get().getValues());
- return *this;
- }
- Renderer& Renderer::update(const Vector3& pos, const Quaternion& rotation) {
- Matrix m = rotation.toMatrix();
- Vector3 right = m * Vector3(1.0f, 0.0f, 0.0f);
- Vector3 up = m * Vector3(0.0f, 1.0f, 0.0f);
- Vector3 back = m * Vector3(0.0f, 0.0f, -1.0f);
- view.set(0, right[0]);
- view.set(1, up[0]);
- view.set(2, back[0]);
- view.set(4, right[1]);
- view.set(5, up[1]);
- view.set(6, back[1]);
- view.set(8, right[2]);
- view.set(9, up[2]);
- view.set(10, back[2]);
- view.set(12, right.dot(-pos));
- view.set(13, up.dot(-pos));
- view.set(14, back.dot(-pos));
-
- shader.setMatrix("view", view.getValues());
- return *this;
- }
- Renderer& Renderer::scale(float sx, float sy, float sz) {
- stack.get().scale(sx, sy, sz);
- return *this;
- }
- Renderer& Renderer::scale(float s) {
- stack.get().scale(s);
- return *this;
- }
- Renderer& Renderer::translate(float tx, float ty, float tz) {
- stack.get().translate(tx, ty, tz);
- return *this;
- }
- Renderer& Renderer::translateX(float tx) {
- stack.get().translateX(tx);
- return *this;
- }
- Renderer& Renderer::translateY(float ty) {
- stack.get().translateY(ty);
- return *this;
- }
- Renderer& Renderer::translateZ(float tz) {
- stack.get().translateZ(tz);
- return *this;
- }
- Renderer& Renderer::translateTo(float tx, float ty, float tz) {
- stack.get().translateTo(tx, ty, tz);
- return *this;
- }
- Renderer& Renderer::rotateX(float degrees) {
- stack.get().rotateX(degrees);
- return *this;
- }
- Renderer& Renderer::rotateY(float degrees) {
- stack.get().rotateY(degrees);
- return *this;
- }
- Renderer& Renderer::rotateZ(float degrees) {
- stack.get().rotateZ(degrees);
- return *this;
- }
|