123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- #include "client/rendering/Renderer.h"
- Renderer::Renderer(Shader& shader, MatrixStack<16>& 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.peek().getValues());
- return *this;
- }
- Renderer& Renderer::update(const Vector3& pos, const Quaternion& rotation) {
- Vector3 right = rotation * Vector3(1.0f, 0.0f, 0.0f);
- Vector3 up = rotation * Vector3(0.0f, 1.0f, 0.0f);
- Vector3 back = rotation * Vector3(0.0f, 0.0f, -1.0f);
- view.set(0, Vector4(right[0], right[1], right[2], right.dot(-pos)));
- view.set(1, Vector4(up[0], up[1], up[2], up.dot(-pos)));
- view.set(2, Vector4(back[0], back[1], back[2], back.dot(-pos)));
- view.set(3, Vector4(0.0f, 0.0f, 0.0f, 1.0f));
-
- shader.setMatrix("view", view.getValues());
- return *this;
- }
- Renderer& Renderer::scale(float sx, float sy, float sz) {
- stack.peek().scale(Vector3(sx, sy, sz));
- return *this;
- }
- Renderer& Renderer::scale(float s) {
- stack.peek().scale(s);
- return *this;
- }
- Renderer& Renderer::translate(float tx, float ty, float tz) {
- stack.peek().translate(Vector3(tx, ty, tz));
- return *this;
- }
- Renderer& Renderer::translateX(float tx) {
- stack.peek().translateX(tx);
- return *this;
- }
- Renderer& Renderer::translateY(float ty) {
- stack.peek().translateY(ty);
- return *this;
- }
- Renderer& Renderer::translateZ(float tz) {
- stack.peek().translateZ(tz);
- return *this;
- }
- Renderer& Renderer::translateTo(float tx, float ty, float tz) {
- stack.peek().translateTo(Vector3(tx, ty, tz));
- return *this;
- }
- Renderer& Renderer::rotateX(float degrees) {
- stack.peek().rotateX(degrees);
- return *this;
- }
- Renderer& Renderer::rotateY(float degrees) {
- stack.peek().rotateY(degrees);
- return *this;
- }
- Renderer& Renderer::rotateZ(float degrees) {
- stack.peek().rotateZ(degrees);
- return *this;
- }
|