Advertisement Jump to content
Sign in to follow this  

D3DXMatrixPerspectiveFovLH and fovy

This topic is 1045 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


I noticed that when fovy is 90 then the below issue is observed when I rotate camera around right camera vector.

   D3DXMatrixPerspectiveFovLH(&d3d::MatProj, D3DXToRadian(45), 1.6f, 0.1f, 1000);

The issue dissapear when I use fovy = 45. Could anybody check and comment that really my code for making rotation is OK and the issue is really connected with fovy=90? 


Before rotation:



After pitch rotation (rotation around right camera vector):


We see that post ends at the ground are narrowed down to inside whereas post ends at crossbarr are expanded to outside. This is distortion.


My code which recalculates view matrix after rotation about some angle is made.

void Camera::Pitch(float angle)
D3DXMatrixRotationAxis(&T, &right[curCamView], angle);
// rotate up and look around right vector
D3DXVec3TransformCoord(&up[curCamView],&up[curCamView], &T); //up=up*T i tak by up(x,y,z,w) w = 1 
D3DXVec3TransformCoord(&look[curCamView],&look[curCamView], &T);
void Camera::SetViewMatrix(CameraView cam)
if(cam >= MaxCams) return;
// Keep camera's axes orthogonal to each other:
D3DXVec3Normalize(&look[cam], &look[cam]);
D3DXVec3Cross(&up[cam], &look[cam], &right[cam]);
D3DXVec3Normalize(&up[cam], &up[cam]);
D3DXVec3Cross(&right[cam], &up[cam], &look[cam]);
D3DXVec3Normalize(&right[cam], &right[cam]);
// Build the view matrix:
float x = -D3DXVec3Dot(&right[cam], &pos[cam]);
float y = -D3DXVec3Dot(&up[cam], &pos[cam]);
float z = -D3DXVec3Dot(&look[cam], &pos[cam]);
MatView[cam](0, 0) = right[cam].x;
MatView[cam](0, 1) = up[cam].x;
MatView[cam](0, 2) = look[cam].x;
MatView[cam](0, 3) = 0.0f;
MatView[cam](1, 0) = right[cam].y;
MatView[cam](1, 1) = up[cam].y;
MatView[cam](1, 2) = look[cam].y;
MatView[cam](1, 3) = 0.0f;
MatView[cam](2, 0) = right[cam].z;
MatView[cam](2, 1) = up[cam].z;
MatView[cam](2, 2) = look[cam].z;
MatView[cam](2, 3) = 0.0f;
MatView[cam](3, 0) = x;
MatView[cam](3, 1) = y;
MatView[cam](3, 2) = z;
MatView[cam](3, 3) = 1.0f;
Edited by anders211

Share this post

Link to post
Share on other sites
Fovy is generally smaller than fovx, unless your monitor is in portrait mode.

You can set the fovy like this:

Fovy = fovx*(height/width)

You will see things get squished as they get further away if your fovy is too large (same if your fovx is too big, except things will get squished vertically instead)

I just realized your not creating your own projection mat, so what I said maybe doesn't really help. Ill leave it up though because it might still help you decide the fov and aspect ratio you want to pass to that function

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!