1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- #include "client/rendering/ShaderMatrix.h"
- ShaderMatrix::ShaderMatrix(Shader* shader, MatrixStack<16>& stack, Matrix* view)
- : shader(shader), stack(stack), view(view) {
- }
- ShaderMatrix& ShaderMatrix::operator=(ShaderMatrix&& other) {
- shader = other.shader;
- stack = other.stack;
- view = other.view;
- return *this;
- }
- void ShaderMatrix::pop() {
- stack.pop();
- }
- void ShaderMatrix::push() {
- stack.push();
- }
- ShaderMatrix& ShaderMatrix::update() {
- shader->setMatrix("model", stack.peek().getValues());
- return *this;
- }
- ShaderMatrix& ShaderMatrix::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;
- }
- ShaderMatrix& ShaderMatrix::scale(float sx, float sy, float sz) {
- stack.peek().scale(Vector3(sx, sy, sz));
- return *this;
- }
- ShaderMatrix& ShaderMatrix::scale(float s) {
- stack.peek().scale(s);
- return *this;
- }
- ShaderMatrix& ShaderMatrix::translate(float tx, float ty, float tz) {
- stack.peek().translate(Vector3(tx, ty, tz));
- return *this;
- }
- ShaderMatrix& ShaderMatrix::translateX(float tx) {
- stack.peek().translateX(tx);
- return *this;
- }
- ShaderMatrix& ShaderMatrix::translateY(float ty) {
- stack.peek().translateY(ty);
- return *this;
- }
- ShaderMatrix& ShaderMatrix::translateZ(float tz) {
- stack.peek().translateZ(tz);
- return *this;
- }
- ShaderMatrix& ShaderMatrix::translateTo(float tx, float ty, float tz) {
- stack.peek().translateTo(Vector3(tx, ty, tz));
- return *this;
- }
- ShaderMatrix& ShaderMatrix::rotateX(float degrees) {
- stack.peek().rotateX(degrees);
- return *this;
- }
- ShaderMatrix& ShaderMatrix::rotateY(float degrees) {
- stack.peek().rotateY(degrees);
- return *this;
- }
- ShaderMatrix& ShaderMatrix::rotateZ(float degrees) {
- stack.peek().rotateZ(degrees);
- return *this;
- }
- ShaderMatrix& ShaderMatrix::identity() {
- stack.peek().translateTo(Vector3());
- return *this;
- }
|