Ignore:
Timestamp:
Feb 18, 2011, 1:09:15 AM (10 years ago)
Author:
sam
Message:

Implement float4x4::ortho() and float4x4::translate().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/matrix.cpp

    r655 r660  
    6363}
    6464
     65template<> float4x4 float4x4::ortho(float left, float right, float bottom,
     66                                    float top, float near, float far)
     67{
     68    float invrl = (right != left) ? 1.0f / (right - left) : 0.0f;
     69    float invtb = (top != bottom) ? 1.0f / (top - bottom) : 0.0f;
     70    float invfn = (far != near) ? 1.0f / (far - near) : 0.0f;
     71
     72    float4x4 ret(0.0f);
     73    ret[0][0] = 2.0f * invrl;
     74    ret[1][1] = 2.0f * invtb;
     75    ret[2][2] = -2.0f * invfn;
     76    ret[3][0] = - (right + left) * invrl;
     77    ret[3][1] = - (top + bottom) * invtb;
     78    ret[3][2] = - (far + near) * invfn;
     79    ret[3][3] = 1.0f;
     80    return ret;
     81}
     82
    6583template<> float4x4 float4x4::frustum(float left, float right, float bottom,
    6684                                      float top, float near, float far)
     
    90108}
    91109
     110template<> float4x4 float4x4::translate(float x, float y, float z)
     111{
     112    float4x4 ret(1.0f);
     113    ret[3][0] = x;
     114    ret[3][1] = y;
     115    ret[3][2] = z;
     116    return ret;
     117}
     118
Note: See TracChangeset for help on using the changeset viewer.