Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 5 down vote accepted

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.

share|improve this answer
1  
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. –  Panda Pajama Apr 21 at 7:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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