When I draw a quad that is rotating the aspect ratio of the quad gets messed up and the size changes.
I am confident it has something to do with the way I calculate the size because that is relative to the width and height of the screen, I just don't know why the aspect ratio would change since the aspect ratio of the screen doesn't change.
Code of transformationMatrix creation:
Matrix4f matrix = Maths.createTransformationMatrix(
new Vector2f(
gui.getPosition().getX() / Display.getWidth() * 2 - 1 + gui.getSize().getX() / Display.getWidth(),
-gui.getPosition().getY() / Display.getHeight() * 2 + 1 - gui.getSize().getY() / Display.getHeight()
), gui.getRotation()
,new Vector2f(
gui.getSize().getX() / Display.getWidth(),
gui.getSize().getY() / Display.getHeight()
)
);
shader.loadTransformation(matrix);
The x size, y size, x position and y position are in pixels, if you put in 1600 pixels for x position and the screen is 1600 pixels wide it will fill the whole screen. The calculation that is done here will translate those sizes to a value that the shaders will display on the screen.
I had tried calculating the sizes in a different way:
gui.getSize().getX() / (float) (Display.getWidth() * Math.abs(Math.cos((Math.toRadians(gui.getRotation())))) + Display.getHeight() * Math.abs(Math.sin((Math.toRadians(gui.getRotation()))))),
but this does not work at all, my thought process was that if it is sideways it should use Display.getHeight to calculate the x size and if it is vertical it should use Display.getWidth. This does work for 0, 90, 180 and 270 degrees rotation, but in between it gets smaller and weird. Of course I've also done this for the x position but then cos and sin switched around.
And this is the createTransformationMatrix method:
public static Matrix4f createTransformationMatrix(Vector2f translation, float rotation, Vector2f scale) {
Matrix4f matrix = new Matrix4f();
matrix.setIdentity();
Matrix4f.translate(translation, matrix, matrix);
Matrix4f.rotate((float) Math.toRadians(rotation), new Vector3f(0, 0, 1), matrix, matrix);
Matrix4f.scale(new Vector3f(scale.x, scale.y, 1f), matrix, matrix);
return matrix;
}
gui.getSize
andDisplay.GetWidth
should probably not appear together in one argument like that. \$\endgroup\$ – DMGregory♦ Jan 18 '16 at 23:56