test_compose_matrix.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. from panda3d import core
  2. import pytest
  3. @pytest.mark.parametrize("coordsys", (core.CS_zup_right, core.CS_yup_right, core.CS_zup_left, core.CS_yup_left))
  4. def test_compose_matrix(coordsys):
  5. scale = core.LVecBase3(1.2, 0.5, 2)
  6. hpr = core.LVecBase3(45, -90, 12.5)
  7. shear = core.LVecBase3(0, 0, 0)
  8. mat = core.LMatrix3()
  9. core.compose_matrix(mat, scale, shear, hpr, coordsys)
  10. new_scale = core.LVecBase3()
  11. new_hpr = core.LVecBase3()
  12. new_shear = core.LVecBase3()
  13. core.decompose_matrix(mat, new_scale, new_shear, new_hpr, coordsys)
  14. assert new_scale.almost_equal(scale)
  15. assert new_shear.almost_equal(shear)
  16. quat = core.LQuaternion()
  17. quat.set_hpr(hpr, coordsys)
  18. new_quat = core.LQuaternion()
  19. new_quat.set_hpr(new_hpr, coordsys)
  20. assert quat.is_same_direction(new_quat)
  21. @pytest.mark.parametrize("coordsys", (core.CS_zup_right, core.CS_yup_right, core.CS_zup_left, core.CS_yup_left))
  22. def test_compose_matrix2(coordsys):
  23. mat = core.LMatrix3(1, 0, 0, 0, 0, -1, 0, 1, 0)
  24. new_scale = core.LVecBase3()
  25. new_hpr = core.LVecBase3()
  26. new_shear = core.LVecBase3()
  27. core.decompose_matrix(mat, new_scale, new_shear, new_hpr, coordsys)
  28. assert new_scale.almost_equal(core.LVecBase3(1, 1, 1))
  29. if coordsys in (core.CS_zup_left, core.CS_yup_left):
  30. assert new_hpr.almost_equal(core.LVecBase3(0, 90, 0))
  31. else:
  32. assert new_hpr.almost_equal(core.LVecBase3(0, -90, 0))
  33. assert new_shear.almost_equal(core.LVecBase3(0, 0, 0))