Skip to content

Commit 979f050

Browse files
committed
matrix4 traspose
1 parent 27a1bfb commit 979f050

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

inc/vector_math/mat.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ namespace systems::leal::vector_math {
4040
return toReturn;
4141
}
4242

43+
Mat<DATA_TYPE,COLS,ROWS> transpose() const {
44+
Mat<DATA_TYPE,COLS,ROWS> toReturn;
45+
46+
int ownIndex=0;
47+
for (int a=0; a<COLS; a++)
48+
for (int b=0; b<ROWS; b++) {
49+
toReturn.data[COLS*b + a] = this->data[ownIndex];
50+
ownIndex++;
51+
}
52+
53+
return toReturn;
54+
}
4355

4456
};
4557

inc/vector_math/matrix4.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ namespace systems::leal::vector_math
4242
static Matrix4<DATA_TYPE> rotateX(DATA_TYPE angle);
4343
static Matrix4<DATA_TYPE> rotateY(DATA_TYPE angle);
4444
static Matrix4<DATA_TYPE> rotateZ(DATA_TYPE angle);
45+
4546

4647
};
4748

test/main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ TEST(Matrix4Float, mul) {
4343
EXPECT_EQ(Matrix4<float>::identity()*Matrix4<float>(1), Matrix4<float>(1));
4444
}
4545

46+
TEST(Matrix4Float, transpose) {
47+
EXPECT_EQ(Matrix4<float>::identity().transpose(), Matrix4<float>::identity());
48+
}
49+
4650
TEST(Matrix4Double, constructors) {
4751
EXPECT_EQ(sizeof(Matrix4<double>), 128);
4852
EXPECT_EQ(Matrix4<double>::identity(), Matrix4<double>::identity());
@@ -59,6 +63,10 @@ TEST(Matrix4Double, mul) {
5963
EXPECT_EQ(Matrix4<double>::identity()*Matrix4<double>(1), Matrix4<double>(1));
6064
}
6165

66+
TEST(Matrix4Double, transpose) {
67+
EXPECT_EQ(Matrix4<double>::identity().transpose(), Matrix4<double>::identity());
68+
}
69+
6270
int main(int argc, char **argv) {
6371
testing::InitGoogleTest(&argc, argv);
6472
return RUN_ALL_TESTS();

0 commit comments

Comments
 (0)