mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-15 00:24:40 +00:00
Update mMatrix.h
most working example
This commit is contained in:
parent
504b549ac0
commit
2fa15191ae
1 changed files with 9 additions and 19 deletions
|
|
@ -750,8 +750,8 @@ public:
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// col * rows + row
|
// row + col * cols
|
||||||
static U32 idx(U32 i, U32 j) { return (i * rows + j); }
|
static U32 idx(U32 i, U32 j) { return (i + j * cols); }
|
||||||
bool isAffine() const;
|
bool isAffine() const;
|
||||||
bool isIdentity() const;
|
bool isIdentity() const;
|
||||||
/// Take inverse of matrix assuming it is affine (rotation,
|
/// Take inverse of matrix assuming it is affine (rotation,
|
||||||
|
|
@ -893,14 +893,14 @@ public:
|
||||||
if (row >= rows || col >= cols)
|
if (row >= rows || col >= cols)
|
||||||
AssertFatal(false, "Matrix indices out of range");
|
AssertFatal(false, "Matrix indices out of range");
|
||||||
|
|
||||||
return data[col * rows + row];
|
return data[idx(col,row)];
|
||||||
}
|
}
|
||||||
|
|
||||||
const DATA_TYPE& operator () (U32 row, U32 col) const {
|
const DATA_TYPE& operator () (U32 row, U32 col) const {
|
||||||
if (row >= rows || col >= cols)
|
if (row >= rows || col >= cols)
|
||||||
AssertFatal(false, "Matrix indices out of range");
|
AssertFatal(false, "Matrix indices out of range");
|
||||||
|
|
||||||
return data[col * rows + row];
|
return data[idx(col, row)];
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
@ -911,23 +911,13 @@ public:
|
||||||
template<typename DATA_TYPE, U32 rows, U32 cols>
|
template<typename DATA_TYPE, U32 rows, U32 cols>
|
||||||
inline Matrix<DATA_TYPE, rows, cols>& Matrix<DATA_TYPE, rows, cols>::transpose()
|
inline Matrix<DATA_TYPE, rows, cols>& Matrix<DATA_TYPE, rows, cols>::transpose()
|
||||||
{
|
{
|
||||||
// square matrices can just swap, non square requires a temp mat.
|
Matrix<DATA_TYPE, rows, cols> result;
|
||||||
if (rows == cols) {
|
for (U32 i = 0; i < rows; i++) {
|
||||||
for (U32 i = 0; i < rows; i++) {
|
for (U32 j = 0; j < cols; j++) {
|
||||||
for (U32 j = 0; j < cols; j++) {
|
result(j, i) = (*this)(i, j);
|
||||||
std::swap((*this)(j, i), (*this)(i, j));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
std::copy(std::begin(result.data), std::end(result.data), std::begin(data));
|
||||||
Matrix<DATA_TYPE, rows, cols> result;
|
|
||||||
for (U32 i = 0; i < rows; i++) {
|
|
||||||
for (U32 j = 0; j < cols; j++) {
|
|
||||||
result(j, i) = (*this)(i, j);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::copy(std::begin(result.data), std::end(result.data), std::begin(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
return (*this);
|
return (*this);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue