## News:

LWJGL 3.3.2 released

Main Menu

## Aspect ratio problem

Started by Mihai_Ionut_Floares, December 01, 2020, 20:59:18

#### Mihai_Ionut_Floares

Hi. This should be a square, instea it is a rectangle:
https://streamable.com/nympw7

Isn't that why we are using projection matrices?

This is the perspective code. I copied it from c++ glm and adapt it to java. The code works, the camera movement feels good, the distances between object are normal, just it stretches objects sides.
My window is 1024:768 which is 4/3

I know that because the window is a rectangle it fits a square in it and that cause the stretch. I would prefer to render more of the scene instead of stretching the square.

#### KaiHH

Quote from: Mihai_Ionut_Floares on December 01, 2020, 20:59:18

The problem is that (float)(4/3) first performs an integer division, since both 4 and 3 are integers, whose result is 1, and then you cast that 1 to a float 1.0f. You should change this to (float) 4 / 3 in order to first cast the 4 to a float and then divide by 3 using a floating point division, since one of the operands is float.

#### Mihai_Ionut_Floares

I simply used 1.333f since 4/3=1,(3).

UPDATE: I casted the both 4 and 3 with f(4f/3f). It is working too.

Thank you.

#### Mihai_Ionut_Floares

Also, do you know why when I set the model matrix with a simple rotation, it rotates the object, but it scales it too?

#### KaiHH

Quote from: Mihai_Ionut_Floares on December 01, 2020, 22:36:20
Also, do you know why when I set the model matrix with a simple rotation, it rotates the object, but it scales it too?
Check if the three column vectors of the upper-left 3x3 submatrix of your 4x4 model matrix are unit vectors.

#### Mihai_Ionut_Floares

I don't know I build the matrices alreade transposed. The translation matrix should be:
1 0 0 X
0 1 0 Y
0 0 1 Z
0 0 0 1
(put in float[] each column)
Instead I built it like that
1 0 0 0
0 1 0 0
0 0 1 0
X Y Z 1

#### KaiHH

You asked about why your rotation matrix also contains a scaling. What you now showed is not a rotation matrix, only a translation matrix. So, what exactly is the problem?

#### Mihai_Ionut_Floares

cosÃŽÂ¸+Rx2(1Ã¢Ë†â€™cosÃŽÂ¸)                         Rx*Ry(1Ã¢Ë†â€™cosÃŽÂ¸)Ã¢Ë†â€™Rz*sinÃŽÂ¸        Rx*Rz(1Ã¢Ë†â€™cosÃŽÂ¸)+Ry*sinÃŽÂ¸   0
Ry*Rx(1Ã¢Ë†â€™cosÃŽÂ¸)+Rz*sinÃŽÂ¸         cosÃŽÂ¸+Ry2(1Ã¢Ë†â€™cosÃŽÂ¸)                Ry*Rz(1Ã¢Ë†â€™cosÃŽÂ¸)Ã¢Ë†â€™Rx*sinÃŽÂ¸   0
Rz*Rx(1Ã¢Ë†â€™cosÃŽÂ¸)Ã¢Ë†â€™Ry*sinÃŽÂ¸         Rz*Ry(1Ã¢Ë†â€™cosÃŽÂ¸)+Rx*sinÃŽÂ¸        cosÃŽÂ¸+Rz2(1Ã¢Ë†â€™cosÃŽÂ¸)           0
0                                                 0                                        0                                           1
(Where vec3(Rx, Ry, Rz) is the rotation axis and ÃŽÂ¸ is the angle)

With this it works now. Thanks