瀏覽代碼

Make the float4x4 constructor fill only the matrix's diagonal. Thus

the float4x4::identity() method is no longer necessary.
legacy
Sam Hocevar sam 14 年之前
父節點
當前提交
4b484d5bc8
共有 2 個檔案被更改,包括 10 行新增12 行删除
  1. +9
    -11
      src/matrix.h
  2. +1
    -1
      test/matrix.cpp

+ 9
- 11
src/matrix.h 查看文件

@@ -178,21 +178,19 @@ GLOBALS(4)
template <typename T> struct Mat4
{
inline Mat4() { }
inline Mat4(T val) { for (int i = 0; i < 4; i++) v[i] = val; }
inline Mat4(Vec4<T> v0, Vec4<T> v1, Vec4<T> v2, Vec4<T> v3)
{ v[0] = v0; v[1] = v1; v[2] = v2; v[3] = v3; }

inline Vec4<T>& operator[](int n) { return v[n]; }
inline Vec4<T> const& operator[](int n) const { return v[n]; }

static inline Mat4<T> identity()
inline Mat4(T val)
{
Mat4<T> ret;
for (int j = 0; j < 4; j++)
for (int i = 0; i < 4; i++)
ret[i][j] = i == j;
return ret;
v[i][j] = (i == j) ? val : 0;
}
inline Mat4(Vec4<T> v0, Vec4<T> v1, Vec4<T> v2, Vec4<T> v3)
{
v[0] = v0; v[1] = v1; v[2] = v2; v[3] = v3;
}

inline Vec4<T>& operator[](int n) { return v[n]; }
inline Vec4<T> const& operator[](int n) const { return v[n]; }

T det() const;
Mat4<T> invert() const;


+ 1
- 1
test/matrix.cpp 查看文件

@@ -32,7 +32,7 @@ public:

void setUp()
{
identity = float4x4::identity();
identity = float4x4(1.0f);
triangular = float4x4(float4(1.0f, 0.0f, 0.0f, 0.0f),
float4(7.0f, 2.0f, 0.0f, 0.0f),
float4(1.0f, 5.0f, 3.0f, 0.0f),


Loading…
取消
儲存