Skip to main content
GameDev.net gamedev.net
🔒 Locked

Aspect ratio for tall windows

Started by keym Apr 8, 2013 at 12:01 PM 3 replies 3k views
Original Post
keym
keym

Hello,

I'm having troubles with maintaining aspect ratio while my window is taller than wider. How do I readjust that in my perspective matrix? I calculate aspect ratio simply dividing width / height and it works great when window is wider than taller but the other way around my image is stretched. Any solutions to this? I make my perspective matrix using D3DXMatrixPerspectiveFovRH.

Jason Z
Jason Z

Are you certain that the width and height are being interpreted as floating point numbers before doing the division? If not, then try casting the values to float individually prior to the division. It could be that you are accidentally using integer division, which will give you step changes in situations like this.

Jason Zink :: DirectX MVP   Direct3D 11 engine on CodePlex: Hieroglyph 3 Direct3D Books: 
keym
keym

Yes, I was casting them to floats from the very beginning so that's not the issue. Thanks though.

Jason Z
Jason Z

There is no inherent limitation to a particular aspect ratio for the function you are using to calculate the perspective matrix. Can you post a screen shot of what you are seeing that looks incorrect? That might help clarify what is the issue.

Jason Zink :: DirectX MVP   Direct3D 11 engine on CodePlex: Hieroglyph 3 Direct3D Books: 
keym
keym

Ok, it seems that the problem was related to my part of code responsible for resizing texture that I use for drawing. When I fixed it, it now works as I want (clipping on sides when the window is taller than wider). I don't even have to alter aspect value and perspective matrix in any way. Funny how often you resolve problems after posting ><

Anyways, thanks for looking ya'll.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.