Example #1
0
////////////////////////////////////////////////////////////////////////////////
// Create Orthographic projection. From Guide to OpenGL ES 2.0
////////////////////////////////////////////////////////////////////////////////
Matrix44 Matrix44::CreateOrtho(float left, float right, float bottom, float top, float nearZ, float farZ)
{
	// Get bounds
    float       deltaX = right - left;
    float       deltaY = top - bottom;
    float       deltaZ = farZ - nearZ;
	//
    Matrix44    ortho;
	ortho.SetIndentity();
	
	// Check bad parameters
    if ( (deltaX == 0.0f) || (deltaY == 0.0f) || (deltaZ == 0.0f) )
        return ortho;
	
	// 
	ortho.SetIndentity();
    ortho.m[0][0] = 2.0f / deltaX;
    ortho.m[3][0] = -(right + left) / deltaX;
    ortho.m[1][1] = 2.0f / deltaY;
    ortho.m[3][1] = -(top + bottom) / deltaY;
    ortho.m[2][2] = -2.0f / deltaZ;
    ortho.m[3][2] = -(nearZ + farZ) / deltaZ;
	
    return ortho;
}
Example #2
0
////////////////////////////////////////////////////////////////////////////////
// Create a frustum projection. From Guide to OpenGL ES 2.0
////////////////////////////////////////////////////////////////////////////////
Matrix44 Matrix44::CreateFrustum(float left, float right, float bottom, float top, float nearZ, float farZ)
{
	float       deltaX = right - left;
    float       deltaY = top - bottom;
    float       deltaZ = farZ - nearZ;
	//
    Matrix44    frust;
	frust.SetIndentity();
	
    if ( (nearZ <= 0.0f) || (farZ <= 0.0f) ||
		(deltaX <= 0.0f) || (deltaY <= 0.0f) || (deltaZ <= 0.0f) )
		return frust;
	
    frust.m[0][0] = 2.0f * nearZ / deltaX;
    frust.m[0][1] = frust.m[0][2] = frust.m[0][3] = 0.0f;
	
    frust.m[1][1] = 2.0f * nearZ / deltaY;
    frust.m[1][0] = frust.m[1][2] = frust.m[1][3] = 0.0f;
	
    frust.m[2][0] = (right + left) / deltaX;
    frust.m[2][1] = (top + bottom) / deltaY;
    frust.m[2][2] = -(nearZ + farZ) / deltaZ;
    frust.m[2][3] = -1.0f;
	
    frust.m[3][2] = -2.0f * nearZ * farZ / deltaZ;
    frust.m[3][0] = frust.m[3][1] = frust.m[3][3] = 0.0f;
	
    return frust;
}