Changeset 660


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

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

Location:
trunk/src
Files:
2 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
  • trunk/src/matrix.h

    r652 r660  
    196196    Mat4<T> invert() const;
    197197
     198    static Mat4<T> ortho(T left, T right, T bottom, T top, T near, T far);
    198199    static Mat4<T> frustum(T left, T right, T bottom, T top, T near, T far);
    199200    static Mat4<T> perspective(T theta, T width, T height, T near, T far);
     201    static Mat4<T> translate(T x, T y, T z);
    200202
    201203    inline Mat4<T> operator +(Mat4<T> const val) const
Note: See TracChangeset for help on using the changeset viewer.