Browse Source

Implement +=, -= and *= for matrices and vectors.

Add new types, closer to the GLSL ones.
legacy
Sam Hocevar sam 13 years ago
parent
commit
dde16a9dd6
2 changed files with 46 additions and 10 deletions
  1. +42
    -6
      src/matrix.h
  2. +4
    -4
      src/scene.cpp

+ 42
- 6
src/matrix.h View File

@@ -26,6 +26,12 @@
for (int n = 0; n < elems; n++) \
ret[n] = (*this)[n] op val[n]; \
return ret; \
} \
\
template<typename U> \
inline Vec##elems<T> operator op##=(Vec##elems<U> const &val) \
{ \
return *this = (*this) op val; \
}

#define BOOL_OP(elems, op, ret) \
@@ -44,6 +50,11 @@
for (int n = 0; n < elems; n++) \
ret[n] = (*this)[n] op val; \
return ret; \
} \
\
inline Vec##elems<T> operator op##=(T const &val) \
{ \
return *this = (*this) op val; \
}

#define CAST_OP(elems, dest) \
@@ -114,8 +125,8 @@ template <typename T> struct Vec2
union { T y; T b; T j; };
};

typedef Vec2<float> float2;
typedef Vec2<int> int2;
typedef Vec2<float> vec2;
typedef Vec2<int> vec2i;

template <typename T> struct Vec3
{
@@ -130,8 +141,8 @@ template <typename T> struct Vec3
union { T z; T c; T k; };
};

typedef Vec3<float> float3;
typedef Vec3<int> int3;
typedef Vec3<float> vec3;
typedef Vec3<int> vec3i;

template <typename T> struct Vec4
{
@@ -147,8 +158,8 @@ template <typename T> struct Vec4
union { T w; T d; T l; };
};

typedef Vec4<float> float4;
typedef Vec4<int> int4;
typedef Vec4<float> vec4;
typedef Vec4<int> vec4i;

#define SCALAR_GLOBAL(elems, op, U) \
template<typename T> \
@@ -210,6 +221,11 @@ template <typename T> struct Mat4
return ret;
}

inline Mat4<T> operator +=(Mat4<T> const val)
{
return *this = *this + val;
}

inline Mat4<T> operator -(Mat4<T> const val) const
{
Mat4<T> ret;
@@ -219,6 +235,11 @@ template <typename T> struct Mat4
return ret;
}

inline Mat4<T> operator -=(Mat4<T> const val)
{
return *this = *this - val;
}

inline Mat4<T> operator *(Mat4<T> const val) const
{
Mat4<T> ret;
@@ -233,6 +254,11 @@ template <typename T> struct Mat4
return ret;
}

inline Mat4<T> operator *=(Mat4<T> const val)
{
return *this = *this * val;
}

inline Vec4<T> operator *(Vec4<T> const val) const
{
Vec4<T> ret;
@@ -249,6 +275,16 @@ template <typename T> struct Mat4
Vec4<T> v[4];
};

typedef Mat4<float> mat4;
typedef Mat4<int> mat4i;

/* Aliases for deprecated stuff */
typedef Vec2<float> float2;
typedef Vec2<int> int2;
typedef Vec3<float> float3;
typedef Vec3<int> int3;
typedef Vec4<float> float4;
typedef Vec4<int> int4;
typedef Mat4<float> float4x4;
typedef Mat4<int> int4x4;



+ 4
- 4
src/scene.cpp View File

@@ -137,14 +137,14 @@ void Scene::Render() // XXX: rename to Blit()

// XXX: debug stuff
model_matrix = float4x4::translate(320.0f, 240.0f, 0.0f);
model_matrix = model_matrix * float4x4::rotate(-data->angle, 1.0f, 0.0f, 0.0f);
model_matrix *= float4x4::rotate(-data->angle, 1.0f, 0.0f, 0.0f);
#if 0
static float f = 0.0f;
f += 0.01f;
model_matrix = model_matrix * float4x4::rotate(0.1f * sinf(f), 1.0f, 0.0f, 0.0f);
model_matrix = model_matrix * float4x4::rotate(0.3f * cosf(f), 0.0f, 0.0f, 1.0f);
model_matrix *= float4x4::rotate(0.1f * sinf(f), 1.0f, 0.0f, 0.0f);
model_matrix *= float4x4::rotate(0.3f * cosf(f), 0.0f, 0.0f, 1.0f);
#endif
model_matrix = model_matrix * float4x4::translate(-320.0f, -240.0f, 0.0f);
model_matrix *= float4x4::translate(-320.0f, -240.0f, 0.0f);
// XXX: end of debug stuff

#if LOL_EXPERIMENTAL


Loading…
Cancel
Save