xform_tut.cpp

Go to the documentation of this file.
00001 
00034 #include <tut/tut.h>
00035 #include "linden_common.h"
00036 #include "lltut.h"
00037 #include "xform.h"
00038 
00039 namespace tut
00040 {
00041         struct xform_test
00042         {
00043         };
00044         typedef test_group<xform_test> xform_test_t;
00045         typedef xform_test_t::object xform_test_object_t;
00046         tut::xform_test_t tut_xform_test("xform_test");
00047 
00048         //test case for init(), getParent(), getRotation(), getPositionW(), getWorldRotation() fns.
00049         template<> template<>
00050         void xform_test_object_t::test<1>()
00051         {
00052                 LLXform xform_obj;
00053                 LLVector3 emptyVec(0.f,0.f,0.f);
00054                 LLVector3 initialScaleVec(1.f,1.f,1.f);
00055 
00056                 ensure("LLXform empty constructor failed: ", !xform_obj.getParent() && !xform_obj.isChanged() &&
00057                         xform_obj.getPosition() == emptyVec && 
00058                         (xform_obj.getRotation()).isIdentity() &&
00059                         xform_obj.getScale() == initialScaleVec && 
00060                         xform_obj.getPositionW() == emptyVec && 
00061                         (xform_obj.getWorldRotation()).isIdentity() &&
00062                         !xform_obj.getScaleChildOffset());
00063         }
00064 
00065         // test cases for 
00066         // setScale(const LLVector3& scale) 
00067         // setScale(const F32 x, const F32 y, const F32 z)
00068         // setRotation(const F32 x, const F32 y, const F32 z) 
00069         // setPosition(const F32 x, const F32 y, const F32 z) 
00070         // getLocalMat4(LLMatrix4 &mat)
00071         template<> template<>
00072         void xform_test_object_t::test<2>()     
00073         {
00074                 LLMatrix4 llmat4;
00075                 LLXform xform_obj;
00076 
00077                 F32 x = 3.6f;
00078                 F32 y = 5.5f;
00079                 F32 z = 4.2f;
00080                 F32 w = 0.f;
00081                 F32 posz = z + 2.122f;
00082                 LLVector3 vec(x, y, z);
00083                 xform_obj.setScale(x, y, z);
00084                 xform_obj.setPosition(x, y, posz);
00085                 ensure("setScale failed: ", xform_obj.getScale() == vec);
00086 
00087                 vec.setVec(x, y, posz);
00088                 ensure("getPosition failed: ", xform_obj.getPosition() == vec);
00089 
00090                 x = x * 2.f;
00091                 y = y + 2.3f;
00092                 z = posz * 4.f; 
00093                 vec.setVec(x, y, z);
00094                 xform_obj.setPositionX(x);
00095                 xform_obj.setPositionY(y);
00096                 xform_obj.setPositionZ(z);
00097                 ensure("setPositionX/Y/Z failed: ", xform_obj.getPosition() == vec);
00098 
00099                 xform_obj.setScaleChildOffset(TRUE);
00100                 ensure("setScaleChildOffset failed: ", xform_obj.getScaleChildOffset());
00101 
00102                 vec.setVec(x, y, z);
00103 
00104                 xform_obj.addPosition(vec);
00105                 vec += vec;
00106                 ensure("addPosition failed: ", xform_obj.getPosition() == vec);
00107 
00108                 xform_obj.setScale(vec);
00109                 ensure("setScale vector failed: ", xform_obj.getScale() == vec);
00110 
00111                 LLQuaternion quat(x, y, z, w);
00112                 xform_obj.setRotation(quat);
00113                 ensure("setRotation quat failed: ", xform_obj.getRotation() == quat);
00114 
00115                 xform_obj.setRotation(x, y, z, w);
00116                 ensure("getRotation 2 failed: ", xform_obj.getRotation() == quat);
00117 
00118                 xform_obj.setRotation(x, y, z);
00119                 quat.setQuat(x,y,z); 
00120                 ensure("setRotation xyz failed: ", xform_obj.getRotation() == quat);
00121 
00122                 // LLXform::setRotation(const F32 x, const F32 y, const F32 z) 
00123                 //              Does normalization
00124                 // LLXform::setRotation(const F32 x, const F32 y, const F32 z, const F32 s) 
00125                 //              Simply copies the individual values - does not do any normalization. 
00126                 // Is that the expected behavior?
00127         }
00128 
00129         // test cases for inline BOOL setParent(LLXform *parent) and getParent() fn.
00130         template<> template<>
00131         void xform_test_object_t::test<3>()     
00132         {               
00133                 LLXform xform_obj;
00134                 LLXform par;
00135                 LLXform grandpar;
00136                 xform_obj.setParent(&par); 
00137                 par.setParent(&grandpar); 
00138                 ensure("setParent/getParent failed: ", &par == xform_obj.getParent());
00139                 ensure("getRoot failed: ", &grandpar == xform_obj.getRoot());
00140                 ensure("isRoot failed: ", grandpar.isRoot() && !par.isRoot() && !xform_obj.isRoot());
00141                 ensure("isRootEdit failed: ", grandpar.isRootEdit() && !par.isRootEdit() && !xform_obj.isRootEdit());
00142         }
00143 
00144         template<> template<>
00145         void xform_test_object_t::test<4>()     
00146         {
00147                 LLXform xform_obj;
00148                 xform_obj.setChanged(LLXform::TRANSLATED | LLXform::ROTATED | LLXform::SCALED);
00149                 ensure("setChanged/isChanged failed: ", xform_obj.isChanged());
00150 
00151                 xform_obj.clearChanged(LLXform::TRANSLATED | LLXform::ROTATED | LLXform::SCALED);
00152                 ensure("clearChanged failed: ", !xform_obj.isChanged());
00153                 
00154                 LLVector3 llvect3(12.4f, -5.6f, 0.34f);
00155                 xform_obj.setScale(llvect3);
00156                 ensure("setScale did not set SCALED flag: ", xform_obj.isChanged(LLXform::SCALED));
00157                 xform_obj.setPosition(1.2f, 2.3f, 3.4f);
00158                 ensure("setScale did not set TRANSLATED flag: ", xform_obj.isChanged(LLXform::TRANSLATED));
00159                 ensure("TRANSLATED reset SCALED flag: ", xform_obj.isChanged(LLXform::TRANSLATED | LLXform::SCALED));
00160                 xform_obj.clearChanged(LLXform::SCALED);
00161                 ensure("reset SCALED failed: ", !xform_obj.isChanged(LLXform::SCALED));
00162                 xform_obj.setRotation(1, 2, 3, 4);
00163                 ensure("ROTATION flag not set ", xform_obj.isChanged(LLXform::TRANSLATED | LLXform::ROTATED));
00164                 xform_obj.setScale(llvect3);
00165                 ensure("ROTATION flag not set ", xform_obj.isChanged(LLXform::MOVED));
00166         }
00167 
00168         //to test init() and getWorldMatrix() fns.
00169         template<> template<>
00170         void xform_test_object_t::test<5>()     
00171         {
00172                 LLXformMatrix formMatrix_obj;
00173                 formMatrix_obj.init();
00174                 LLMatrix4 mat4_obj;
00175                 
00176                 ensure("1. The value is not NULL", 1.f == formMatrix_obj.getWorldMatrix().mMatrix[0][0]);
00177                 ensure("2. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[0][1]);
00178                 ensure("3. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[0][2]);
00179                 ensure("4. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[0][3]);
00180                 ensure("5. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[1][0]);
00181                 ensure("6. The value is not NULL", 1.f == formMatrix_obj.getWorldMatrix().mMatrix[1][1]);
00182                 ensure("7. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[1][2]);
00183                 ensure("8. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[1][3]);
00184                 ensure("9. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[2][0]);
00185                 ensure("10. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[2][1]);
00186                 ensure("11. The value is not NULL", 1.f == formMatrix_obj.getWorldMatrix().mMatrix[2][2]);
00187                 ensure("12. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[2][3]);
00188                 ensure("13. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[3][0]);
00189                 ensure("14. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[3][1]);
00190                 ensure("15. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[3][2]);
00191                 ensure("16. The value is not NULL", 1.f == formMatrix_obj.getWorldMatrix().mMatrix[3][3]);
00192         }
00193 
00194         //to test mMin.clearVec() and mMax.clearVec() fns
00195         template<> template<>
00196         void xform_test_object_t::test<6>()     
00197         {
00198                 LLXformMatrix formMatrix_obj;
00199                 formMatrix_obj.init();
00200                 LLVector3 llmin_vec3;
00201                 LLVector3 llmax_vec3;
00202                 formMatrix_obj.getMinMax(llmin_vec3, llmax_vec3);
00203                 ensure("1. The value is not NULL", 0.f == llmin_vec3.mV[0]);
00204                 ensure("2. The value is not NULL", 0.f == llmin_vec3.mV[1]);
00205                 ensure("3. The value is not NULL", 0.f == llmin_vec3.mV[2]);
00206                 ensure("4. The value is not NULL", 0.f == llmin_vec3.mV[0]);
00207                 ensure("5. The value is not NULL", 0.f == llmin_vec3.mV[1]);
00208                 ensure("6. The value is not NULL", 0.f == llmin_vec3.mV[2]);
00209         }
00210 
00211         //test case of update() fn.
00212         template<> template<>
00213         void xform_test_object_t::test<7>()     
00214         {
00215                 LLXformMatrix formMatrix_obj;
00216 
00217                 LLXformMatrix parent;
00218                 LLVector3 llvecpos(1.0, 2.0, 3.0);
00219                 LLVector3 llvecpospar(10.0, 20.0, 30.0);
00220                 formMatrix_obj.setPosition(llvecpos);
00221                 parent.setPosition(llvecpospar);
00222 
00223                 LLVector3 llvecparentscale(1.0, 2.0, 0);
00224                 parent.setScaleChildOffset(TRUE);
00225                 parent.setScale(llvecparentscale);
00226 
00227                 LLQuaternion quat(1, 2, 3, 4);
00228                 LLQuaternion quatparent(5, 6, 7, 8);
00229                 formMatrix_obj.setRotation(quat);
00230                 parent.setRotation(quatparent);
00231                 formMatrix_obj.setParent(&parent);
00232 
00233                 parent.update();
00234                 formMatrix_obj.update();
00235 
00236                 LLVector3 worldPos = llvecpos;
00237                 worldPos.scaleVec(llvecparentscale);
00238                 worldPos *= quatparent;
00239                 worldPos += llvecpospar;
00240 
00241                 LLQuaternion worldRot = quat * quatparent; 
00242 
00243                 ensure("getWorldPosition failed: ", formMatrix_obj.getWorldPosition() == worldPos);
00244                 ensure("getWorldRotation failed: ", formMatrix_obj.getWorldRotation() == worldRot);
00245 
00246                 ensure("getWorldPosition for parent failed: ", parent.getWorldPosition() == llvecpospar);
00247                 ensure("getWorldRotation for parent failed: ", parent.getWorldRotation() == quatparent);
00248         }
00249 }       
00250 

Generated on Thu Jul 1 06:10:03 2010 for Second Life Viewer by  doxygen 1.4.7