mirror of
https://github.com/minetest/irrlicht.git
synced 2025-07-01 07:40:26 +02:00
Add lens shift support for the camera and the perspective projection functions
As Blender docs describe it so nicely: Using lens shift is equivalent to rendering an image with a larger FOV and cropping it off-center. This can be quite useful for architecture renderings, but I guess also has it's use in other situations. Note: Didn't make the ICameraSceneNode functions pure virtual so users don't have to update their cameras for this Also some change in serialization - same as in other places by now, do use existing values as defaults values when they are not found instead of resetting them to 0. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6565 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
@ -120,6 +120,13 @@ namespace scene
|
||||
/** \return The field of view of the camera in radians. */
|
||||
virtual f32 getFOV() const =0;
|
||||
|
||||
//! Get the horizontal and vertical lens/projection plane shift
|
||||
/** \return Project plane offset */
|
||||
virtual core::vector2df getLensShift() const
|
||||
{
|
||||
return core::vector2df(0.f, 0.f);
|
||||
}
|
||||
|
||||
//! Sets the value of the near clipping plane. (default: 1.0f)
|
||||
/** Also changes projection matrix and resets IsOrthogonal flag.
|
||||
\param zn: New z near value. */
|
||||
@ -140,6 +147,16 @@ namespace scene
|
||||
\param fovy: New field of view in radians. */
|
||||
virtual void setFOV(f32 fovy) =0;
|
||||
|
||||
//! Set the horizontal and vertical lens/projection plane shift
|
||||
/** Like rendering a larger field of view and then cropping
|
||||
it off-center. Allows for things like 2-point perspective.
|
||||
\param shift: Offset by which the projection plane is moved.
|
||||
If you move by 1 or -1 it will move the center by half a screen.
|
||||
Positive X go to the left and positive Y go down.
|
||||
By default it will be 0,0 */
|
||||
virtual void setLensShift(const core::vector2df& shift)
|
||||
{}
|
||||
|
||||
//! Get the view frustum.
|
||||
/** \return The current view frustum. */
|
||||
virtual const SViewFrustum* getViewFrustum() const =0;
|
||||
|
@ -311,26 +311,28 @@ namespace core
|
||||
\param zNear: Distance to near plane
|
||||
\param zFar: Distance to far plane
|
||||
param zClipFromZero: Clipping of z can be projected from 0 to w when true (D3D style) and from -w to w when false (OGL style)
|
||||
\param zSign: 1 for left-handed projection matrix, -1 for right-handed projection matrix */
|
||||
CMatrix4<T>& buildProjectionMatrixPerspectiveFov(T sx, T sy, T zNear, T zFar, bool zClipFromZero, T zSign);
|
||||
\param zSign: 1 for left-handed projection matrix, -1 for right-handed projection matrix
|
||||
\param shiftX: Shift projection plane of camera left/right
|
||||
\param shiftY: Shift projection plane of camera up/down */
|
||||
CMatrix4<T>& buildProjectionMatrixPerspectiveFov(T sx, T sy, T zNear, T zFar, bool zClipFromZero, T zSign, T shiftX, T shiftY);
|
||||
|
||||
//! Builds a right-handed perspective projection matrix based on a field of view
|
||||
//\param zClipFromZero: Clipping of z can be projected from 0 to w when true (D3D style) and from -w to w when false (OGL style).
|
||||
CMatrix4<T>& buildProjectionMatrixPerspectiveFovRH(f32 fieldOfViewRadiansY, f32 aspectRatio, f32 zNear, f32 zFar, bool zClipFromZero=true);
|
||||
CMatrix4<T>& buildProjectionMatrixPerspectiveFovRH(f32 fieldOfViewRadiansY, f32 aspectRatio, f32 zNear, f32 zFar, bool zClipFromZero=true, f32 shiftX=0.f, f32 shiftY=0.f);
|
||||
|
||||
//! Builds a left-handed perspective projection matrix based on a field of view
|
||||
CMatrix4<T>& buildProjectionMatrixPerspectiveFovLH(f32 fieldOfViewRadiansY, f32 aspectRatio, f32 zNear, f32 zFar, bool zClipFromZero=true);
|
||||
CMatrix4<T>& buildProjectionMatrixPerspectiveFovLH(f32 fieldOfViewRadiansY, f32 aspectRatio, f32 zNear, f32 zFar, bool zClipFromZero=true, f32 shiftX=0.f, f32 shiftY=0.f);
|
||||
|
||||
//! Builds a left-handed perspective projection matrix based on a field of view, with far plane at infinity
|
||||
CMatrix4<T>& buildProjectionMatrixPerspectiveFovInfinityLH(f32 fieldOfViewRadiansY, f32 aspectRatio, f32 zNear, f32 epsilon=0);
|
||||
|
||||
//! Builds a right-handed perspective projection matrix.
|
||||
CMatrix4<T>& buildProjectionMatrixPerspectiveRH(f32 widthOfViewVolume, f32 heightOfViewVolume, f32 zNear, f32 zFar, bool zClipFromZero=true);
|
||||
CMatrix4<T>& buildProjectionMatrixPerspectiveRH(f32 widthOfViewVolume, f32 heightOfViewVolume, f32 zNear, f32 zFar, bool zClipFromZero=true, f32 shiftX=0.f, f32 shiftY=0.f);
|
||||
|
||||
//! Builds a left-handed perspective projection matrix.
|
||||
//\param widthOfViewVolume: width of clipped near frustum plane
|
||||
//\param heightOfViewVolume: height of clipped near frustum plane
|
||||
CMatrix4<T>& buildProjectionMatrixPerspectiveLH(f32 widthOfViewVolume, f32 heightOfViewVolume, f32 zNear, f32 zFar, bool zClipFromZero=true);
|
||||
CMatrix4<T>& buildProjectionMatrixPerspectiveLH(f32 widthOfViewVolume, f32 heightOfViewVolume, f32 zNear, f32 zFar, bool zClipFromZero=true, f32 shiftX=0.f, f32 shiftY=0.f);
|
||||
|
||||
//! Builds a left-handed orthogonal projection matrix.
|
||||
//\param zClipFromZero: Clipping of z can be projected from 0 to 1 when true (D3D style) and from -1 to 1 when false (OGL style).
|
||||
@ -1583,7 +1585,7 @@ namespace core
|
||||
|
||||
// Builds a perspective projection matrix
|
||||
template <class T>
|
||||
inline CMatrix4<T>& CMatrix4<T>::buildProjectionMatrixPerspectiveFov(T sx, T sy, T zNear, T zFar, bool zClipFromZero, T zSign)
|
||||
inline CMatrix4<T>& CMatrix4<T>::buildProjectionMatrixPerspectiveFov(T sx, T sy, T zNear, T zFar, bool zClipFromZero, T zSign, T shiftX, T shiftY)
|
||||
{
|
||||
IRR_DEBUG_BREAK_IF(zNear==zFar); //divide by zero
|
||||
M[0] = sx;
|
||||
@ -1596,8 +1598,8 @@ namespace core
|
||||
M[6] = 0;
|
||||
M[7] = 0;
|
||||
|
||||
M[8] = 0;
|
||||
M[9] = 0;
|
||||
M[8] = shiftX;
|
||||
M[9] = shiftY;
|
||||
//M[10] below
|
||||
M[11] = zSign;
|
||||
|
||||
@ -1626,23 +1628,23 @@ namespace core
|
||||
// Builds a right-handed perspective projection matrix based on a field of view
|
||||
template <class T>
|
||||
inline CMatrix4<T>& CMatrix4<T>::buildProjectionMatrixPerspectiveFovRH(
|
||||
f32 fieldOfViewRadians, f32 aspectRatio, f32 zNear, f32 zFar, bool zClipFromZero)
|
||||
f32 fieldOfViewRadians, f32 aspectRatio, f32 zNear, f32 zFar, bool zClipFromZero, f32 shiftX, f32 shiftY)
|
||||
{
|
||||
const f64 sy = reciprocal(tan(fieldOfViewRadians*0.5));
|
||||
IRR_DEBUG_BREAK_IF(aspectRatio==0.f); //divide by zero
|
||||
const T sx = static_cast<T>(sy / aspectRatio);
|
||||
return buildProjectionMatrixPerspectiveFov(sx, static_cast<T>(sy), zNear, zFar, zClipFromZero, (T)-1);
|
||||
return buildProjectionMatrixPerspectiveFov(sx, static_cast<T>(sy), zNear, zFar, zClipFromZero, (T)-1, shiftX, shiftY);
|
||||
}
|
||||
|
||||
// Builds a left-handed perspective projection matrix based on a field of view
|
||||
template <class T>
|
||||
inline CMatrix4<T>& CMatrix4<T>::buildProjectionMatrixPerspectiveFovLH(
|
||||
f32 fieldOfViewRadians, f32 aspectRatio, f32 zNear, f32 zFar, bool zClipFromZero)
|
||||
f32 fieldOfViewRadians, f32 aspectRatio, f32 zNear, f32 zFar, bool zClipFromZero, f32 shiftX, f32 shiftY)
|
||||
{
|
||||
const f64 sy = reciprocal(tan(fieldOfViewRadians*0.5));
|
||||
IRR_DEBUG_BREAK_IF(aspectRatio==0.f); //divide by zero
|
||||
const T sx = static_cast<T>(sy / aspectRatio);
|
||||
return buildProjectionMatrixPerspectiveFov(sx, static_cast<T>(sy), zNear, zFar, zClipFromZero, (T)1);
|
||||
return buildProjectionMatrixPerspectiveFov(sx, static_cast<T>(sy), zNear, zFar, zClipFromZero, (T)1, shiftX, shiftY);
|
||||
}
|
||||
|
||||
// Builds a left-handed perspective projection matrix based on a field of view, with far plane culling at infinity
|
||||
@ -1775,26 +1777,26 @@ namespace core
|
||||
// Builds a right-handed perspective projection matrix.
|
||||
template <class T>
|
||||
inline CMatrix4<T>& CMatrix4<T>::buildProjectionMatrixPerspectiveRH(
|
||||
f32 widthOfViewVolume, f32 heightOfViewVolume, f32 zNear, f32 zFar, bool zClipFromZero)
|
||||
f32 widthOfViewVolume, f32 heightOfViewVolume, f32 zNear, f32 zFar, bool zClipFromZero, f32 shiftX, f32 shiftY)
|
||||
{
|
||||
IRR_DEBUG_BREAK_IF(widthOfViewVolume==0.f); //divide by zero
|
||||
IRR_DEBUG_BREAK_IF(heightOfViewVolume==0.f); //divide by zero
|
||||
const T sx = (T)(2*zNear/widthOfViewVolume);
|
||||
const T sy = (T)(2*zNear/heightOfViewVolume);
|
||||
return buildProjectionMatrixPerspectiveFov(sx, sy, zNear, zFar, zClipFromZero, (T)-1);
|
||||
return buildProjectionMatrixPerspectiveFov(sx, sy, zNear, zFar, zClipFromZero, (T)-1, shiftX, shiftY);
|
||||
}
|
||||
|
||||
// Builds a left-handed perspective projection matrix.
|
||||
template <class T>
|
||||
inline CMatrix4<T>& CMatrix4<T>::buildProjectionMatrixPerspectiveLH(
|
||||
f32 widthOfViewVolume, f32 heightOfViewVolume, f32 zNear, f32 zFar, bool zClipFromZero)
|
||||
f32 widthOfViewVolume, f32 heightOfViewVolume, f32 zNear, f32 zFar, bool zClipFromZero, f32 shiftX, f32 shiftY)
|
||||
{
|
||||
IRR_DEBUG_BREAK_IF(widthOfViewVolume==0.f); //divide by zero
|
||||
IRR_DEBUG_BREAK_IF(heightOfViewVolume==0.f); //divide by zero
|
||||
const T sx = (T)(2*zNear/widthOfViewVolume);
|
||||
const T sy = (T)(2*zNear/heightOfViewVolume);
|
||||
|
||||
return buildProjectionMatrixPerspectiveFov(sx, sy, zNear, zFar, zClipFromZero, (T)1);
|
||||
return buildProjectionMatrixPerspectiveFov(sx, sy, zNear, zFar, zClipFromZero, (T)1, shiftX, shiftY);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user