# Changeset 641Tweet

Ignore:
Timestamp:
Feb 14, 2011, 2:26:19 AM (10 years ago)
Message:

Create a few matrix handling classes and operators.

File:
1 edited

Unmodified
Added
Removed
• ## trunk/src/matrix.h

 r295 GLOBALS(4) template struct Vec4x4 { inline Vec4x4() { v[0] = v[1] = v[2] = v[3] = 0; } inline Vec4x4(T val) { v[0] = v[1] = v[2] = v[3] = val; } inline Vec4x4(Vec4 v0, Vec4 v1, Vec4 v2, Vec4 v3) { v[0] = v0; v[1] = v1; v[2] = v2; v[3] = v3; } inline Vec4& operator[](int n) { return v[n]; } inline Vec4 const& operator[](int n) const { return v[n]; } inline Vec4x4 operator +(Vec4x4 const val) const { Vec4x4 ret; for (int j = 0; j < 4; j++) for (int i = 0; i < 4; i++) ret[i][j] = v[i][j] + val[i][j]; return ret; } inline Vec4x4 operator -(Vec4x4 const val) const { Vec4x4 ret; for (int j = 0; j < 4; j++) for (int i = 0; i < 4; i++) ret[i][j] = v[i][j] - val[i][j]; return ret; } inline Vec4x4 operator *(Vec4x4 const val) const { Vec4x4 ret; for (int j = 0; j < 4; j++) for (int i = 0; i < 4; i++) { T tmp = 0; for (int k = 0; k < 4; k++) tmp += v[k][j] * val[i][k]; ret[i][j] = tmp; } return ret; } inline Vec4 operator *(Vec4 const val) const { Vec4 ret; for (int j = 0; j < 4; j++) { T tmp = 0; for (int i = 0; i < 4; i++) tmp += v[i][j] * val[i]; ret[j] = tmp; } return ret; } Vec4 v[4]; }; typedef Vec4x4 float4x4; typedef Vec4x4 int4x4; #endif // __DH_MATRIX_H__
Note: See TracChangeset for help on using the changeset viewer.