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