Skip to content

Commit

Permalink
Rewrite float4x4::D3DPerspProjRH to coincide with D3DXMatrixPerspecti…
Browse files Browse the repository at this point in the history
…veFovRH ( http://msdn.microsoft.com/en-us/library/windows/desktop/bb205351(v=vs.85).aspx ). Added float4x4::OpenGLPerspProjRH function to achieve the same for OpenGL.
  • Loading branch information
juj committed Jun 18, 2012
1 parent 662b27c commit 8ff1eec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/Math/float4x4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,19 @@ float4x4 float4x4::D3DPerspProjRH(float n, float f, float h, float v)
float4x4 p;
p[0][0] = 2.f * n / h; p[0][1] = 0; p[0][2] = 0; p[0][3] = 0.f;
p[1][0] = 0; p[1][1] = 2.f * n / v; p[1][2] = 0; p[1][3] = 0.f;
p[2][0] = 0; p[2][1] = 0; p[2][2] = f / (f-n); p[2][3] = n * f / (f-n);
p[3][0] = 0; p[3][1] = 0; p[3][2] = 1.f; p[3][3] = 1.f;
p[2][0] = 0; p[2][1] = 0; p[2][2] = f / (n-f); p[2][3] = n * f / (n-f);
p[3][0] = 0; p[3][1] = 0; p[3][2] = -1.f; p[3][3] = 0.f;

return p;
}

float4x4 float4x4::OpenGLPerspProjRH(float n, float f, float h, float v)
{
float4x4 p;
p[0][0] = 2.f *n / h; p[0][1] = 0; p[0][2] = 0; p[0][3] = 0.f;
p[1][0] = 0; p[1][1] = 2.f * n / v; p[1][2] = 0; p[1][3] = 0.f;
p[2][0] = 0; p[2][1] = 0; p[2][2] = (n+f) / (n-f); p[2][3] = 2.f*n*f / (n-f);
p[3][0] = 0; p[3][1] = 0; p[3][2] = -1.f; p[3][3] = 1.f;

return p;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Math/float4x4.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ class float4x4
/// Creates a new float4x4 that performs orthographic projection. [indexTitle: OrthographicProjection/YZ/XZ/XY]
static float4x4 D3DOrthoProjRH(float nearPlaneDistance, float farPlaneDistance, float horizontalViewportSize, float verticalViewportSize);
static float4x4 D3DPerspProjRH(float nearPlaneDistance, float farPlaneDistance, float horizontalViewportSize, float verticalViewportSize);
static float4x4 OpenGLPerspProjRH(float n, float f, float h, float v);
static float4x4 OrthographicProjection(const Plane &target);
static float4x4 OrthographicProjectionYZ(); ///< [similarOverload: OrthographicProjection] [hideIndex]
static float4x4 OrthographicProjectionXZ(); ///< [similarOverload: OrthographicProjection] [hideIndex]
Expand Down Expand Up @@ -809,7 +810,7 @@ class float4x4
#endif

/// Extracts the rotation part of this matrix into Euler rotation angles (in radians). [indexTitle: ToEuler***]
/// @note It is better to thinkg about the returned float3 as an array of three floats, and
/// @note It is better to think about the returned float3 as an array of three floats, and
/// not as a triple of xyz, because e.g. the .y component returned by ToEulerYXZ() does
/// not return the amount of rotation about the y axis, but contains the amount of rotation
/// in the second axis, in this case the x axis.
Expand Down

0 comments on commit 8ff1eec

Please sign in to comment.