Implement Mat4x4::FromTranslation
This commit is contained in:
@@ -440,4 +440,85 @@ namespace LinearAlgebra {
|
||||
Vector3 Matrix4x4::GetRow3(int index) const {
|
||||
return Vector3{ At(index, 0), At(index, 1), At(index, 2)};
|
||||
}
|
||||
|
||||
void Matrix4x4::SwapColumns(int col1, int col2) {
|
||||
Swap(At(0, col1), At(0, col2));
|
||||
Swap(At(1, col1), At(1, col2));
|
||||
Swap(At(2, col1), At(2, col2));
|
||||
Swap(At(3, col1), At(3, col2));
|
||||
}
|
||||
|
||||
void Matrix4x4::SwapRows(int row1, int row2) {
|
||||
Swap(At(row1, 0), At(row2, 0));
|
||||
Swap(At(row1, 1), At(row2, 1));
|
||||
Swap(At(row1, 2), At(row2, 2));
|
||||
Swap(At(row1, 3), At(row2, 3));
|
||||
}
|
||||
|
||||
void Matrix4x4::SwapRows3(int row1, int row2) {
|
||||
Swap(At(row1, 0), At(row2, 0));
|
||||
Swap(At(row1, 1), At(row2, 1));
|
||||
Swap(At(row1, 2), At(row2, 2));
|
||||
}
|
||||
|
||||
void Matrix4x4::Pivot() {
|
||||
int rowIndex = 0;
|
||||
|
||||
for(int col = 0; col < Cols; ++col)
|
||||
{
|
||||
int greatest = rowIndex;
|
||||
|
||||
// find the rowIndex k with k >= 1 for which Mkj has the largest absolute value.
|
||||
for(int i = rowIndex; i < Rows; ++i)
|
||||
if (std::abs(At(i, col)) > std::abs(At(greatest, col)))
|
||||
greatest = i;
|
||||
|
||||
if (std::abs(At(greatest, col)) != 0)
|
||||
{
|
||||
if (rowIndex != greatest)
|
||||
SwapRows(rowIndex, greatest); // the greatest now in rowIndex
|
||||
|
||||
ScaleRow(rowIndex, 1.f/At(rowIndex, col));
|
||||
|
||||
for(int r = 0; r < Rows; ++r)
|
||||
if (r != rowIndex)
|
||||
SetRow(r, GetRow(r) - GetRow(rowIndex) * At(r, col));
|
||||
|
||||
++rowIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Matrix4x4::ScaleColumn3(int col, float scalar) {
|
||||
At(0, col) *= scalar;
|
||||
At(1, col) *= scalar;
|
||||
At(2, col) *= scalar;
|
||||
}
|
||||
|
||||
void Matrix4x4::ScaleColumn(int col, float scalar) {
|
||||
At(0, col) *= scalar;
|
||||
At(1, col) *= scalar;
|
||||
At(2, col) *= scalar;
|
||||
At(3, col) *= scalar;
|
||||
}
|
||||
|
||||
void Matrix4x4::ScaleRow3(int row, float scalar) {
|
||||
At(row, 0) *= scalar;
|
||||
At(row, 1) *= scalar;
|
||||
At(row, 2) *= scalar;
|
||||
}
|
||||
|
||||
void Matrix4x4::ScaleRow(int row, float scalar) {
|
||||
At(row, 0) *= scalar;
|
||||
At(row, 1) *= scalar;
|
||||
At(row, 2) *= scalar;
|
||||
At(row, 3) *= scalar;
|
||||
}
|
||||
|
||||
Matrix4x4 Matrix4x4::FromTranslation(const Vector3 &translation) {
|
||||
Matrix4x4 m;
|
||||
m.SetTranslatePart(translation);
|
||||
m.Set3x3Part(Matrix3x3::Identity);
|
||||
return m;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user