# D3DXMatrixPerspectiveFovLH and fovy

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

## Recommended Posts

Hi

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

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:

[attachment=31076:before.JPG]

After pitch rotation (rotation around right camera vector):

[attachment=31077:afterPitchRotation.JPG]

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)
{
D3DXMATRIX T;
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

L. Spiro

##### Share on other sites

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.

No, it's not distortion.  It's absolutely standard perspective; please see: https://en.wikipedia.org/wiki/Perspective_%28visual%29 and https://commons.wikimedia.org/wiki/File:Perspective-foreshortening.svg

Also:

##### 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

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 14
• 30
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631782
• Total Posts
3002324
×