|
|
@@ -1466,77 +1466,6 @@ namespace CamelotEngine
|
|
|
}
|
|
|
}
|
|
|
//---------------------------------------------------------------------
|
|
|
- void D3D9RenderSystem::_makeProjectionMatrix(const Radian& fovy, float aspect, float nearPlane,
|
|
|
- float farPlane, Matrix4& dest, bool forGpuProgram)
|
|
|
- {
|
|
|
- Radian theta ( fovy * 0.5 );
|
|
|
- float h = 1 / Math::Tan(theta);
|
|
|
- float w = h / aspect;
|
|
|
- float q, qn;
|
|
|
- if (farPlane == 0)
|
|
|
- {
|
|
|
- q = 1 - Camera::INFINITE_FAR_PLANE_ADJUST;
|
|
|
- qn = nearPlane * (Camera::INFINITE_FAR_PLANE_ADJUST - 1);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- q = farPlane / ( farPlane - nearPlane );
|
|
|
- qn = -q * nearPlane;
|
|
|
- }
|
|
|
-
|
|
|
- dest = Matrix4::ZERO;
|
|
|
- dest[0][0] = w;
|
|
|
- dest[1][1] = h;
|
|
|
-
|
|
|
- if (forGpuProgram)
|
|
|
- {
|
|
|
- dest[2][2] = -q;
|
|
|
- dest[3][2] = -1.0f;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- dest[2][2] = q;
|
|
|
- dest[3][2] = 1.0f;
|
|
|
- }
|
|
|
-
|
|
|
- dest[2][3] = qn;
|
|
|
- }
|
|
|
- //---------------------------------------------------------------------
|
|
|
- void D3D9RenderSystem::_makeOrthoMatrix(const Radian& fovy, float aspect, float nearPlane, float farPlane,
|
|
|
- Matrix4& dest, bool forGpuProgram )
|
|
|
- {
|
|
|
- Radian thetaY (fovy / 2.0f);
|
|
|
- float tanThetaY = Math::Tan(thetaY);
|
|
|
-
|
|
|
- //float thetaX = thetaY * aspect;
|
|
|
- float tanThetaX = tanThetaY * aspect; //Math::Tan(thetaX);
|
|
|
- float half_w = tanThetaX * nearPlane;
|
|
|
- float half_h = tanThetaY * nearPlane;
|
|
|
- float iw = static_cast<float>(1.0 / half_w);
|
|
|
- float ih = static_cast<float>(1.0 / half_h);
|
|
|
- float q;
|
|
|
- if (farPlane == 0)
|
|
|
- {
|
|
|
- q = 0;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- q = static_cast<float>(1.0 / (farPlane - nearPlane));
|
|
|
- }
|
|
|
-
|
|
|
- dest = Matrix4::ZERO;
|
|
|
- dest[0][0] = iw;
|
|
|
- dest[1][1] = ih;
|
|
|
- dest[2][2] = q;
|
|
|
- dest[2][3] = -nearPlane / (farPlane - nearPlane);
|
|
|
- dest[3][3] = 1;
|
|
|
-
|
|
|
- if (forGpuProgram)
|
|
|
- {
|
|
|
- dest[2][2] = -dest[2][2];
|
|
|
- }
|
|
|
- }
|
|
|
- //---------------------------------------------------------------------
|
|
|
void D3D9RenderSystem::_setViewMatrix( const Matrix4 &m )
|
|
|
{
|
|
|
// save latest view matrix
|
|
|
@@ -2553,12 +2482,6 @@ namespace CamelotEngine
|
|
|
|
|
|
}
|
|
|
//---------------------------------------------------------------------
|
|
|
- void D3D9RenderSystem::setNormaliseNormals(bool normalise)
|
|
|
- {
|
|
|
- __SetRenderState(D3DRS_NORMALIZENORMALS,
|
|
|
- normalise ? TRUE : FALSE);
|
|
|
- }
|
|
|
- //---------------------------------------------------------------------
|
|
|
void D3D9RenderSystem::bindGpuProgram(GpuProgram* prg)
|
|
|
{
|
|
|
HRESULT hr;
|
|
|
@@ -2858,54 +2781,6 @@ namespace CamelotEngine
|
|
|
CM_EXCEPT(RenderingAPIException, "Error clearing frame buffer : " + msg);
|
|
|
}
|
|
|
}
|
|
|
- //---------------------------------------------------------------------
|
|
|
- void D3D9RenderSystem::_makeProjectionMatrix(float left, float right,
|
|
|
- float bottom, float top, float nearPlane, float farPlane, Matrix4& dest,
|
|
|
- bool forGpuProgram)
|
|
|
- {
|
|
|
- // Correct position for off-axis projection matrix
|
|
|
- if (!forGpuProgram)
|
|
|
- {
|
|
|
- float offsetX = left + right;
|
|
|
- float offsetY = top + bottom;
|
|
|
-
|
|
|
- left -= offsetX;
|
|
|
- right -= offsetX;
|
|
|
- top -= offsetY;
|
|
|
- bottom -= offsetY;
|
|
|
- }
|
|
|
-
|
|
|
- float width = right - left;
|
|
|
- float height = top - bottom;
|
|
|
- float q, qn;
|
|
|
- if (farPlane == 0)
|
|
|
- {
|
|
|
- q = 1 - Camera::INFINITE_FAR_PLANE_ADJUST;
|
|
|
- qn = nearPlane * (Camera::INFINITE_FAR_PLANE_ADJUST - 1);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- q = farPlane / ( farPlane - nearPlane );
|
|
|
- qn = -q * nearPlane;
|
|
|
- }
|
|
|
- dest = Matrix4::ZERO;
|
|
|
- dest[0][0] = 2 * nearPlane / width;
|
|
|
- dest[0][2] = (right+left) / width;
|
|
|
- dest[1][1] = 2 * nearPlane / height;
|
|
|
- dest[1][2] = (top+bottom) / height;
|
|
|
- if (forGpuProgram)
|
|
|
- {
|
|
|
- dest[2][2] = -q;
|
|
|
- dest[3][2] = -1.0f;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- dest[2][2] = q;
|
|
|
- dest[3][2] = 1.0f;
|
|
|
- }
|
|
|
- dest[2][3] = qn;
|
|
|
- }
|
|
|
-
|
|
|
// ------------------------------------------------------------------
|
|
|
void D3D9RenderSystem::setClipPlane (UINT16 index, float A, float B, float C, float D)
|
|
|
{
|
|
|
@@ -2941,53 +2816,6 @@ namespace CamelotEngine
|
|
|
return -0.5f;
|
|
|
}
|
|
|
//---------------------------------------------------------------------
|
|
|
- void D3D9RenderSystem::_applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane,
|
|
|
- bool forGpuProgram)
|
|
|
- {
|
|
|
- // Thanks to Eric Lenyel for posting this calculation at www.terathon.com
|
|
|
-
|
|
|
- // Calculate the clip-space corner point opposite the clipping plane
|
|
|
- // as (sgn(clipPlane.x), sgn(clipPlane.y), 1, 1) and
|
|
|
- // transform it into camera space by multiplying it
|
|
|
- // by the inverse of the projection matrix
|
|
|
-
|
|
|
- /* generalised version
|
|
|
- Vector4 q = matrix.inverse() *
|
|
|
- Vector4(Math::Sign(plane.normal.x), Math::Sign(plane.normal.y), 1.0f, 1.0f);
|
|
|
- */
|
|
|
- Vector4 q;
|
|
|
- q.x = Math::Sign(plane.normal.x) / matrix[0][0];
|
|
|
- q.y = Math::Sign(plane.normal.y) / matrix[1][1];
|
|
|
- q.z = 1.0F;
|
|
|
- // flip the next bit from Lengyel since we're right-handed
|
|
|
- if (forGpuProgram)
|
|
|
- {
|
|
|
- q.w = (1.0F - matrix[2][2]) / matrix[2][3];
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- q.w = (1.0F + matrix[2][2]) / matrix[2][3];
|
|
|
- }
|
|
|
-
|
|
|
- // Calculate the scaled plane vector
|
|
|
- Vector4 clipPlane4d(plane.normal.x, plane.normal.y, plane.normal.z, plane.d);
|
|
|
- Vector4 c = clipPlane4d * (1.0F / (clipPlane4d.dotProduct(q)));
|
|
|
-
|
|
|
- // Replace the third row of the projection matrix
|
|
|
- matrix[2][0] = c.x;
|
|
|
- matrix[2][1] = c.y;
|
|
|
- // flip the next bit from Lengyel since we're right-handed
|
|
|
- if (forGpuProgram)
|
|
|
- {
|
|
|
- matrix[2][2] = c.z;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- matrix[2][2] = -c.z;
|
|
|
- }
|
|
|
- matrix[2][3] = c.w;
|
|
|
- }
|
|
|
- //---------------------------------------------------------------------
|
|
|
float D3D9RenderSystem::getMinimumDepthInputValue()
|
|
|
{
|
|
|
// Range [0.0f, 1.0f]
|