PageRenderTime 30ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llmath/tests/xform_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 245 lines | 168 code | 34 blank | 43 comment | 47 complexity | d725eeb1a1ed2ed85b957a4c36e9cd96 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file xform_test.cpp
  3. * @author Adroit
  4. * @date March 2007
  5. * @brief Test cases for LLXform
  6. *
  7. * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  8. * Second Life Viewer Source Code
  9. * Copyright (C) 2010, Linden Research, Inc.
  10. *
  11. * This library is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU Lesser General Public
  13. * License as published by the Free Software Foundation;
  14. * version 2.1 of the License only.
  15. *
  16. * This library is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public
  22. * License along with this library; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. *
  25. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  26. * $/LicenseInfo$
  27. */
  28. #include "linden_common.h"
  29. #include "../test/lltut.h"
  30. #include "../xform.h"
  31. namespace tut
  32. {
  33. struct xform_test
  34. {
  35. };
  36. typedef test_group<xform_test> xform_test_t;
  37. typedef xform_test_t::object xform_test_object_t;
  38. tut::xform_test_t tut_xform_test("LLXForm");
  39. //test case for init(), getParent(), getRotation(), getPositionW(), getWorldRotation() fns.
  40. template<> template<>
  41. void xform_test_object_t::test<1>()
  42. {
  43. LLXform xform_obj;
  44. LLVector3 emptyVec(0.f,0.f,0.f);
  45. LLVector3 initialScaleVec(1.f,1.f,1.f);
  46. ensure("LLXform empty constructor failed: ", !xform_obj.getParent() && !xform_obj.isChanged() &&
  47. xform_obj.getPosition() == emptyVec &&
  48. (xform_obj.getRotation()).isIdentity() &&
  49. xform_obj.getScale() == initialScaleVec &&
  50. xform_obj.getPositionW() == emptyVec &&
  51. (xform_obj.getWorldRotation()).isIdentity() &&
  52. !xform_obj.getScaleChildOffset());
  53. }
  54. // test cases for
  55. // setScale(const LLVector3& scale)
  56. // setScale(const F32 x, const F32 y, const F32 z)
  57. // setRotation(const F32 x, const F32 y, const F32 z)
  58. // setPosition(const F32 x, const F32 y, const F32 z)
  59. // getLocalMat4(LLMatrix4 &mat)
  60. template<> template<>
  61. void xform_test_object_t::test<2>()
  62. {
  63. LLMatrix4 llmat4;
  64. LLXform xform_obj;
  65. F32 x = 3.6f;
  66. F32 y = 5.5f;
  67. F32 z = 4.2f;
  68. F32 w = 0.f;
  69. F32 posz = z + 2.122f;
  70. LLVector3 vec(x, y, z);
  71. xform_obj.setScale(x, y, z);
  72. xform_obj.setPosition(x, y, posz);
  73. ensure("setScale failed: ", xform_obj.getScale() == vec);
  74. vec.setVec(x, y, posz);
  75. ensure("getPosition failed: ", xform_obj.getPosition() == vec);
  76. x = x * 2.f;
  77. y = y + 2.3f;
  78. z = posz * 4.f;
  79. vec.setVec(x, y, z);
  80. xform_obj.setPositionX(x);
  81. xform_obj.setPositionY(y);
  82. xform_obj.setPositionZ(z);
  83. ensure("setPositionX/Y/Z failed: ", xform_obj.getPosition() == vec);
  84. xform_obj.setScaleChildOffset(TRUE);
  85. ensure("setScaleChildOffset failed: ", xform_obj.getScaleChildOffset());
  86. vec.setVec(x, y, z);
  87. xform_obj.addPosition(vec);
  88. vec += vec;
  89. ensure("addPosition failed: ", xform_obj.getPosition() == vec);
  90. xform_obj.setScale(vec);
  91. ensure("setScale vector failed: ", xform_obj.getScale() == vec);
  92. LLQuaternion quat(x, y, z, w);
  93. xform_obj.setRotation(quat);
  94. ensure("setRotation quat failed: ", xform_obj.getRotation() == quat);
  95. xform_obj.setRotation(x, y, z, w);
  96. ensure("getRotation 2 failed: ", xform_obj.getRotation() == quat);
  97. xform_obj.setRotation(x, y, z);
  98. quat.setQuat(x,y,z);
  99. ensure("setRotation xyz failed: ", xform_obj.getRotation() == quat);
  100. // LLXform::setRotation(const F32 x, const F32 y, const F32 z)
  101. // Does normalization
  102. // LLXform::setRotation(const F32 x, const F32 y, const F32 z, const F32 s)
  103. // Simply copies the individual values - does not do any normalization.
  104. // Is that the expected behavior?
  105. }
  106. // test cases for inline BOOL setParent(LLXform *parent) and getParent() fn.
  107. template<> template<>
  108. void xform_test_object_t::test<3>()
  109. {
  110. LLXform xform_obj;
  111. LLXform par;
  112. LLXform grandpar;
  113. xform_obj.setParent(&par);
  114. par.setParent(&grandpar);
  115. ensure("setParent/getParent failed: ", &par == xform_obj.getParent());
  116. ensure("getRoot failed: ", &grandpar == xform_obj.getRoot());
  117. ensure("isRoot failed: ", grandpar.isRoot() && !par.isRoot() && !xform_obj.isRoot());
  118. ensure("isRootEdit failed: ", grandpar.isRootEdit() && !par.isRootEdit() && !xform_obj.isRootEdit());
  119. }
  120. template<> template<>
  121. void xform_test_object_t::test<4>()
  122. {
  123. LLXform xform_obj;
  124. xform_obj.setChanged(LLXform::TRANSLATED | LLXform::ROTATED | LLXform::SCALED);
  125. ensure("setChanged/isChanged failed: ", xform_obj.isChanged());
  126. xform_obj.clearChanged(LLXform::TRANSLATED | LLXform::ROTATED | LLXform::SCALED);
  127. ensure("clearChanged failed: ", !xform_obj.isChanged());
  128. LLVector3 llvect3(12.4f, -5.6f, 0.34f);
  129. xform_obj.setScale(llvect3);
  130. ensure("setScale did not set SCALED flag: ", xform_obj.isChanged(LLXform::SCALED));
  131. xform_obj.setPosition(1.2f, 2.3f, 3.4f);
  132. ensure("setScale did not set TRANSLATED flag: ", xform_obj.isChanged(LLXform::TRANSLATED));
  133. ensure("TRANSLATED reset SCALED flag: ", xform_obj.isChanged(LLXform::TRANSLATED | LLXform::SCALED));
  134. xform_obj.clearChanged(LLXform::SCALED);
  135. ensure("reset SCALED failed: ", !xform_obj.isChanged(LLXform::SCALED));
  136. xform_obj.setRotation(1, 2, 3, 4);
  137. ensure("ROTATION flag not set ", xform_obj.isChanged(LLXform::TRANSLATED | LLXform::ROTATED));
  138. xform_obj.setScale(llvect3);
  139. ensure("ROTATION flag not set ", xform_obj.isChanged(LLXform::MOVED));
  140. }
  141. //to test init() and getWorldMatrix() fns.
  142. template<> template<>
  143. void xform_test_object_t::test<5>()
  144. {
  145. LLXformMatrix formMatrix_obj;
  146. formMatrix_obj.init();
  147. LLMatrix4 mat4_obj;
  148. ensure("1. The value is not NULL", 1.f == formMatrix_obj.getWorldMatrix().mMatrix[0][0]);
  149. ensure("2. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[0][1]);
  150. ensure("3. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[0][2]);
  151. ensure("4. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[0][3]);
  152. ensure("5. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[1][0]);
  153. ensure("6. The value is not NULL", 1.f == formMatrix_obj.getWorldMatrix().mMatrix[1][1]);
  154. ensure("7. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[1][2]);
  155. ensure("8. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[1][3]);
  156. ensure("9. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[2][0]);
  157. ensure("10. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[2][1]);
  158. ensure("11. The value is not NULL", 1.f == formMatrix_obj.getWorldMatrix().mMatrix[2][2]);
  159. ensure("12. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[2][3]);
  160. ensure("13. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[3][0]);
  161. ensure("14. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[3][1]);
  162. ensure("15. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[3][2]);
  163. ensure("16. The value is not NULL", 1.f == formMatrix_obj.getWorldMatrix().mMatrix[3][3]);
  164. }
  165. //to test mMin.clearVec() and mMax.clearVec() fns
  166. template<> template<>
  167. void xform_test_object_t::test<6>()
  168. {
  169. LLXformMatrix formMatrix_obj;
  170. formMatrix_obj.init();
  171. LLVector3 llmin_vec3;
  172. LLVector3 llmax_vec3;
  173. formMatrix_obj.getMinMax(llmin_vec3, llmax_vec3);
  174. ensure("1. The value is not NULL", 0.f == llmin_vec3.mV[0]);
  175. ensure("2. The value is not NULL", 0.f == llmin_vec3.mV[1]);
  176. ensure("3. The value is not NULL", 0.f == llmin_vec3.mV[2]);
  177. ensure("4. The value is not NULL", 0.f == llmin_vec3.mV[0]);
  178. ensure("5. The value is not NULL", 0.f == llmin_vec3.mV[1]);
  179. ensure("6. The value is not NULL", 0.f == llmin_vec3.mV[2]);
  180. }
  181. //test case of update() fn.
  182. template<> template<>
  183. void xform_test_object_t::test<7>()
  184. {
  185. LLXformMatrix formMatrix_obj;
  186. LLXformMatrix parent;
  187. LLVector3 llvecpos(1.0, 2.0, 3.0);
  188. LLVector3 llvecpospar(10.0, 20.0, 30.0);
  189. formMatrix_obj.setPosition(llvecpos);
  190. parent.setPosition(llvecpospar);
  191. LLVector3 llvecparentscale(1.0, 2.0, 0);
  192. parent.setScaleChildOffset(TRUE);
  193. parent.setScale(llvecparentscale);
  194. LLQuaternion quat(1, 2, 3, 4);
  195. LLQuaternion quatparent(5, 6, 7, 8);
  196. formMatrix_obj.setRotation(quat);
  197. parent.setRotation(quatparent);
  198. formMatrix_obj.setParent(&parent);
  199. parent.update();
  200. formMatrix_obj.update();
  201. LLVector3 worldPos = llvecpos;
  202. worldPos.scaleVec(llvecparentscale);
  203. worldPos *= quatparent;
  204. worldPos += llvecpospar;
  205. LLQuaternion worldRot = quat * quatparent;
  206. ensure("getWorldPosition failed: ", formMatrix_obj.getWorldPosition() == worldPos);
  207. ensure("getWorldRotation failed: ", formMatrix_obj.getWorldRotation() == worldRot);
  208. ensure("getWorldPosition for parent failed: ", parent.getWorldPosition() == llvecpospar);
  209. ensure("getWorldRotation for parent failed: ", parent.getWorldRotation() == quatparent);
  210. }
  211. }