|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.DirectX;
namespace MdxScene.Cameras
{
public class D3dPerspectiveOffCenterCamera : D3dPerspectiveCameraBase
{
public D3dPerspectiveOffCenterCamera()
{
Left = -0.5f;
Right = 0.5f;
Bottom = 0.5f;
Top = -0.5f;
}
#region D3dPerspectiveCameraBase implementation
public override Matrix GetProjectionMatrix()
{
return CameraCoordinateSystem.LeftHanded == CoordinateSystem
? Matrix.PerspectiveOffCenterLH(Left, Right, Bottom, Top, ZNearPlane, ZFarPlane)
: Matrix.PerspectiveOffCenterRH(Left, Right, Bottom, Top, ZNearPlane, ZFarPlane);
}
public override void Zoom(float scalingFactorX, float scalingFactorY)
{
float centerX = (Left + Right) / 2;
float centerY = (Bottom + Top) / 2;
float halfWidth = ((Right - Left) / 2) * scalingFactorX;
float halfHeight = ((Top - Bottom) / 2) * scalingFactorY;
Left = centerX - halfWidth;
Right = centerX + halfWidth;
Bottom = centerY - halfHeight;
Top = centerY + halfHeight;
}
public override void GetFov(out float fovX, out float fovY)
{
float width = Right - Left;
float height = Top - Bottom;
fovX = (float)Math.Atan(width / (2 * ZNearPlane)) * 2;
fovY = (float)Math.Atan(height / (2 * ZNearPlane)) * 2;
}
#endregion
#region properties
#region Left
private float _left;
public float Left
{
get { return _left; }
set
{
lock (this)
{
_left = value;
_isProjectionMatrixValid = false;
}
}
}
#endregion
#region Right
private float _right;
public float Right
{
get { return _right; }
set
{
lock (this)
{
_right = value;
_isProjectionMatrixValid = false;
}
}
}
#endregion
#region Bottom
private float _bottom;
public float Bottom
{
get { return _bottom; }
set
{
lock (this)
{
_bottom = value;
_isProjectionMatrixValid = false;
}
}
}
#endregion
#region Top
private float _top;
public float Top
{
get { return _top; }
set
{
lock (this)
{
_top = value;
_isProjectionMatrixValid = false;
}
}
}
#endregion
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.