TransformUtils.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /****************************************************************************
  2. Copyright (c) 2008-2010 Ricardo Quesada
  3. Copyright (c) 2011-2012 cocos2d-x.org
  4. Copyright (c) 2013-2014 Chukong Technologies Inc.
  5. Copyright (c) 2009 Valentin Milea
  6. http://www.cocos2d-x.org
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. ****************************************************************************/
  23. /**
  24. * convert an affine transform object to a kmMat4 object
  25. * @param {cc.AffineTransform} trans
  26. * @param {cc.kmMat4} mat
  27. * @function
  28. */
  29. cc.CGAffineToGL = function (trans, mat) {
  30. // | m[0] m[4] m[8] m[12] | | m11 m21 m31 m41 | | a c 0 tx |
  31. // | m[1] m[5] m[9] m[13] | | m12 m22 m32 m42 | | b d 0 ty |
  32. // | m[2] m[6] m[10] m[14] | <=> | m13 m23 m33 m43 | <=> | 0 0 1 0 |
  33. // | m[3] m[7] m[11] m[15] | | m14 m24 m34 m44 | | 0 0 0 1 |
  34. mat[2] = mat[3] = mat[6] = mat[7] = mat[8] = mat[9] = mat[11] = mat[14] = 0.0;
  35. mat[10] = mat[15] = 1.0;
  36. mat[0] = trans.a;
  37. mat[4] = trans.c;
  38. mat[12] = trans.tx;
  39. mat[1] = trans.b;
  40. mat[5] = trans.d;
  41. mat[13] = trans.ty;
  42. };
  43. /**
  44. * Convert a kmMat4 object to an affine transform object
  45. * @param {cc.kmMat4} mat
  46. * @param {cc.AffineTransform} trans
  47. * @function
  48. */
  49. cc.GLToCGAffine = function (mat, trans) {
  50. trans.a = mat[0];
  51. trans.c = mat[4];
  52. trans.tx = mat[12];
  53. trans.b = mat[1];
  54. trans.d = mat[5];
  55. trans.ty = mat[13];
  56. };