123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358 |
- /****************************************************************************
- Copyright (c) 2010-2012 cocos2d-x.org
- Copyright (c) 2008-2010 Ricardo Quesada
- Copyright (c) 2011 Zynga Inc.
- http://www.cocos2d-x.org
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- ****************************************************************************/
- /**
- * @constant
- * @type Number
- */
- cc.INVALID_INDEX = -1;
- /**
- * PI is the ratio of a circle's circumference to its diameter.
- * @constant
- * @type Number
- */
- cc.PI = Math.PI;
- /**
- * @constant
- * @type Number
- */
- cc.FLT_MAX = parseFloat('3.402823466e+38F');
- /**
- * @constant
- * @type Number
- */
- cc.RAD = cc.PI / 180;
- /**
- * @constant
- * @type Number
- */
- cc.DEG = 180 / cc.PI;
- /**
- * maximum unsigned int value
- * @constant
- * @type Number
- */
- cc.UINT_MAX = 0xffffffff;
- /**
- * <p>
- * simple macro that swaps 2 variables<br/>
- * modified from c++ macro, you need to pass in the x and y variables names in string, <br/>
- * and then a reference to the whole object as third variable
- * </p>
- * @param x
- * @param y
- * @param ref
- * @function
- * @deprecated
- */
- cc.SWAP = function (x, y, ref) {
- if ((typeof ref) == 'object' && (typeof ref.x) != 'undefined' && (typeof ref.y) != 'undefined') {
- var tmp = ref[x];
- ref[x] = ref[y];
- ref[y] = tmp;
- } else
- cc.log("cc.SWAP is being modified from original macro, please check usage");
- };
- /**
- * <p>
- * Linear interpolation between 2 numbers, the ratio sets how much it is biased to each end
- * </p>
- * @param {Number} a number A
- * @param {Number} b number B
- * @param {Number} r ratio between 0 and 1
- * @function
- * @example
- * cc.lerp(2,10,0.5)//returns 6<br/>
- * cc.lerp(2,10,0.2)//returns 3.6
- */
- cc.lerp = function (a, b, r) {
- return a + (b - a) * r;
- };
- /**
- * returns a random float between -1 and 1
- * @return {Number}
- * @function
- */
- cc.RANDOM_MINUS1_1 = function () {
- return (Math.random() - 0.5) * 2;
- };
- /**
- * returns a random float between 0 and 1
- * @return {Number}
- * @function
- */
- cc.RANDOM_0_1 = function () {
- return Math.random();
- };
- /**
- * converts degrees to radians
- * @param {Number} angle
- * @return {Number}
- * @function
- */
- cc.DEGREES_TO_RADIANS = function (angle) {
- return angle * cc.RAD;
- };
- /**
- * converts radians to degrees
- * @param {Number} angle
- * @return {Number}
- * @function
- */
- cc.RADIANS_TO_DEGREES = function (angle) {
- return angle * cc.DEG;
- };
- /**
- * @constant
- * @type Number
- */
- cc.REPEAT_FOREVER = Number.MAX_VALUE - 1;
- /**
- * default gl blend src function. Compatible with premultiplied alpha images.
- * @constant
- * @type Number
- */
- cc.BLEND_SRC = cc.OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA ? 1 : 0x0302;
- /**
- * default gl blend dst function. Compatible with premultiplied alpha images.
- * @constant
- * @type Number
- */
- cc.BLEND_DST = 0x0303;
- /**
- * Helpful macro that setups the GL server state, the correct GL program and sets the Model View Projection matrix
- * @param {cc.Node} node setup node
- * @function
- */
- cc.NODE_DRAW_SETUP = function (node) {
- //cc.glEnable(node._glServerState);
- if (node._shaderProgram) {
- //cc.renderContext.useProgram(node._shaderProgram._programObj);
- node._shaderProgram.use();
- node._shaderProgram.setUniformForModelViewAndProjectionMatrixWithMat4();
- }
- };
- /**
- * <p>
- * GL states that are enabled:<br/>
- * - GL_TEXTURE_2D<br/>
- * - GL_VERTEX_ARRAY<br/>
- * - GL_TEXTURE_COORD_ARRAY<br/>
- * - GL_COLOR_ARRAY<br/>
- * </p>
- * @function
- */
- cc.ENABLE_DEFAULT_GL_STATES = function () {
- //TODO OPENGL STUFF
- /*
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_COLOR_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glEnable(GL_TEXTURE_2D);*/
- };
- /**
- * <p>
- * Disable default GL states:<br/>
- * - GL_TEXTURE_2D<br/>
- * - GL_TEXTURE_COORD_ARRAY<br/>
- * - GL_COLOR_ARRAY<br/>
- * </p>
- * @function
- */
- cc.DISABLE_DEFAULT_GL_STATES = function () {
- //TODO OPENGL
- /*
- glDisable(GL_TEXTURE_2D);
- glDisableClientState(GL_COLOR_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- glDisableClientState(GL_VERTEX_ARRAY);
- */
- };
- /**
- * <p>
- * Increments the GL Draws counts by one.<br/>
- * The number of calls per frame are displayed on the screen when the CCDirector's stats are enabled.<br/>
- * </p>
- * @param {Number} addNumber
- * @function
- */
- cc.INCREMENT_GL_DRAWS = function (addNumber) {
- cc.g_NumberOfDraws += addNumber;
- };
- /**
- * @constant
- * @type Number
- */
- cc.FLT_EPSILON = 0.0000001192092896;
- /**
- * <p>
- * On Mac it returns 1;<br/>
- * On iPhone it returns 2 if RetinaDisplay is On. Otherwise it returns 1
- * </p>
- * @function
- */
- cc.CONTENT_SCALE_FACTOR = cc.IS_RETINA_DISPLAY_SUPPORTED ? function () {
- return cc.Director.getInstance().getContentScaleFactor();
- } : function () {
- return 1;
- };
- /**
- * Converts a Point in points to pixels
- * @param {cc.Point} points
- * @return {cc.Point}
- * @function
- */
- cc.POINT_POINTS_TO_PIXELS = function (points) {
- var scale = cc.CONTENT_SCALE_FACTOR();
- return cc.p(points.x * scale, points.y * scale);
- };
- /**
- * Converts a Size in points to pixels
- * @param {cc.Size} sizeInPoints
- * @return {cc.Size}
- * @function
- */
- cc.SIZE_POINTS_TO_PIXELS = function (sizeInPoints) {
- var scale = cc.CONTENT_SCALE_FACTOR();
- return cc.size(sizeInPoints.width * scale, sizeInPoints.height * scale);
- };
- /**
- * Converts a size in pixels to points
- * @param {cc.Size} sizeInPixels
- * @return {cc.Size}
- * @function
- */
- cc.SIZE_PIXELS_TO_POINTS = function (sizeInPixels) {
- var scale = cc.CONTENT_SCALE_FACTOR();
- return cc.size(sizeInPixels.width / scale, sizeInPixels.height / scale);
- };
- /**
- * Converts a Point in pixels to points
- * @param {Point} pixels
- * @function
- */
- cc.POINT_PIXELS_TO_POINTS = function (pixels) {
- var scale = cc.CONTENT_SCALE_FACTOR();
- return cc.p(pixels.x / scale, pixels.y / scale);
- };
- /**
- * Converts a rect in pixels to points
- * @param {cc.Rect} pixel
- * @function
- */
- cc.RECT_PIXELS_TO_POINTS = cc.IS_RETINA_DISPLAY_SUPPORTED ? function (pixel) {
- var scale = cc.CONTENT_SCALE_FACTOR();
- return cc.rect(pixel.x / scale, pixel.y / scale,
- pixel.width / scale, pixel.height / scale);
- } : function (p) {
- return p;
- };
- /**
- * Converts a rect in points to pixels
- * @param {cc.Rect} point
- * @function
- */
- cc.RECT_POINTS_TO_PIXELS = cc.IS_RETINA_DISPLAY_SUPPORTED ? function (point) {
- var scale = cc.CONTENT_SCALE_FACTOR();
- return cc.rect(point.x * scale, point.y * scale,
- point.width * scale, point.height * scale);
- } : function (p) {
- return p;
- };
- if (!cc.Browser.supportWebGL) {
- /**
- * WebGL constants
- * @type {object}
- */
- var gl = gl || {};
- /**
- * @constant
- * @type Number
- */
- gl.ONE = 1;
- /**
- * @constant
- * @type Number
- */
- gl.ZERO = 0;
- /**
- * @constant
- * @type Number
- */
- gl.SRC_ALPHA = 0x0302;
- /**
- * @constant
- * @type Number
- */
- gl.ONE_MINUS_SRC_ALPHA = 0x0303;
- /**
- * @constant
- * @type Number
- */
- gl.ONE_MINUS_DST_COLOR = 0x0307;
- }
- cc.CHECK_GL_ERROR_DEBUG = function () {
- if (cc.renderMode == cc.WEBGL) {
- var _error = cc.renderContext.getError();
- if (_error) {
- cc.log("WebGL error " + _error);
- }
- }
- };
|