D3DXMatrixPerspectiveFovLH and fovy

Started by
2 comments, last by iedoc 8 years, 1 month ago

Hi

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:

[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;
}
Advertisement
Your results are correct.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

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:

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

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

This topic is closed to new replies.

Advertisement