Changeset 663


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

Implement +=, -= and *= for matrices and vectors.
Add new types, closer to the GLSL ones.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/matrix.h

    r661 r663  
    2727            ret[n] = (*this)[n] op val[n]; \
    2828        return ret; \
     29    } \
     30    \
     31    template<typename U> \
     32    inline Vec##elems<T> operator op##=(Vec##elems<U> const &val) \
     33    { \
     34        return *this = (*this) op val; \
    2935    }
    3036
     
    4551            ret[n] = (*this)[n] op val; \
    4652        return ret; \
     53    } \
     54    \
     55    inline Vec##elems<T> operator op##=(T const &val) \
     56    { \
     57        return *this = (*this) op val; \
    4758    }
    4859
     
    115126};
    116127
    117 typedef Vec2<float> float2;
    118 typedef Vec2<int> int2;
     128typedef Vec2<float> vec2;
     129typedef Vec2<int> vec2i;
    119130
    120131template <typename T> struct Vec3
     
    131142};
    132143
    133 typedef Vec3<float> float3;
    134 typedef Vec3<int> int3;
     144typedef Vec3<float> vec3;
     145typedef Vec3<int> vec3i;
    135146
    136147template <typename T> struct Vec4
     
    148159};
    149160
    150 typedef Vec4<float> float4;
    151 typedef Vec4<int> int4;
     161typedef Vec4<float> vec4;
     162typedef Vec4<int> vec4i;
    152163
    153164#define SCALAR_GLOBAL(elems, op, U) \
     
    211222    }
    212223
     224    inline Mat4<T> operator +=(Mat4<T> const val)
     225    {
     226        return *this = *this + val;
     227    }
     228
    213229    inline Mat4<T> operator -(Mat4<T> const val) const
    214230    {
     
    218234                ret[i][j] = v[i][j] - val[i][j];
    219235        return ret;
     236    }
     237
     238    inline Mat4<T> operator -=(Mat4<T> const val)
     239    {
     240        return *this = *this - val;
    220241    }
    221242
     
    234255    }
    235256
     257    inline Mat4<T> operator *=(Mat4<T> const val)
     258    {
     259        return *this = *this * val;
     260    }
     261
    236262    inline Vec4<T> operator *(Vec4<T> const val) const
    237263    {
     
    250276};
    251277
     278typedef Mat4<float> mat4;
     279typedef Mat4<int> mat4i;
     280
     281/* Aliases for deprecated stuff */
     282typedef Vec2<float> float2;
     283typedef Vec2<int> int2;
     284typedef Vec3<float> float3;
     285typedef Vec3<int> int3;
     286typedef Vec4<float> float4;
     287typedef Vec4<int> int4;
    252288typedef Mat4<float> float4x4;
    253289typedef Mat4<int> int4x4;
  • trunk/src/scene.cpp

    r662 r663  
    138138    // XXX: debug stuff
    139139    model_matrix = float4x4::translate(320.0f, 240.0f, 0.0f);
    140     model_matrix = model_matrix * float4x4::rotate(-data->angle, 1.0f, 0.0f, 0.0f);
     140    model_matrix *= float4x4::rotate(-data->angle, 1.0f, 0.0f, 0.0f);
    141141#if 0
    142142    static float f = 0.0f;
    143143    f += 0.01f;
    144     model_matrix = model_matrix * float4x4::rotate(0.1f * sinf(f), 1.0f, 0.0f, 0.0f);
    145     model_matrix = model_matrix * float4x4::rotate(0.3f * cosf(f), 0.0f, 0.0f, 1.0f);
    146 #endif
    147     model_matrix = model_matrix * float4x4::translate(-320.0f, -240.0f, 0.0f);
     144    model_matrix *= float4x4::rotate(0.1f * sinf(f), 1.0f, 0.0f, 0.0f);
     145    model_matrix *= float4x4::rotate(0.3f * cosf(f), 0.0f, 0.0f, 1.0f);
     146#endif
     147    model_matrix *= float4x4::translate(-320.0f, -240.0f, 0.0f);
    148148    // XXX: end of debug stuff
    149149
Note: See TracChangeset for help on using the changeset viewer.