Skip to content
Browse files

Add a test for kmVec2Tranform, fix an error in kmMat3RotationZ

  • Loading branch information...
1 parent 6948875 commit bcb1fb8ff0332d96747e360349e4f990d77939f1 @Kazade committed Jan 23, 2011
Showing with 38 additions and 5 deletions.
  1. +2 −2 src/mat3.c
  2. +10 −3 src/vec2.c
  3. +3 −0 tests/CMakeLists.txt
  4. +23 −0 tests/test_vec2.cpp
View
4 src/mat3.c
@@ -355,10 +355,10 @@ kmMat3* const kmMat3RotationZ(kmMat3* pOut, const float radians)
*/
pOut->mat[0] = cosf(radians);
- pOut->mat[1] = sinf(radians);
+ pOut->mat[1] =-sinf(radians);
pOut->mat[2] = 0.0f;
- pOut->mat[3] = -sinf(radians);;
+ pOut->mat[3] = sinf(radians);;
pOut->mat[4] = cosf(radians);
pOut->mat[5] = 0.0f;
View
13 src/vec2.c
@@ -78,10 +78,17 @@ kmVec2* kmVec2Subtract(kmVec2* pOut, const kmVec2* pV1, const kmVec2* pV2)
return pOut;
}
-kmVec2* kmVec2Transform(kmVec2* pOut, const kmVec2* pV1, const kmMat3* pM)
+kmVec2* kmVec2Transform(kmVec2* pOut, const kmVec2* pV, const kmMat3* pM)
{
- assert(0);
- return NULL;
+ kmVec2 v;
+
+ v.x = pV->x * pM->mat[0] + pV->y * pM->mat[3] + pM->mat[6];
+ v.y = pV->x * pM->mat[1] + pV->y * pM->mat[4] + pM->mat[7];
+
+ pOut->x = v.x;
+ pOut->y = v.y;
+
+ return pOut;
}
kmVec2* kmVec2TransformCoord(kmVec2* pOut, const kmVec2* pV, const kmMat3* pM)
View
3 tests/CMakeLists.txt
@@ -11,4 +11,7 @@ ADD_TEST(test_mat3 test_mat3)
ADD_EXECUTABLE(test_ray2 ${KAZMATH_SOURCES} test_ray2.cpp)
ADD_TEST(test_ray2 test_ray2)
+ADD_EXECUTABLE(test_vec2 ${KAZMATH_SOURCES} test_vec2.cpp)
+ADD_TEST(test_vec2 test_vec2)
+
View
23 tests/test_vec2.cpp
@@ -0,0 +1,23 @@
+#include <unittest++/UnitTest++.h>
+
+#include "kazmath/vec2.h"
+#include "kazmath/utility.h"
+#include "kazmath/mat3.h"
+
+TEST(test_transform) {
+ kmVec2 orig;
+ kmVec2Fill(&orig, 0.0, 1.0f);
+
+ kmMat3 rotate;
+ kmMat3RotationZ(&rotate, kmDegreesToRadians(90.0f));
+
+ kmVec2 rotated;
+ kmVec2Transform(&rotated, &orig, &rotate);
+
+ CHECK_CLOSE(1.0f, rotated.x, 0.001f);
+ CHECK_CLOSE(0.0f, rotated.y, 0.001f);
+}
+
+int main() {
+ return UnitTest::RunAllTests();
+}

0 comments on commit bcb1fb8

Please sign in to comment.
Something went wrong with that request. Please try again.