matrixOps.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. // Copyright (C) 2008-2012 Colin MacDonald
  2. // No rights reserved: this software is in the public domain.
  3. #include "testUtils.h"
  4. using namespace irr;
  5. using namespace core;
  6. using namespace scene;
  7. using namespace video;
  8. using namespace io;
  9. using namespace gui;
  10. namespace
  11. {
  12. // Basic tests for identity matrix
  13. bool identity(void)
  14. {
  15. bool result = true;
  16. matrix4 m;
  17. // Check default init
  18. result &= (m==core::IdentityMatrix);
  19. result &= (core::IdentityMatrix==m);
  20. assert_log(result);
  21. // Since the last test can be made with isDefinitelyIdentityMatrix we set it to false here
  22. m.setDefinitelyIdentityMatrix(false);
  23. result &= (m==core::IdentityMatrix);
  24. result &= (core::IdentityMatrix==m);
  25. assert_log(result);
  26. // also equals should see this
  27. result &= m.equals(core::IdentityMatrix);
  28. result &= core::IdentityMatrix.equals(m);
  29. assert_log(result);
  30. // Check inequality
  31. m[12]=5.f;
  32. result &= (m!=core::IdentityMatrix);
  33. result &= (core::IdentityMatrix!=m);
  34. result &= !m.equals(core::IdentityMatrix);
  35. result &= !core::IdentityMatrix.equals(m);
  36. assert_log(result);
  37. // Test multiplication
  38. result &= (m==(core::IdentityMatrix*m));
  39. result &= m.equals(core::IdentityMatrix*m);
  40. result &= (m==(m*core::IdentityMatrix));
  41. result &= m.equals(m*core::IdentityMatrix);
  42. assert_log(result);
  43. return result;
  44. }
  45. // Test rotations
  46. bool transformations(void)
  47. {
  48. bool result = true;
  49. matrix4 m, s;
  50. m.setRotationDegrees(core::vector3df(30,40,50));
  51. s.setScale(core::vector3df(2,3,4));
  52. m *= s;
  53. m.setTranslation(core::vector3df(5,6,7));
  54. result &= (core::vector3df(5,6,7).equals(m.getTranslation()));
  55. assert_log(result);
  56. result &= (core::vector3df(2,3,4).equals(m.getScale()));
  57. assert_log(result);
  58. core::vector3df newRotation = m.getRotationDegrees();
  59. result &= (core::vector3df(30,40,50).equals(newRotation, 0.000004f));
  60. assert_log(result);
  61. m.setRotationDegrees(vector3df(90.0001f, 270.85f, 180.0f));
  62. s.setRotationDegrees(vector3df(0,0, 0.860866f));
  63. m *= s;
  64. newRotation = m.getRotationDegrees();
  65. result &= (core::vector3df(0,270,270).equals(newRotation, 0.0001f));
  66. assert_log(result);
  67. m.setRotationDegrees(vector3df(270.0f, 89.8264f, 0.000100879f));
  68. s.setRotationDegrees(vector3df(0,0, 0.189398f));
  69. m *= s;
  70. newRotation = m.getRotationDegrees();
  71. result &= (core::vector3df(0,90,90).equals(newRotation, 0.0001f));
  72. assert_log(result);
  73. m.setRotationDegrees(vector3df(270.0f, 89.0602f, 359.999f));
  74. s.setRotationDegrees(vector3df(0,0, 0.949104f));
  75. m *= s;
  76. newRotation = m.getRotationDegrees();
  77. result &= (core::vector3df(0,90,89.999f).equals(newRotation));
  78. assert_log(result);
  79. return result;
  80. }
  81. // Test rotations
  82. bool rotations(void)
  83. {
  84. bool result = true;
  85. matrix4 rot1,rot2,rot3,rot4,rot5;
  86. core::vector3df vec1(1,2,3),vec12(1,2,3);
  87. core::vector3df vec2(-5,0,0),vec22(-5,0,0);
  88. core::vector3df vec3(20,0,-20), vec32(20,0,-20);
  89. // Make sure the matrix multiplication and rotation application give same results
  90. rot1.setRotationDegrees(core::vector3df(90,0,0));
  91. rot2.setRotationDegrees(core::vector3df(0,90,0));
  92. rot3.setRotationDegrees(core::vector3df(0,0,90));
  93. rot4.setRotationDegrees(core::vector3df(90,90,90));
  94. rot5 = rot3*rot2*rot1;
  95. result &= (rot4.equals(rot5, ROUNDING_ERROR_f32));
  96. assert_log(result);
  97. rot4.transformVect(vec1);rot5.transformVect(vec12);
  98. rot4.transformVect(vec2);rot5.transformVect(vec22);
  99. rot4.transformVect(vec3);rot5.transformVect(vec32);
  100. result &= (vec1.equals(vec12));
  101. result &= (vec2.equals(vec22));
  102. result &= (vec3.equals(vec32));
  103. assert_log(result);
  104. vec1.set(1,2,3);vec12.set(1,2,3);
  105. vec2.set(-5,0,0);vec22.set(-5,0,0);
  106. vec3.set(20,0,-20);vec32.set(20,0,-20);
  107. rot1.setRotationDegrees(core::vector3df(45,0,0));
  108. rot2.setRotationDegrees(core::vector3df(0,45,0));
  109. rot3.setRotationDegrees(core::vector3df(0,0,45));
  110. rot4.setRotationDegrees(core::vector3df(45,45,45));
  111. rot5 = rot3*rot2*rot1;
  112. result &= (rot4.equals(rot5, ROUNDING_ERROR_f32));
  113. assert_log(result);
  114. rot4.transformVect(vec1);rot5.transformVect(vec12);
  115. rot4.transformVect(vec2);rot5.transformVect(vec22);
  116. rot4.transformVect(vec3);rot5.transformVect(vec32);
  117. result &= (vec1.equals(vec12));
  118. result &= (vec2.equals(vec22));
  119. result &= (vec3.equals(vec32, 2*ROUNDING_ERROR_f32));
  120. assert_log(result);
  121. vec1.set(1,2,3);vec12.set(1,2,3);
  122. vec2.set(-5,0,0);vec22.set(-5,0,0);
  123. vec3.set(20,0,-20);vec32.set(20,0,-20);
  124. rot1.setRotationDegrees(core::vector3df(-60,0,0));
  125. rot2.setRotationDegrees(core::vector3df(0,-60,0));
  126. rot3.setRotationDegrees(core::vector3df(0,0,-60));
  127. rot4.setRotationDegrees(core::vector3df(-60,-60,-60));
  128. rot5 = rot3*rot2*rot1;
  129. result &= (rot4.equals(rot5, ROUNDING_ERROR_f32));
  130. assert_log(result);
  131. rot4.transformVect(vec1);rot5.transformVect(vec12);
  132. rot4.transformVect(vec2);rot5.transformVect(vec22);
  133. rot4.transformVect(vec3);rot5.transformVect(vec32);
  134. result &= (vec1.equals(vec12));
  135. result &= (vec2.equals(vec22));
  136. // this one needs higher tolerance due to rounding issues
  137. result &= (vec3.equals(vec32, 0.000002f));
  138. assert_log(result);
  139. vec1.set(1,2,3);vec12.set(1,2,3);
  140. vec2.set(-5,0,0);vec22.set(-5,0,0);
  141. vec3.set(20,0,-20);vec32.set(20,0,-20);
  142. rot1.setRotationDegrees(core::vector3df(113,0,0));
  143. rot2.setRotationDegrees(core::vector3df(0,-27,0));
  144. rot3.setRotationDegrees(core::vector3df(0,0,193));
  145. rot4.setRotationDegrees(core::vector3df(113,-27,193));
  146. rot5 = rot3*rot2*rot1;
  147. result &= (rot4.equals(rot5, ROUNDING_ERROR_f32));
  148. assert_log(result);
  149. rot4.transformVect(vec1);rot5.transformVect(vec12);
  150. rot4.transformVect(vec2);rot5.transformVect(vec22);
  151. rot4.transformVect(vec3);rot5.transformVect(vec32);
  152. // these ones need higher tolerance due to rounding issues
  153. result &= (vec1.equals(vec12, 0.000002f));
  154. assert_log(result);
  155. result &= (vec2.equals(vec22));
  156. assert_log(result);
  157. result &= (vec3.equals(vec32, 0.000002f));
  158. assert_log(result);
  159. rot1.setRotationDegrees(core::vector3df(0,0,34));
  160. rot2.setRotationDegrees(core::vector3df(0,43,0));
  161. vec1=(rot2*rot1).getRotationDegrees();
  162. result &= (vec1.equals(core::vector3df(27.5400505f, 34.4302292f, 42.6845398f), 0.000002f));
  163. assert_log(result);
  164. // corner cases
  165. rot1.setRotationDegrees(irr::core::vector3df(180.0f, 0.f, 0.f));
  166. vec1=rot1.getRotationDegrees();
  167. result &= (vec1.equals(core::vector3df(180.0f, 0.f, 0.f), 0.000002f));
  168. assert_log(result);
  169. rot1.setRotationDegrees(irr::core::vector3df(0.f, 180.0f, 0.f));
  170. vec1=rot1.getRotationDegrees();
  171. result &= (vec1.equals(core::vector3df(180.0f, 360, 180.0f), 0.000002f));
  172. assert_log(result);
  173. rot1.setRotationDegrees(irr::core::vector3df(0.f, 0.f, 180.0f));
  174. vec1=rot1.getRotationDegrees();
  175. result &= (vec1.equals(core::vector3df(0.f, 0.f, 180.0f), 0.000002f));
  176. assert_log(result);
  177. rot1.makeIdentity();
  178. rot1.setRotationDegrees(core::vector3df(270.f,0,0));
  179. rot2.makeIdentity();
  180. rot2.setRotationDegrees(core::vector3df(-90.f,0,0));
  181. vec1=(rot1*rot2).getRotationDegrees();
  182. result &= (vec1.equals(core::vector3df(180.f, 0.f, 0.0f)));
  183. assert_log(result);
  184. return result;
  185. }
  186. // Test isOrthogonal
  187. bool isOrthogonal(void)
  188. {
  189. matrix4 rotationMatrix;
  190. if (!rotationMatrix.isOrthogonal())
  191. {
  192. logTestString("irr::core::matrix4::isOrthogonal() failed with Identity.\n");
  193. return false;
  194. }
  195. rotationMatrix.setRotationDegrees(vector3df(90, 0, 0));
  196. if (!rotationMatrix.isOrthogonal())
  197. {
  198. logTestString("irr::core::matrix4::isOrthogonal() failed with rotation.\n");
  199. return false;
  200. }
  201. matrix4 translationMatrix;
  202. translationMatrix.setTranslation(vector3df(0, 3, 0));
  203. if (translationMatrix.isOrthogonal())
  204. {
  205. logTestString("irr::core::matrix4::isOrthogonal() failed with translation.\n");
  206. return false;
  207. }
  208. matrix4 scaleMatrix;
  209. scaleMatrix.setScale(vector3df(1, 2, 3));
  210. if (!scaleMatrix.isOrthogonal())
  211. {
  212. logTestString("irr::core::matrix4::isOrthogonal() failed with scale.\n");
  213. return false;
  214. }
  215. return true;
  216. }
  217. bool checkMatrixRotation(irr::core::matrix4& m, const vector3df& vector, const vector3df& expectedResult)
  218. {
  219. vector3df v(vector);
  220. m.rotateVect(v);
  221. if ( expectedResult.equals(v) )
  222. return true;
  223. logTestString("checkMatrixRotation failed for vector %f %f %f. Expected %f %f %f, got %f %f %f \n"
  224. , vector.X, vector.Y, vector.Z, expectedResult.X, expectedResult.Y, expectedResult.Z, v.X, v.Y, v.Z);
  225. logTestString("matrix: ");
  226. for ( int i=0; i<16; ++i )
  227. logTestString("%.2f ", m[i]);
  228. logTestString("\n");
  229. return false;
  230. }
  231. bool setRotationAxis()
  232. {
  233. matrix4 m;
  234. vector3df v;
  235. // y up, x right, z depth (as usual)
  236. // y rotated around x-axis
  237. if ( !checkMatrixRotation( m.setRotationAxisRadians(90.f*DEGTORAD, vector3df(1,0,0)), vector3df(0,1,0), vector3df(0, 0, 1)) )
  238. {
  239. logTestString("%s:%d", __FILE__, __LINE__);
  240. return false;
  241. }
  242. if ( !checkMatrixRotation( m.setRotationAxisRadians(180.f*DEGTORAD, vector3df(1,0,0)), vector3df(0,1,0), vector3df(0, -1, 0)) )
  243. {
  244. logTestString("%s:%d", __FILE__, __LINE__);
  245. return false;
  246. }
  247. // y rotated around negative x-axis
  248. m.makeIdentity();
  249. if ( !checkMatrixRotation( m.setRotationAxisRadians(90.f*DEGTORAD, vector3df(-1,0,0)), vector3df(0,1,0), vector3df(0, 0, -1)) )
  250. {
  251. logTestString("%s:%d", __FILE__, __LINE__);
  252. return false;
  253. }
  254. // x rotated around x-axis
  255. if ( !checkMatrixRotation( m.setRotationAxisRadians(90.f*DEGTORAD, vector3df(1,0,0)), vector3df(1,0,0), vector3df(1, 0, 0)) )
  256. {
  257. logTestString("%s:%d", __FILE__, __LINE__);
  258. return false;
  259. }
  260. // x rotated around y-axis
  261. if ( !checkMatrixRotation( m.setRotationAxisRadians(90.f*DEGTORAD, vector3df(0,1,0)), vector3df(1,0,0), vector3df(0, 0, -1)) )
  262. {
  263. logTestString("%s:%d", __FILE__, __LINE__);
  264. return false;
  265. }
  266. if ( !checkMatrixRotation( m.setRotationAxisRadians(180.f*DEGTORAD, vector3df(0,1,0)), vector3df(1,0,0), vector3df(-1, 0, 0)) )
  267. {
  268. logTestString("%s:%d", __FILE__, __LINE__);
  269. return false;
  270. }
  271. // x rotated around negative y-axis
  272. if ( !checkMatrixRotation( m.setRotationAxisRadians(90.f*DEGTORAD, vector3df(0,-1,0)), vector3df(1,0,0), vector3df(0, 0, 1)) )
  273. {
  274. logTestString("%s:%d", __FILE__, __LINE__);
  275. return false;
  276. }
  277. // y rotated around y-axis
  278. if ( !checkMatrixRotation( m.setRotationAxisRadians(90.f*DEGTORAD, vector3df(0,1,0)), vector3df(0,1,0), vector3df(0, 1, 0)) )
  279. {
  280. logTestString("%s:%d", __FILE__, __LINE__);
  281. return false;
  282. }
  283. // x rotated around z-axis
  284. if ( !checkMatrixRotation( m.setRotationAxisRadians(90.f*DEGTORAD, vector3df(0,0,1)), vector3df(1,0,0), vector3df(0, 1, 0)) )
  285. {
  286. logTestString("%s:%d", __FILE__, __LINE__);
  287. return false;
  288. }
  289. if ( !checkMatrixRotation( m.setRotationAxisRadians(180.f*DEGTORAD, vector3df(0,0,1)), vector3df(1,0,0), vector3df(-1, 0, 0)) )
  290. {
  291. logTestString("%s:%d", __FILE__, __LINE__);
  292. return false;
  293. }
  294. // x rotated around negative z-axis
  295. if ( !checkMatrixRotation( m.setRotationAxisRadians(90.f*DEGTORAD, vector3df(0,0,-1)), vector3df(1,0,0), vector3df(0, -1, 0)) )
  296. {
  297. logTestString("%s:%d", __FILE__, __LINE__);
  298. return false;
  299. }
  300. // y rotated around z-axis
  301. if ( !checkMatrixRotation( m.setRotationAxisRadians(90.f*DEGTORAD, vector3df(0,0,1)), vector3df(0,1,0), vector3df(-1, 0, 0)) )
  302. {
  303. logTestString("%s:%d", __FILE__, __LINE__);
  304. return false;
  305. }
  306. if ( !checkMatrixRotation( m.setRotationAxisRadians(180.f*DEGTORAD, vector3df(0,0,1)), vector3df(0,1,0), vector3df(0, -1, 0)) )
  307. {
  308. logTestString("%s:%d", __FILE__, __LINE__);
  309. return false;
  310. }
  311. // z rotated around z-axis
  312. if ( !checkMatrixRotation( m.setRotationAxisRadians(90.f*DEGTORAD, vector3df(0,0,1)), vector3df(0,0,1), vector3df(0, 0, 1)) )
  313. {
  314. logTestString("%s:%d", __FILE__, __LINE__);
  315. return false;
  316. }
  317. return true;
  318. }
  319. // Note: pretty high tolerance needed
  320. bool check_getRotationDegreesWithScale2(const core::matrix4& m, const irr::core::vector3df& scale, irr::f32 tolerance = 0.01f)
  321. {
  322. core::vector3df rot = m.getRotationDegrees(scale);
  323. core::matrix4 m2;
  324. m2.setRotationDegrees(rot);
  325. core::matrix4 smat;
  326. smat.setScale(scale);
  327. m2 *= smat;
  328. core::vector3df v1(5,10,15);
  329. core::vector3df v2 = v1;
  330. m.transformVect(v1);
  331. m2.transformVect(v2);
  332. if ( v1.equals(v2, tolerance) )
  333. return true;
  334. logTestString("v1: %.3f %.3f %.3f\nv2: %.3f %.3f %.3f\n", v1.X, v1.Y, v1.Z, v2.X, v2.Y, v2.Z);
  335. //logTestString("matrix (3x3): ");
  336. //for ( int k=0; k<3; ++k)
  337. // for ( int i=0; i<3; ++i )
  338. // logTestString("%.3f ", m[k*4+i]);
  339. //logTestString("\n");
  340. return false;
  341. }
  342. // This can only work if the matrix is pure scale or pure rotation
  343. bool check_getRotationDegreesWithScale(const core::matrix4& m, irr::f32 tolerance = 0.001f)
  344. {
  345. core::vector3df scale = m.getScale();
  346. return check_getRotationDegreesWithScale2(m, scale, tolerance);
  347. }
  348. // Lazy macro only to be used inside the loop where it is used
  349. // (can't use lambda yet, still testing on older compilers)
  350. #define log_check_getRotationDegreesWithScaleIJK \
  351. do { \
  352. smat.setScale(scale); \
  353. m2 = m1*smat; \
  354. if ( !check_getRotationDegreesWithScale2(m2, scale) ) { \
  355. logTestString("%s:%d i:%f j:%f k:%f\n", __FILE__, __LINE__, i, j, k); \
  356. result = false; } \
  357. } while (false)
  358. bool decompose()
  359. {
  360. bool result = true;
  361. core::matrix4 m1;
  362. result &= check_getRotationDegreesWithScale(m1);
  363. // check pure scaling/90° rotations and 0 values
  364. for ( irr::f32 i = -2.f; i <= 2.f; i += 1.f )
  365. for ( irr::f32 j = -2.f; j <= 2.f; j += 1.f )
  366. for ( irr::f32 k = -2.f; k <= 2.f; k += 1.f )
  367. {
  368. m1 = core::matrix4();
  369. m1[0] = i;
  370. m1[5] = j;
  371. m1[10] = k;
  372. if ( !check_getRotationDegreesWithScale(m1) )
  373. {
  374. logTestString("%s:%d i:%f j:%f k:%f\n", __FILE__, __LINE__, i, j, k);
  375. result = false;
  376. }
  377. }
  378. // check some rotations (note that we avoid the 0 case - which won't work)
  379. for ( irr::f32 i = -180.f; i <= 360.f; i += 30.1f )
  380. for ( irr::f32 j = -120.f; j <= 200.f; j += 44.4f )
  381. for ( irr::f32 k = -10.f; k <= 180.f; k += 33.3f )
  382. {
  383. m1 = core::matrix4();
  384. m1.setRotationDegrees(core::vector3df(i,j,k));
  385. result &= check_getRotationDegreesWithScale(m1); // pure rotation
  386. // rotation + scaling tests
  387. // We can't use check_getRotationDegreesWithScale as we have no way so far to decompose a combined matrix
  388. core::matrix4 smat, m2;
  389. core::vector3df scale;
  390. scale = core::vector3df(2.f, 2.f, 2.f); // simple uniform scaling
  391. log_check_getRotationDegreesWithScaleIJK;
  392. scale = core::vector3df(-2.f, 2.f, 2.f); // simple uniform scaling which swaps handedness
  393. log_check_getRotationDegreesWithScaleIJK; // (TODO: can't decompose this yet)
  394. scale = core::vector3df(i, i, i); // flexible uniform scaling
  395. log_check_getRotationDegreesWithScaleIJK; // (TODO: can't decompose this yet)
  396. scale = core::vector3df(1, 2, 3); // simple non-uniform scaling
  397. log_check_getRotationDegreesWithScaleIJK;
  398. scale = core::vector3df(-1, -2, -3); // negative non-uniform scaling with swap of handedness
  399. log_check_getRotationDegreesWithScaleIJK; // (TODO: can't decompose this yet)
  400. scale = core::vector3df(-1, 2, -3); // +- non-uniform scaling
  401. log_check_getRotationDegreesWithScaleIJK;
  402. scale = core::vector3df(i,k,j); // non-uniform scaling
  403. log_check_getRotationDegreesWithScaleIJK; // (TODO: can't decompose this yet)
  404. }
  405. if ( !result )
  406. logTestString("decomposing matrix failed\n");
  407. return result;
  408. }
  409. // just calling each function once to find compile problems
  410. void calltest()
  411. {
  412. matrix4 mat;
  413. matrix4 mat2(mat);
  414. f32& f1 = mat(0,0);
  415. const f32& f2 = mat(0,0);
  416. f32& f3 = mat[0];
  417. const f32& f4 = mat[0];
  418. mat = mat;
  419. mat = 1.f;
  420. const f32 * pf1 = mat.pointer();
  421. f32 * pf2 = mat.pointer();
  422. bool b = mat == mat2;
  423. b = mat != mat2;
  424. mat = mat + mat2;
  425. mat += mat2;
  426. mat = mat - mat2;
  427. mat -= mat2;
  428. mat.setbyproduct(mat, mat2);
  429. mat.setbyproduct_nocheck(mat, mat2);
  430. mat = mat * mat2;
  431. mat *= mat2;
  432. mat = mat * 10.f;
  433. mat *= 10.f;
  434. mat.makeIdentity();
  435. b = mat.isIdentity();
  436. b = mat.isOrthogonal();
  437. b = mat.isIdentity_integer_base ();
  438. mat.setTranslation(vector3df(1.f, 1.f, 1.f) );
  439. vector3df v1 = mat.getTranslation();
  440. mat.setInverseTranslation(vector3df(1.f, 1.f, 1.f) );
  441. mat.setRotationRadians(vector3df(1.f, 1.f, 1.f) );
  442. mat.setRotationDegrees(vector3df(1.f, 1.f, 1.f) );
  443. vector3df v2 = mat.getRotationDegrees();
  444. mat.setInverseRotationRadians(vector3df(1.f, 1.f, 1.f) );
  445. mat.setInverseRotationDegrees(vector3df(1.f, 1.f, 1.f) );
  446. mat.setRotationAxisRadians(1.f, vector3df(1.f, 1.f, 1.f) );
  447. mat.setScale(vector3df(1.f, 1.f, 1.f) );
  448. mat.setScale(1.f);
  449. vector3df v3 = mat.getScale();
  450. mat.inverseTranslateVect(v1);
  451. mat.inverseRotateVect(v1);
  452. mat.rotateVect(v1);
  453. mat.rotateVect(v1, v2);
  454. f32 fv3[3];
  455. mat.rotateVect(fv3, v1);
  456. mat.transformVect(v1);
  457. mat.transformVect(v1, v1);
  458. f32 fv4[4];
  459. mat.transformVect(fv4, v1);
  460. mat.transformVec3(fv3, fv3);
  461. mat.translateVect(v1);
  462. plane3df p1;
  463. mat.transformPlane(p1);
  464. mat.transformPlane(p1, p1);
  465. aabbox3df bb1;
  466. mat.transformBox(bb1);
  467. mat.transformBoxEx(bb1);
  468. mat.multiplyWith1x4Matrix(fv4);
  469. mat.makeInverse();
  470. b = mat.getInversePrimitive(mat2);
  471. b = mat.getInverse(mat2);
  472. mat.buildProjectionMatrixPerspectiveFovRH(1.f, 1.f, 1.f, 1000.f);
  473. mat.buildProjectionMatrixPerspectiveFovLH(1.f, 1.f, 1.f, 1000.f);
  474. mat.buildProjectionMatrixPerspectiveFovInfinityLH(1.f, 1.f, 1.f);
  475. mat.buildProjectionMatrixPerspectiveRH(100.f, 100.f, 1.f, 1000.f);
  476. mat.buildProjectionMatrixPerspectiveLH(10000.f, 10000.f, 1.f, 1000.f);
  477. mat.buildProjectionMatrixOrthoLH(10000.f, 10000.f, 1.f, 1000.f);
  478. mat.buildProjectionMatrixOrthoRH(10000.f, 10000.f, 1.f, 1000.f);
  479. mat.buildCameraLookAtMatrixLH(vector3df(1.f, 1.f, 1.f), vector3df(0.f, 0.f, 0.f), vector3df(0.f, 1.f, 0.f) );
  480. mat.buildCameraLookAtMatrixRH(vector3df(1.f, 1.f, 1.f), vector3df(0.f, 0.f, 0.f), vector3df(0.f, 1.f, 0.f) );
  481. mat.buildShadowMatrix(vector3df(1.f, 1.f, 1.f), p1);
  482. core::rect<s32> a1(0,0,100,100);
  483. mat.buildNDCToDCMatrix(a1, 1.f);
  484. mat.interpolate(mat2, 1.f);
  485. mat = mat.getTransposed();
  486. mat.getTransposed(mat2);
  487. mat.buildRotateFromTo(vector3df(1.f, 1.f, 1.f), vector3df(1.f, 1.f, 1.f));
  488. mat.setRotationCenter(vector3df(1.f, 1.f, 1.f), vector3df(1.f, 1.f, 1.f));
  489. mat.buildAxisAlignedBillboard(vector3df(1.f, 1.f, 1.f), vector3df(1.f, 1.f, 1.f), vector3df(1.f, 1.f, 1.f), vector3df(1.f, 1.f, 1.f), vector3df(1.f, 1.f, 1.f));
  490. mat.buildTextureTransform( 1.f,vector2df(1.f, 1.f), vector2df(1.f, 1.f), vector2df(1.f, 1.f));
  491. mat.setTextureRotationCenter( 1.f );
  492. mat.setTextureTranslate( 1.f, 1.f );
  493. mat.setTextureTranslateTransposed(1.f, 1.f);
  494. mat.setTextureScale( 1.f, 1.f );
  495. mat.setTextureScaleCenter( 1.f, 1.f );
  496. f32 fv16[16];
  497. mat.setM(fv16);
  498. mat.setDefinitelyIdentityMatrix(false);
  499. b = mat.getDefinitelyIdentityMatrix();
  500. b = mat.equals(mat2);
  501. f1 = f1+f2+f3+f4+*pf1+*pf2; // getting rid of unused variable warnings.
  502. }
  503. }
  504. bool matrixOps(void)
  505. {
  506. bool result = true;
  507. calltest();
  508. result &= identity();
  509. result &= rotations();
  510. result &= isOrthogonal();
  511. result &= transformations();
  512. result &= setRotationAxis();
  513. result &= decompose();
  514. return result;
  515. }