OSG_BEGIN_NAMESPACE

OSG_BASE_DLLMAPPING bool MatrixOrthogonal(OSG::Matrix &result,
                                          OSG::Real32  rLeft,
                                          OSG::Real32  rRight,
                                          OSG::Real32  rBottom,
                                          OSG::Real32  rTop,
                                          OSG::Real32  rNear,
                                          OSG::Real32  rFar)
{
    result.setValueTransposed(

         2.f / (rRight - rLeft), 
         0.f, 
         0.f, 
         0.f,

         0.f, 
         2.f / (rTop - rBottom), 
         0.f, 
         0.f,

         0.f, 
         0.f, 
        -2.f / (rFar - rNear), 
         0.f,

        -(rRight + rLeft  ) / (rRight - rLeft  ),
        -(rTop   + rBottom) / (rTop   - rBottom),
        -(rFar   + rNear  ) / (rFar   - rNear  ), 
         1.);

    return false;
}
OSG_BASE_DLLMAPPING bool MatrixFrustum(OSG::Matrix &result,
                                       OSG::Real32  rLeft,
                                       OSG::Real32  rRight,
                                       OSG::Real32  rBottom,
                                       OSG::Real32  rTop,
                                       OSG::Real32  rNear,
                                       OSG::Real32  rFar)
{
    Real32 dz = rFar   - rNear;
    Real32 dx = rRight - rLeft;
    Real32 dy = rTop   - rBottom;
    Real32 n2 = 2.f    * rNear;

    result.setValueTransposed(
         n2 / dx, 
         0.f, 
         0.f, 
         0.f,

         0.f,
         n2 / dy, 
         0.f, 
         0.f,

         (rRight + rLeft  ) / dx,
         (rTop   + rBottom) / dy,
        -(rFar   + rNear  ) / dz, 
        -1.f,

         0.f, 
         0.f, 
        -(rFar * n2) / dz, 
         0.f);

    return false;
}