I am rendering bunch of cubes of unit size, but for some reason they look like they are squeezed a bit in the screen-space y axis. Why is this?

My projection matrix:

Projection = Matrix4.CreatePerspectiveFieldOfView (fovy, width / height, zNear, zFar);

My view matrix:

View = Matrix4.LookAt (position, position + Direction, up);

My Model matrix:

Matrix4 modelMatrix = Matrix4.CreateTranslation(new Vector3(chunkPos.X * 32, chunkPos.Y * 32, chunkPos.Z * 32));

Here's how I form the MVP matrix:

ViewProjection = View * Projection;
ModelViewProjection = Model * ViewProjection;

And finally the vertex shader:

gl_Position = mMVP * vertex;

Screenshots displaying the problem:

Squeezed Y-axis in screen-space Squeezed Y-axis in screen-space

I tried to fix the problem by adding a y-axis scale of 1.5 to my View matrix, and it seems it helped a bit with the problem. The result:

enter image description here

The question

I want to understand why I have to scale it this way. I thought the aspect ratio I give to the CreatePerspectiveFieldOfView would do this correction for me.


And literally 1min after I post the question I found out the answer. The problem was that on my projection matrix creation the width and height are integers, and thus the aspect ratio would be always 1. I changed the width and height to floats, and it started working.

| improve this answer | |
  • 1
    \$\begingroup\$ Glad you found your answer. Asking the question by itself usually leads to more clarity into the problem at hand. This story comes to mind. \$\endgroup\$ – Panda Pajama Apr 21 '14 at 7:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.