0
\$\begingroup\$

I am attempting to rotate the sprites in my game, but they get stretched whenever it happens. I know that it is due to the screen not being square, but I can not figure out the correct way to compensate for that.

enter image description here enter image description here

The left was taken from a non square screen, and the right is from a square screen. I need to scale it in a way that it will be normal again. The code that I am using to move and rotate the sprites is below:

glm::mat4 temp = glm::mat4(1.0f);
float angle = glm::radians(45.0f);
temp = glm::scale(temp, glm::vec3(xScale,yScale, zScale));
temp = glm::rotate(temp, angle, glm::vec3(0f, 0f, 0f));
temp = glm::translate(temp, glm::vec3(coor[0], coor[1], 0.0f));
trans = temp;

coor is just the new coordinate to move the sprite to. What is an equation that can get me the X,Y,and Z Scale? I have access to the screen aspect ratio, and I know it has something to do with it. I tried multiplying it by the screen ratio, but that didn't work. I multiplied them by the sin and cos of the angle, but that didn't work either. What is an equation that works?

\$\endgroup\$
3
  • \$\begingroup\$ What happens if you rotate before scaling? \$\endgroup\$
    – Pikalek
    Jul 15, 2021 at 4:13
  • \$\begingroup\$ @Pikalek The same stretching would happen. I would still need the x,y,and z scale \$\endgroup\$ Jul 15, 2021 at 14:16
  • \$\begingroup\$ I'm not suggest that you drop the scaling, I'm suggesting that you scale after rotating. Matrix multiplication is not commutative, which means the order of operations matters, as shown here for example. \$\endgroup\$
    – Pikalek
    Jul 15, 2021 at 15:11

0

You must log in to answer this question.

Browse other questions tagged .