Rotating Y axis to flip Texture facing inverts X axis

390 views Asked by At

I want to rotate my sprites (applying the rotation to the transformation matrix) along the Y axis to flip the direction of the sprite.

But it somehow seems like it also affects my inputs system...
Pressing right becomes left... And it seems that the sprite is no longer rendered at the entity real position.. The "real position" is ruled by the inputs system and followed by the camera, but the sprite goes the opposite way, as if inputs were inverted. (inputs change the velocity corresponding to the key pressed and the transform component is translate by this vector each update)

Here's the code i use to get the matrices :

    public Matrix4f getTransformationMatrix() {
            Matrix4f matrix = new Matrix4f();
            matrix.scale(scale);
            matrix.rotateX((float) Math.toRadians(rotation.getX()));
            matrix.rotateY((float) Math.toRadians(rotation.getY()));
            matrix.rotateZ((float) Math.toRadians(rotation.getZ()));
            matrix.translate(position);
            return matrix;
        }
    
       
        public Matrix4f getViewMatrix() {
            Matrix4f matrix = new Matrix4f();
            matrix.rotateZ((float) Math.toRadians(rotation.getZ()));
            matrix.translate(Vector3f.scale(position, -1));
            return matrix;
        }

I have check and re-check my rotations matrix but affraid over confidence here they are :

X = new Matrix4f(new float[][] { {1, 0, 0, 0}, {0, cos, -sin, 0}, {0, sin, cos, 0}, {0, 0, 0, 1} })
Y = new Matrix4f(new float[][] { {cos, 0, sin, 0}, {0, 1, 0, 0}, {-sin, 0, cos, 0}, {0, 0, 0, 1} })
Z = new Matrix4f(new float[][] { {cos, sin, 0, 0}, {-sin, cos, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1} })

I use the mvp matrices in my shader in that order projection_matrix * view_matrix * transformation_matrix * vec4(attribute_position, 1.0).

0

There are 0 answers