diff --git a/Base64Images.js b/Base64Images.js
deleted file mode 100644
index 0d983506be..0000000000
--- a/Base64Images.js
+++ /dev/null
@@ -1,32 +0,0 @@
-/****************************************************************************
- Copyright (c) 2011-2012 cocos2d-x.org
- Copyright (c) 2013-2014 Chukong Technologies 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.
- ****************************************************************************/
-
-var cc = cc || {};
-
-cc._loadingImage = "data:image/gif;base64,R0lGODlhEAAQALMNAD8/P7+/vyoqKlVVVX9/fxUVFUBAQGBgYMDAwC8vL5CQkP///wAAAP///wAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQFAAANACwAAAAAEAAQAAAEO5DJSau9OOvNex0IMnDIsiCkiW6g6BmKYlBFkhSUEgQKlQCARG6nEBwOgl+QApMdCIRD7YZ5RjlGpCUCACH5BAUAAA0ALAAAAgAOAA4AAAQ6kLGB0JA4M7QW0hrngRllkYyhKAYqKUGguAws0ypLS8JxCLQDgXAIDg+FRKIA6v0SAECCBpXSkstMBAAh+QQFAAANACwAAAAACgAQAAAEOJDJORAac6K1kDSKYmydpASBUl0mqmRfaGTCcQgwcxDEke+9XO2WkxQSiUIuAQAkls0n7JgsWq8RACH5BAUAAA0ALAAAAAAOAA4AAAQ6kMlplDIzTxWC0oxwHALnDQgySAdBHNWFLAvCukc215JIZihVIZEogDIJACBxnCSXTcmwGK1ar1hrBAAh+QQFAAANACwAAAAAEAAKAAAEN5DJKc4RM+tDyNFTkSQF5xmKYmQJACTVpQSBwrpJNteZSGYoFWjIGCAQA2IGsVgglBOmEyoxIiMAIfkEBQAADQAsAgAAAA4ADgAABDmQSVZSKjPPBEDSGucJxyGA1XUQxAFma/tOpDlnhqIYN6MEAUXvF+zldrMBAjHoIRYLhBMqvSmZkggAIfkEBQAADQAsBgAAAAoAEAAABDeQyUmrnSWlYhMASfeFVbZdjHAcgnUQxOHCcqWylKEohqUEAYVkgEAMfkEJYrFA6HhKJsJCNFoiACH5BAUAAA0ALAIAAgAOAA4AAAQ3kMlJq704611SKloCAEk4lln3DQgyUMJxCBKyLAh1EMRR3wiDQmHY9SQslyIQUMRmlmVTIyRaIgA7";
-
-cc._fpsImage = "data:image/png;base64,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";
-
-cc._loaderImage = "data:image/jpeg;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAAAlAAD/4QMpaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCI/PiA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJBZG9iZSBYTVAgQ29yZSA1LjAtYzA2MCA2MS4xMzQ3NzcsIDIwMTAvMDIvMTItMTc6MzI6MDAgICAgICAgICI+IDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI+IDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PSIiIHhtbG5zOnhtcE1NPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvbW0vIiB4bWxuczpzdFJlZj0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL3NUeXBlL1Jlc291cmNlUmVmIyIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bXBNTTpEb2N1bWVudElEPSJ4bXAuZGlkOjM4MDBEMDY2QTU1MjExRTFBQTAzQjEzMUNFNzMxRkQwIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOjM4MDBEMDY1QTU1MjExRTFBQTAzQjEzMUNFNzMxRkQwIiB4bXA6Q3JlYXRvclRvb2w9IkFkb2JlIFBob3Rvc2hvcCBDUzUgV2luZG93cyI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkU2RTk0OEM4OERCNDExRTE5NEUyRkE3M0M3QkE1NTlEIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOkU2RTk0OEM5OERCNDExRTE5NEUyRkE3M0M3QkE1NTlEIi8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+/+4ADkFkb2JlAGTAAAAAAf/bAIQADQkJCQoJDQoKDRMMCwwTFhENDREW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";
diff --git a/cocos2d/actions/CCActionCamera.js b/cocos2d/actions/CCActionCamera.js
index 90b8a432c0..9f57d1a1f8 100644
--- a/cocos2d/actions/CCActionCamera.js
+++ b/cocos2d/actions/CCActionCamera.js
@@ -193,9 +193,9 @@ cc.OrbitCamera = cc.ActionCamera.extend({
var r = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2));
var s = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
if (s === 0.0)
- s = cc.Macro.FLT_EPSILON;
+ s = cc.macro.FLT_EPSILON;
if (r === 0.0)
- r = cc.Macro.FLT_EPSILON;
+ r = cc.macro.FLT_EPSILON;
zenith = Math.acos(z / r);
if (x < 0)
diff --git a/cocos2d/actions/CCActionCatmullRom.js b/cocos2d/actions/CCActionCatmullRom.js
index b85de71125..d7ee983e17 100644
--- a/cocos2d/actions/CCActionCatmullRom.js
+++ b/cocos2d/actions/CCActionCatmullRom.js
@@ -216,7 +216,7 @@ cc.CardinalSplineTo = cc.ActionInterval.extend({
cc.getControlPointAt(ps, p + 2),
this._tension, lt);
- if (cc.Macro.ENABLE_STACKABLE_ACTIONS) {
+ if (cc.macro.ENABLE_STACKABLE_ACTIONS) {
var tempX, tempY;
tempX = this.target.getPositionX() - this._previousPosition.x;
tempY = this.target.getPositionY() - this._previousPosition.y;
diff --git a/cocos2d/actions/CCActionInterval.js b/cocos2d/actions/CCActionInterval.js
index 11b0b7822c..59c2761741 100644
--- a/cocos2d/actions/CCActionInterval.js
+++ b/cocos2d/actions/CCActionInterval.js
@@ -1093,7 +1093,7 @@ cc.MoveBy = cc.ActionInterval.extend({
var x = this._positionDelta.x * dt;
var y = this._positionDelta.y * dt;
var locStartPosition = this._startPosition;
- if (cc.Macro.ENABLE_STACKABLE_ACTIONS) {
+ if (cc.macro.ENABLE_STACKABLE_ACTIONS) {
var targetX = this.target.getPositionX();
var targetY = this.target.getPositionY();
var locPreviousPosition = this._previousPosition;
@@ -1460,7 +1460,7 @@ cc.JumpBy = cc.ActionInterval.extend({
var x = this._delta.x * dt;
var locStartPosition = this._startPosition;
- if (cc.Macro.ENABLE_STACKABLE_ACTIONS) {
+ if (cc.macro.ENABLE_STACKABLE_ACTIONS) {
var targetX = this.target.getPositionX();
var targetY = this.target.getPositionY();
var locPreviousPosition = this._previousPosition;
@@ -1680,7 +1680,7 @@ cc.BezierBy = cc.ActionInterval.extend({
var y = cc.bezierAt(ya, yb, yc, yd, dt);
var locStartPosition = this._startPosition;
- if (cc.Macro.ENABLE_STACKABLE_ACTIONS) {
+ if (cc.macro.ENABLE_STACKABLE_ACTIONS) {
var targetX = this.target.getPositionX();
var targetY = this.target.getPositionY();
var locPreviousPosition = this._previousPosition;
diff --git a/cocos2d/clipping-nodes/CCClippingNodeWebGLRenderCmd.js b/cocos2d/clipping-nodes/CCClippingNodeWebGLRenderCmd.js
index c4dd0bdeb9..c66867c9e9 100644
--- a/cocos2d/clipping-nodes/CCClippingNodeWebGLRenderCmd.js
+++ b/cocos2d/clipping-nodes/CCClippingNodeWebGLRenderCmd.js
@@ -144,28 +144,28 @@
proto._drawFullScreenQuadClearStencil = function () {
// draw a fullscreen solid rectangle to clear the stencil buffer
- var projStack = cc.projection_matrix_stack;
- //cc.kmGLMatrixMode(cc.KM_GL_PROJECTION);
- //cc.kmGLPushMatrix();
- //cc.kmGLLoadIdentity();
+ var projStack = cc.math.projection_matrix_stack;
+ //cc.math.glMatrixMode(cc.math.KM_GL_PROJECTION);
+ //cc.math.glPushMatrix();
+ //cc.math.glLoadIdentity();
projStack.push();
projStack.top.identity();
- //cc.kmGLMatrixMode(cc.KM_GL_MODELVIEW);
- //cc.kmGLPushMatrix();
- //cc.kmGLLoadIdentity();
- var modelViewStack = cc.modelview_matrix_stack;
+ //cc.math.glMatrixMode(cc.math.KM_GL_MODELVIEW);
+ //cc.math.glPushMatrix();
+ //cc.math.glLoadIdentity();
+ var modelViewStack = cc.math.modelview_matrix_stack;
modelViewStack.push();
modelViewStack.top.identity();
cc._drawingUtil.drawSolidRect(cc.p(-1, -1), cc.p(1, 1), cc.color(255, 255, 255, 255));
- //cc.kmGLMatrixMode(cc.KM_GL_PROJECTION);
- //cc.kmGLPopMatrix();
+ //cc.math.glMatrixMode(cc.math.KM_GL_PROJECTION);
+ //cc.math.glPopMatrix();
projStack.pop();
- //cc.kmGLMatrixMode(cc.KM_GL_MODELVIEW);
- //cc.kmGLPopMatrix();
+ //cc.math.glMatrixMode(cc.math.KM_GL_MODELVIEW);
+ //cc.math.glPopMatrix();
modelViewStack.pop();
};
@@ -206,8 +206,8 @@
gl.stencilOp(!node.inverted ? gl.REPLACE : gl.ZERO, gl.KEEP, gl.KEEP);
if (node.alphaThreshold < 1) { //TODO desktop
- var program = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLORALPHATEST);
- var alphaValueLocation = gl.getUniformLocation(program.getProgram(), cc.Macro.UNIFORM_ALPHA_TEST_VALUE_S);
+ var program = cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLORALPHATEST);
+ var alphaValueLocation = gl.getUniformLocation(program.getProgram(), cc.macro.UNIFORM_ALPHA_TEST_VALUE_S);
// set our alphaThreshold
cc.glUseProgram(program.getProgram());
program.setUniformLocationWith1f(alphaValueLocation, node.alphaThreshold);
diff --git a/cocos2d/core/CCCamera.js b/cocos2d/core/CCCamera.js
index de35d78e95..c55aaed99a 100644
--- a/cocos2d/core/CCCamera.js
+++ b/cocos2d/core/CCCamera.js
@@ -119,7 +119,7 @@ cc.Camera = cc._Class.extend({
this._lookupMatrix.lookAt(eye, center, up);
this._dirty = false;
}
- cc.kmGLMultMatrix( this._lookupMatrix);
+ cc.math.glMultMatrix( this._lookupMatrix);
},
_locateForRenderer: function(matrix){
@@ -278,5 +278,5 @@ cc.Camera = cc._Class.extend({
* @return {Number}
*/
cc.Camera.getZEye = function () {
- return cc.Macro.FLT_EPSILON;
+ return cc.macro.FLT_EPSILON;
};
diff --git a/cocos2d/core/CCConfiguration.js b/cocos2d/core/CCConfiguration.js
index 519b12650a..a27ee0f88b 100644
--- a/cocos2d/core/CCConfiguration.js
+++ b/cocos2d/core/CCConfiguration.js
@@ -91,7 +91,7 @@ cc.configuration = /** @lends cc.configuration# */{
var locValueDict = this._valueDict;
locValueDict["cocos2d.x.version"] = cc.ENGINE_VERSION;
locValueDict["cocos2d.x.compiled_with_profiler"] = false;
- locValueDict["cocos2d.x.compiled_with_gl_state_cache"] = cc.Macro.ENABLE_GL_STATE_CACHE;
+ locValueDict["cocos2d.x.compiled_with_gl_state_cache"] = cc.macro.ENABLE_GL_STATE_CACHE;
this._inited = true;
},
@@ -220,7 +220,7 @@ cc.configuration = /** @lends cc.configuration# */{
* Dumps the current configuration on the console
*/
dumpInfo: function(){
- if(cc.Macro.ENABLE_GL_STATE_CACHE === 0){
+ if(cc.macro.ENABLE_GL_STATE_CACHE === 0){
cc.log("");
cc.log(cc._LogInfos.configuration.dumpInfo);
cc.log("")
diff --git a/cocos2d/core/CCDirector.js b/cocos2d/core/CCDirector.js
index d8ed84957d..b6bfcd99e0 100644
--- a/cocos2d/core/CCDirector.js
+++ b/cocos2d/core/CCDirector.js
@@ -381,7 +381,7 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
* Removes cached all cocos2d cached data. It will purge the cc.textureCache, cc.spriteFrameCache, cc.spriteFrameAnimationCache
*/
purgeCachedData: function () {
- cc.spriteFrameAnimationCache._clear();
+ // cc.spriteFrameAnimationCache._clear();
cc.spriteFrameCache._clear();
cc.textureCache._clear();
},
diff --git a/cocos2d/core/CCDirectorCanvas.js b/cocos2d/core/CCDirectorCanvas.js
index 0117446e45..773a612d3d 100644
--- a/cocos2d/core/CCDirectorCanvas.js
+++ b/cocos2d/core/CCDirectorCanvas.js
@@ -73,13 +73,5 @@ cc.game.once(cc.game.EVENT_RENDERER_INITED, function () {
return cc.p(0, 0);
//}
};
- } else {
- cc.Director._fpsImage = new Image();
- cc.Director._fpsImage.addEventListener("load", function () {
- cc.Director._fpsImageLoaded = true;
- });
- if (cc._fpsImage) {
- cc.Director._fpsImage.src = cc._fpsImage;
- }
}
});
\ No newline at end of file
diff --git a/cocos2d/core/CCDirectorWebGL.js b/cocos2d/core/CCDirectorWebGL.js
index 3ee7064c32..09393ccb89 100644
--- a/cocos2d/core/CCDirectorWebGL.js
+++ b/cocos2d/core/CCDirectorWebGL.js
@@ -26,14 +26,17 @@
require('./CCDirector');
require('./CCGame');
+require('../kazmath');
+
+var math = cc.math;
var GLToClipTransform = function (transformOut) {
- //var projection = new cc.math.Matrix4();
- //cc.kmGLGetMatrix(cc.KM_GL_PROJECTION, projection);
- cc.kmGLGetMatrix(cc.KM_GL_PROJECTION, transformOut);
+ //var projection = new math.Matrix4();
+ //math.glGetMatrix(math.KM_GL_PROJECTION, projection);
+ math.glGetMatrix(math.KM_GL_PROJECTION, transformOut);
- var modelview = new cc.math.Matrix4();
- cc.kmGLGetMatrix(cc.KM_GL_MODELVIEW, modelview);
+ var modelview = new math.Matrix4();
+ math.glGetMatrix(math.KM_GL_MODELVIEW, modelview);
transformOut.multiply(modelview);
};
@@ -89,36 +92,36 @@ cc.game.once(cc.game.EVENT_RENDERER_INITED, function () {
switch (projection) {
case cc.Director.PROJECTION_2D:
- cc.kmGLMatrixMode(cc.KM_GL_PROJECTION);
- cc.kmGLLoadIdentity();
- var orthoMatrix = cc.math.Matrix4.createOrthographicProjection(
+ math.glMatrixMode(math.KM_GL_PROJECTION);
+ math.glLoadIdentity();
+ var orthoMatrix = math.Matrix4.createOrthographicProjection(
-ox,
size.width - ox,
-oy,
size.height - oy,
-1024, 1024);
- cc.kmGLMultMatrix(orthoMatrix);
- cc.kmGLMatrixMode(cc.KM_GL_MODELVIEW);
- cc.kmGLLoadIdentity();
+ math.glMultMatrix(orthoMatrix);
+ math.glMatrixMode(math.KM_GL_MODELVIEW);
+ math.glLoadIdentity();
break;
case cc.Director.PROJECTION_3D:
var zeye = _t.getZEye();
- var matrixPerspective = new cc.math.Matrix4(), matrixLookup = new cc.math.Matrix4();
- cc.kmGLMatrixMode(cc.KM_GL_PROJECTION);
- cc.kmGLLoadIdentity();
+ var matrixPerspective = new math.Matrix4(), matrixLookup = new math.Matrix4();
+ math.glMatrixMode(math.KM_GL_PROJECTION);
+ math.glLoadIdentity();
// issue #1334
- matrixPerspective = cc.math.Matrix4.createPerspectiveProjection(60, size.width / size.height, 0.1, zeye * 2);
+ matrixPerspective = math.Matrix4.createPerspectiveProjection(60, size.width / size.height, 0.1, zeye * 2);
- cc.kmGLMultMatrix(matrixPerspective);
+ math.glMultMatrix(matrixPerspective);
- cc.kmGLMatrixMode(cc.KM_GL_MODELVIEW);
- cc.kmGLLoadIdentity();
- var eye = new cc.math.Vec3(-ox + size.width / 2, -oy + size.height / 2, zeye);
- var center = new cc.math.Vec3( -ox + size.width / 2, -oy + size.height / 2, 0.0);
- var up = new cc.math.Vec3( 0.0, 1.0, 0.0);
+ math.glMatrixMode(math.KM_GL_MODELVIEW);
+ math.glLoadIdentity();
+ var eye = new math.Vec3(-ox + size.width / 2, -oy + size.height / 2, zeye);
+ var center = new math.Vec3( -ox + size.width / 2, -oy + size.height / 2, 0.0);
+ var up = new math.Vec3( 0.0, 1.0, 0.0);
matrixLookup.lookAt(eye, center, up);
- cc.kmGLMultMatrix(matrixLookup);
+ math.glMultMatrix(matrixLookup);
break;
case cc.Director.PROJECTION_CUSTOM:
if (_t._projectionDelegate)
@@ -179,15 +182,15 @@ cc.game.once(cc.game.EVENT_RENDERER_INITED, function () {
};
_p._beforeVisitScene = function () {
- cc.kmGLPushMatrix();
+ math.glPushMatrix();
};
_p._afterVisitScene = function () {
- cc.kmGLPopMatrix();
+ math.glPopMatrix();
};
_p.convertToGL = function (uiPoint) {
- var transform = new cc.math.Matrix4();
+ var transform = new math.Matrix4();
GLToClipTransform(transform);
var transformInv = transform.inverse();
@@ -195,16 +198,16 @@ cc.game.once(cc.game.EVENT_RENDERER_INITED, function () {
// Calculate z=0 using -> transform*[0, 0, 0, 1]/w
var zClip = transform.mat[14] / transform.mat[15];
var glSize = this._openGLView.getDesignResolutionSize();
- var glCoord = new cc.math.Vec3(2.0 * uiPoint.x / glSize.width - 1.0, 1.0 - 2.0 * uiPoint.y / glSize.height, zClip);
+ var glCoord = new math.Vec3(2.0 * uiPoint.x / glSize.width - 1.0, 1.0 - 2.0 * uiPoint.y / glSize.height, zClip);
glCoord.transformCoord(transformInv);
return cc.p(glCoord.x, glCoord.y);
};
_p.convertToUI = function (glPoint) {
- var transform = new cc.math.Matrix4();
+ var transform = new math.Matrix4();
GLToClipTransform(transform);
- var clipCoord = new cc.math.Vec3(glPoint.x, glPoint.y, 0.0);
+ var clipCoord = new math.Vec3(glPoint.x, glPoint.y, 0.0);
// Need to calculate the zero depth from the transform.
clipCoord.transformCoord(transform);
@@ -250,9 +253,9 @@ cc.game.once(cc.game.EVENT_RENDERER_INITED, function () {
_p.setAlphaBlending = function (on) {
if (on)
- cc.glBlendFunc(cc.Macro.BLEND_SRC, cc.Macro.BLEND_DST);
+ cc.glBlendFunc(cc.macro.BLEND_SRC, cc.macro.BLEND_DST);
else
- cc.glBlendFunc(cc.Macro.ONE, cc.Macro.ZERO);
+ cc.glBlendFunc(cc.macro.ONE, cc.macro.ZERO);
//cc.checkGLErrorDebug();
};
diff --git a/cocos2d/core/CCDrawingPrimitivesCanvas.js b/cocos2d/core/CCDrawingPrimitivesCanvas.js
index ccd16b324a..059b264910 100644
--- a/cocos2d/core/CCDrawingPrimitivesCanvas.js
+++ b/cocos2d/core/CCDrawingPrimitivesCanvas.js
@@ -360,7 +360,7 @@ cc.DrawingPrimitiveCanvas = cc._Class.extend(/** @lends cc.DrawingPrimitiveCanva
//context.fillStyle = g1;
context.beginPath();
var startAngle_1 = 0;
- var endAngle_1 = cc.Macro.PI2;
+ var endAngle_1 = cc.macro.PI2;
context.arc(0, 0, radius - subRadius, startAngle_1, endAngle_1, false);
context.closePath();
context.fill();
@@ -388,7 +388,7 @@ cc.DrawingPrimitiveCanvas = cc._Class.extend(/** @lends cc.DrawingPrimitiveCanva
//context.fillStyle = g1;
context.beginPath();
var startAngle_1 = 0;
- var endAngle_1 = cc.Macro.PI2;
+ var endAngle_1 = cc.macro.PI2;
context.arc(0, 0, radius, startAngle_1, endAngle_1, false);
context.closePath();
context.fill();
diff --git a/cocos2d/core/CCDrawingPrimitivesWebGL.js b/cocos2d/core/CCDrawingPrimitivesWebGL.js
index 90d1c4c949..9de26e294d 100644
--- a/cocos2d/core/CCDrawingPrimitivesWebGL.js
+++ b/cocos2d/core/CCDrawingPrimitivesWebGL.js
@@ -24,6 +24,8 @@
THE SOFTWARE.
****************************************************************************/
+var macro = cc.macro;
+
/**
* Canvas of DrawingPrimitive implement version use for WebGlMode
* @class
@@ -58,7 +60,7 @@ cc.DrawingPrimitiveWebGL = cc._Class.extend(/** @lends cc.DrawingPrimitiveWebGL#
//
// Position and 1 color passed as a uniform (to similate glColor4ub )
//
- _t._shader = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_UCOLOR);
+ _t._shader = cc.shaderCache.programForKey(macro.SHADER_POSITION_UCOLOR);
_t._colorLocation = _t._renderContext.getUniformLocation(_t._shader.getProgram(), "u_color");
_t._pointSizeLocation = _t._renderContext.getUniformLocation(_t._shader.getProgram(), "u_pointSize");
@@ -83,14 +85,14 @@ cc.DrawingPrimitiveWebGL = cc._Class.extend(/** @lends cc.DrawingPrimitiveWebGL#
var glContext = this._renderContext;
this._shader.use();
this._shader.setUniformForModelViewAndProjectionMatrixWithMat4();
- cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POSITION);
+ cc.glEnableVertexAttribs(macro.VERTEX_ATTRIB_FLAG_POSITION);
glContext.uniform4fv(this._colorLocation, this._colorArray);
this._shader.setUniformLocationWith1f(this._pointSizeLocation, this._pointSize);
var pointBuffer = glContext.createBuffer();
glContext.bindBuffer(glContext.ARRAY_BUFFER, pointBuffer);
glContext.bufferData(glContext.ARRAY_BUFFER, new Float32Array([point.x, point.y]), glContext.STATIC_DRAW);
- glContext.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0);
+ glContext.vertexAttribPointer(macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0);
glContext.drawArrays(glContext.POINTS, 0, 1);
glContext.deleteBuffer(pointBuffer);
@@ -112,14 +114,14 @@ cc.DrawingPrimitiveWebGL = cc._Class.extend(/** @lends cc.DrawingPrimitiveWebGL#
var glContext = this._renderContext;
this._shader.use();
this._shader.setUniformForModelViewAndProjectionMatrixWithMat4();
- cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POSITION);
+ cc.glEnableVertexAttribs(macro.VERTEX_ATTRIB_FLAG_POSITION);
glContext.uniform4fv(this._colorLocation, this._colorArray);
this._shader.setUniformLocationWith1f(this._pointSizeLocation, this._pointSize);
var pointBuffer = glContext.createBuffer();
glContext.bindBuffer(glContext.ARRAY_BUFFER, pointBuffer);
glContext.bufferData(glContext.ARRAY_BUFFER, this._pointsToTypeArray(points), glContext.STATIC_DRAW);
- glContext.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0);
+ glContext.vertexAttribPointer(macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0);
glContext.drawArrays(glContext.POINTS, 0, points.length);
glContext.deleteBuffer(pointBuffer);
@@ -147,13 +149,13 @@ cc.DrawingPrimitiveWebGL = cc._Class.extend(/** @lends cc.DrawingPrimitiveWebGL#
var glContext = this._renderContext;
this._shader.use();
this._shader.setUniformForModelViewAndProjectionMatrixWithMat4();
- cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POSITION);
+ cc.glEnableVertexAttribs(macro.VERTEX_ATTRIB_FLAG_POSITION);
glContext.uniform4fv(this._colorLocation, this._colorArray);
var pointBuffer = glContext.createBuffer();
glContext.bindBuffer(glContext.ARRAY_BUFFER, pointBuffer);
glContext.bufferData(glContext.ARRAY_BUFFER, this._pointsToTypeArray([origin, destination]), glContext.STATIC_DRAW);
- glContext.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0);
+ glContext.vertexAttribPointer(macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0);
glContext.drawArrays(glContext.LINES, 0, 2);
glContext.deleteBuffer(pointBuffer);
@@ -202,13 +204,13 @@ cc.DrawingPrimitiveWebGL = cc._Class.extend(/** @lends cc.DrawingPrimitiveWebGL#
var glContext = this._renderContext;
this._shader.use();
this._shader.setUniformForModelViewAndProjectionMatrixWithMat4();
- cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POSITION);
+ cc.glEnableVertexAttribs(macro.VERTEX_ATTRIB_FLAG_POSITION);
glContext.uniform4fv(this._colorLocation, this._colorArray);
var pointBuffer = glContext.createBuffer();
glContext.bindBuffer(glContext.ARRAY_BUFFER, pointBuffer);
glContext.bufferData(glContext.ARRAY_BUFFER, this._pointsToTypeArray(vertices), glContext.STATIC_DRAW);
- glContext.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0);
+ glContext.vertexAttribPointer(macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0);
if (closePolygon)
glContext.drawArrays(glContext.LINE_LOOP, 0, vertices.length);
@@ -233,13 +235,13 @@ cc.DrawingPrimitiveWebGL = cc._Class.extend(/** @lends cc.DrawingPrimitiveWebGL#
var glContext = this._renderContext;
this._shader.use();
this._shader.setUniformForModelViewAndProjectionMatrixWithMat4();
- cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POSITION);
+ cc.glEnableVertexAttribs(macro.VERTEX_ATTRIB_FLAG_POSITION);
glContext.uniform4fv(this._colorLocation, this._colorArray);
var pointBuffer = glContext.createBuffer();
glContext.bindBuffer(glContext.ARRAY_BUFFER, pointBuffer);
glContext.bufferData(glContext.ARRAY_BUFFER, this._pointsToTypeArray(poli), glContext.STATIC_DRAW);
- glContext.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0);
+ glContext.vertexAttribPointer(macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0);
glContext.drawArrays(glContext.TRIANGLE_FAN, 0, poli.length);
glContext.deleteBuffer(pointBuffer);
@@ -281,13 +283,13 @@ cc.DrawingPrimitiveWebGL = cc._Class.extend(/** @lends cc.DrawingPrimitiveWebGL#
var glContext = this._renderContext;
this._shader.use();
this._shader.setUniformForModelViewAndProjectionMatrixWithMat4();
- cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POSITION);
+ cc.glEnableVertexAttribs(macro.VERTEX_ATTRIB_FLAG_POSITION);
glContext.uniform4fv(this._colorLocation, this._colorArray);
var pointBuffer = glContext.createBuffer();
glContext.bindBuffer(glContext.ARRAY_BUFFER, pointBuffer);
glContext.bufferData(glContext.ARRAY_BUFFER, vertices, glContext.STATIC_DRAW);
- glContext.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0);
+ glContext.vertexAttribPointer(macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0);
glContext.drawArrays(glContext.LINE_STRIP, 0, segments + additionalSegment);
glContext.deleteBuffer(pointBuffer);
@@ -319,13 +321,13 @@ cc.DrawingPrimitiveWebGL = cc._Class.extend(/** @lends cc.DrawingPrimitiveWebGL#
var glContext = this._renderContext;
this._shader.use();
this._shader.setUniformForModelViewAndProjectionMatrixWithMat4();
- cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POSITION);
+ cc.glEnableVertexAttribs(macro.VERTEX_ATTRIB_FLAG_POSITION);
glContext.uniform4fv(this._colorLocation, this._colorArray);
var pointBuffer = glContext.createBuffer();
glContext.bindBuffer(glContext.ARRAY_BUFFER, pointBuffer);
glContext.bufferData(glContext.ARRAY_BUFFER, vertices, glContext.STATIC_DRAW);
- glContext.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0);
+ glContext.vertexAttribPointer(macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0);
glContext.drawArrays(glContext.LINE_STRIP, 0, segments + 1);
glContext.deleteBuffer(pointBuffer);
@@ -358,13 +360,13 @@ cc.DrawingPrimitiveWebGL = cc._Class.extend(/** @lends cc.DrawingPrimitiveWebGL#
var glContext = this._renderContext;
this._shader.use();
this._shader.setUniformForModelViewAndProjectionMatrixWithMat4();
- cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POSITION);
+ cc.glEnableVertexAttribs(macro.VERTEX_ATTRIB_FLAG_POSITION);
glContext.uniform4fv(this._colorLocation, this._colorArray);
var pointBuffer = glContext.createBuffer();
glContext.bindBuffer(glContext.ARRAY_BUFFER, pointBuffer);
glContext.bufferData(glContext.ARRAY_BUFFER, vertices, glContext.STATIC_DRAW);
- glContext.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0);
+ glContext.vertexAttribPointer(macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0);
glContext.drawArrays(glContext.LINE_STRIP, 0, segments + 1);
glContext.deleteBuffer(pointBuffer);
@@ -418,13 +420,13 @@ cc.DrawingPrimitiveWebGL = cc._Class.extend(/** @lends cc.DrawingPrimitiveWebGL#
var glContext = this._renderContext;
this._shader.use();
this._shader.setUniformForModelViewAndProjectionMatrixWithMat4();
- cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POSITION);
+ cc.glEnableVertexAttribs(macro.VERTEX_ATTRIB_FLAG_POSITION);
glContext.uniform4fv(this._colorLocation, this._colorArray);
var pointBuffer = glContext.createBuffer();
glContext.bindBuffer(glContext.ARRAY_BUFFER, pointBuffer);
glContext.bufferData(glContext.ARRAY_BUFFER, vertices, glContext.STATIC_DRAW);
- glContext.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0);
+ glContext.vertexAttribPointer(macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0);
glContext.drawArrays(glContext.LINE_STRIP, 0, segments + 1);
glContext.deleteBuffer(pointBuffer);
diff --git a/cocos2d/core/CCScheduler.js b/cocos2d/core/CCScheduler.js
index 37bdffac25..0ac6974a3a 100644
--- a/cocos2d/core/CCScheduler.js
+++ b/cocos2d/core/CCScheduler.js
@@ -124,7 +124,7 @@ cc.Timer = cc._Class.extend(/** @lends cc.Timer# */{
this._delay = delay;
this._useDelay = (this._delay > 0);
this._repeat = repeat;
- this._runForever = (this._repeat === cc.Macro.REPEAT_FOREVER);
+ this._runForever = (this._repeat === cc.macro.REPEAT_FOREVER);
},
trigger: function(){
@@ -519,7 +519,7 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
* If paused is YES, then it won't be called until it is resumed.
* If 'interval' is 0, it will be called every frame, but if so, it recommended to use 'scheduleUpdateForTarget:' instead.
* If the callback function is already scheduled, then only the interval parameter will be updated without re-scheduling it again.
- * repeat let the action be repeated repeat + 1 times, use cc.Macro.REPEAT_FOREVER to let the action run continuously
+ * repeat let the action be repeated repeat + 1 times, use cc.macro.REPEAT_FOREVER to let the action run continuously
* delay is the amount of time the action will wait before it'll start
*
* @method scheduleCallbackForTarget
@@ -563,14 +563,14 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
key = delay;
paused = repeat;
delay = 0;
- repeat = cc.Macro.REPEAT_FOREVER;
+ repeat = cc.macro.REPEAT_FOREVER;
}
}else{
//selector, target, interval, repeat, delay, paused
//selector, target, interval, paused
if(arguments.length === 4){
paused = repeat;
- repeat = cc.Macro.REPEAT_FOREVER;
+ repeat = cc.macro.REPEAT_FOREVER;
delay = 0;
}
}
diff --git a/cocos2d/core/base-nodes/CCAtlasNode.js b/cocos2d/core/base-nodes/CCAtlasNode.js
index 03a5a677d4..1f1582fbab 100644
--- a/cocos2d/core/base-nodes/CCAtlasNode.js
+++ b/cocos2d/core/base-nodes/CCAtlasNode.js
@@ -84,7 +84,7 @@ cc.AtlasNode = _ccsg.Node.extend(/** @lends cc.AtlasNode# */{
_ccsg.Node.prototype.ctor.call(this);
EventTarget.call(this);
- this._blendFunc = {src: cc.Macro.BLEND_SRC, dst: cc.Macro.BLEND_DST};
+ this._blendFunc = {src: cc.macro.BLEND_SRC, dst: cc.macro.BLEND_DST};
this._ignoreContentScaleFactor = false;
itemsToRender !== undefined && this.initWithTileFile(tile, tileWidth, tileHeight, itemsToRender);
},
diff --git a/cocos2d/core/base-nodes/CCAtlasNodeWebGLRenderCmd.js b/cocos2d/core/base-nodes/CCAtlasNodeWebGLRenderCmd.js
index f1c08e9e74..fbbbc15d80 100644
--- a/cocos2d/core/base-nodes/CCAtlasNodeWebGLRenderCmd.js
+++ b/cocos2d/core/base-nodes/CCAtlasNodeWebGLRenderCmd.js
@@ -35,7 +35,7 @@
this._uniformColor = null;
//shader stuff
- this._shaderProgram = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURE_UCOLOR);
+ this._shaderProgram = cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURE_UCOLOR);
this._uniformColor = cc._renderContext.getUniformLocation(this._shaderProgram.getProgram(), "u_color");
};
@@ -45,8 +45,8 @@
proto._updateBlendFunc = function () {
var node = this._node;
if (!this._textureAtlas.texture.hasPremultipliedAlpha()) {
- node._blendFunc.src = cc.Macro.SRC_ALPHA;
- node._blendFunc.dst = cc.Macro.ONE_MINUS_SRC_ALPHA;
+ node._blendFunc.src = cc.macro.SRC_ALPHA;
+ node._blendFunc.dst = cc.macro.ONE_MINUS_SRC_ALPHA;
}
};
@@ -74,8 +74,8 @@
this._colorUnmodified = cc.Color.WHITE;
node._opacityModifyRGB = true;
- node._blendFunc.src = cc.Macro.BLEND_SRC;
- node._blendFunc.dst = cc.Macro.BLEND_DST;
+ node._blendFunc.src = cc.macro.BLEND_SRC;
+ node._blendFunc.dst = cc.macro.BLEND_DST;
var locRealColor = node._realColor;
this._colorF32Array = new Float32Array([locRealColor.r / 255.0, locRealColor.g / 255.0, locRealColor.b / 255.0, node._realOpacity / 255.0]);
diff --git a/cocos2d/core/base-nodes/CCSGNode.js b/cocos2d/core/base-nodes/CCSGNode.js
index 4dff9cd970..abc4f99a70 100644
--- a/cocos2d/core/base-nodes/CCSGNode.js
+++ b/cocos2d/core/base-nodes/CCSGNode.js
@@ -24,14 +24,7 @@
THE SOFTWARE.
****************************************************************************/
-/**
- * Default Node tag
- * @constant
- * @type Number
- */
-cc.NODE_TAG_INVALID = -1;
-
-/**
+/*
* XXX: Yes, nodes might have a sort problem once every 15 days if the game runs at 60 FPS and each frame sprites are reordered.
*/
cc.s_globalOrderOfArrival = 1;
@@ -149,7 +142,7 @@ _ccsg.Node = cc.Class({
// "whole screen" objects. like Scenes and Layers, should set _ignoreAnchorPointForPosition to true
_ignoreAnchorPointForPosition: false,
- tag: cc.NODE_TAG_INVALID,
+ tag: cc.macro.NODE_TAG_INVALID,
_showNode: false,
_name: '', ///= 0, cc._LogInfos.Node.schedule_2);
interval = interval || 0;
- repeat = (repeat == null) ? cc.Macro.REPEAT_FOREVER : repeat;
+ repeat = (repeat == null) ? cc.macro.REPEAT_FOREVER : repeat;
delay = delay || 0;
this.scheduler.schedule(callback, this, interval, repeat, delay, !this._running, key);
@@ -2009,7 +2002,7 @@ _ccsg.Node = cc.Class({
* @function
* @param {cc.GLProgram} newShaderProgram The shader program which fetches from CCShaderCache.
* @example
- * node.setGLProgram(cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLOR));
+ * node.setGLProgram(cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLOR));
*/
setShaderProgram: function (newShaderProgram) {
this._renderCmd.setShaderProgram(newShaderProgram);
@@ -2243,16 +2236,6 @@ _ccsg.Node.extend = function (options) {
// to support calling this._super in sub class
_ccsg.Node.prototype.ctor = _ccsg.Node;
-/**
- * Allocates and initializes a node.
- * @deprecated since v3.0, please use new construction instead.
- * @see _ccsg.Node
- * @return {_ccsg.Node}
- */
-_ccsg.Node.create = function () {
- return new _ccsg.Node();
-};
-
_ccsg.Node._stateCallbackType = {onEnter: 1, onExit: 2, cleanup: 3, onEnterTransitionDidFinish: 4, updateTransform: 5, onExitTransitionDidStart: 6, sortAllChildren: 7};
cc.assert(cc.js.isFunction(cc._tmp.PrototypeCCNode), cc._LogInfos.MissingFile, "BaseNodesPropertyDefine.js");
diff --git a/cocos2d/core/base-nodes/CCSGNodeCanvasRenderCmd.js b/cocos2d/core/base-nodes/CCSGNodeCanvasRenderCmd.js
index caedf8dc2f..b0fc26c2b8 100644
--- a/cocos2d/core/base-nodes/CCSGNodeCanvasRenderCmd.js
+++ b/cocos2d/core/base-nodes/CCSGNodeCanvasRenderCmd.js
@@ -511,11 +511,11 @@ _ccsg.Node.RenderCmd.prototype = {
if (!blendFunc)
return "source-over";
else {
- if (( blendFunc.src === cc.Macro.SRC_ALPHA && blendFunc.dst === cc.Macro.ONE) || (blendFunc.src === cc.Macro.ONE && blendFunc.dst === cc.Macro.ONE))
+ if (( blendFunc.src === cc.macro.SRC_ALPHA && blendFunc.dst === cc.macro.ONE) || (blendFunc.src === cc.macro.ONE && blendFunc.dst === cc.macro.ONE))
return "lighter";
- else if (blendFunc.src === cc.Macro.ZERO && blendFunc.dst === cc.Macro.SRC_ALPHA)
+ else if (blendFunc.src === cc.macro.ZERO && blendFunc.dst === cc.macro.SRC_ALPHA)
return "destination-in";
- else if (blendFunc.src === cc.Macro.ZERO && blendFunc.dst === cc.Macro.ONE_MINUS_SRC_ALPHA)
+ else if (blendFunc.src === cc.macro.ZERO && blendFunc.dst === cc.macro.ONE_MINUS_SRC_ALPHA)
return "destination-out";
else
return "source-over";
diff --git a/cocos2d/core/base-nodes/CCSGNodeWebGLRenderCmd.js b/cocos2d/core/base-nodes/CCSGNodeWebGLRenderCmd.js
index a3f24d95a4..d74a371e0c 100644
--- a/cocos2d/core/base-nodes/CCSGNodeWebGLRenderCmd.js
+++ b/cocos2d/core/base-nodes/CCSGNodeWebGLRenderCmd.js
@@ -22,83 +22,84 @@
THE SOFTWARE.
****************************************************************************/
// ------------------------------ The ccsg.Node's render command for WebGL ----------------------------------
-(function() {
- _ccsg.Node.WebGLRenderCmd = function (renderable) {
- _ccsg.Node.RenderCmd.call(this, renderable);
- var mat4 = new cc.math.Matrix4(), mat = mat4.mat;
- mat[2] = mat[3] = mat[6] = mat[7] = mat[8] = mat[9] = mat[11] = mat[14] = 0.0;
- mat[10] = mat[15] = 1.0;
- this._transform4x4 = mat4;
- this._stackMatrix = new cc.math.Matrix4();
- this._shaderProgram = null;
+var math = cc.math;
- this._camera = null;
- };
+_ccsg.Node.WebGLRenderCmd = function (renderable) {
+ _ccsg.Node.RenderCmd.call(this, renderable);
- var proto = _ccsg.Node.WebGLRenderCmd.prototype = Object.create(_ccsg.Node.RenderCmd.prototype);
- proto.constructor = _ccsg.Node.WebGLRenderCmd;
+ var mat4 = new math.Matrix4(), mat = mat4.mat;
+ mat[2] = mat[3] = mat[6] = mat[7] = mat[8] = mat[9] = mat[11] = mat[14] = 0.0;
+ mat[10] = mat[15] = 1.0;
+ this._transform4x4 = mat4;
+ this._stackMatrix = new math.Matrix4();
+ this._shaderProgram = null;
- proto._updateColor = function(){};
+ this._camera = null;
+};
- proto.visit = function (parentCmd) {
- var node = this._node;
- // quick return if not visible
- if (!node._visible)
- return;
+var proto = _ccsg.Node.WebGLRenderCmd.prototype = Object.create(_ccsg.Node.RenderCmd.prototype);
+proto.constructor = _ccsg.Node.WebGLRenderCmd;
- parentCmd = parentCmd || this.getParentRenderCmd();
- if (node._parent && node._parent._renderCmd)
- this._curLevel = node._parent._renderCmd._curLevel + 1;
+proto._updateColor = function(){};
- var currentStack = cc.current_stack;
+proto.visit = function (parentCmd) {
+ var node = this._node;
+ // quick return if not visible
+ if (!node._visible)
+ return;
- //optimize performance for javascript
- currentStack.stack.push(currentStack.top);
- this._syncStatus(parentCmd);
- currentStack.top = this._stackMatrix;
- this.visitChildren();
- //optimize performance for javascript
- currentStack.top = currentStack.stack.pop();
- };
+ parentCmd = parentCmd || this.getParentRenderCmd();
+ if (node._parent && node._parent._renderCmd)
+ this._curLevel = node._parent._renderCmd._curLevel + 1;
- proto.transform = function (parentCmd, recursive) {
- var t4x4 = this._transform4x4, stackMatrix = this._stackMatrix, node = this._node;
- parentCmd = parentCmd || this.getParentRenderCmd();
- var parentMatrix = (parentCmd ? parentCmd._stackMatrix : cc.current_stack.top);
+ var currentStack = cc.current_stack;
- // Convert 3x3 into 4x4 matrix
- var trans = this.getNodeToParentTransform();
+ //optimize performance for javascript
+ currentStack.stack.push(currentStack.top);
+ this._syncStatus(parentCmd);
+ currentStack.top = this._stackMatrix;
+ this.visitChildren();
+ //optimize performance for javascript
+ currentStack.top = currentStack.stack.pop();
+};
- this._dirtyFlag = this._dirtyFlag & _ccsg.Node._dirtyFlags.transformDirty ^ this._dirtyFlag;
+proto.transform = function (parentCmd, recursive) {
+ var t4x4 = this._transform4x4, stackMatrix = this._stackMatrix, node = this._node;
+ parentCmd = parentCmd || this.getParentRenderCmd();
+ var parentMatrix = (parentCmd ? parentCmd._stackMatrix : cc.current_stack.top);
- var t4x4Mat = t4x4.mat;
- t4x4Mat[0] = trans.a;
- t4x4Mat[4] = trans.c;
- t4x4Mat[12] = trans.tx;
- t4x4Mat[1] = trans.b;
- t4x4Mat[5] = trans.d;
- t4x4Mat[13] = trans.ty;
+ // Convert 3x3 into 4x4 matrix
+ var trans = this.getNodeToParentTransform();
- // Update Z vertex manually
- t4x4Mat[14] = node._vertexZ;
+ this._dirtyFlag = this._dirtyFlag & _ccsg.Node._dirtyFlags.transformDirty ^ this._dirtyFlag;
- //optimize performance for Javascript
- cc.kmMat4Multiply(stackMatrix, parentMatrix, t4x4);
+ var t4x4Mat = t4x4.mat;
+ t4x4Mat[0] = trans.a;
+ t4x4Mat[4] = trans.c;
+ t4x4Mat[12] = trans.tx;
+ t4x4Mat[1] = trans.b;
+ t4x4Mat[5] = trans.d;
+ t4x4Mat[13] = trans.ty;
- if(!recursive || !node._children || node._children.length === 0)
- return;
- var i, len, locChildren = node._children;
- for(i = 0, len = locChildren.length; i< len; i++){
- locChildren[i]._renderCmd.transform(this, recursive);
- }
- };
+ // Update Z vertex manually
+ t4x4Mat[14] = node._vertexZ;
- proto.setShaderProgram = function (shaderProgram) {
- this._shaderProgram = shaderProgram;
- };
+ //optimize performance for Javascript
+ math.mat4Multiply(stackMatrix, parentMatrix, t4x4);
- proto.getShaderProgram = function () {
- return this._shaderProgram;
- };
-})();
+ if(!recursive || !node._children || node._children.length === 0)
+ return;
+ var i, len, locChildren = node._children;
+ for(i = 0, len = locChildren.length; i< len; i++){
+ locChildren[i]._renderCmd.transform(this, recursive);
+ }
+};
+
+proto.setShaderProgram = function (shaderProgram) {
+ this._shaderProgram = shaderProgram;
+};
+
+proto.getShaderProgram = function () {
+ return this._shaderProgram;
+};
diff --git a/cocos2d/core/components/CCComponent.js b/cocos2d/core/components/CCComponent.js
index d28dfade68..0b0cc48efb 100644
--- a/cocos2d/core/components/CCComponent.js
+++ b/cocos2d/core/components/CCComponent.js
@@ -696,7 +696,7 @@ var Component = cc.Class({
* @method schedule
* @param {function} callback The callback function
* @param {Number} [interval=0] Tick interval in seconds. 0 means tick every frame. If interval = 0, it's recommended to use scheduleUpdate() instead.
- * @param {Number} [repeat=cc.Macro.REPEAT_FOREVER] The selector will be executed (repeat + 1) times, you can use kCCRepeatForever for tick infinitely.
+ * @param {Number} [repeat=cc.macro.REPEAT_FOREVER] The selector will be executed (repeat + 1) times, you can use kCCRepeatForever for tick infinitely.
* @param {Number} [delay=0] The amount of time that the first tick will wait before execution.
*/
schedule: function (callback, interval, repeat, delay) {
@@ -704,7 +704,7 @@ var Component = cc.Class({
cc.assert(interval >= 0, cc._LogInfos.Node.schedule_2);
interval = interval || 0;
- repeat = isNaN(repeat) ? cc.Macro.REPEAT_FOREVER : repeat;
+ repeat = isNaN(repeat) ? cc.macro.REPEAT_FOREVER : repeat;
delay = delay || 0;
cc.director.getScheduler().schedule(callback, this, interval, repeat, delay, !this.enabledInHierarchy, this.__instanceId);
diff --git a/cocos2d/core/editbox/CCSGEditBox.js b/cocos2d/core/editbox/CCSGEditBox.js
index 3ddd557ed2..94c1acbbdb 100644
--- a/cocos2d/core/editbox/CCSGEditBox.js
+++ b/cocos2d/core/editbox/CCSGEditBox.js
@@ -1081,19 +1081,6 @@ _ccsg.EditBox.getRect = function (node) {
return cc.rectApplyAffineTransform(rect, node.getNodeToWorldTransform());
};
-/**
- * create a edit box with size and background-color or
- * @deprecated since v3.0, please use new cc.EditBox(size, normal9SpriteBg, press9SpriteBg, disabled9SpriteBg) instead
- * @param {cc.Size} size
- * @param {cc.Scale9Sprite } normal9SpriteBg
- * @param {cc.Scale9Sprite } [press9SpriteBg]
- * @param {cc.Scale9Sprite } [disabled9SpriteBg]
- * @return {cc.EditBox}
- */
-_ccsg.EditBox.create = function (size, normal9SpriteBg, press9SpriteBg, disabled9SpriteBg) {
- return new _ccsg.EditBox(size, normal9SpriteBg, press9SpriteBg, disabled9SpriteBg);
-};
-
_ccsg.EditBox.InputMode = InputMode;
_ccsg.EditBox.InputFlag = InputFlag;
_ccsg.EditBox.KeyboardReturnType = KeyboardReturnType;
diff --git a/cocos2d/core/event-manager/CCEventListener.js b/cocos2d/core/event-manager/CCEventListener.js
index 38c14ea5ca..18a4f2ecb4 100644
--- a/cocos2d/core/event-manager/CCEventListener.js
+++ b/cocos2d/core/event-manager/CCEventListener.js
@@ -299,10 +299,6 @@ cc._EventListenerCustom = cc.EventListener.extend({
}
});
-cc._EventListenerCustom.create = function (eventName, callback) {
- return new cc._EventListenerCustom(eventName, callback);
-};
-
cc._EventListenerMouse = cc.EventListener.extend({
onMouseDown: null,
onMouseUp: null,
@@ -353,10 +349,6 @@ cc._EventListenerMouse = cc.EventListener.extend({
cc._EventListenerMouse.LISTENER_ID = "__cc_mouse";
-cc._EventListenerMouse.create = function () {
- return new cc._EventListenerMouse();
-};
-
cc._EventListenerTouchOneByOne = cc.EventListener.extend({
_claimedTouches: null,
swallowTouches: false,
@@ -399,10 +391,6 @@ cc._EventListenerTouchOneByOne = cc.EventListener.extend({
cc._EventListenerTouchOneByOne.LISTENER_ID = "__cc_touch_one_by_one";
-cc._EventListenerTouchOneByOne.create = function () {
- return new cc._EventListenerTouchOneByOne();
-};
-
cc._EventListenerTouchAllAtOnce = cc.EventListener.extend({
onTouchesBegan: null,
onTouchesMoved: null,
@@ -434,10 +422,6 @@ cc._EventListenerTouchAllAtOnce = cc.EventListener.extend({
cc._EventListenerTouchAllAtOnce.LISTENER_ID = "__cc_touch_all_at_once";
-cc._EventListenerTouchAllAtOnce.create = function(){
- return new cc._EventListenerTouchAllAtOnce();
-};
-
/**
* Create a EventListener object by json object
* @method create
@@ -532,10 +516,6 @@ cc._EventListenerAcceleration = cc.EventListener.extend({
cc._EventListenerAcceleration.LISTENER_ID = "__cc_acceleration";
-cc._EventListenerAcceleration.create = function (callback) {
- return new cc._EventListenerAcceleration(callback);
-};
-
//Keyboard
cc._EventListenerKeyboard = cc.EventListener.extend({
@@ -572,8 +552,4 @@ cc._EventListenerKeyboard = cc.EventListener.extend({
}
});
-cc._EventListenerKeyboard.LISTENER_ID = "__cc_keyboard";
-
-cc._EventListenerKeyboard.create = function () {
- return new cc._EventListenerKeyboard();
-};
\ No newline at end of file
+cc._EventListenerKeyboard.LISTENER_ID = "__cc_keyboard";
\ No newline at end of file
diff --git a/cocos2d/core/event-manager/CCEventManager.js b/cocos2d/core/event-manager/CCEventManager.js
index 0f8a4bfce7..0a214f5c6d 100644
--- a/cocos2d/core/event-manager/CCEventManager.js
+++ b/cocos2d/core/event-manager/CCEventManager.js
@@ -23,7 +23,7 @@
THE SOFTWARE.
****************************************************************************/
-cc._EventListenerVector = cc._Class.extend({
+var _EventListenerVector = cc._Class.extend({
_fixedListeners: null,
_sceneGraphListeners: null,
gt0Index: 0,
@@ -70,7 +70,7 @@ cc._EventListenerVector = cc._Class.extend({
}
});
-cc.__getListenerID = function (event) {
+var __getListenerID = function (event) {
var eventType = cc.Event, type = event.getType();
if (type === eventType.ACCELERATION)
return cc._EventListenerAcceleration.LISTENER_ID;
@@ -179,7 +179,7 @@ cc.eventManager = {
var listenerID = listener._getListenerID();
var listeners = this._listenersMap[listenerID];
if (!listeners) {
- listeners = new cc._EventListenerVector();
+ listeners = new _EventListenerVector();
this._listenersMap[listenerID] = listeners;
}
listeners.push(listener);
@@ -389,7 +389,7 @@ cc.eventManager = {
this._onUpdateListeners(cc._EventListenerTouchOneByOne.LISTENER_ID);
this._onUpdateListeners(cc._EventListenerTouchAllAtOnce.LISTENER_ID);
} else
- this._onUpdateListeners(cc.__getListenerID(event));
+ this._onUpdateListeners(__getListenerID(event));
cc.assert(locInDispatch === 1, cc._LogInfos.EventManager._updateListeners_2);
var locListenersMap = this._listenersMap, locPriorityDirtyFlagMap = this._priorityDirtyFlagMap;
@@ -934,7 +934,7 @@ cc.eventManager = {
return;
}
- var listenerID = cc.__getListenerID(event);
+ var listenerID = __getListenerID(event);
this._sortEventListeners(listenerID);
var selListeners = this._listenersMap[listenerID];
if (selListeners != null)
diff --git a/cocos2d/core/event-manager/index.js b/cocos2d/core/event-manager/index.js
new file mode 100644
index 0000000000..4aad791882
--- /dev/null
+++ b/cocos2d/core/event-manager/index.js
@@ -0,0 +1,29 @@
+/****************************************************************************
+ Copyright (c) 2013-2016 Chukong Technologies Inc.
+
+ http://www.cocos.com
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated engine source code (the "Software"), a limited,
+ worldwide, royalty-free, non-assignable, revocable and non-exclusive license
+ to use Cocos Creator solely to develop games on your target platforms. You shall
+ not use Cocos Creator software for developing other software or tools that's
+ used for developing games. You are not granted to publish, distribute,
+ sublicense, and/or sell copies of Cocos Creator.
+
+ The software or tools in this License Agreement are licensed, not sold.
+ Chukong Aipu reserves all rights not expressly granted to you.
+
+ 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.
+ ****************************************************************************/
+
+require('./CCTouch');
+require('./CCSystemEvent');
+require('./CCEventListener');
+require('./CCEventManager');
\ No newline at end of file
diff --git a/cocos2d/core/index.js b/cocos2d/core/index.js
index 73dd696629..7d83232884 100644
--- a/cocos2d/core/index.js
+++ b/cocos2d/core/index.js
@@ -26,6 +26,10 @@
require('./platform');
require('./assets');
+if (!CC_JSB) {
+ require('./sprites/CCSpriteFrameCache');
+}
+
if (!CC_EDITOR || !Editor.isCoreLevel) {
require('./CCNode');
require('./CCScene');
diff --git a/cocos2d/core/label/CCSGLabel.js b/cocos2d/core/label/CCSGLabel.js
index 94f855c41f..98966095a4 100644
--- a/cocos2d/core/label/CCSGLabel.js
+++ b/cocos2d/core/label/CCSGLabel.js
@@ -26,7 +26,7 @@
var EventTarget = require("../cocos2d/core/event/event-target");
-cc.FontLetterDefinition = function() {
+var FontLetterDefinition = function() {
this._u = 0;
this._v = 0;
this._width = 0;
@@ -59,7 +59,7 @@ cc.FontAtlas.prototype = {
cloneLetterDefinition: function() {
var copyLetterDefinitions = {};
for (var key in this._letterDefinitions) {
- var value = new cc.FontLetterDefinition();
+ var value = new FontLetterDefinition();
cc.js.mixin(value, this._letterDefinitions[key]);
copyLetterDefinitions[key] = value;
}
@@ -95,8 +95,8 @@ cc.FontAtlas.prototype = {
}
};
-cc.LetterInfo = function() {
- this._char = "";
+var LetterInfo = function() {
+ this._char = '';
this._valid = true;
this._positionX = 0;
this._positionY = 0;
@@ -609,7 +609,7 @@ cc.BMFontHelper = {
_recordPlaceholderInfo: function(letterIndex, char) {
if (letterIndex >= this._lettersInfo.length) {
- var tmpInfo = new cc.LetterInfo();
+ var tmpInfo = new LetterInfo();
this._lettersInfo.push(tmpInfo);
}
@@ -619,7 +619,7 @@ cc.BMFontHelper = {
_recordLetterInfo: function(letterPosition, character, letterIndex, lineIndex) {
if (letterIndex >= this._lettersInfo.length) {
- var tmpInfo = new cc.LetterInfo();
+ var tmpInfo = new LetterInfo();
this._lettersInfo.push(tmpInfo);
}
character = character.charCodeAt(0);
@@ -1040,7 +1040,7 @@ cc.BMFontHelper = {
var locFontDict = locCfg.fontDefDictionary;
for (var fontDef in locFontDict) {
- var letterDefinition = new cc.FontLetterDefinition();
+ var letterDefinition = new FontLetterDefinition();
var tempRect = locFontDict[fontDef].rect;
diff --git a/cocos2d/core/label/CCSGLabelWebGLRenderCmd.js b/cocos2d/core/label/CCSGLabelWebGLRenderCmd.js
index a26447fee5..55ddb784b7 100644
--- a/cocos2d/core/label/CCSGLabelWebGLRenderCmd.js
+++ b/cocos2d/core/label/CCSGLabelWebGLRenderCmd.js
@@ -37,7 +37,7 @@
this._labelTexture = new cc.Texture2D();
this._quadWebBuffer = cc._renderContext.createBuffer();
- this._shaderProgram = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLOR);
+ this._shaderProgram = cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLOR);
this._quad = new cc.V3F_C4B_T2F_Quad();
this._labelCanvas = document.createElement("canvas");
@@ -72,7 +72,7 @@
cc.glBlendFunc(node._blendFunc.src,node._blendFunc.dst);
cc.glBindTexture2DN(0,this._labelTexture);
- cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
+ cc.glEnableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
gl.bindBuffer(gl.ARRAY_BUFFER, this._quadWebBuffer);
@@ -81,9 +81,9 @@
this._quadDirty = false;
}
- gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 24, 0); //cc.Macro.VERTEX_ATTRIB_POSITION
- gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, true, 24, 12); //cc.Macro.VERTEX_ATTRIB_COLOR
- gl.vertexAttribPointer(2, 2, gl.FLOAT, false, 24, 16); //cc.Macro.VERTEX_ATTRIB_TEX_COORDS
+ gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 24, 0); //cc.macro.VERTEX_ATTRIB_POSITION
+ gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, true, 24, 12); //cc.macro.VERTEX_ATTRIB_COLOR
+ gl.vertexAttribPointer(2, 2, gl.FLOAT, false, 24, 16); //cc.macro.VERTEX_ATTRIB_TEX_COORDS
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
}
diff --git a/cocos2d/core/labelttf/CCLabelTTF.js b/cocos2d/core/labelttf/CCLabelTTF.js
index d8d5ecd10c..ad4084b35c 100644
--- a/cocos2d/core/labelttf/CCLabelTTF.js
+++ b/cocos2d/core/labelttf/CCLabelTTF.js
@@ -806,10 +806,10 @@ cc.LabelTTF.create = function (text, fontName, fontSize, dimensions, hAlignment,
*/
cc.LabelTTF.createWithFontDefinition = cc.LabelTTF.create;
-if (cc.Macro.USE_LA88_LABELS)
- cc.LabelTTF._SHADER_PROGRAM = cc.Macro.SHADER_POSITION_TEXTURECOLOR;
+if (cc.macro.USE_LA88_LABELS)
+ cc.LabelTTF._SHADER_PROGRAM = cc.macro.SHADER_POSITION_TEXTURECOLOR;
else
- cc.LabelTTF._SHADER_PROGRAM = cc.Macro.SHADER_POSITION_TEXTUREA8COLOR;
+ cc.LabelTTF._SHADER_PROGRAM = cc.macro.SHADER_POSITION_TEXTUREA8COLOR;
cc.LabelTTF.__labelHeightDiv = document.createElement("div");
cc.LabelTTF.__labelHeightDiv.style.fontFamily = "Arial";
diff --git a/cocos2d/core/layers/CCLayer.js b/cocos2d/core/layers/CCLayer.js
index 9c4f1d271b..28cfce1eef 100644
--- a/cocos2d/core/layers/CCLayer.js
+++ b/cocos2d/core/layers/CCLayer.js
@@ -99,16 +99,6 @@ cc.Layer = _ccsg.Node.extend(/** @lends cc.Layer# */{
}
});
-/**
- * Creates a layer
- * @deprecated since v3.0, please use the new construction instead
- * @see cc.Layer
- * @return {cc.Layer|Null}
- */
-cc.Layer.create = function () {
- return new cc.Layer();
-};
-
/**
*
* CCLayerColor is a subclass of CCLayer that implements the CCRGBAProtocol protocol.
@@ -191,7 +181,7 @@ cc.LayerColor = cc.Layer.extend(/** @lends cc.LayerColor# */{
*/
ctor: function(color, width, height){
cc.Layer.prototype.ctor.call(this);
- this._blendFunc = new cc.BlendFunc(cc.Macro.SRC_ALPHA, cc.Macro.ONE_MINUS_SRC_ALPHA);
+ this._blendFunc = new cc.BlendFunc(cc.macro.SRC_ALPHA, cc.macro.ONE_MINUS_SRC_ALPHA);
cc.LayerColor.prototype.init.call(this, color, width, height);
},
@@ -204,7 +194,7 @@ cc.LayerColor = cc.Layer.extend(/** @lends cc.LayerColor# */{
*/
init: function (color, width, height) {
if (cc._renderType !== cc.game.RENDER_TYPE_CANVAS)
- this.shaderProgram = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_COLOR);
+ this.shaderProgram = cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_COLOR);
var winSize = cc.director.getWinSize();
color = color || cc.color(0, 0, 0, 255);
@@ -262,19 +252,6 @@ cc.LayerColor = cc.Layer.extend(/** @lends cc.LayerColor# */{
}
});
-/**
- * Creates a cc.Layer with color, width and height in Points
- * @deprecated since v3.0 please use the new construction instead
- * @see cc.LayerColor
- * @param {cc.Color} color
- * @param {Number|Null} [width=]
- * @param {Number|Null} [height=]
- * @return {cc.LayerColor}
- */
-cc.LayerColor.create = function (color, width, height) {
- return new cc.LayerColor(color, width, height);
-};
-
//LayerColor - Getter Setter
(function(){
var proto = cc.LayerColor.prototype;
@@ -581,19 +558,6 @@ cc.LayerGradient = cc.LayerColor.extend(/** @lends cc.LayerGradient# */{
}
});
-/**
- * Creates a gradient layer
- * @deprecated since v3.0, please use the new construction instead
- * @see cc.layerGradient
- * @param {cc.Color} start starting color
- * @param {cc.Color} end ending color
- * @param {cc.Vec2|Null} v
- * @param {Array|NULL} stops
- * @return {cc.LayerGradient}
- */
-cc.LayerGradient.create = function (start, end, v, stops) {
- return new cc.LayerGradient(start, end, v, stops);
-};
//LayerGradient - Getter Setter
(function(){
var proto = cc.LayerGradient.prototype;
@@ -708,14 +672,4 @@ cc.LayerMultiplex = cc.Layer.extend(/** @lends cc.LayerMultiplex# */{
}
this._layers.push(layer);
}
-});
-
-/**
- * Creates a cc.LayerMultiplex with one or more layers using a variable argument list.
- * @deprecated since v3.0, please use new construction instead
- * @see cc.LayerMultiplex
- * @return {cc.LayerMultiplex|Null}
- */
-cc.LayerMultiplex.create = function (/*Multiple Arguments*/) {
- return new cc.LayerMultiplex(Array.prototype.slice.call(arguments));
-};
\ No newline at end of file
+});
\ No newline at end of file
diff --git a/cocos2d/core/layers/CCLayerWebGLRenderCmd.js b/cocos2d/core/layers/CCLayerWebGLRenderCmd.js
index 78ebbfe8a4..4d6149f475 100644
--- a/cocos2d/core/layers/CCLayerWebGLRenderCmd.js
+++ b/cocos2d/core/layers/CCLayerWebGLRenderCmd.js
@@ -81,17 +81,17 @@
this._shaderProgram.use();
this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix);
- cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POSITION | cc.Macro.VERTEX_ATTRIB_FLAG_COLOR);
+ cc.glEnableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POSITION | cc.macro.VERTEX_ATTRIB_FLAG_COLOR);
cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst);
//
// Attributes
//
context.bindBuffer(context.ARRAY_BUFFER, this._verticesFloat32Buffer);
- context.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, context.FLOAT, false, 0, 0);
+ context.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_POSITION, 2, context.FLOAT, false, 0, 0);
context.bindBuffer(context.ARRAY_BUFFER, this._colorsUint8Buffer);
- context.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_COLOR, 4, context.UNSIGNED_BYTE, true, 0, 0);
+ context.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_COLOR, 4, context.UNSIGNED_BYTE, true, 0, 0);
context.drawArrays(context.TRIANGLE_STRIP, 0, this._squareVertices.length);
};
@@ -285,15 +285,15 @@
//draw gradient layer
this._shaderProgram.use();
this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix);
- cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POSITION | cc.Macro.VERTEX_ATTRIB_FLAG_COLOR);
+ cc.glEnableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POSITION | cc.macro.VERTEX_ATTRIB_FLAG_COLOR);
cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst);
//
// Attributes
//
context.bindBuffer(context.ARRAY_BUFFER, this._verticesFloat32Buffer);
- context.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, context.FLOAT, false, 0, 0);
+ context.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_POSITION, 2, context.FLOAT, false, 0, 0);
context.bindBuffer(context.ARRAY_BUFFER, this._colorsUint8Buffer);
- context.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_COLOR, 4, context.UNSIGNED_BYTE, true, 0, 0);
+ context.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_COLOR, 4, context.UNSIGNED_BYTE, true, 0, 0);
context.drawArrays(context.TRIANGLE_STRIP, 0, this._squareVertices.length);
context.disable(context.SCISSOR_TEST);
diff --git a/cocos2d/core/platform/CCEGLView.js b/cocos2d/core/platform/CCEGLView.js
index 969abf81a4..3c0f917446 100644
--- a/cocos2d/core/platform/CCEGLView.js
+++ b/cocos2d/core/platform/CCEGLView.js
@@ -24,18 +24,7 @@
THE SOFTWARE.
****************************************************************************/
-/**
- * @ignore
- */
-cc.Touches = [];
-cc.TouchesIntergerDict = {};
-
-cc.DENSITYDPI_DEVICE = "device-dpi";
-cc.DENSITYDPI_HIGH = "high-dpi";
-cc.DENSITYDPI_MEDIUM = "medium-dpi";
-cc.DENSITYDPI_LOW = "low-dpi";
-
-cc.__BrowserGetter = {
+var __BrowserGetter = {
init: function(){
this.html = document.getElementsByTagName("html")[0];
},
@@ -58,36 +47,36 @@ cc.__BrowserGetter = {
};
if(window.navigator.userAgent.indexOf("OS 8_1_") > -1) //this mistake like MIUI, so use of MIUI treatment method
- cc.__BrowserGetter.adaptationType = cc.sys.BROWSER_TYPE_MIUI;
+ __BrowserGetter.adaptationType = cc.sys.BROWSER_TYPE_MIUI;
if(cc.sys.os === cc.sys.OS_IOS) // All browsers are WebView
- cc.__BrowserGetter.adaptationType = cc.sys.BROWSER_TYPE_SAFARI;
+ __BrowserGetter.adaptationType = cc.sys.BROWSER_TYPE_SAFARI;
-switch(cc.__BrowserGetter.adaptationType){
+switch(__BrowserGetter.adaptationType){
case cc.sys.BROWSER_TYPE_SAFARI:
- cc.__BrowserGetter.meta["minimal-ui"] = "true";
- cc.__BrowserGetter.availWidth = function(frame){
+ __BrowserGetter.meta["minimal-ui"] = "true";
+ __BrowserGetter.availWidth = function(frame){
return frame.clientWidth;
};
- cc.__BrowserGetter.availHeight = function(frame){
+ __BrowserGetter.availHeight = function(frame){
return frame.clientHeight;
};
break;
case cc.sys.BROWSER_TYPE_CHROME:
- cc.__BrowserGetter.__defineGetter__("target-densitydpi", function(){
+ __BrowserGetter.__defineGetter__("target-densitydpi", function(){
return cc.view._targetDensityDPI;
});
case cc.sys.BROWSER_TYPE_SOUGOU:
case cc.sys.BROWSER_TYPE_UC:
- cc.__BrowserGetter.availWidth = function(frame){
+ __BrowserGetter.availWidth = function(frame){
return frame.clientWidth;
};
- cc.__BrowserGetter.availHeight = function(frame){
+ __BrowserGetter.availHeight = function(frame){
return frame.clientHeight;
};
break;
case cc.sys.BROWSER_TYPE_MIUI:
- cc.__BrowserGetter.init = function(view){
+ __BrowserGetter.init = function(view){
if(view.__resizeWithBrowserSize) return;
var resize = function(){
view.setDesignResolutionSize(
@@ -167,7 +156,7 @@ cc.EGLView = cc._Class.extend({
ctor: function () {
var _t = this, d = document, _strategyer = cc.ContainerStrategy, _strategy = cc.ContentStrategy;
- cc.__BrowserGetter.init(this);
+ __BrowserGetter.init(this);
_t._frameSize = cc.size(0, 0);
_t._initFrameSize();
@@ -193,7 +182,7 @@ cc.EGLView = cc._Class.extend({
_t._hDC = cc.game.canvas;
_t._hRC = cc._renderContext;
- _t._targetDensityDPI = cc.DENSITYDPI_HIGH;
+ _t._targetDensityDPI = cc.macro.DENSITYDPI_HIGH;
},
// Resize helper functions
@@ -226,10 +215,10 @@ cc.EGLView = cc._Class.extend({
/**
*
* Sets view's target-densitydpi for android mobile browser. it can be set to:
- * 1. cc.DENSITYDPI_DEVICE, value is "device-dpi"
- * 2. cc.DENSITYDPI_HIGH, value is "high-dpi" (default value)
- * 3. cc.DENSITYDPI_MEDIUM, value is "medium-dpi" (browser's default value)
- * 4. cc.DENSITYDPI_LOW, value is "low-dpi"
+ * 1. cc.macro.DENSITYDPI_DEVICE, value is "device-dpi"
+ * 2. cc.macro.DENSITYDPI_HIGH, value is "high-dpi" (default value)
+ * 3. cc.macro.DENSITYDPI_MEDIUM, value is "medium-dpi" (browser's default value)
+ * 4. cc.macro.DENSITYDPI_LOW, value is "low-dpi"
* 5. Custom value, e.g: "480"
*
*
@@ -290,8 +279,8 @@ cc.EGLView = cc._Class.extend({
_initFrameSize: function () {
var locFrameSize = this._frameSize;
- locFrameSize.width = cc.__BrowserGetter.availWidth(cc.game.frame);
- locFrameSize.height = cc.__BrowserGetter.availHeight(cc.game.frame);
+ locFrameSize.width = __BrowserGetter.availWidth(cc.game.frame);
+ locFrameSize.height = __BrowserGetter.availHeight(cc.game.frame);
},
// hack
@@ -340,7 +329,7 @@ cc.EGLView = cc._Class.extend({
_adjustViewportMeta: function () {
if (this._isAdjustViewPort) {
- this._setViewportMeta(cc.__BrowserGetter.meta, false);
+ this._setViewportMeta(__BrowserGetter.meta, false);
}
},
diff --git a/cocos2d/core/platform/CCMacro.js b/cocos2d/core/platform/CCMacro.js
index 22da1cb40a..4c7b91776e 100644
--- a/cocos2d/core/platform/CCMacro.js
+++ b/cocos2d/core/platform/CCMacro.js
@@ -795,7 +795,7 @@ cc.getImageFormatByData = function (imgData) {
* @type {Object}
* @namespace cc
*/
-cc.Macro = {
+cc.macro = {
/**
* @property INVALID_INDEX
* @type {Number}
@@ -803,6 +803,14 @@ cc.Macro = {
*/
INVALID_INDEX: -1,
+ /**
+ * Default Node tag
+ * @property NODE_TAG_INVALID
+ * @type {Number}
+ * @readonly
+ */
+ NODE_TAG_INVALID: -1,
+
/**
* PI is the ratio of a circle's circumference to its diameter.
* @property PI
@@ -1024,6 +1032,12 @@ cc.Macro = {
DEVICE_MAX_ORIENTATIONS: 2,
+ DENSITYDPI_DEVICE: 'device-dpi',
+ DENSITYDPI_HIGH: 'high-dpi',
+ DENSITYDPI_MEDIUM: 'medium-dpi',
+ DENSITYDPI_LOW: 'low-dpi',
+
+
// ------------------- vertex attrib flags -----------------------------
/**
* @property VERTEX_ATTRIB_FLAG_NONE
@@ -1549,13 +1563,13 @@ cc.Macro = {
* @type {Number}
* @readonly
*/
-cc.defineGetterSetter(cc.Macro, "BLEND_SRC", function (){
+cc.defineGetterSetter(cc.macro, "BLEND_SRC", function (){
if (cc._renderType === cc.game.RENDER_TYPE_WEBGL
- && cc.Macro.OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA) {
- return cc.Macro.ONE;
+ && cc.macro.OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA) {
+ return cc.macro.ONE;
}
else {
- return cc.Macro.SRC_ALPHA;
+ return cc.macro.SRC_ALPHA;
}
});
@@ -1598,7 +1612,7 @@ cc.randomMinus1To1 = function () {
* @method degreesToRadians
*/
cc.degreesToRadians = function (angle) {
- return angle * cc.Macro.RAD;
+ return angle * cc.macro.RAD;
};
/**
@@ -1608,7 +1622,7 @@ cc.degreesToRadians = function (angle) {
* @method radiansToDegrees
*/
cc.radiansToDegrees = function (angle) {
- return angle * cc.Macro.DEG;
+ return angle * cc.macro.DEG;
};
/**
diff --git a/cocos2d/core/platform/index.js b/cocos2d/core/platform/index.js
index 351bf1a3b9..e5574b739d 100644
--- a/cocos2d/core/platform/index.js
+++ b/cocos2d/core/platform/index.js
@@ -38,3 +38,8 @@ require('./CCMacro');
if (cc.sys.isBrowser || cc.sys.isNative) {
require('./CCAssetLibrary');
}
+
+if (!CC_JSB && !(CC_EDITOR && Editor.isCoreLevel)) {
+ require('./miniFramework');
+ require('./CCVisibleRect');
+}
diff --git a/cocos2d/core/platform/js.js b/cocos2d/core/platform/js.js
index ee1294934a..f926c0500f 100644
--- a/cocos2d/core/platform/js.js
+++ b/cocos2d/core/platform/js.js
@@ -534,6 +534,7 @@ js.obsoletes = function (obj, objName, props, writable) {
* for example:
* cc.js.formatStr("a: %d, b: %b", a, b);
* cc.js.formatStr(a, b, c);
+ * @method formatStr
* @returns {String}
*/
js.formatStr = function formatStr() {
diff --git a/cocos2d/core/platform/miniFramework.js b/cocos2d/core/platform/miniFramework.js
index 2e53f45aa9..5cdf4898ca 100644
--- a/cocos2d/core/platform/miniFramework.js
+++ b/cocos2d/core/platform/miniFramework.js
@@ -246,7 +246,7 @@ cc.$.skew = function (a) {
* @return {$}
*/
cc.$new = function (x) {
- return cc.$(document.createElement(x))
+ return cc.$(document.createElement(x));
};
cc.$.findpos = function (obj) {
var curleft = 0;
diff --git a/cocos2d/core/renderer/index.js b/cocos2d/core/renderer/index.js
new file mode 100644
index 0000000000..bbaf445ae4
--- /dev/null
+++ b/cocos2d/core/renderer/index.js
@@ -0,0 +1,27 @@
+/****************************************************************************
+ Copyright (c) 2013-2016 Chukong Technologies Inc.
+
+ http://www.cocos.com
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated engine source code (the "Software"), a limited,
+ worldwide, royalty-free, non-assignable, revocable and non-exclusive license
+ to use Cocos Creator solely to develop games on your target platforms. You shall
+ not use Cocos Creator software for developing other software or tools that's
+ used for developing games. You are not granted to publish, distribute,
+ sublicense, and/or sell copies of Cocos Creator.
+
+ The software or tools in this License Agreement are licensed, not sold.
+ Chukong Aipu reserves all rights not expressly granted to you.
+
+ 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.
+ ****************************************************************************/
+
+require('./RendererCanvas');
+require('./RendererWebGL');
\ No newline at end of file
diff --git a/cocos2d/core/scenes/CCSGScene.js b/cocos2d/core/scenes/CCSGScene.js
index bac2ec04e8..948b475701 100644
--- a/cocos2d/core/scenes/CCSGScene.js
+++ b/cocos2d/core/scenes/CCSGScene.js
@@ -49,12 +49,3 @@ _ccsg.Scene = _ccsg.Node.extend(/** @lends _ccsg.Scene# */{
this.setContentSize(cc.director.getWinSize());
}
});
-
-/**
- * creates a scene
- * @deprecated since v3.0,please use new _ccsg.Scene() instead.
- * @return {_ccsg.Scene}
- */
-_ccsg.Scene.create = function () {
- return new _ccsg.Scene();
-};
diff --git a/cocos2d/core/sprites/CCAnimationCache.js b/cocos2d/core/sprites/CCAnimationCache.js
index 613150fcdb..7297f19402 100644
--- a/cocos2d/core/sprites/CCAnimationCache.js
+++ b/cocos2d/core/sprites/CCAnimationCache.js
@@ -172,7 +172,7 @@ cc.spriteFrameAnimationCache = {
var isLoop = animationDict["loop"];
var loopsTemp = parseInt(animationDict["loops"]);
- var loops = isLoop ? cc.Macro.REPEAT_FOREVER : ((isNaN(loopsTemp)) ? 1 : loopsTemp);
+ var loops = isLoop ? cc.macro.REPEAT_FOREVER : ((isNaN(loopsTemp)) ? 1 : loopsTemp);
var restoreOriginalFrame = (animationDict["restoreOriginalFrame"] && animationDict["restoreOriginalFrame"] == true) ? true : false;
var frameArray = animationDict["frames"];
diff --git a/cocos2d/core/sprites/CCSGSprite.js b/cocos2d/core/sprites/CCSGSprite.js
index 818c7ae057..02db734c08 100644
--- a/cocos2d/core/sprites/CCSGSprite.js
+++ b/cocos2d/core/sprites/CCSGSprite.js
@@ -130,7 +130,7 @@ _ccsg.Sprite = _ccsg.Node.extend({
self._shouldBeHidden = false;
self._offsetPosition = cc.p(0, 0);
self._unflippedOffsetPositionFromCenter = cc.p(0, 0);
- self._blendFunc = {src: cc.Macro.BLEND_SRC, dst: cc.Macro.BLEND_DST};
+ self._blendFunc = {src: cc.macro.BLEND_SRC, dst: cc.macro.BLEND_DST};
self._rect = cc.rect(0, 0, 0, 0);
self._softInit(fileName, rect, rotated);
@@ -627,8 +627,8 @@ _ccsg.Sprite = _ccsg.Node.extend({
_ccsg.Node.prototype.init.call(_t);
_t.dirty = _t._recursiveDirty = false;
- _t._blendFunc.src = cc.Macro.BLEND_SRC;
- _t._blendFunc.dst = cc.Macro.BLEND_DST;
+ _t._blendFunc.src = cc.macro.BLEND_SRC;
+ _t._blendFunc.dst = cc.macro.BLEND_DST;
_t.texture = null;
_t._flippedX = _t._flippedY = false;
@@ -704,8 +704,8 @@ _ccsg.Sprite = _ccsg.Node.extend({
_t.dirty = false;
_t._opacityModifyRGB = true;
- _t._blendFunc.src = cc.Macro.BLEND_SRC;
- _t._blendFunc.dst = cc.Macro.BLEND_DST;
+ _t._blendFunc.src = cc.macro.BLEND_SRC;
+ _t._blendFunc.dst = cc.macro.BLEND_DST;
_t._flippedX = _t._flippedY = false;
@@ -986,39 +986,6 @@ _ccsg.Sprite = _ccsg.Node.extend({
}
});
-/**
- * Create a sprite with image path or frame name or texture or spriteFrame.
- * @deprecated since v3.0, please use new construction instead
- * @see _ccsg.Sprite
- * @param {String|cc.SpriteFrame|HTMLImageElement|cc.Texture2D} fileName The string which indicates a path to image file, e.g., "scene1/monster.png".
- * @param {cc.Rect} rect Only the contents inside rect of pszFileName's texture will be applied for this sprite.
- * @param {Boolean} [rotated] Whether or not the texture rectangle is rotated.
- * @return {_ccsg.Sprite} A valid sprite object
- */
-_ccsg.Sprite.create = function (fileName, rect, rotated) {
- return new _ccsg.Sprite(fileName, rect, rotated);
-};
-
-/**
- * @deprecated since v3.0, please use new construction instead
- * @see _ccsg.Sprite
- * @function
- */
-_ccsg.Sprite.createWithTexture = _ccsg.Sprite.create;
-
-/**
- * @deprecated since v3.0, please use new construction instead
- * @see _ccsg.Sprite
- * @function
- */
-_ccsg.Sprite.createWithSpriteFrameName = _ccsg.Sprite.create;
-
-/**
- * @deprecated since v3.0, please use new construction instead
- * @see _ccsg.Sprite
- * @function
- */
-_ccsg.Sprite.createWithSpriteFrame = _ccsg.Sprite.create;
/**
* _ccsg.Sprite invalid index on the cc.SpriteBatchNode
* @constant
diff --git a/cocos2d/core/sprites/CCSGSpriteWebGLRenderCmd.js b/cocos2d/core/sprites/CCSGSpriteWebGLRenderCmd.js
index eeba97d680..921b7d1cdd 100644
--- a/cocos2d/core/sprites/CCSGSpriteWebGLRenderCmd.js
+++ b/cocos2d/core/sprites/CCSGSpriteWebGLRenderCmd.js
@@ -22,478 +22,478 @@
THE SOFTWARE.
****************************************************************************/
+var macro = cc.macro;
+
//Sprite's WebGL render command
-(function() {
- _ccsg.Sprite.WebGLRenderCmd = function (renderable) {
- _ccsg.Node.WebGLRenderCmd.call(this, renderable);
- this._needDraw = true;
+_ccsg.Sprite.WebGLRenderCmd = function (renderable) {
+ _ccsg.Node.WebGLRenderCmd.call(this, renderable);
+ this._needDraw = true;
- this._quad = new cc.V3F_C4B_T2F_Quad();
- this._quadWebBuffer = cc._renderContext.createBuffer();
- this._quadDirty = true;
+ this._quad = new cc.V3F_C4B_T2F_Quad();
+ this._quadWebBuffer = cc._renderContext.createBuffer();
+ this._quadDirty = true;
+ this._dirty = false;
+ this._recursiveDirty = false;
+};
+
+var proto = _ccsg.Sprite.WebGLRenderCmd.prototype = Object.create(_ccsg.Node.WebGLRenderCmd.prototype);
+proto.constructor = _ccsg.Sprite.WebGLRenderCmd;
+
+proto.updateBlendFunc = function (blendFunc) {};
+
+proto.setDirtyFlag = function(dirtyFlag){
+ _ccsg.Node.WebGLRenderCmd.prototype.setDirtyFlag.call(this, dirtyFlag);
+ this._dirty = true;
+};
+
+proto.setDirtyRecursively = function (value) {
+ this._recursiveDirty = value;
+ this._dirty = value;
+ // recursively set dirty
+ var locChildren = this._node._children, child, l = locChildren ? locChildren.length : 0;
+ for (var i = 0; i < l; i++) {
+ child = locChildren[i];
+ (child instanceof _ccsg.Sprite) && child._renderCmd.setDirtyRecursively(value);
+ }
+};
+
+proto._setBatchNodeForAddChild = function (child) {
+ var node = this._node;
+ if (node._batchNode) {
+ if (!(child instanceof _ccsg.Sprite)) {
+ cc.log(cc._LogInfos.Sprite.addChild);
+ return false;
+ }
+ if (child.texture._webTextureObj !== node.textureAtlas.texture._webTextureObj)
+ cc.log(cc._LogInfos.Sprite_addChild_2);
+
+ //put it in descendants array of batch node
+ node._batchNode.appendChild(child);
+ if (!node._reorderChildDirty)
+ node._setReorderChildDirtyRecursively();
+ }
+ return true;
+};
+
+proto._handleTextureForRotatedTexture = function (texture) {
+ return texture;
+};
+
+proto.isFrameDisplayed = function (frame) {
+ var node = this._node;
+ return (cc.rectEqualToRect(frame.getRect(), node._rect) && frame.getTexture().getName() === node._texture.getName()
+ && cc.pointEqualToPoint(frame.getOffset(), node._unflippedOffsetPositionFromCenter));
+};
+
+proto._init = function () {
+ var tempColor = {r: 255, g: 255, b: 255, a: 255}, quad = this._quad;
+ quad.bl.colors = tempColor;
+ quad.br.colors = tempColor;
+ quad.tl.colors = tempColor;
+ quad.tr.colors = tempColor;
+ this._quadDirty = true;
+};
+
+proto._resetForBatchNode = function () {
+ var node = this._node;
+ var x1 = node._offsetPosition.x;
+ var y1 = node._offsetPosition.y;
+ var x2 = x1 + node._rect.width;
+ var y2 = y1 + node._rect.height;
+ var locQuad = this._quad;
+ locQuad.bl.vertices = {x: x1, y: y1, z: 0};
+ locQuad.br.vertices = {x: x2, y: y1, z: 0};
+ locQuad.tl.vertices = {x: x1, y: y2, z: 0};
+ locQuad.tr.vertices = {x: x2, y: y2, z: 0};
+ this._quadDirty = true;
+};
+
+proto.getQuad = function () {
+ return this._quad;
+};
+
+proto._updateForSetSpriteFrame = function () {};
+
+proto._spriteFrameLoadedCallback = function (event) {
+ var spriteFrame = event.currentTarget;
+ this._node.setTextureRect(spriteFrame.getRect(), spriteFrame.isRotated(), spriteFrame.getOriginalSize());
+ this._node.emit("load");
+};
+
+proto._textureLoadedCallback = function (event) {
+ var node = this._node, sender = event.currentTarget;
+ if (node._textureLoaded)
+ return;
+
+ node._textureLoaded = true;
+ var locRect = node._rect;
+ if (!locRect) {
+ locRect = cc.rect(0, 0, sender.width, sender.height);
+ } else if (cc._rectEqualToZero(locRect)) {
+ locRect.width = sender.width;
+ locRect.height = sender.height;
+ }
+
+ node.texture = sender;
+ node.setTextureRect(locRect, node._rectRotated);
+
+ // by default use "Self Render".
+ // if the sprite is added to a batchnode, then it will automatically switch to "batchnode Render"
+ node.setBatchNode(node._batchNode);
+ this._quadDirty = true;
+ node.emit("load");
+};
+
+proto._setTextureCoords = function (rect) {
+ var node = this._node;
+
+ var tex = node._batchNode ? node.textureAtlas.texture : node._texture;
+ if (!tex)
+ return;
+
+ var atlasWidth = tex.pixelWidth;
+ var atlasHeight = tex.pixelHeight;
+
+ var left, right, top, bottom, tempSwap, locQuad = this._quad;
+ if (node._rectRotated) {
+ if (macro.FIX_ARTIFACTS_BY_STRECHING_TEXEL) {
+ left = (2 * rect.x + 1) / (2 * atlasWidth);
+ right = left + (rect.height * 2 - 2) / (2 * atlasWidth);
+ top = (2 * rect.y + 1) / (2 * atlasHeight);
+ bottom = top + (rect.width * 2 - 2) / (2 * atlasHeight);
+ } else {
+ left = rect.x / atlasWidth;
+ right = (rect.x + rect.height) / atlasWidth;
+ top = rect.y / atlasHeight;
+ bottom = (rect.y + rect.width) / atlasHeight;
+ }
+
+ if (node._flippedX) {
+ tempSwap = top;
+ top = bottom;
+ bottom = tempSwap;
+ }
+
+ if (node._flippedY) {
+ tempSwap = left;
+ left = right;
+ right = tempSwap;
+ }
+
+ locQuad.bl.texCoords.u = left;
+ locQuad.bl.texCoords.v = top;
+ locQuad.br.texCoords.u = left;
+ locQuad.br.texCoords.v = bottom;
+ locQuad.tl.texCoords.u = right;
+ locQuad.tl.texCoords.v = top;
+ locQuad.tr.texCoords.u = right;
+ locQuad.tr.texCoords.v = bottom;
+ } else {
+ if (macro.FIX_ARTIFACTS_BY_STRECHING_TEXEL) {
+ left = (2 * rect.x + 1) / (2 * atlasWidth);
+ right = left + (rect.width * 2 - 2) / (2 * atlasWidth);
+ top = (2 * rect.y + 1) / (2 * atlasHeight);
+ bottom = top + (rect.height * 2 - 2) / (2 * atlasHeight);
+ } else {
+ left = rect.x / atlasWidth;
+ right = (rect.x + rect.width) / atlasWidth;
+ top = rect.y / atlasHeight;
+ bottom = (rect.y + rect.height) / atlasHeight;
+ }
+
+ if (node._flippedX) {
+ tempSwap = left;
+ left = right;
+ right = tempSwap;
+ }
+
+ if (node._flippedY) {
+ tempSwap = top;
+ top = bottom;
+ bottom = tempSwap;
+ }
+
+ locQuad.bl.texCoords.u = left;
+ locQuad.bl.texCoords.v = bottom;
+ locQuad.br.texCoords.u = right;
+ locQuad.br.texCoords.v = bottom;
+ locQuad.tl.texCoords.u = left;
+ locQuad.tl.texCoords.v = top;
+ locQuad.tr.texCoords.u = right;
+ locQuad.tr.texCoords.v = top;
+ }
+ this._quadDirty = true;
+};
+
+proto.transform = function(parentCmd, recursive){
+ _ccsg.Node.WebGLRenderCmd.prototype.transform.call(this, parentCmd, recursive);
+ this._dirty = true; //use for batching
+};
+
+proto._setColorDirty = function () {};
+
+proto._updateColor = function () {
+ var node = this._node,
+ locDisplayedColor = this._displayedColor,
+ r = locDisplayedColor.r,
+ g = locDisplayedColor.g,
+ b = locDisplayedColor.b,
+ a = locDisplayedColor.a = this._displayedOpacity;
+ // special opacity for premultiplied textures
+ if (node._opacityModifyRGB) {
+ locDisplayedColor.r *= a / 255.0;
+ locDisplayedColor.g *= a / 255.0;
+ locDisplayedColor.b *= a / 255.0;
+ }
+ var locQuad = this._quad;
+ locQuad.bl.colors = locDisplayedColor;
+ locQuad.br.colors = locDisplayedColor;
+ locQuad.tl.colors = locDisplayedColor;
+ locQuad.tr.colors = locDisplayedColor;
+
+ // Roll back color
+ locDisplayedColor.r = r;
+ locDisplayedColor.g = g;
+ locDisplayedColor.b = b;
+
+ // renders using Sprite Manager
+ if (node._batchNode) {
+ if (node.atlasIndex !== _ccsg.Sprite.INDEX_NOT_INITIALIZED) {
+ node.textureAtlas.updateQuad(locQuad, node.atlasIndex)
+ } else {
+ // no need to set it recursively
+ // update dirty_, don't update recursiveDirty_
+ this._dirty = true;
+ }
+ }
+ // self render
+ // do nothing
+ this._quadDirty = true;
+};
+
+proto._updateBlendFunc = function () {
+ if (this._batchNode) {
+ cc.log(cc._LogInfos.Sprite__updateBlendFunc);
+ return;
+ }
+
+ // it's possible to have an untextured sprite
+ var node = this._node;
+ if (!node._texture || !node._texture.hasPremultipliedAlpha()) {
+ node._blendFunc.src = macro.SRC_ALPHA;
+ node._blendFunc.dst = macro.ONE_MINUS_SRC_ALPHA;
+ node.opacityModifyRGB = false;
+ } else {
+ node._blendFunc.src = macro.BLEND_SRC;
+ node._blendFunc.dst = macro.BLEND_DST;
+ node.opacityModifyRGB = true;
+ }
+};
+
+proto._setTexture = function (texture) {
+ var node = this._node;
+ // If batchnode, then texture id should be the same
+ if (node._batchNode) {
+ if(node._batchNode.texture !== texture){
+ cc.log(cc._LogInfos.Sprite_setTexture);
+ return;
+ }
+ }else{
+ if(node._texture !== texture){
+ node._textureLoaded = texture ? texture._textureLoaded : false;
+ node._texture = texture;
+ this._updateBlendFunc();
+ }
+ }
+
+ if (texture)
+ this._shaderProgram = cc.shaderCache.programForKey(macro.SHADER_POSITION_TEXTURECOLOR);
+ else
+ this._shaderProgram = cc.shaderCache.programForKey(macro.SHADER_POSITION_COLOR);
+
+};
+
+proto.updateTransform = function () { //called only at batching.
+ var _t = this, node = this._node;
+
+ // recalculate matrix only if it is dirty
+ if (this._dirty) {
+ var locQuad = _t._quad, locParent = node._parent;
+ // If it is not visible, or one of its ancestors is not visible, then do nothing:
+ if (!node._visible || ( locParent && locParent !== node._batchNode && locParent._shouldBeHidden)) {
+ locQuad.br.vertices = locQuad.tl.vertices = locQuad.tr.vertices = locQuad.bl.vertices = {x: 0, y: 0, z: 0};
+ node._shouldBeHidden = true;
+ } else {
+ node._shouldBeHidden = false;
+ if(this._dirtyFlag !== 0){ //because changing color and opacity uses dirty flag at visit, but visit doesn't call at batching.
+ this.updateStatus();
+ this._dirtyFlag = 0;
+ }
+
+ if (!locParent || locParent === node._batchNode) {
+ node._transformToBatch = _t.getNodeToParentTransform();
+ } else {
+ node._transformToBatch = cc.affineTransformConcat(_t.getNodeToParentTransform(), locParent._transformToBatch);
+ }
+
+ //
+ // calculate the Quad based on the Affine Matrix
+ //
+ var locTransformToBatch = node._transformToBatch;
+ var rect = node._rect;
+ var x1 = node._offsetPosition.x;
+ var y1 = node._offsetPosition.y;
+
+ var x2 = x1 + rect.width;
+ var y2 = y1 + rect.height;
+ var x = locTransformToBatch.tx;
+ var y = locTransformToBatch.ty;
+
+ var cr = locTransformToBatch.a;
+ var sr = locTransformToBatch.b;
+ var cr2 = locTransformToBatch.d;
+ var sr2 = -locTransformToBatch.c;
+ var ax = x1 * cr - y1 * sr2 + x;
+ var ay = x1 * sr + y1 * cr2 + y;
+
+ var bx = x2 * cr - y1 * sr2 + x;
+ var by = x2 * sr + y1 * cr2 + y;
+
+ var cx = x2 * cr - y2 * sr2 + x;
+ var cy = x2 * sr + y2 * cr2 + y;
+
+ var dx = x1 * cr - y2 * sr2 + x;
+ var dy = x1 * sr + y2 * cr2 + y;
+
+ var locVertexZ = node._vertexZ;
+ if (!macro.SPRITEBATCHNODE_RENDER_SUBPIXEL) {
+ ax = 0 | ax;
+ ay = 0 | ay;
+ bx = 0 | bx;
+ by = 0 | by;
+ cx = 0 | cx;
+ cy = 0 | cy;
+ dx = 0 | dx;
+ dy = 0 | dy;
+ }
+ locQuad.bl.vertices = {x: ax, y: ay, z: locVertexZ};
+ locQuad.br.vertices = {x: bx, y: by, z: locVertexZ};
+ locQuad.tl.vertices = {x: dx, y: dy, z: locVertexZ};
+ locQuad.tr.vertices = {x: cx, y: cy, z: locVertexZ};
+ }
+ node.textureAtlas.updateQuad(locQuad, node.atlasIndex);
+ node._recursiveDirty = false;
this._dirty = false;
- this._recursiveDirty = false;
- };
+ }
- var proto = _ccsg.Sprite.WebGLRenderCmd.prototype = Object.create(_ccsg.Node.WebGLRenderCmd.prototype);
- proto.constructor = _ccsg.Sprite.WebGLRenderCmd;
+ // recursively iterate over children
+ if (node._hasChildren)
+ node._arrayMakeObjectsPerformSelector(node._children, _ccsg.Node._stateCallbackType.updateTransform);
- proto.updateBlendFunc = function (blendFunc) {};
+ /*if (macro.SPRITE_DEBUG_DRAW) { //TODO
+ // draw bounding box
+ var vertices = [
+ cc.p(_t._quad.bl.vertices.x, _t._quad.bl.vertices.y),
+ cc.p(_t._quad.br.vertices.x, _t._quad.br.vertices.y),
+ cc.p(_t._quad.tr.vertices.x, _t._quad.tr.vertices.y),
+ cc.p(_t._quad.tl.vertices.x, _t._quad.tl.vertices.y)
+ ];
+ cc._drawingUtil.drawPoly(vertices, 4, true);
+ }*/
+};
- proto.setDirtyFlag = function(dirtyFlag){
- _ccsg.Node.WebGLRenderCmd.prototype.setDirtyFlag.call(this, dirtyFlag);
- this._dirty = true;
- };
-
- proto.setDirtyRecursively = function (value) {
- this._recursiveDirty = value;
- this._dirty = value;
- // recursively set dirty
- var locChildren = this._node._children, child, l = locChildren ? locChildren.length : 0;
- for (var i = 0; i < l; i++) {
- child = locChildren[i];
- (child instanceof _ccsg.Sprite) && child._renderCmd.setDirtyRecursively(value);
- }
- };
-
- proto._setBatchNodeForAddChild = function (child) {
- var node = this._node;
- if (node._batchNode) {
- if (!(child instanceof _ccsg.Sprite)) {
- cc.log(cc._LogInfos.Sprite.addChild);
- return false;
- }
- if (child.texture._webTextureObj !== node.textureAtlas.texture._webTextureObj)
- cc.log(cc._LogInfos.Sprite_addChild_2);
-
- //put it in descendants array of batch node
- node._batchNode.appendChild(child);
- if (!node._reorderChildDirty)
- node._setReorderChildDirtyRecursively();
- }
- return true;
- };
-
- proto._handleTextureForRotatedTexture = function (texture) {
- return texture;
- };
-
- proto.isFrameDisplayed = function (frame) {
- var node = this._node;
- return (cc.rectEqualToRect(frame.getRect(), node._rect) && frame.getTexture().getName() === node._texture.getName()
- && cc.pointEqualToPoint(frame.getOffset(), node._unflippedOffsetPositionFromCenter));
- };
-
- proto._init = function () {
- var tempColor = {r: 255, g: 255, b: 255, a: 255}, quad = this._quad;
- quad.bl.colors = tempColor;
- quad.br.colors = tempColor;
- quad.tl.colors = tempColor;
- quad.tr.colors = tempColor;
- this._quadDirty = true;
- };
-
- proto._resetForBatchNode = function () {
- var node = this._node;
- var x1 = node._offsetPosition.x;
- var y1 = node._offsetPosition.y;
- var x2 = x1 + node._rect.width;
- var y2 = y1 + node._rect.height;
- var locQuad = this._quad;
- locQuad.bl.vertices = {x: x1, y: y1, z: 0};
- locQuad.br.vertices = {x: x2, y: y1, z: 0};
- locQuad.tl.vertices = {x: x1, y: y2, z: 0};
- locQuad.tr.vertices = {x: x2, y: y2, z: 0};
- this._quadDirty = true;
- };
-
- proto.getQuad = function () {
- return this._quad;
- };
-
- proto._updateForSetSpriteFrame = function () {};
-
- proto._spriteFrameLoadedCallback = function (event) {
- var spriteFrame = event.currentTarget;
- this._node.setTextureRect(spriteFrame.getRect(), spriteFrame.isRotated(), spriteFrame.getOriginalSize());
- this._node.emit("load");
- };
-
- proto._textureLoadedCallback = function (event) {
- var node = this._node, sender = event.currentTarget;
- if (node._textureLoaded)
- return;
-
- node._textureLoaded = true;
- var locRect = node._rect;
- if (!locRect) {
- locRect = cc.rect(0, 0, sender.width, sender.height);
- } else if (cc._rectEqualToZero(locRect)) {
- locRect.width = sender.width;
- locRect.height = sender.height;
- }
-
- node.texture = sender;
- node.setTextureRect(locRect, node._rectRotated);
-
- // by default use "Self Render".
- // if the sprite is added to a batchnode, then it will automatically switch to "batchnode Render"
- node.setBatchNode(node._batchNode);
- this._quadDirty = true;
- node.emit("load");
- };
-
- proto._setTextureCoords = function (rect) {
- var node = this._node;
-
- var tex = node._batchNode ? node.textureAtlas.texture : node._texture;
- if (!tex)
- return;
-
- var atlasWidth = tex.pixelWidth;
- var atlasHeight = tex.pixelHeight;
-
- var left, right, top, bottom, tempSwap, locQuad = this._quad;
- if (node._rectRotated) {
- if (cc.Macro.FIX_ARTIFACTS_BY_STRECHING_TEXEL) {
- left = (2 * rect.x + 1) / (2 * atlasWidth);
- right = left + (rect.height * 2 - 2) / (2 * atlasWidth);
- top = (2 * rect.y + 1) / (2 * atlasHeight);
- bottom = top + (rect.width * 2 - 2) / (2 * atlasHeight);
- } else {
- left = rect.x / atlasWidth;
- right = (rect.x + rect.height) / atlasWidth;
- top = rect.y / atlasHeight;
- bottom = (rect.y + rect.width) / atlasHeight;
- }
-
- if (node._flippedX) {
- tempSwap = top;
- top = bottom;
- bottom = tempSwap;
- }
-
- if (node._flippedY) {
- tempSwap = left;
- left = right;
- right = tempSwap;
- }
-
- locQuad.bl.texCoords.u = left;
- locQuad.bl.texCoords.v = top;
- locQuad.br.texCoords.u = left;
- locQuad.br.texCoords.v = bottom;
- locQuad.tl.texCoords.u = right;
- locQuad.tl.texCoords.v = top;
- locQuad.tr.texCoords.u = right;
- locQuad.tr.texCoords.v = bottom;
+proto._checkTextureBoundary = function (texture, rect, rotated) {
+ if (texture && texture.url) {
+ var _x, _y;
+ if (rotated) {
+ _x = rect.x + rect.height;
+ _y = rect.y + rect.width;
} else {
- if (cc.Macro.FIX_ARTIFACTS_BY_STRECHING_TEXEL) {
- left = (2 * rect.x + 1) / (2 * atlasWidth);
- right = left + (rect.width * 2 - 2) / (2 * atlasWidth);
- top = (2 * rect.y + 1) / (2 * atlasHeight);
- bottom = top + (rect.height * 2 - 2) / (2 * atlasHeight);
- } else {
- left = rect.x / atlasWidth;
- right = (rect.x + rect.width) / atlasWidth;
- top = rect.y / atlasHeight;
- bottom = (rect.y + rect.height) / atlasHeight;
- }
-
- if (node._flippedX) {
- tempSwap = left;
- left = right;
- right = tempSwap;
- }
-
- if (node._flippedY) {
- tempSwap = top;
- top = bottom;
- bottom = tempSwap;
- }
-
- locQuad.bl.texCoords.u = left;
- locQuad.bl.texCoords.v = bottom;
- locQuad.br.texCoords.u = right;
- locQuad.br.texCoords.v = bottom;
- locQuad.tl.texCoords.u = left;
- locQuad.tl.texCoords.v = top;
- locQuad.tr.texCoords.u = right;
- locQuad.tr.texCoords.v = top;
+ _x = rect.x + rect.width;
+ _y = rect.y + rect.height;
}
- this._quadDirty = true;
- };
-
- proto.transform = function(parentCmd, recursive){
- _ccsg.Node.WebGLRenderCmd.prototype.transform.call(this, parentCmd, recursive);
- this._dirty = true; //use for batching
- };
-
- proto._setColorDirty = function () {};
-
- proto._updateColor = function () {
- var node = this._node,
- locDisplayedColor = this._displayedColor,
- r = locDisplayedColor.r,
- g = locDisplayedColor.g,
- b = locDisplayedColor.b,
- a = locDisplayedColor.a = this._displayedOpacity;
- // special opacity for premultiplied textures
- if (node._opacityModifyRGB) {
- locDisplayedColor.r *= a / 255.0;
- locDisplayedColor.g *= a / 255.0;
- locDisplayedColor.b *= a / 255.0;
+ if (_x > texture.width) {
+ cc.error(cc._LogInfos.RectWidth, texture.url);
}
- var locQuad = this._quad;
- locQuad.bl.colors = locDisplayedColor;
- locQuad.br.colors = locDisplayedColor;
- locQuad.tl.colors = locDisplayedColor;
- locQuad.tr.colors = locDisplayedColor;
-
- // Roll back color
- locDisplayedColor.r = r;
- locDisplayedColor.g = g;
- locDisplayedColor.b = b;
-
- // renders using Sprite Manager
- if (node._batchNode) {
- if (node.atlasIndex !== _ccsg.Sprite.INDEX_NOT_INITIALIZED) {
- node.textureAtlas.updateQuad(locQuad, node.atlasIndex)
- } else {
- // no need to set it recursively
- // update dirty_, don't update recursiveDirty_
- this._dirty = true;
- }
+ if (_y > texture.height) {
+ cc.error(cc._LogInfos.RectHeight, texture.url);
}
- // self render
- // do nothing
- this._quadDirty = true;
- };
+ }
+};
- proto._updateBlendFunc = function () {
- if (this._batchNode) {
- cc.log(cc._LogInfos.Sprite__updateBlendFunc);
- return;
- }
+proto.rendering = function (ctx) {
+ var node = this._node, locTexture = node._texture;
+ if ((locTexture &&!locTexture._textureLoaded) || this._displayedOpacity === 0)
+ return;
- // it's possible to have an untextured sprite
- var node = this._node;
- if (!node._texture || !node._texture.hasPremultipliedAlpha()) {
- node._blendFunc.src = cc.Macro.SRC_ALPHA;
- node._blendFunc.dst = cc.Macro.ONE_MINUS_SRC_ALPHA;
- node.opacityModifyRGB = false;
- } else {
- node._blendFunc.src = cc.Macro.BLEND_SRC;
- node._blendFunc.dst = cc.Macro.BLEND_DST;
- node.opacityModifyRGB = true;
- }
- };
+ var gl = ctx || cc._renderContext;
+ //cc.assert(!_t._batchNode, "If _ccsg.Sprite is being rendered by cc.SpriteBatchNode, _ccsg.Sprite#draw SHOULD NOT be called");
- proto._setTexture = function (texture) {
- var node = this._node;
- // If batchnode, then texture id should be the same
- if (node._batchNode) {
- if(node._batchNode.texture !== texture){
- cc.log(cc._LogInfos.Sprite_setTexture);
- return;
- }
- }else{
- if(node._texture !== texture){
- node._textureLoaded = texture ? texture._textureLoaded : false;
- node._texture = texture;
- this._updateBlendFunc();
- }
- }
-
- if (texture)
- this._shaderProgram = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLOR);
- else
- this._shaderProgram = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_COLOR);
-
- };
-
- proto.updateTransform = function () { //called only at batching.
- var _t = this, node = this._node;
-
- // recalculate matrix only if it is dirty
- if (this._dirty) {
- var locQuad = _t._quad, locParent = node._parent;
- // If it is not visible, or one of its ancestors is not visible, then do nothing:
- if (!node._visible || ( locParent && locParent !== node._batchNode && locParent._shouldBeHidden)) {
- locQuad.br.vertices = locQuad.tl.vertices = locQuad.tr.vertices = locQuad.bl.vertices = {x: 0, y: 0, z: 0};
- node._shouldBeHidden = true;
- } else {
- node._shouldBeHidden = false;
- if(this._dirtyFlag !== 0){ //because changing color and opacity uses dirty flag at visit, but visit doesn't call at batching.
- this.updateStatus();
- this._dirtyFlag = 0;
- }
-
- if (!locParent || locParent === node._batchNode) {
- node._transformToBatch = _t.getNodeToParentTransform();
- } else {
- node._transformToBatch = cc.affineTransformConcat(_t.getNodeToParentTransform(), locParent._transformToBatch);
- }
-
- //
- // calculate the Quad based on the Affine Matrix
- //
- var locTransformToBatch = node._transformToBatch;
- var rect = node._rect;
- var x1 = node._offsetPosition.x;
- var y1 = node._offsetPosition.y;
-
- var x2 = x1 + rect.width;
- var y2 = y1 + rect.height;
- var x = locTransformToBatch.tx;
- var y = locTransformToBatch.ty;
-
- var cr = locTransformToBatch.a;
- var sr = locTransformToBatch.b;
- var cr2 = locTransformToBatch.d;
- var sr2 = -locTransformToBatch.c;
- var ax = x1 * cr - y1 * sr2 + x;
- var ay = x1 * sr + y1 * cr2 + y;
-
- var bx = x2 * cr - y1 * sr2 + x;
- var by = x2 * sr + y1 * cr2 + y;
-
- var cx = x2 * cr - y2 * sr2 + x;
- var cy = x2 * sr + y2 * cr2 + y;
-
- var dx = x1 * cr - y2 * sr2 + x;
- var dy = x1 * sr + y2 * cr2 + y;
-
- var locVertexZ = node._vertexZ;
- if (!cc.Macro.SPRITEBATCHNODE_RENDER_SUBPIXEL) {
- ax = 0 | ax;
- ay = 0 | ay;
- bx = 0 | bx;
- by = 0 | by;
- cx = 0 | cx;
- cy = 0 | cy;
- dx = 0 | dx;
- dy = 0 | dy;
- }
- locQuad.bl.vertices = {x: ax, y: ay, z: locVertexZ};
- locQuad.br.vertices = {x: bx, y: by, z: locVertexZ};
- locQuad.tl.vertices = {x: dx, y: dy, z: locVertexZ};
- locQuad.tr.vertices = {x: cx, y: cy, z: locVertexZ};
- }
- node.textureAtlas.updateQuad(locQuad, node.atlasIndex);
- node._recursiveDirty = false;
- this._dirty = false;
- }
-
- // recursively iterate over children
- if (node._hasChildren)
- node._arrayMakeObjectsPerformSelector(node._children, _ccsg.Node._stateCallbackType.updateTransform);
-
- /*if (cc.Macro.SPRITE_DEBUG_DRAW) { //TODO
- // draw bounding box
- var vertices = [
- cc.p(_t._quad.bl.vertices.x, _t._quad.bl.vertices.y),
- cc.p(_t._quad.br.vertices.x, _t._quad.br.vertices.y),
- cc.p(_t._quad.tr.vertices.x, _t._quad.tr.vertices.y),
- cc.p(_t._quad.tl.vertices.x, _t._quad.tl.vertices.y)
- ];
- cc._drawingUtil.drawPoly(vertices, 4, true);
- }*/
- };
-
- proto._checkTextureBoundary = function (texture, rect, rotated) {
- if (texture && texture.url) {
- var _x, _y;
- if (rotated) {
- _x = rect.x + rect.height;
- _y = rect.y + rect.width;
- } else {
- _x = rect.x + rect.width;
- _y = rect.y + rect.height;
- }
- if (_x > texture.width) {
- cc.error(cc._LogInfos.RectWidth, texture.url);
- }
- if (_y > texture.height) {
- cc.error(cc._LogInfos.RectHeight, texture.url);
- }
- }
- };
-
- proto.rendering = function (ctx) {
- var node = this._node, locTexture = node._texture;
- if ((locTexture &&!locTexture._textureLoaded) || this._displayedOpacity === 0)
- return;
-
- var gl = ctx || cc._renderContext;
- //cc.assert(!_t._batchNode, "If _ccsg.Sprite is being rendered by cc.SpriteBatchNode, _ccsg.Sprite#draw SHOULD NOT be called");
-
- if (locTexture) {
- if (locTexture._textureLoaded) {
- this._shaderProgram.use();
- this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix);
-
- cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst);
- //optimize performance for javascript
- cc.glBindTexture2DN(0, locTexture); // = cc.glBindTexture2D(locTexture);
- cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
-
- gl.bindBuffer(gl.ARRAY_BUFFER, this._quadWebBuffer);
- if (this._quadDirty) {
- gl.bufferData(gl.ARRAY_BUFFER, this._quad.arrayBuffer, gl.DYNAMIC_DRAW);
- this._quadDirty = false;
- }
- gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 24, 0); //cc.Macro.VERTEX_ATTRIB_POSITION
- gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, true, 24, 12); //cc.Macro.VERTEX_ATTRIB_COLOR
- gl.vertexAttribPointer(2, 2, gl.FLOAT, false, 24, 16); //cc.Macro.VERTEX_ATTRIB_TEX_COORDS
- gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
- }
- } else {
+ if (locTexture) {
+ if (locTexture._textureLoaded) {
this._shaderProgram.use();
this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix);
cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst);
- cc.glBindTexture2D(null);
-
- cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POSITION | cc.Macro.VERTEX_ATTRIB_FLAG_COLOR);
+ //optimize performance for javascript
+ cc.glBindTexture2DN(0, locTexture); // = cc.glBindTexture2D(locTexture);
+ cc.glEnableVertexAttribs(macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
gl.bindBuffer(gl.ARRAY_BUFFER, this._quadWebBuffer);
if (this._quadDirty) {
- gl.bufferData(gl.ARRAY_BUFFER, this._quad.arrayBuffer, gl.STATIC_DRAW);
+ gl.bufferData(gl.ARRAY_BUFFER, this._quad.arrayBuffer, gl.DYNAMIC_DRAW);
this._quadDirty = false;
}
- gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 3, gl.FLOAT, false, 24, 0);
- gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_COLOR, 4, gl.UNSIGNED_BYTE, true, 24, 12);
+ gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 24, 0); //macro.VERTEX_ATTRIB_POSITION
+ gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, true, 24, 12); //macro.VERTEX_ATTRIB_COLOR
+ gl.vertexAttribPointer(2, 2, gl.FLOAT, false, 24, 16); //macro.VERTEX_ATTRIB_TEX_COORDS
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
}
- cc.g_NumberOfDraws++;
+ } else {
+ this._shaderProgram.use();
+ this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix);
- if (cc.Macro.SPRITE_DEBUG_DRAW === 0 && !node._showNode)
- return;
+ cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst);
+ cc.glBindTexture2D(null);
- cc.kmGLMatrixMode(cc.KM_GL_MODELVIEW);
- //cc.kmGLPushMatrixWitMat4(node._stackMatrix);
- cc.current_stack.stack.push(cc.current_stack.top);
- cc.current_stack.top = this._stackMatrix;
+ cc.glEnableVertexAttribs(macro.VERTEX_ATTRIB_FLAG_POSITION | macro.VERTEX_ATTRIB_FLAG_COLOR);
- if (cc.Macro.SPRITE_DEBUG_DRAW === 1 || node._showNode) {
- // draw bounding box
- var locQuad = this._quad;
- var verticesG1 = [
- cc.p(locQuad.tl.vertices.x, locQuad.tl.vertices.y),
- cc.p(locQuad.bl.vertices.x, locQuad.bl.vertices.y),
- cc.p(locQuad.br.vertices.x, locQuad.br.vertices.y),
- cc.p(locQuad.tr.vertices.x, locQuad.tr.vertices.y)
- ];
- cc._drawingUtil.drawPoly(verticesG1, 4, true);
- } else if (cc.Macro.SPRITE_DEBUG_DRAW === 2) {
- // draw texture box
- var drawRectG2 = node.getTextureRect();
- var offsetPixG2 = node.getOffsetPosition();
- var verticesG2 = [cc.p(offsetPixG2.x, offsetPixG2.y), cc.p(offsetPixG2.x + drawRectG2.width, offsetPixG2.y),
- cc.p(offsetPixG2.x + drawRectG2.width, offsetPixG2.y + drawRectG2.height), cc.p(offsetPixG2.x, offsetPixG2.y + drawRectG2.height)];
- cc._drawingUtil.drawPoly(verticesG2, 4, true);
- } // CC_SPRITE_DEBUG_DRAW
- cc.current_stack.top = cc.current_stack.stack.pop();
- };
-})();
\ No newline at end of file
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._quadWebBuffer);
+ if (this._quadDirty) {
+ gl.bufferData(gl.ARRAY_BUFFER, this._quad.arrayBuffer, gl.STATIC_DRAW);
+ this._quadDirty = false;
+ }
+ gl.vertexAttribPointer(macro.VERTEX_ATTRIB_POSITION, 3, gl.FLOAT, false, 24, 0);
+ gl.vertexAttribPointer(macro.VERTEX_ATTRIB_COLOR, 4, gl.UNSIGNED_BYTE, true, 24, 12);
+ gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
+ }
+ cc.g_NumberOfDraws++;
+
+ if (macro.SPRITE_DEBUG_DRAW === 0 && !node._showNode)
+ return;
+
+ cc.math.glMatrixMode(cc.math.KM_GL_MODELVIEW);
+ //cc.math.glPushMatrixWitMat4(node._stackMatrix);
+ cc.current_stack.stack.push(cc.current_stack.top);
+ cc.current_stack.top = this._stackMatrix;
+
+ if (macro.SPRITE_DEBUG_DRAW === 1 || node._showNode) {
+ // draw bounding box
+ var locQuad = this._quad;
+ var verticesG1 = [
+ cc.p(locQuad.tl.vertices.x, locQuad.tl.vertices.y),
+ cc.p(locQuad.bl.vertices.x, locQuad.bl.vertices.y),
+ cc.p(locQuad.br.vertices.x, locQuad.br.vertices.y),
+ cc.p(locQuad.tr.vertices.x, locQuad.tr.vertices.y)
+ ];
+ cc._drawingUtil.drawPoly(verticesG1, 4, true);
+ } else if (macro.SPRITE_DEBUG_DRAW === 2) {
+ // draw texture box
+ var drawRectG2 = node.getTextureRect();
+ var offsetPixG2 = node.getOffsetPosition();
+ var verticesG2 = [cc.p(offsetPixG2.x, offsetPixG2.y), cc.p(offsetPixG2.x + drawRectG2.width, offsetPixG2.y),
+ cc.p(offsetPixG2.x + drawRectG2.width, offsetPixG2.y + drawRectG2.height), cc.p(offsetPixG2.x, offsetPixG2.y + drawRectG2.height)];
+ cc._drawingUtil.drawPoly(verticesG2, 4, true);
+ } // CC_SPRITE_DEBUG_DRAW
+ cc.current_stack.top = cc.current_stack.stack.pop();
+};
\ No newline at end of file
diff --git a/cocos2d/core/sprites/CCScale9Sprite.js b/cocos2d/core/sprites/CCScale9Sprite.js
index 415ee6f04f..20115ce9e1 100644
--- a/cocos2d/core/sprites/CCScale9Sprite.js
+++ b/cocos2d/core/sprites/CCScale9Sprite.js
@@ -954,7 +954,7 @@ cc.Scale9Sprite = _ccsg.Node.extend({
* @param textureOrTextureFile The name of the texture file.
*/
setTexture: function (textureOrTextureFile) {
- var spriteFrame = cc.SpriteFrame.createWithTexture(textureOrTextureFile);
+ var spriteFrame = new cc.SpriteFrame(textureOrTextureFile);
this.setSpriteFrame(spriteFrame);
},
@@ -996,12 +996,12 @@ cc.Scale9Sprite = _ccsg.Node.extend({
*/
setBlendFunc: function (blendFunc, dst) {
if (dst === undefined) {
- this._blendFunc.src = blendFunc.src || cc.Macro.BLEND_SRC;
- this._blendFunc.dst = blendFunc.dst || cc.Macro.BLEND_DST;
+ this._blendFunc.src = blendFunc.src || cc.macro.BLEND_SRC;
+ this._blendFunc.dst = blendFunc.dst || cc.macro.BLEND_DST;
}
else {
- this._blendFunc.src = blendFunc || cc.Macro.BLEND_SRC;
- this._blendFunc.dst = dst || cc.Macro.BLEND_DST;
+ this._blendFunc.src = blendFunc || cc.macro.BLEND_SRC;
+ this._blendFunc.dst = dst || cc.macro.BLEND_DST;
}
},
@@ -1275,33 +1275,6 @@ cc.defineGetterSetter(_p, "insetBottom", _p.getInsetBottom, _p.setInsetBottom);
_p = null;
-
-cc.Scale9Sprite.create = function (file) {
- return new cc.Scale9Sprite(file);
-};
-
-/**
- * create a cc.Scale9Sprite with Sprite frame.
- * @deprecated since v3.0, please use "new cc.Scale9Sprite(spriteFrame, capInsets)" instead.
- * @param {cc.SpriteFrame} spriteFrame
- * @param {cc.Rect} capInsets
- * @returns {cc.Scale9Sprite}
- */
-cc.Scale9Sprite.createWithSpriteFrame = function (spriteFrame) {
- return new cc.Scale9Sprite(spriteFrame);
-};
-
-/**
- * create a cc.Scale9Sprite with a Sprite frame name
- * @deprecated since v3.0, please use "new cc.Scale9Sprite(spriteFrameName, capInsets)" instead.
- * @param {string} spriteFrameName
- * @param {cc.Rect} capInsets
- * @returns {Scale9Sprite}
- */
-cc.Scale9Sprite.createWithSpriteFrameName = function (spriteFrameName) {
- return new cc.Scale9Sprite(spriteFrameName);
-};
-
cc.Scale9Sprite.state = {NORMAL: 0, GRAY: 1};
/**
diff --git a/cocos2d/core/sprites/CCScale9SpriteWebGLRenderCmd.js b/cocos2d/core/sprites/CCScale9SpriteWebGLRenderCmd.js
index d9276a7f32..bf17791f3e 100644
--- a/cocos2d/core/sprites/CCScale9SpriteWebGLRenderCmd.js
+++ b/cocos2d/core/sprites/CCScale9SpriteWebGLRenderCmd.js
@@ -65,7 +65,7 @@
cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst);
//optimize performance for javascript
cc.glBindTexture2DN(0, locTexture); // = cc.glBindTexture2D(locTexture);
- cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
+ cc.glEnableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
gl.bindBuffer(gl.ARRAY_BUFFER, this._quadWebBuffer);
@@ -84,9 +84,9 @@
bufferOffset = 0;
for(var i = 0; i < quads.length; ++i)
{
- gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 24, bufferOffset); //cc.Macro.VERTEX_ATTRIB_POSITION
- gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, true, 24, 12 + bufferOffset); //cc.Macro.VERTEX_ATTRIB_COLOR
- gl.vertexAttribPointer(2, 2, gl.FLOAT, false, 24, 16 + bufferOffset); //cc.Macro.VERTEX_ATTRIB_TEX_COORDS
+ gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 24, bufferOffset); //cc.macro.VERTEX_ATTRIB_POSITION
+ gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, true, 24, 12 + bufferOffset); //cc.macro.VERTEX_ATTRIB_COLOR
+ gl.vertexAttribPointer(2, 2, gl.FLOAT, false, 24, 16 + bufferOffset); //cc.macro.VERTEX_ATTRIB_TEX_COORDS
if(node._isTriangle) {
gl.drawArrays(gl.TRIANGLES, 0, 3);
} else {
@@ -116,7 +116,7 @@
proto.setState = function (state) {
var node = this._node;
if (state === cc.Scale9Sprite.state.NORMAL) {
- node.setShaderProgram(cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLOR));
+ node.setShaderProgram(cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLOR));
} else if (state === cc.Scale9Sprite.state.GRAY) {
node.setShaderProgram(cc.Scale9Sprite.WebGLRenderCmd._getGrayShaderProgram());
}
@@ -129,10 +129,10 @@
return grayShader;
grayShader = new cc.GLProgram();
- grayShader.initWithVertexShaderByteArray(cc.Shaders.POSITION_TEXTURE_COLOR_VERT, cc.Scale9Sprite.WebGLRenderCmd._grayShaderFragment);
- grayShader.addAttribute(cc.Macro.ATTRIBUTE_NAME_POSITION, cc.Macro.VERTEX_ATTRIB_POSITION);
- grayShader.addAttribute(cc.Macro.ATTRIBUTE_NAME_COLOR, cc.Macro.VERTEX_ATTRIB_COLOR);
- grayShader.addAttribute(cc.Macro.ATTRIBUTE_NAME_TEX_COORD, cc.Macro.VERTEX_ATTRIB_TEX_COORDS);
+ grayShader.initWithVertexShaderByteArray(cc.PresetShaders.POSITION_TEXTURE_COLOR_VERT, cc.Scale9Sprite.WebGLRenderCmd._grayShaderFragment);
+ grayShader.addAttribute(cc.macro.ATTRIBUTE_NAME_POSITION, cc.macro.VERTEX_ATTRIB_POSITION);
+ grayShader.addAttribute(cc.macro.ATTRIBUTE_NAME_COLOR, cc.macro.VERTEX_ATTRIB_COLOR);
+ grayShader.addAttribute(cc.macro.ATTRIBUTE_NAME_TEX_COORD, cc.macro.VERTEX_ATTRIB_TEX_COORDS);
grayShader.link();
grayShader.updateUniforms();
diff --git a/cocos2d/core/sprites/CCSpriteBatchNode.js b/cocos2d/core/sprites/CCSpriteBatchNode.js
index d432f29424..1201979368 100644
--- a/cocos2d/core/sprites/CCSpriteBatchNode.js
+++ b/cocos2d/core/sprites/CCSpriteBatchNode.js
@@ -64,7 +64,7 @@ cc.SpriteBatchNode = _ccsg.Node.extend(/** @lends cc.SpriteBatchNode# */{
ctor: function (fileImage, capacity) {
_ccsg.Node.prototype.ctor.call(this);
this._descendants = [];
- this._blendFunc = new cc.BlendFunc(cc.Macro.BLEND_SRC, cc.Macro.BLEND_DST);
+ this._blendFunc = new cc.BlendFunc(cc.macro.BLEND_SRC, cc.macro.BLEND_DST);
var texture2D;
capacity = capacity || cc.SpriteBatchNode.DEFAULT_CAPACITY;
@@ -272,7 +272,7 @@ cc.SpriteBatchNode = _ccsg.Node.extend(/** @lends cc.SpriteBatchNode# */{
// ignore parent Z if parent is spriteSheet
var ignoreParent = selParent === this;
var previous = null;
- if (childIndex > 0 && childIndex < cc.Macro.UINT_MAX)
+ if (childIndex > 0 && childIndex < cc.macro.UINT_MAX)
previous = brothers[childIndex - 1];
// first child of the sprite sheet
@@ -650,27 +650,4 @@ cc.defineGetterSetter(_p, "descendants", _p.getDescendants);
* @constant
* @type Number
*/
-cc.SpriteBatchNode.DEFAULT_CAPACITY = 29;
-
-/**
- *
- * creates a cc.SpriteBatchNodeCanvas with a file image (.png, .jpg etc) with a default capacity of 29 children.
- * The capacity will be increased in 33% in runtime if it run out of space.
- * The file will be loaded using the TextureMgr.
- *
- * @deprecated since v3.0, please use new construction instead
- * @see cc.SpriteBatchNode
- * @param {String|cc.Texture2D} fileImage
- * @param {Number} capacity
- * @return {cc.SpriteBatchNode}
- */
-cc.SpriteBatchNode.create = function (fileImage, capacity) {
- return new cc.SpriteBatchNode(fileImage, capacity);
-};
-
-/**
- * @deprecated since v3.0, please use new construction instead
- * @see cc.SpriteBatchNode
- * @function
- */
-cc.SpriteBatchNode.createWithTexture = cc.SpriteBatchNode.create;
\ No newline at end of file
+cc.SpriteBatchNode.DEFAULT_CAPACITY = 29;
\ No newline at end of file
diff --git a/cocos2d/core/sprites/CCSpriteBatchNodeWebGLRenderCmd.js b/cocos2d/core/sprites/CCSpriteBatchNodeWebGLRenderCmd.js
index 87732bffe0..1c3d06397a 100644
--- a/cocos2d/core/sprites/CCSpriteBatchNodeWebGLRenderCmd.js
+++ b/cocos2d/core/sprites/CCSpriteBatchNodeWebGLRenderCmd.js
@@ -114,7 +114,7 @@
this._textureAtlas = new cc.TextureAtlas();
this._textureAtlas.initWithTexture(texture, capacity);
this._updateBlendFunc();
- this._shaderProgram = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLOR);
+ this._shaderProgram = cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLOR);
};
proto.insertQuad = function(sprite, index){
@@ -224,8 +224,8 @@
proto._updateBlendFunc = function () {
if (!this._textureAtlas.texture.hasPremultipliedAlpha()) {
var blendFunc = this._node._blendFunc;
- blendFunc.src = cc.Macro.SRC_ALPHA;
- blendFunc.dst = cc.Macro.ONE_MINUS_SRC_ALPHA;
+ blendFunc.src = cc.macro.SRC_ALPHA;
+ blendFunc.dst = cc.macro.ONE_MINUS_SRC_ALPHA;
}
};
diff --git a/cocos2d/core/sprites/CCSpriteFrame.js b/cocos2d/core/sprites/CCSpriteFrame.js
index 8d5d5e49af..ee9e7f4e8f 100644
--- a/cocos2d/core/sprites/CCSpriteFrame.js
+++ b/cocos2d/core/sprites/CCSpriteFrame.js
@@ -466,31 +466,3 @@ proto.copyWithZone = proto.clone;
*/
proto.copy = proto.clone;
-/**
- *
- * Create a cc.SpriteFrame with a texture filename, rect, rotated, offset and originalSize in pixels.
- * The originalSize is the size in pixels of the frame before being trimmed.
- *
- * since v3.0, please use new constructor {{#crossLink "SpriteFrame/SpriteFrame:method"}}SpriteFrame(){{/crossLink}} instead.
- * @method create
- * @param {String|Texture2D} filename
- * @param {Rect} rect if parameters' length equal 2, rect in points, else rect in pixels
- * @param {Boolean} rotated
- * @param {Vec2} offset
- * @param {Size} originalSize
- * @return {SpriteFrame}
- */
-cc.SpriteFrame.create = function (filename, rect, rotated, offset, originalSize) {
- return new cc.SpriteFrame(filename, rect, rotated, offset, originalSize);
-};
-
-/**
- * deprecated since v3.0, please use new construction instead
- * @method createWithTexture
- * @deprecated
- */
-cc.SpriteFrame.createWithTexture = cc.SpriteFrame.create;
-
-cc.SpriteFrame._frameWithTextureForCanvas = function (texture, rect, rotated, offset, originalSize) {
- return new cc.SpriteFrame(texture, rect, rotated, offset, originalSize);
-};
diff --git a/cocos2d/core/sprites/CCSpriteFrameCache.js b/cocos2d/core/sprites/CCSpriteFrameCache.js
index bbb5ec46a8..4c94bcbabd 100644
--- a/cocos2d/core/sprites/CCSpriteFrameCache.js
+++ b/cocos2d/core/sprites/CCSpriteFrameCache.js
@@ -25,7 +25,7 @@
****************************************************************************/
// init CCSpriteFrame
-require("../cocos2d/core/sprites/CCSpriteFrame");
+require("./CCSpriteFrame");
diff --git a/cocos2d/core/support/CCVertex.js b/cocos2d/core/support/CCVertex.js
index 44b92f0d22..5b85b64f7d 100644
--- a/cocos2d/core/support/CCVertex.js
+++ b/cocos2d/core/support/CCVertex.js
@@ -87,7 +87,7 @@ cc.vertexLineToPolygon = function (points, stroke, vertices, offset, nuPoints) {
var v4 = cc.vertex2(vertices[(idx1 + 1) * 2], vertices[(idx1 + 1) * 2 + 1]);
//BOOL fixVertex = !ccpLineIntersect(ccp(p1.x, p1.y), ccp(p4.x, p4.y), ccp(p2.x, p2.y), ccp(p3.x, p3.y), &s, &t);
- var fixVertexResult = !cc.vertexLineIntersect(v1.x, v1.y, v4.x, v4.y, v2.x, v2.y, v3.x, v3.y);
+ var fixVertexResult = !vertexLineIntersect(v1.x, v1.y, v4.x, v4.y, v2.x, v2.y, v3.x, v3.y);
if (!fixVertexResult.isSuccess)
if (fixVertexResult.value < 0.0 || fixVertexResult.value > 1.0)
fixVertexResult.isSuccess = true;
@@ -113,7 +113,7 @@ cc.vertexLineToPolygon = function (points, stroke, vertices, offset, nuPoints) {
* @param {Number} Dy
* @return {Object}
*/
-cc.vertexLineIntersect = function (Ax, Ay, Bx, By, Cx, Cy, Dx, Dy) {
+function vertexLineIntersect (Ax, Ay, Bx, By, Cx, Cy, Dx, Dy) {
var distAB, theCos, theSin, newX;
// FAIL: Line undefined
@@ -156,7 +156,7 @@ cc.vertexLineIntersect = function (Ax, Ay, Bx, By, Cx, Cy, Dx, Dy) {
* @param {Array} verts
* @return {Boolean}
*/
-cc.vertexListIsClockwise = function(verts) {
+function vertexListIsClockwise (verts) {
for (var i = 0, len = verts.length; i < len; i++) {
var a = verts[i];
var b = verts[(i + 1) % len];
diff --git a/cocos2d/core/textures/CCTexture2D.js b/cocos2d/core/textures/CCTexture2D.js
index b012f880c1..98f184a4d3 100644
--- a/cocos2d/core/textures/CCTexture2D.js
+++ b/cocos2d/core/textures/CCTexture2D.js
@@ -30,71 +30,6 @@ var game = require('../CCGame');
require('../platform/_CCClass');
require('../platform/CCClass');
-//CONSTANTS:
-
-/**
- * Horizontal center and vertical center.
- * @constant
- * @type Number
- */
-cc.ALIGN_CENTER = 0x33;
-
-/**
- * Horizontal center and vertical top.
- * @constant
- * @type Number
- */
-cc.ALIGN_TOP = 0x13;
-
-/**
- * Horizontal right and vertical top.
- * @constant
- * @type Number
- */
-cc.ALIGN_TOP_RIGHT = 0x12;
-
-/**
- * Horizontal right and vertical center.
- * @constant
- * @type Number
- */
-cc.ALIGN_RIGHT = 0x32;
-
-/**
- * Horizontal right and vertical bottom.
- * @constant
- * @type Number
- */
-cc.ALIGN_BOTTOM_RIGHT = 0x22;
-
-/**
- * Horizontal center and vertical bottom.
- * @constant
- * @type Number
- */
-cc.ALIGN_BOTTOM = 0x23;
-
-/**
- * Horizontal left and vertical bottom.
- * @constant
- * @type Number
- */
-cc.ALIGN_BOTTOM_LEFT = 0x21;
-
-/**
- * Horizontal left and vertical center.
- * @constant
- * @type Number
- */
-cc.ALIGN_LEFT = 0x31;
-
-/**
- * Horizontal left and vertical top.
- * @constant
- * @type Number
- */
-cc.ALIGN_TOP_LEFT = 0x11;
-
/**
* The texture wrap mode
* @class Texture2D.WrapMode
diff --git a/cocos2d/core/textures/CCTextureAtlas.js b/cocos2d/core/textures/CCTextureAtlas.js
index ddc01ea42b..cbc065eb57 100644
--- a/cocos2d/core/textures/CCTextureAtlas.js
+++ b/cocos2d/core/textures/CCTextureAtlas.js
@@ -179,7 +179,7 @@ var TextureAtlas = Class.extend(/** @lends cc.TextureAtlas# */{ //WebGL only
return;
var locIndices = this._indices, locCapacity = this._capacity;
for (var i = 0; i < locCapacity; i++) {
- if (cc.Macro.TEXTURE_ATLAS_USE_TRIANGLE_STRIP) {
+ if (cc.macro.TEXTURE_ATLAS_USE_TRIANGLE_STRIP) {
locIndices[i * 6 + 0] = i * 4 + 0;
locIndices[i * 6 + 1] = i * 4 + 0;
locIndices[i * 6 + 2] = i * 4 + 2;
@@ -669,7 +669,7 @@ if (cc._renderType === game.RENDER_TYPE_WEBGL) {
//vertices
//gl.bindBuffer(gl.ARRAY_BUFFER, _t._buffersVBO[0]);
// XXX: update is done in draw... perhaps it should be done in a timer
- cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
+ cc.glEnableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
gl.bindBuffer(gl.ARRAY_BUFFER, _t._quadsWebBuffer);
if (_t.dirty){
@@ -677,13 +677,13 @@ if (cc._renderType === game.RENDER_TYPE_WEBGL) {
_t.dirty = false;
}
- gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 3, gl.FLOAT, false, 24, 0); // vertices
- gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_COLOR, 4, gl.UNSIGNED_BYTE, true, 24, 12); // colors
- gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_TEX_COORDS, 2, gl.FLOAT, false, 24, 16); // tex coords
+ gl.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_POSITION, 3, gl.FLOAT, false, 24, 0); // vertices
+ gl.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_COLOR, 4, gl.UNSIGNED_BYTE, true, 24, 12); // colors
+ gl.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_TEX_COORDS, 2, gl.FLOAT, false, 24, 16); // tex coords
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _t._buffersVBO[1]);
- if (cc.Macro.TEXTURE_ATLAS_USE_TRIANGLE_STRIP)
+ if (cc.macro.TEXTURE_ATLAS_USE_TRIANGLE_STRIP)
gl.drawElements(gl.TRIANGLE_STRIP, n * 6, gl.UNSIGNED_SHORT, start * 6 * _t._indices.BYTES_PER_ELEMENT);
else
gl.drawElements(gl.TRIANGLES, n * 6, gl.UNSIGNED_SHORT, start * 6 * _t._indices.BYTES_PER_ELEMENT);
diff --git a/cocos2d/core/textures/CCTextureCache.js b/cocos2d/core/textures/CCTextureCache.js
index 0573eb8264..657c66a408 100644
--- a/cocos2d/core/textures/CCTextureCache.js
+++ b/cocos2d/core/textures/CCTextureCache.js
@@ -349,7 +349,7 @@ game.once(game.EVENT_RENDERER_INITED, function () {
tex = locTexs[url] = new Texture2D();
tex.url = url;
}
- premultiplied = cc.Macro.AUTO_PREMULTIPLIED_ALPHA_FOR_PNG && (cc.path.extname(url) === ".png");
+ premultiplied = cc.macro.AUTO_PREMULTIPLIED_ALPHA_FOR_PNG && (cc.path.extname(url) === ".png");
tex.handleLoadedTexture(premultiplied);
};
diff --git a/cocos2d/core/utils/CCProfiler.js b/cocos2d/core/utils/CCProfiler.js
index 9ecb57fbc5..7b7d9624cc 100644
--- a/cocos2d/core/utils/CCProfiler.js
+++ b/cocos2d/core/utils/CCProfiler.js
@@ -45,7 +45,7 @@ cc.profiler = (function () {
var createStatsLabel = function () {
var fontSize = 0;
var w = cc.winSize.width, h = cc.winSize.height;
- var locStatsPosition = cc.Macro.DIRECTOR_STATS_POSITION;
+ var locStatsPosition = cc.macro.DIRECTOR_STATS_POSITION;
if (w > h)
fontSize = 0 | (h / 320 * 20);
else
@@ -110,7 +110,7 @@ cc.profiler = (function () {
_frames++;
_accumDt += cc.director.getDeltaTime();
- if (_accumDt > cc.Macro.DIRECTOR_FPS_INTERVAL) {
+ if (_accumDt > cc.macro.DIRECTOR_FPS_INTERVAL) {
_frameRate = _frames / _accumDt;
_frames = 0;
_accumDt = 0;
@@ -151,7 +151,7 @@ cc.profiler = (function () {
setProfileDuration: function (duration) {
if (!isNaN(duration) && duration > 0) {
- _levelDetCycle = duration / cc.Macro.DIRECTOR_FPS_INTERVAL;
+ _levelDetCycle = duration / cc.macro.DIRECTOR_FPS_INTERVAL;
}
},
diff --git a/cocos2d/core/utils/base-node.js b/cocos2d/core/utils/base-node.js
index 3e8f4931fb..84bd52f0b5 100644
--- a/cocos2d/core/utils/base-node.js
+++ b/cocos2d/core/utils/base-node.js
@@ -90,7 +90,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
_skewY: 0,
_localZOrder: 0,
_globalZOrder: 0,
- _tag: cc.NODE_TAG_INVALID,
+ _tag: cc.macro.NODE_TAG_INVALID,
_opacityModifyRGB: false,
// API
@@ -1085,7 +1085,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
* @see cc.Node#removeChildByTag
*/
removeChildByTag: function (tag, cleanup) {
- if (tag === cc.NODE_TAG_INVALID)
+ if (tag === cc.macro.NODE_TAG_INVALID)
cc.log(cc._LogInfos.Node.removeChildByTag);
var child = this.getChildByTag(tag);
diff --git a/cocos2d/core/value-types/CCTypes.js b/cocos2d/core/value-types/CCTypes.js
index f0445309c3..86fae67c79 100644
--- a/cocos2d/core/value-types/CCTypes.js
+++ b/cocos2d/core/value-types/CCTypes.js
@@ -61,16 +61,16 @@ cc.BlendFunc = function (src1, dst1) {
};
var BlendFactor = cc.Enum({
- ONE: 1, //cc.Macro.ONE
- ZERO: 0, //cc.Macro.ZERO
- SRC_ALPHA: 0x302, //cc.Macro.SRC_ALPHA
- SRC_COLOR: 0x300, //cc.Macro.SRC_COLOR
- DST_ALPHA: 0x304, //cc.Macro.DST_ALPHA
- DST_COLOR: 0x306, //cc.Macro.DST_COLOR
- ONE_MINUS_SRC_ALPHA: 0x303, //cc.Macro.ONE_MINUS_SRC_ALPHA
- ONE_MINUS_SRC_COLOR: 0x301, //cc.Macro.ONE_MINUS_SRC_COLOR
- ONE_MINUS_DST_ALPHA: 0x305, //cc.Macro.ONE_MINUS_DST_ALPHA
- ONE_MINUS_DST_COLOR: 0x307, //cc.Macro.ONE_MINUS_DST_COLOR
+ ONE: 1, //cc.macro.ONE
+ ZERO: 0, //cc.macro.ZERO
+ SRC_ALPHA: 0x302, //cc.macro.SRC_ALPHA
+ SRC_COLOR: 0x300, //cc.macro.SRC_COLOR
+ DST_ALPHA: 0x304, //cc.macro.DST_ALPHA
+ DST_COLOR: 0x306, //cc.macro.DST_COLOR
+ ONE_MINUS_SRC_ALPHA: 0x303, //cc.macro.ONE_MINUS_SRC_ALPHA
+ ONE_MINUS_SRC_COLOR: 0x301, //cc.macro.ONE_MINUS_SRC_COLOR
+ ONE_MINUS_DST_ALPHA: 0x305, //cc.macro.ONE_MINUS_DST_ALPHA
+ ONE_MINUS_DST_COLOR: 0x307, //cc.macro.ONE_MINUS_DST_COLOR
});
//var BlendFactor = cc;
diff --git a/cocos2d/deprecated.js b/cocos2d/deprecated.js
index 1dc8b5a754..80a503e97c 100644
--- a/cocos2d/deprecated.js
+++ b/cocos2d/deprecated.js
@@ -243,7 +243,7 @@ if (CC_DEV) {
deprecateEnum(_ccsg.ParticleSystem, '_ccsg.ParticleSystem.MODE', '_ccsg.ParticleSystem.Mode');
deprecateEnum(cc.ParticleSystem, 'cc.ParticleSystem.TYPE', 'cc.ParticleSystem.PositionType');
deprecateEnum(cc.ParticleSystem, 'cc.ParticleSystem.MODE', 'cc.ParticleSystem.EmitterMode');
- deprecateEnum(cc.ProgressTimer, 'cc.ProgressTimer.TYPE', 'cc.ProgressTimer.Type');
+ // deprecateEnum(cc.ProgressTimer, 'cc.ProgressTimer.TYPE', 'cc.ProgressTimer.Type');
deprecateEnum(cc.game, 'cc.game.DEBUG_MODE', 'cc.DebugMode');
deprecateEnum(cc, 'cc', 'cc.Texture2D.WrapMode', false);
if (_ccsg.EditBox) {
diff --git a/cocos2d/effects/CCGrid.js b/cocos2d/effects/CCGrid.js
index 9260ee5100..64b1141c31 100644
--- a/cocos2d/effects/CCGrid.js
+++ b/cocos2d/effects/CCGrid.js
@@ -228,7 +228,7 @@ cc.GridBase = cc._Class.extend(/** @lends cc.GridBase# */{
if (!this._grabber)
return false;
this._grabber.grab(this._texture);
- this._shaderProgram = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURE);
+ this._shaderProgram = cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURE);
this.calculateVertexPoints();
return true;
},
@@ -296,31 +296,18 @@ cc.GridBase = cc._Class.extend(/** @lends cc.GridBase# */{
var gl = cc._renderContext;
gl.viewport(0, 0, winSize.width , winSize.height);
- cc.kmGLMatrixMode(cc.KM_GL_PROJECTION);
- cc.kmGLLoadIdentity();
+ cc.math.glMatrixMode(cc.math.KM_GL_PROJECTION);
+ cc.math.glLoadIdentity();
var orthoMatrix = cc.math.Matrix4.createOrthographicProjection(0, winSize.width, 0, winSize.height, -1, 1);
- cc.kmGLMultMatrix(orthoMatrix);
+ cc.math.glMultMatrix(orthoMatrix);
- cc.kmGLMatrixMode(cc.KM_GL_MODELVIEW);
- cc.kmGLLoadIdentity();
- cc.setProjectionMatrixDirty()
+ cc.math.glMatrixMode(cc.math.KM_GL_MODELVIEW);
+ cc.math.glLoadIdentity();
+ cc.setProjectionMatrixDirty();
}
});
-/**
- * create one cc.GridBase Object
- * @deprecated
- * @param {cc.Size} gridSize
- * @param {cc.Texture2D} [texture=]
- * @param {Boolean} [flipped=]
- * @param {cc.Rect} [rect=]
- * @return {cc.GridBase}
- */
-cc.GridBase.create = function (gridSize, texture, flipped, rect) {
- return new cc.GridBase(gridSize, texture, flipped, rect);
-};
-
/**
* cc.Grid3D is a 3D grid implementation. Each vertex has 3 dimensions: x,y,z
* @class
@@ -449,7 +436,7 @@ cc.Grid3D = cc.GridBase.extend(/** @lends cc.Grid3D# */{
blit:function (target) {
var n = this._gridSize.width * this._gridSize.height;
- cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POSITION | cc.Macro.VERTEX_ATTRIB_FLAG_TEX_COORDS);
+ cc.glEnableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POSITION | cc.macro.VERTEX_ATTRIB_FLAG_TEX_COORDS);
this._shaderProgram.use();
//this._shaderProgram.setUniformsForBuiltins();
this._shaderProgram._setUniformForMVPMatrixWithMat4(target._renderCmd._stackMatrix);
@@ -462,13 +449,13 @@ cc.Grid3D = cc.GridBase.extend(/** @lends cc.Grid3D# */{
gl.bindBuffer(gl.ARRAY_BUFFER, this._verticesBuffer);
if (locDirty)
gl.bufferData(gl.ARRAY_BUFFER, this._vertices, gl.DYNAMIC_DRAW);
- gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 3, gl.FLOAT, false, 0, 0);
+ gl.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_POSITION, 3, gl.FLOAT, false, 0, 0);
// texCoords
gl.bindBuffer(gl.ARRAY_BUFFER, this._texCoordinateBuffer);
if (locDirty)
gl.bufferData(gl.ARRAY_BUFFER, this._texCoordinates, gl.DYNAMIC_DRAW);
- gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_TEX_COORDS, 2, gl.FLOAT, false, 0, 0);
+ gl.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_TEX_COORDS, 2, gl.FLOAT, false, 0, 0);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indicesBuffer);
if (locDirty)
@@ -574,18 +561,6 @@ cc.Grid3D = cc.GridBase.extend(/** @lends cc.Grid3D# */{
}
});
-/**
- * create one Grid3D object
- * @deprecated
- * @param {cc.Size} gridSize
- * @param {cc.Texture2D} [texture=]
- * @param {Boolean} [flipped=]
- * @return {cc.Grid3D}
- */
-cc.Grid3D.create = function (gridSize, texture, flipped) {
- return new cc.Grid3D(gridSize, texture, flipped);
-};
-
/**
* cc.TiledGrid3D is a 3D grid implementation. It differs from Grid3D in that
* the tiles can be separated from the grid.
@@ -715,19 +690,19 @@ cc.TiledGrid3D = cc.GridBase.extend(/** @lends cc.TiledGrid3D# */{
// Attributes
//
var gl = cc._renderContext, locDirty = this._dirty;
- cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POSITION | cc.Macro.VERTEX_ATTRIB_FLAG_TEX_COORDS);
+ cc.glEnableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POSITION | cc.macro.VERTEX_ATTRIB_FLAG_TEX_COORDS);
// position
gl.bindBuffer(gl.ARRAY_BUFFER, this._verticesBuffer);
if (locDirty)
gl.bufferData(gl.ARRAY_BUFFER, this._vertices, gl.DYNAMIC_DRAW);
- gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 3, gl.FLOAT, false, 0, this._vertices);
+ gl.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_POSITION, 3, gl.FLOAT, false, 0, this._vertices);
// texCoords
gl.bindBuffer(gl.ARRAY_BUFFER, this._texCoordinateBuffer);
if (locDirty)
gl.bufferData(gl.ARRAY_BUFFER, this._texCoordinates, gl.DYNAMIC_DRAW);
- gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_TEX_COORDS, 2, gl.FLOAT, false, 0, this._texCoordinates);
+ gl.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_TEX_COORDS, 2, gl.FLOAT, false, 0, this._texCoordinates);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indicesBuffer);
if (locDirty)
@@ -832,15 +807,3 @@ cc.TiledGrid3D = cc.GridBase.extend(/** @lends cc.TiledGrid3D# */{
this._dirty = true;
}
});
-
-/**
- * create one TiledGrid3D object
- * @deprecated since v3.0, please use new cc.TiledGrid3D(gridSize, texture, flipped) instead
- * @param {cc.Size} gridSize
- * @param {cc.Texture2D} [texture=]
- * @param {Boolean} [flipped=]
- * @return {cc.TiledGrid3D}
- */
-cc.TiledGrid3D.create = function (gridSize, texture, flipped) {
- return new cc.TiledGrid3D(gridSize, texture, flipped);
-};
diff --git a/cocos2d/kazmath/SIMDPolyfill.js b/cocos2d/kazmath/SIMDPolyfill.js
index 7c65b0a214..6efabbbd2b 100644
--- a/cocos2d/kazmath/SIMDPolyfill.js
+++ b/cocos2d/kazmath/SIMDPolyfill.js
@@ -26,53 +26,51 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-(function(cc) {
- var _useSIMD = false;
+var _useSIMD = false;
- var mat4Proto = cc.math.Matrix4.prototype;
- var mat4Inverse = mat4Proto.inverse;
- var mat4IsIdentity = mat4Proto.isIdentity;
- var mat4Transpose = mat4Proto.transpose;
- var mat4Multiply = mat4Proto.multiply;
- var mat4GetMat4MultiplyValue = mat4Proto.getMat4MultiplyValue;
- var mat4AssignFrom = mat4Proto.assignFrom;
- var mat4Equals = mat4Proto.equals;
- var mat4LookAt = mat4Proto.lookAt;
+var mat4Proto = cc.math.Matrix4.prototype;
+var mat4Inverse = mat4Proto.inverse;
+var mat4IsIdentity = mat4Proto.isIdentity;
+var mat4Transpose = mat4Proto.transpose;
+var mat4Multiply = mat4Proto.multiply;
+var mat4GetMat4MultiplyValue = mat4Proto.getMat4MultiplyValue;
+var mat4AssignFrom = mat4Proto.assignFrom;
+var mat4Equals = mat4Proto.equals;
+var mat4LookAt = mat4Proto.lookAt;
- var vec3Proto = cc.math.Vec3.prototype;
- var vec3TransformCoord = vec3Proto.transformCoord;
+var vec3Proto = cc.math.Vec3.prototype;
+var vec3TransformCoord = vec3Proto.transformCoord;
- function _isEnabledSIMD () {
- return _useSIMD;
- }
+function _isEnabledSIMD () {
+ return _useSIMD;
+}
- function _enableSIMD (enable) {
- if(typeof(SIMD) === 'undefined')
- return;
+function _enableSIMD (enable) {
+ if(typeof(SIMD) === 'undefined')
+ return;
- if (enable) {
- mat4Proto.inverse = mat4Proto.inverseSIMD;
- mat4Proto.isIdentity = mat4Proto.isIdentitySIMD;
- mat4Proto.transpose = mat4Proto.transposeSIMD;
- mat4Proto.multiply = mat4Proto.multiplySIMD;
- mat4Proto.getMat4MultiplyValue = mat4Proto.getMat4MultiplyValueSIMD;
- mat4Proto.assignFrom = mat4Proto.assignFromSIMD;
- mat4Proto.equals = mat4Proto.equalsSIMD;
- mat4Proto.lookAt = mat4Proto.lookAtSIMD;
- vec3Proto.transformCoord = vec3Proto.transformCoordSIMD;
- } else {
- mat4Proto.inverse = mat4Inverse;
- mat4Proto.isIdentity = mat4IsIdentity;
- mat4Proto.transpose = mat4Transpose;
- mat4Proto.multiply = mat4Multiply;
- mat4Proto.getMat4MultiplyValue = mat4GetMat4MultiplyValue;
- mat4Proto.assignFrom = mat4AssignFrom;
- mat4Proto.equals = mat4Equals;
- mat4Proto.lookAt = mat4LookAt;
- vec3Proto.transformCoord = vec3TransformCoord;
- }
- _useSIMD = enable;
- }
+ if (enable) {
+ mat4Proto.inverse = mat4Proto.inverseSIMD;
+ mat4Proto.isIdentity = mat4Proto.isIdentitySIMD;
+ mat4Proto.transpose = mat4Proto.transposeSIMD;
+ mat4Proto.multiply = mat4Proto.multiplySIMD;
+ mat4Proto.getMat4MultiplyValue = mat4Proto.getMat4MultiplyValueSIMD;
+ mat4Proto.assignFrom = mat4Proto.assignFromSIMD;
+ mat4Proto.equals = mat4Proto.equalsSIMD;
+ mat4Proto.lookAt = mat4Proto.lookAtSIMD;
+ vec3Proto.transformCoord = vec3Proto.transformCoordSIMD;
+ } else {
+ mat4Proto.inverse = mat4Inverse;
+ mat4Proto.isIdentity = mat4IsIdentity;
+ mat4Proto.transpose = mat4Transpose;
+ mat4Proto.multiply = mat4Multiply;
+ mat4Proto.getMat4MultiplyValue = mat4GetMat4MultiplyValue;
+ mat4Proto.assignFrom = mat4AssignFrom;
+ mat4Proto.equals = mat4Equals;
+ mat4Proto.lookAt = mat4LookAt;
+ vec3Proto.transformCoord = vec3TransformCoord;
+ }
+ _useSIMD = enable;
+}
- cc.defineGetterSetter(cc.sys, "useSIMD", _isEnabledSIMD, _enableSIMD);
-})(cc);
\ No newline at end of file
+cc.defineGetterSetter(cc.sys, "useSIMD", _isEnabledSIMD, _enableSIMD);
\ No newline at end of file
diff --git a/cocos2d/kazmath/gl/mat4stack.js b/cocos2d/kazmath/gl/mat4stack.js
index ecd3aceba3..d9a1cbe783 100644
--- a/cocos2d/kazmath/gl/mat4stack.js
+++ b/cocos2d/kazmath/gl/mat4stack.js
@@ -26,73 +26,51 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-(function(cc){
- /**
- * The stack of cc.math.Matrix4
- * @param {cc.math.Matrix4} [top]
- * @param {Array} [stack]
- * @constructor
- */
- cc.math.Matrix4Stack = function(top, stack) {
- this.top = top;
- this.stack = stack || [];
- //this._matrixPool = []; // use pool in next version
- };
- cc.km_mat4_stack = cc.math.Matrix4Stack;
- var proto = cc.math.Matrix4Stack.prototype;
+/**
+ * The stack of cc.math.Matrix4
+ * @param {cc.math.Matrix4} [top]
+ * @param {Array} [stack]
+ * @constructor
+ */
+cc.math.Matrix4Stack = function(top, stack) {
+ this.top = top;
+ this.stack = stack || [];
+ //this._matrixPool = []; // use pool in next version
+};
+var proto = cc.math.Matrix4Stack.prototype;
- proto.initialize = function() { //cc.km_mat4_stack_initialize
- this.stack.length = 0;
- this.top = null;
- };
+proto.initialize = function() { //cc.km_mat4_stack_initialize
+ this.stack.length = 0;
+ this.top = null;
+};
- //for compatibility
- cc.km_mat4_stack_push = function(stack, item){
- stack.stack.push(stack.top);
- stack.top = new cc.math.Matrix4(item);
- };
-
- cc.km_mat4_stack_pop = function(stack, pOut){
- stack.top = stack.stack.pop();
- };
-
- cc.km_mat4_stack_release = function(stack){
- stack.stack = null;
- stack.top = null;
- };
-
- proto.push = function(item) {
- item = item || this.top;
- this.stack.push(this.top);
- this.top = new cc.math.Matrix4(item);
- //this.top = this._getFromPool(item);
- };
-
- proto.pop = function() {
- //this._putInPool(this.top);
- this.top = this.stack.pop();
- };
-
- proto.release = function(){
- this.stack = null;
- this.top = null;
- this._matrixPool = null;
- };
-
- proto._getFromPool = function (item) {
- var pool = this._matrixPool;
- if (pool.length === 0)
- return new cc.math.Matrix4(item);
- var ret = pool.pop();
- ret.assignFrom(item);
- return ret;
- };
-
- proto._putInPool = function(matrix){
- this._matrixPool.push(matrix);
- };
-})(cc);
+proto.push = function(item) {
+ item = item || this.top;
+ this.stack.push(this.top);
+ this.top = new cc.math.Matrix4(item);
+ //this.top = this._getFromPool(item);
+};
+proto.pop = function() {
+ //this._putInPool(this.top);
+ this.top = this.stack.pop();
+};
+proto.release = function(){
+ this.stack = null;
+ this.top = null;
+ this._matrixPool = null;
+};
+proto._getFromPool = function (item) {
+ var pool = this._matrixPool;
+ if (pool.length === 0)
+ return new cc.math.Matrix4(item);
+ var ret = pool.pop();
+ ret.assignFrom(item);
+ return ret;
+};
+proto._putInPool = function(matrix){
+ this._matrixPool.push(matrix);
+};
\ No newline at end of file
diff --git a/cocos2d/kazmath/gl/matrix.js b/cocos2d/kazmath/gl/matrix.js
index d1c5683587..3aa868815d 100644
--- a/cocos2d/kazmath/gl/matrix.js
+++ b/cocos2d/kazmath/gl/matrix.js
@@ -26,142 +26,141 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-(function(cc) {
- cc.KM_GL_MODELVIEW = 0x1700;
- cc.KM_GL_PROJECTION = 0x1701;
- cc.KM_GL_TEXTURE = 0x1702;
+var math = cc.math;
- cc.modelview_matrix_stack = new cc.math.Matrix4Stack();
- cc.projection_matrix_stack = new cc.math.Matrix4Stack();
- cc.texture_matrix_stack = new cc.math.Matrix4Stack();
+math.KM_GL_MODELVIEW = 0x1700;
+math.KM_GL_PROJECTION = 0x1701;
+math.KM_GL_TEXTURE = 0x1702;
- cc.current_stack = null;
- var initialized = false;
+math.modelview_matrix_stack = new math.Matrix4Stack();
+math.projection_matrix_stack = new math.Matrix4Stack();
+math.texture_matrix_stack = new math.Matrix4Stack();
- cc.lazyInitialize = function () {
- if (!initialized) {
- var identity = new cc.math.Matrix4(); //Temporary identity matrix
+cc.current_stack = null;
+var initialized = false;
- //Initialize all 3 stacks
- cc.modelview_matrix_stack.initialize();
- cc.projection_matrix_stack.initialize();
- cc.texture_matrix_stack.initialize();
+var lazyInitialize = function () {
+ if (!initialized) {
+ var identity = new math.Matrix4(); //Temporary identity matrix
- cc.current_stack = cc.modelview_matrix_stack;
- cc.initialized = true;
- identity.identity();
+ //Initialize all 3 stacks
+ math.modelview_matrix_stack.initialize();
+ math.projection_matrix_stack.initialize();
+ math.texture_matrix_stack.initialize();
- //Make sure that each stack has the identity matrix
- cc.modelview_matrix_stack.push(identity);
- cc.projection_matrix_stack.push(identity);
- cc.texture_matrix_stack.push(identity);
- }
- };
+ cc.current_stack = math.modelview_matrix_stack;
+ initialized = true;
+ identity.identity();
- cc.lazyInitialize();
+ //Make sure that each stack has the identity matrix
+ math.modelview_matrix_stack.push(identity);
+ math.projection_matrix_stack.push(identity);
+ math.texture_matrix_stack.push(identity);
+ }
+};
- cc.kmGLFreeAll = function () {
- //Clear the matrix stacks
- cc.modelview_matrix_stack.release();
- cc.modelview_matrix_stack = null;
- cc.projection_matrix_stack.release();
- cc.projection_matrix_stack = null;
- cc.texture_matrix_stack.release();
- cc.texture_matrix_stack = null;
+lazyInitialize();
- //Delete the matrices
- cc.initialized = false; //Set to uninitialized
- cc.current_stack = null; //Set the current stack to point nowhere
- };
+math.glFreeAll = function () {
+ //Clear the matrix stacks
+ math.modelview_matrix_stack.release();
+ math.modelview_matrix_stack = null;
+ math.projection_matrix_stack.release();
+ math.projection_matrix_stack = null;
+ math.texture_matrix_stack.release();
+ math.texture_matrix_stack = null;
- cc.kmGLPushMatrix = function () {
- cc.current_stack.push(cc.current_stack.top);
- };
+ //Delete the matrices
+ initialized = false; //Set to uninitialized
+ cc.current_stack = null; //Set the current stack to point nowhere
+};
- cc.kmGLPushMatrixWitMat4 = function (saveMat) {
- cc.current_stack.stack.push(cc.current_stack.top);
- saveMat.assignFrom(cc.current_stack.top);
- cc.current_stack.top = saveMat;
- };
+math.glPushMatrix = function () {
+ cc.current_stack.push(cc.current_stack.top);
+};
- cc.kmGLPopMatrix = function () {
- //No need to lazy initialize, you shouldnt be popping first anyway!
- //cc.km_mat4_stack_pop(cc.current_stack, null);
- cc.current_stack.top = cc.current_stack.stack.pop();
- };
+math.glPushMatrixWitMat4 = function (saveMat) {
+ cc.current_stack.stack.push(cc.current_stack.top);
+ saveMat.assignFrom(cc.current_stack.top);
+ cc.current_stack.top = saveMat;
+};
- cc.kmGLMatrixMode = function (mode) {
- //cc.lazyInitialize();
- switch (mode) {
- case cc.KM_GL_MODELVIEW:
- cc.current_stack = cc.modelview_matrix_stack;
- break;
- case cc.KM_GL_PROJECTION:
- cc.current_stack = cc.projection_matrix_stack;
- break;
- case cc.KM_GL_TEXTURE:
- cc.current_stack = cc.texture_matrix_stack;
- break;
- default:
- throw new Error("Invalid matrix mode specified"); //TODO: Proper error handling
- break;
- }
- };
+math.glPopMatrix = function () {
+ //No need to lazy initialize, you shouldnt be popping first anyway!
+ cc.current_stack.top = cc.current_stack.stack.pop();
+};
- cc.kmGLLoadIdentity = function () {
- //cc.lazyInitialize();
- cc.current_stack.top.identity(); //Replace the top matrix with the identity matrix
- };
+math.glMatrixMode = function (mode) {
+ //lazyInitialize();
+ switch (mode) {
+ case math.KM_GL_MODELVIEW:
+ cc.current_stack = math.modelview_matrix_stack;
+ break;
+ case math.KM_GL_PROJECTION:
+ cc.current_stack = math.projection_matrix_stack;
+ break;
+ case math.KM_GL_TEXTURE:
+ cc.current_stack = math.texture_matrix_stack;
+ break;
+ default:
+ throw new Error("Invalid matrix mode specified"); //TODO: Proper error handling
+ break;
+ }
+};
- cc.kmGLLoadMatrix = function (pIn) {
- //cc.lazyInitialize();
- cc.current_stack.top.assignFrom(pIn);
- };
+math.glLoadIdentity = function () {
+ //lazyInitialize();
+ cc.current_stack.top.identity(); //Replace the top matrix with the identity matrix
+};
- cc.kmGLMultMatrix = function (pIn) {
- //cc.lazyInitialize();
- cc.current_stack.top.multiply(pIn);
- };
+math.glLoadMatrix = function (pIn) {
+ //lazyInitialize();
+ cc.current_stack.top.assignFrom(pIn);
+};
- var tempMatrix = new cc.math.Matrix4(); //an internal matrix
- cc.kmGLTranslatef = function (x, y, z) {
- //Create a rotation matrix using translation
- var translation = cc.math.Matrix4.createByTranslation(x, y, z, tempMatrix);
+math.glMultMatrix = function (pIn) {
+ //lazyInitialize();
+ cc.current_stack.top.multiply(pIn);
+};
- //Multiply the rotation matrix by the current matrix
- cc.current_stack.top.multiply(translation);
- };
+var tempMatrix = new math.Matrix4(); //an internal matrix
+math.glTranslatef = function (x, y, z) {
+ //Create a rotation matrix using translation
+ var translation = math.Matrix4.createByTranslation(x, y, z, tempMatrix);
- var tempVector3 = new cc.math.Vec3();
- cc.kmGLRotatef = function (angle, x, y, z) {
- tempVector3.fill(x, y, z);
- //Create a rotation matrix using the axis and the angle
- var rotation = cc.math.Matrix4.createByAxisAndAngle(tempVector3, cc.degreesToRadians(angle), tempMatrix);
+ //Multiply the rotation matrix by the current matrix
+ cc.current_stack.top.multiply(translation);
+};
- //Multiply the rotation matrix by the current matrix
- cc.current_stack.top.multiply(rotation);
- };
+var tempVector3 = new math.Vec3();
+math.glRotatef = function (angle, x, y, z) {
+ tempVector3.fill(x, y, z);
+ //Create a rotation matrix using the axis and the angle
+ var rotation = math.Matrix4.createByAxisAndAngle(tempVector3, cc.degreesToRadians(angle), tempMatrix);
- cc.kmGLScalef = function (x, y, z) {
- var scaling = cc.math.Matrix4.createByScale(x, y, z, tempMatrix);
- cc.current_stack.top.multiply(scaling);
- };
+ //Multiply the rotation matrix by the current matrix
+ cc.current_stack.top.multiply(rotation);
+};
- cc.kmGLGetMatrix = function (mode, pOut) {
- //cc.lazyInitialize();
- switch (mode) {
- case cc.KM_GL_MODELVIEW:
- pOut.assignFrom(cc.modelview_matrix_stack.top);
- break;
- case cc.KM_GL_PROJECTION:
- pOut.assignFrom(cc.projection_matrix_stack.top);
- break;
- case cc.KM_GL_TEXTURE:
- pOut.assignFrom(cc.texture_matrix_stack.top);
- break;
- default:
- throw new Error("Invalid matrix mode specified"); //TODO: Proper error handling
- break;
- }
- };
-})(cc);
+math.glScalef = function (x, y, z) {
+ var scaling = math.Matrix4.createByScale(x, y, z, tempMatrix);
+ cc.current_stack.top.multiply(scaling);
+};
+
+math.glGetMatrix = function (mode, pOut) {
+ //lazyInitialize();
+ switch (mode) {
+ case math.KM_GL_MODELVIEW:
+ pOut.assignFrom(math.modelview_matrix_stack.top);
+ break;
+ case math.KM_GL_PROJECTION:
+ pOut.assignFrom(math.projection_matrix_stack.top);
+ break;
+ case math.KM_GL_TEXTURE:
+ pOut.assignFrom(math.texture_matrix_stack.top);
+ break;
+ default:
+ throw new Error("Invalid matrix mode specified"); //TODO: Proper error handling
+ break;
+ }
+};
diff --git a/cocos2d/kazmath/index.js b/cocos2d/kazmath/index.js
new file mode 100644
index 0000000000..798130d9fa
--- /dev/null
+++ b/cocos2d/kazmath/index.js
@@ -0,0 +1,12 @@
+require('./utility');
+require('./vec2');
+require('./vec3');
+require('./vec4');
+require('./ray2');
+require('./mat3');
+require('./mat4');
+require('./plane');
+require('./quaternion');
+require('./aabb');
+require('./gl/mat4stack');
+require('./gl/matrix');
\ No newline at end of file
diff --git a/cocos2d/kazmath/mat3.js b/cocos2d/kazmath/mat3.js
index aa04fe3d1d..30703a49c0 100644
--- a/cocos2d/kazmath/mat3.js
+++ b/cocos2d/kazmath/mat3.js
@@ -26,319 +26,312 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-window.Uint16Array = window.Uint16Array || window.Array;
-window.Float32Array = window.Float32Array || window.Array;
-(function(cc){
- cc.math.Matrix3 = function(mat3) {
- if (mat3 && mat3.mat) {
- this.mat = new Float32Array(mat3.mat);
- } else {
- this.mat = new Float32Array(9);
- }
- };
- cc.kmMat3 = cc.math.Matrix3;
- var proto = cc.math.Matrix3.prototype;
+if (!(CC_EDITOR && Editor.isCoreLevel)) {
+ window.Uint16Array = window.Uint16Array || window.Array;
+ window.Float32Array = window.Float32Array || window.Array;
+}
- proto.fill = function(mat3) { //cc.kmMat3Fill
- var mat = this.mat, matIn = mat3.mat;
- mat[0] = matIn[0];
- mat[1] = matIn[1];
- mat[2] = matIn[2];
- mat[3] = matIn[3];
- mat[4] = matIn[4];
- mat[5] = matIn[5];
- mat[6] = matIn[6];
- mat[7] = matIn[7];
- mat[8] = matIn[8];
- return this;
- };
-
- proto.adjugate = function(){ //= cc.kmMat3Adjugate
- var mat = this.mat;
- var m0 = mat[0], m1 = mat[1], m2 = mat[2], m3 = mat[3], m4 = mat[4],
- m5 = mat[5], m6 = mat[6], m7 = mat[7], m8 = mat[8];
- mat[0] = m4 * m8 - m5 * m7;
- mat[1] = m2 * m7 - m1 * m8;
- mat[2] = m1 * m5 - m2 * m4;
- mat[3] = m5 * m6 - m3 * m8;
- mat[4] = m0 * m8 - m2 * m6;
- mat[5] = m2 * m3 - m0 * m5;
- mat[6] = m3 * m7 - m4 * m6;
-
- // XXX: pIn.mat[9] is invalid!
- //mat[7] = m1 * m6 - pIn.mat[9] * m7;
- mat[8] = m0 * m4 - m1 * m3;
- return this;
- };
-
- proto.identity = function() { //cc.kmMat3Identity
- var mat = this.mat;
- mat[1] = mat[2] = mat[3] =
- mat[5] = mat[6] = mat[7] = 0;
- mat[0] = mat[4] = mat[8] = 1.0;
- return this;
- };
-
- var tmpMatrix = new cc.math.Matrix3(); // internal matrix
-
- proto.inverse = function(determinate){ //cc.kmMat3Inverse
- if (determinate === 0.0)
- return this;
- tmpMatrix.assignFrom(this);
- var detInv = 1.0 / determinate;
- this.adjugate();
- this.multiplyScalar(detInv);
- return this;
- };
-
- proto.isIdentity = function(){ //= cc.kmMat3IsIdentity
- var mat = this.mat;
- return (mat[0] === 1 && mat[1] === 0 && mat[2] === 0
- && mat[3] === 0 && mat[4] === 1 && mat[5] === 0
- && mat[6] === 0 && mat[7] === 0 && mat[8] === 1);
- };
-
- proto.transpose = function(){ // cc.kmMat3Transpose
- var mat = this.mat;
- var m1 = mat[1], m2 = mat[2], m3 = mat[3], m5 = mat[5],
- m6 = mat[6], m7 = mat[7];
- // m0 = mat[0],m8 = mat[8], m4 = mat[4];
- //mat[0] = m0;
- //mat[8] = m8;
- //mat[4] = m4
- mat[1] = m3;
- mat[2] = m6;
- mat[3] = m1;
- mat[5] = m7;
- mat[6] = m2;
- mat[7] = m5;
- return this;
- };
-
- proto.determinant = function(){
- var mat = this.mat;
- /*
- calculating the determinant following the rule of sarus,
- | 0 3 6 | 0 3 |
- m = | 1 4 7 | 1 4 |
- | 2 5 8 | 2 5 |
- now sum up the products of the diagonals going to the right (i.e. 0,4,8)
- and substract the products of the other diagonals (i.e. 2,4,6)
- */
- var output = mat[0] * mat[4] * mat[8] + mat[1] * mat[5] * mat[6] + mat[2] * mat[3] * mat[7];
- output -= mat[2] * mat[4] * mat[6] + mat[0] * mat[5] * mat[7] + mat[1] * mat[3] * mat[8];
- return output;
- };
-
- proto.multiply = function(mat3){
- var m1 = this.mat, m2 = mat3.mat;
- var a0 = m1[0], a1 = m1[1], a2 = m1[2], a3 = m1[3], a4 = m1[4], a5 = m1[5],
- a6 = m1[6], a7 = m1[7], a8 = m1[8];
- var b0 = m2[0], b1 = m2[1], b2 = m2[2], b3 = m2[3], b4 = m2[4], b5 = m2[5],
- b6 = m2[6], b7 = m2[7], b8 = m2[8];
-
- m1[0] = a0 * b0 + a3 * b1 + a6 * b2;
- m1[1] = a1 * b0 + a4 * b1 + a7 * b2;
- m1[2] = a2 * b0 + a5 * b1 + a8 * b2;
-
- m1[3] = a2 * b0 + a5 * b1 + a8 * b2;
- m1[4] = a1 * b3 + a4 * b4 + a7 * b5;
- m1[5] = a2 * b3 + a5 * b4 + a8 * b5;
-
- m1[6] = a0 * b6 + a3 * b7 + a6 * b8;
- m1[7] = a1 * b6 + a4 * b7 + a7 * b8;
- m1[8] = a2 * b6 + a5 * b7 + a8 * b8;
- return this;
- };
-
- proto.multiplyScalar = function(factor) {
- var mat = this.mat;
- mat[0] *= factor;
- mat[1] *= factor;
- mat[2] *= factor;
- mat[3] *= factor;
- mat[4] *= factor;
- mat[5] *= factor;
- mat[6] *= factor;
- mat[7] *= factor;
- mat[8] *= factor;
- return this;
- };
-
- cc.math.Matrix3.rotationAxisAngle = function(axis, radians) { //cc.kmMat3RotationAxisAngle
- var rcos = Math.cos(radians), rsin = Math.sin(radians);
- var retMat = new cc.math.Matrix3();
- var mat = retMat.mat;
-
- mat[0] = rcos + axis.x * axis.x * (1 - rcos);
- mat[1] = axis.z * rsin + axis.y * axis.x * (1 - rcos);
- mat[2] = -axis.y * rsin + axis.z * axis.x * (1 - rcos);
-
- mat[3] = -axis.z * rsin + axis.x * axis.y * (1 - rcos);
- mat[4] = rcos + axis.y * axis.y * (1 - rcos);
- mat[5] = axis.x * rsin + axis.z * axis.y * (1 - rcos);
-
- mat[6] = axis.y * rsin + axis.x * axis.z * (1 - rcos);
- mat[7] = -axis.x * rsin + axis.y * axis.z * (1 - rcos);
- mat[8] = rcos + axis.z * axis.z * (1 - rcos);
-
- return retMat;
- };
-
- proto.assignFrom = function(matIn){ // cc.kmMat3Assign
- if(this === matIn) {
- cc.log("cc.math.Matrix3.assign(): current matrix equals matIn");
- return this;
- }
- var mat = this.mat, m2 = matIn.mat;
- mat[0] = m2[0];
- mat[1] = m2[1];
- mat[2] = m2[2];
- mat[3] = m2[3];
- mat[4] = m2[4];
- mat[5] = m2[5];
- mat[6] = m2[6];
- mat[7] = m2[7];
- mat[8] = m2[8];
- return this;
- };
-
- proto.equals = function(mat3) {
- if (this === mat3)
- return true;
- var EPSILON = cc.math.EPSILON,m1 = this.mat, m2 = mat3.mat;
- for (var i = 0; i < 9; ++i) {
- if (!(m1[i] + EPSILON > m2[i] && m1[i] - EPSILON < m2[i]))
- return false;
- }
- return true;
- };
-
- cc.math.Matrix3.createByRotationX = function(radians) {
- var retMat = new cc.math.Matrix3(), mat = retMat.mat;
- mat[0] = 1.0;
- mat[1] = 0.0;
- mat[2] = 0.0;
-
- mat[3] = 0.0;
- mat[4] = Math.cos(radians);
- mat[5] = Math.sin(radians);
-
- mat[6] = 0.0;
- mat[7] = -Math.sin(radians);
- mat[8] = Math.cos(radians);
- return retMat;
- };
-
- cc.math.Matrix3.createByRotationY = function(radians) {
- /*
- | cos(A) 0 sin(A) |
- M = | 0 1 0 |
- | -sin(A) 0 cos(A) |
- */
- var retMat = new cc.math.Matrix3(), mat = retMat.mat;
- mat[0] = Math.cos(radians);
- mat[1] = 0.0;
- mat[2] = -Math.sin(radians);
-
- mat[3] = 0.0;
- mat[4] = 1.0;
- mat[5] = 0.0;
-
- mat[6] = Math.sin(radians);
- mat[7] = 0.0;
- mat[8] = Math.cos(radians);
- return retMat;
- };
-
- cc.math.Matrix3.createByRotationZ = function(radians) {
- /*
- | cos(A) -sin(A) 0 |
- M = | sin(A) cos(A) 0 |
- | 0 0 1 |
- */
- var retMat = new cc.math.Matrix3(), mat = retMat.mat;
- mat[0] = Math.cos(radians);
- mat[1] = -Math.sin(radians);
- mat[2] = 0.0;
-
- mat[3] = Math.sin(radians);
- mat[4] = Math.cos(radians);
- mat[5] = 0.0;
-
- mat[6] = 0.0;
- mat[7] = 0.0;
- mat[8] = 1.0;
- return retMat;
- };
-
- cc.math.Matrix3.createByRotation = function(radians) {
- /*
- | cos(A) -sin(A) 0 |
- M = | sin(A) cos(A) 0 |
- | 0 0 1 |
- */
- var retMat = new cc.math.Matrix3(), mat = retMat.mat;
- mat[0] = Math.cos(radians);
- mat[1] = Math.sin(radians);
- mat[2] = 0.0;
-
- mat[3] = -Math.sin(radians);
- mat[4] = Math.cos(radians);
- mat[5] = 0.0;
-
- mat[6] = 0.0;
- mat[7] = 0.0;
- mat[8] = 1.0;
- return retMat;
- };
-
- cc.math.Matrix3.createByScale = function(x, y) {
- var ret = new cc.math.Matrix3();
- ret.identity();
- ret.mat[0] = x;
- ret.mat[4] = y;
- return ret;
- };
-
- cc.math.Matrix3.createByTranslation = function(x, y){
- var ret = new cc.math.Matrix3();
- ret.identity();
- ret.mat[6] = x;
- ret.mat[7] = y;
- return ret;
- };
-
- cc.math.Matrix3.createByQuaternion = function(quaternion) { //cc.kmMat3RotationQuaternion
- if(!quaternion)
- return null;
-
- var ret = new cc.math.Matrix3(), mat = ret.mat;
- // First row
- mat[0] = 1.0 - 2.0 * (quaternion.y * quaternion.y + quaternion.z * quaternion.z);
- mat[1] = 2.0 * (quaternion.x * quaternion.y - quaternion.w * quaternion.z);
- mat[2] = 2.0 * (quaternion.x * quaternion.z + quaternion.w * quaternion.y);
-
- // Second row
- mat[3] = 2.0 * (quaternion.x * quaternion.y + quaternion.w * quaternion.z);
- mat[4] = 1.0 - 2.0 * (quaternion.x * quaternion.x + quaternion.z * quaternion.z);
- mat[5] = 2.0 * (quaternion.y * quaternion.z - quaternion.w * quaternion.x);
-
- // Third row
- mat[6] = 2.0 * (quaternion.x * quaternion.z - quaternion.w * quaternion.y);
- mat[7] = 2.0 * (quaternion.y * quaternion.z + quaternion.w * quaternion.x);
- mat[8] = 1.0 - 2.0 * (quaternion.x * quaternion.x + quaternion.y * quaternion.y);
- return ret;
- };
-
- proto.rotationToAxisAngle = function() { //cc.kmMat3RotationToAxisAngle
- return cc.math.Quaternion.rotationMatrix(this).toAxisAndAngle();
+cc.math.Matrix3 = function(mat3) {
+ if (mat3 && mat3.mat) {
+ this.mat = new Float32Array(mat3.mat);
+ } else {
+ this.mat = new Float32Array(9);
}
-})(cc);
+};
+var proto = cc.math.Matrix3.prototype;
+proto.fill = function(mat3) { //cc.kmMat3Fill
+ var mat = this.mat, matIn = mat3.mat;
+ mat[0] = matIn[0];
+ mat[1] = matIn[1];
+ mat[2] = matIn[2];
+ mat[3] = matIn[3];
+ mat[4] = matIn[4];
+ mat[5] = matIn[5];
+ mat[6] = matIn[6];
+ mat[7] = matIn[7];
+ mat[8] = matIn[8];
+ return this;
+};
+proto.adjugate = function(){ //= cc.kmMat3Adjugate
+ var mat = this.mat;
+ var m0 = mat[0], m1 = mat[1], m2 = mat[2], m3 = mat[3], m4 = mat[4],
+ m5 = mat[5], m6 = mat[6], m7 = mat[7], m8 = mat[8];
+ mat[0] = m4 * m8 - m5 * m7;
+ mat[1] = m2 * m7 - m1 * m8;
+ mat[2] = m1 * m5 - m2 * m4;
+ mat[3] = m5 * m6 - m3 * m8;
+ mat[4] = m0 * m8 - m2 * m6;
+ mat[5] = m2 * m3 - m0 * m5;
+ mat[6] = m3 * m7 - m4 * m6;
+ // XXX: pIn.mat[9] is invalid!
+ //mat[7] = m1 * m6 - pIn.mat[9] * m7;
+ mat[8] = m0 * m4 - m1 * m3;
+ return this;
+};
+proto.identity = function() { //cc.kmMat3Identity
+ var mat = this.mat;
+ mat[1] = mat[2] = mat[3] =
+ mat[5] = mat[6] = mat[7] = 0;
+ mat[0] = mat[4] = mat[8] = 1.0;
+ return this;
+};
+var tmpMatrix = new cc.math.Matrix3(); // internal matrix
+proto.inverse = function(determinate){ //cc.kmMat3Inverse
+ if (determinate === 0.0)
+ return this;
+ tmpMatrix.assignFrom(this);
+ var detInv = 1.0 / determinate;
+ this.adjugate();
+ this.multiplyScalar(detInv);
+ return this;
+};
+proto.isIdentity = function(){ //= cc.kmMat3IsIdentity
+ var mat = this.mat;
+ return (mat[0] === 1 && mat[1] === 0 && mat[2] === 0
+ && mat[3] === 0 && mat[4] === 1 && mat[5] === 0
+ && mat[6] === 0 && mat[7] === 0 && mat[8] === 1);
+};
+
+proto.transpose = function(){ // cc.kmMat3Transpose
+ var mat = this.mat;
+ var m1 = mat[1], m2 = mat[2], m3 = mat[3], m5 = mat[5],
+ m6 = mat[6], m7 = mat[7];
+ // m0 = mat[0],m8 = mat[8], m4 = mat[4];
+ //mat[0] = m0;
+ //mat[8] = m8;
+ //mat[4] = m4
+ mat[1] = m3;
+ mat[2] = m6;
+ mat[3] = m1;
+ mat[5] = m7;
+ mat[6] = m2;
+ mat[7] = m5;
+ return this;
+};
+
+proto.determinant = function(){
+ var mat = this.mat;
+ /*
+ calculating the determinant following the rule of sarus,
+ | 0 3 6 | 0 3 |
+ m = | 1 4 7 | 1 4 |
+ | 2 5 8 | 2 5 |
+ now sum up the products of the diagonals going to the right (i.e. 0,4,8)
+ and substract the products of the other diagonals (i.e. 2,4,6)
+ */
+ var output = mat[0] * mat[4] * mat[8] + mat[1] * mat[5] * mat[6] + mat[2] * mat[3] * mat[7];
+ output -= mat[2] * mat[4] * mat[6] + mat[0] * mat[5] * mat[7] + mat[1] * mat[3] * mat[8];
+ return output;
+};
+
+proto.multiply = function(mat3){
+ var m1 = this.mat, m2 = mat3.mat;
+ var a0 = m1[0], a1 = m1[1], a2 = m1[2], a3 = m1[3], a4 = m1[4], a5 = m1[5],
+ a6 = m1[6], a7 = m1[7], a8 = m1[8];
+ var b0 = m2[0], b1 = m2[1], b2 = m2[2], b3 = m2[3], b4 = m2[4], b5 = m2[5],
+ b6 = m2[6], b7 = m2[7], b8 = m2[8];
+
+ m1[0] = a0 * b0 + a3 * b1 + a6 * b2;
+ m1[1] = a1 * b0 + a4 * b1 + a7 * b2;
+ m1[2] = a2 * b0 + a5 * b1 + a8 * b2;
+
+ m1[3] = a2 * b0 + a5 * b1 + a8 * b2;
+ m1[4] = a1 * b3 + a4 * b4 + a7 * b5;
+ m1[5] = a2 * b3 + a5 * b4 + a8 * b5;
+
+ m1[6] = a0 * b6 + a3 * b7 + a6 * b8;
+ m1[7] = a1 * b6 + a4 * b7 + a7 * b8;
+ m1[8] = a2 * b6 + a5 * b7 + a8 * b8;
+ return this;
+};
+
+proto.multiplyScalar = function(factor) {
+ var mat = this.mat;
+ mat[0] *= factor;
+ mat[1] *= factor;
+ mat[2] *= factor;
+ mat[3] *= factor;
+ mat[4] *= factor;
+ mat[5] *= factor;
+ mat[6] *= factor;
+ mat[7] *= factor;
+ mat[8] *= factor;
+ return this;
+};
+
+cc.math.Matrix3.rotationAxisAngle = function(axis, radians) { //cc.kmMat3RotationAxisAngle
+ var rcos = Math.cos(radians), rsin = Math.sin(radians);
+ var retMat = new cc.math.Matrix3();
+ var mat = retMat.mat;
+
+ mat[0] = rcos + axis.x * axis.x * (1 - rcos);
+ mat[1] = axis.z * rsin + axis.y * axis.x * (1 - rcos);
+ mat[2] = -axis.y * rsin + axis.z * axis.x * (1 - rcos);
+
+ mat[3] = -axis.z * rsin + axis.x * axis.y * (1 - rcos);
+ mat[4] = rcos + axis.y * axis.y * (1 - rcos);
+ mat[5] = axis.x * rsin + axis.z * axis.y * (1 - rcos);
+
+ mat[6] = axis.y * rsin + axis.x * axis.z * (1 - rcos);
+ mat[7] = -axis.x * rsin + axis.y * axis.z * (1 - rcos);
+ mat[8] = rcos + axis.z * axis.z * (1 - rcos);
+
+ return retMat;
+};
+
+proto.assignFrom = function(matIn){ // cc.kmMat3Assign
+ if(this === matIn) {
+ cc.log("cc.math.Matrix3.assign(): current matrix equals matIn");
+ return this;
+ }
+ var mat = this.mat, m2 = matIn.mat;
+ mat[0] = m2[0];
+ mat[1] = m2[1];
+ mat[2] = m2[2];
+ mat[3] = m2[3];
+ mat[4] = m2[4];
+ mat[5] = m2[5];
+ mat[6] = m2[6];
+ mat[7] = m2[7];
+ mat[8] = m2[8];
+ return this;
+};
+
+proto.equals = function(mat3) {
+ if (this === mat3)
+ return true;
+ var EPSILON = cc.math.EPSILON,m1 = this.mat, m2 = mat3.mat;
+ for (var i = 0; i < 9; ++i) {
+ if (!(m1[i] + EPSILON > m2[i] && m1[i] - EPSILON < m2[i]))
+ return false;
+ }
+ return true;
+};
+
+cc.math.Matrix3.createByRotationX = function(radians) {
+ var retMat = new cc.math.Matrix3(), mat = retMat.mat;
+ mat[0] = 1.0;
+ mat[1] = 0.0;
+ mat[2] = 0.0;
+
+ mat[3] = 0.0;
+ mat[4] = Math.cos(radians);
+ mat[5] = Math.sin(radians);
+
+ mat[6] = 0.0;
+ mat[7] = -Math.sin(radians);
+ mat[8] = Math.cos(radians);
+ return retMat;
+};
+
+cc.math.Matrix3.createByRotationY = function(radians) {
+ /*
+ | cos(A) 0 sin(A) |
+ M = | 0 1 0 |
+ | -sin(A) 0 cos(A) |
+ */
+ var retMat = new cc.math.Matrix3(), mat = retMat.mat;
+ mat[0] = Math.cos(radians);
+ mat[1] = 0.0;
+ mat[2] = -Math.sin(radians);
+
+ mat[3] = 0.0;
+ mat[4] = 1.0;
+ mat[5] = 0.0;
+
+ mat[6] = Math.sin(radians);
+ mat[7] = 0.0;
+ mat[8] = Math.cos(radians);
+ return retMat;
+};
+
+cc.math.Matrix3.createByRotationZ = function(radians) {
+ /*
+ | cos(A) -sin(A) 0 |
+ M = | sin(A) cos(A) 0 |
+ | 0 0 1 |
+ */
+ var retMat = new cc.math.Matrix3(), mat = retMat.mat;
+ mat[0] = Math.cos(radians);
+ mat[1] = -Math.sin(radians);
+ mat[2] = 0.0;
+
+ mat[3] = Math.sin(radians);
+ mat[4] = Math.cos(radians);
+ mat[5] = 0.0;
+
+ mat[6] = 0.0;
+ mat[7] = 0.0;
+ mat[8] = 1.0;
+ return retMat;
+};
+
+cc.math.Matrix3.createByRotation = function(radians) {
+ /*
+ | cos(A) -sin(A) 0 |
+ M = | sin(A) cos(A) 0 |
+ | 0 0 1 |
+ */
+ var retMat = new cc.math.Matrix3(), mat = retMat.mat;
+ mat[0] = Math.cos(radians);
+ mat[1] = Math.sin(radians);
+ mat[2] = 0.0;
+
+ mat[3] = -Math.sin(radians);
+ mat[4] = Math.cos(radians);
+ mat[5] = 0.0;
+
+ mat[6] = 0.0;
+ mat[7] = 0.0;
+ mat[8] = 1.0;
+ return retMat;
+};
+
+cc.math.Matrix3.createByScale = function(x, y) {
+ var ret = new cc.math.Matrix3();
+ ret.identity();
+ ret.mat[0] = x;
+ ret.mat[4] = y;
+ return ret;
+};
+
+cc.math.Matrix3.createByTranslation = function(x, y){
+ var ret = new cc.math.Matrix3();
+ ret.identity();
+ ret.mat[6] = x;
+ ret.mat[7] = y;
+ return ret;
+};
+
+cc.math.Matrix3.createByQuaternion = function(quaternion) { //cc.kmMat3RotationQuaternion
+ if(!quaternion)
+ return null;
+
+ var ret = new cc.math.Matrix3(), mat = ret.mat;
+ // First row
+ mat[0] = 1.0 - 2.0 * (quaternion.y * quaternion.y + quaternion.z * quaternion.z);
+ mat[1] = 2.0 * (quaternion.x * quaternion.y - quaternion.w * quaternion.z);
+ mat[2] = 2.0 * (quaternion.x * quaternion.z + quaternion.w * quaternion.y);
+
+ // Second row
+ mat[3] = 2.0 * (quaternion.x * quaternion.y + quaternion.w * quaternion.z);
+ mat[4] = 1.0 - 2.0 * (quaternion.x * quaternion.x + quaternion.z * quaternion.z);
+ mat[5] = 2.0 * (quaternion.y * quaternion.z - quaternion.w * quaternion.x);
+
+ // Third row
+ mat[6] = 2.0 * (quaternion.x * quaternion.z - quaternion.w * quaternion.y);
+ mat[7] = 2.0 * (quaternion.y * quaternion.z + quaternion.w * quaternion.x);
+ mat[8] = 1.0 - 2.0 * (quaternion.x * quaternion.x + quaternion.y * quaternion.y);
+ return ret;
+};
+
+proto.rotationToAxisAngle = function() { //cc.kmMat3RotationToAxisAngle
+ return cc.math.Quaternion.rotationMatrix(this).toAxisAndAngle();
+}
diff --git a/cocos2d/kazmath/mat4.js b/cocos2d/kazmath/mat4.js
index d211589531..56d02efe85 100644
--- a/cocos2d/kazmath/mat4.js
+++ b/cocos2d/kazmath/mat4.js
@@ -26,989 +26,982 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-(function(cc) {
- /**
- *
- * A 4x4 matrix
- *
- * mat =
- * | 0 4 8 12 |
- * | 1 5 9 13 |
- * | 2 6 10 14 |
- * | 3 7 11 15 |
- *
- * @param {cc.math.Matrix4} [mat4]
- */
- cc.math.Matrix4 = function (mat4) {
- if(mat4 && mat4.mat){
- this.mat = new Float32Array(mat4.mat);
- } else {
- this.mat = new Float32Array(16);
- }
- };
- cc.kmMat4 = cc.math.Matrix4;
- var proto = cc.math.Matrix4.prototype;
+/**
+ *
+ * A 4x4 matrix
+ *
+ * mat =
+ * | 0 4 8 12 |
+ * | 1 5 9 13 |
+ * | 2 6 10 14 |
+ * | 3 7 11 15 |
+ *
+ * @param {cc.math.Matrix4} [mat4]
+ */
+cc.math.Matrix4 = function (mat4) {
+ if(mat4 && mat4.mat){
+ this.mat = new Float32Array(mat4.mat);
+ } else {
+ this.mat = new Float32Array(16);
+ }
+};
+var proto = cc.math.Matrix4.prototype;
- /**
- * Fills a cc.math.Matrix4 structure with the values from a 16 element array of floats
- * @param {Array} scalarArr
- */
- proto.fill = function(scalarArr){ //cc.kmMat4Fill
- var mat = this.mat;
- for(var i = 0; i < 16; i++){
- mat[i] = scalarArr[i];
- }
- return this;
- };
+/**
+ * Fills a cc.math.Matrix4 structure with the values from a 16 element array of floats
+ * @param {Array} scalarArr
+ */
+proto.fill = function(scalarArr){ //cc.kmMat4Fill
+ var mat = this.mat;
+ for(var i = 0; i < 16; i++){
+ mat[i] = scalarArr[i];
+ }
+ return this;
+};
- /**
- * Sets pOut to an identity matrix returns pOut
- * @Params pOut - A pointer to the matrix to set to identity
- * @Return Returns pOut so that the call can be nested
- */
- cc.kmMat4Identity = function (pOut) {
- var mat = pOut.mat;
- mat[1] = mat[2] = mat[3] = mat[4] = mat[6] = mat[7]
- = mat[8] = mat[9] = mat[11] = mat[12] = mat[13] = mat[14] = 0;
- mat[0] = mat[5] = mat[10] = mat[15] = 1.0;
- return pOut;
- };
+/**
+ * Sets pOut to an identity matrix returns pOut
+ * @Params pOut - A pointer to the matrix to set to identity
+ * @Return Returns pOut so that the call can be nested
+ */
+cc.math.mat4Identity = function (pOut) {
+ var mat = pOut.mat;
+ mat[1] = mat[2] = mat[3] = mat[4] = mat[6] = mat[7]
+ = mat[8] = mat[9] = mat[11] = mat[12] = mat[13] = mat[14] = 0;
+ mat[0] = mat[5] = mat[10] = mat[15] = 1.0;
+ return pOut;
+};
- /**
- * Sets matrix to identity value.
- * @returns {cc.math.Matrix4}
- */
- proto.identity = function(){
- var mat = this.mat;
- mat[1] = mat[2] = mat[3] = mat[4] = mat[6] = mat[7]
- = mat[8] = mat[9] = mat[11] = mat[12] = mat[13] = mat[14] = 0;
- mat[0] = mat[5] = mat[10] = mat[15] = 1.0;
- return this;
- };
+/**
+ * Sets matrix to identity value.
+ * @returns {cc.math.Matrix4}
+ */
+proto.identity = function(){
+ var mat = this.mat;
+ mat[1] = mat[2] = mat[3] = mat[4] = mat[6] = mat[7]
+ = mat[8] = mat[9] = mat[11] = mat[12] = mat[13] = mat[14] = 0;
+ mat[0] = mat[5] = mat[10] = mat[15] = 1.0;
+ return this;
+};
- proto.get = function(row, col){
- return this.mat[row + 4 * col];
- };
+proto.get = function(row, col){
+ return this.mat[row + 4 * col];
+};
- proto.set = function(row, col, value){
- this.mat[row + 4 * col] = value;
- };
+proto.set = function(row, col, value){
+ this.mat[row + 4 * col] = value;
+};
- proto.swap = function(r1, c1, r2, c2) {
+proto.swap = function(r1, c1, r2, c2) {
/* var tmp = this.get(r1, c1);
- this.set(r1, c1, this.get(r2, c2));
- this.set(r2, c2, tmp);*/
- var mat = this.mat, tmp = mat[r1 + 4 * c1];
- mat[r1 + 4 * c1] = mat[r2 + 4 * c2];
- mat[r2 + 4 * c2] = tmp;
- };
+ this.set(r1, c1, this.get(r2, c2));
+ this.set(r2, c2, tmp);*/
+ var mat = this.mat, tmp = mat[r1 + 4 * c1];
+ mat[r1 + 4 * c1] = mat[r2 + 4 * c2];
+ mat[r2 + 4 * c2] = tmp;
+};
- //Returns an upper and a lower triangular matrix which are L and R in the Gauss algorithm
- cc.math.Matrix4._gaussj = function (a, b) {
- var i, icol = 0, irow = 0, j, k, l, ll, n = 4, m = 4, selElement;
- var big, dum, pivinv;
- var indxc = [0, 0, 0, 0], indxr = [0, 0, 0, 0], ipiv = [0, 0, 0, 0];
+//Returns an upper and a lower triangular matrix which are L and R in the Gauss algorithm
+cc.math.Matrix4._gaussj = function (a, b) {
+ var i, icol = 0, irow = 0, j, k, l, ll, n = 4, m = 4, selElement;
+ var big, dum, pivinv;
+ var indxc = [0, 0, 0, 0], indxr = [0, 0, 0, 0], ipiv = [0, 0, 0, 0];
- /* for (j = 0; j < n; j++) {
- ipiv[j] = 0;
- }*/
+ /* for (j = 0; j < n; j++) {
+ ipiv[j] = 0;
+ }*/
- for (i = 0; i < n; i++) {
- big = 0.0;
- for (j = 0; j < n; j++) {
- if (ipiv[j] !== 1) {
- for (k = 0; k < n; k++) {
- if (ipiv[k] === 0) {
- selElement = Math.abs(a.get(j, k));
- if (selElement >= big) {
- big = selElement;
- irow = j;
- icol = k;
- }
+ for (i = 0; i < n; i++) {
+ big = 0.0;
+ for (j = 0; j < n; j++) {
+ if (ipiv[j] !== 1) {
+ for (k = 0; k < n; k++) {
+ if (ipiv[k] === 0) {
+ selElement = Math.abs(a.get(j, k));
+ if (selElement >= big) {
+ big = selElement;
+ irow = j;
+ icol = k;
}
}
}
}
- ++(ipiv[icol]);
- if (irow !== icol) {
- for (l = 0; l < n; l++)
- a.swap(irow, l, icol, l);
- for (l = 0; l < m; l++)
- b.swap(irow, l, icol, l);
- }
- indxr[i] = irow;
- indxc[i] = icol;
- if (a.get(icol, icol) === 0.0)
- return false;
-
- pivinv = 1.0 / a.get(icol, icol);
- a.set(icol, icol, 1.0);
+ }
+ ++(ipiv[icol]);
+ if (irow !== icol) {
for (l = 0; l < n; l++)
- a.set(icol, l, a.get(icol, l) * pivinv);
-
+ a.swap(irow, l, icol, l);
for (l = 0; l < m; l++)
- b.set(icol, l, b.get(icol, l) * pivinv);
+ b.swap(irow, l, icol, l);
+ }
+ indxr[i] = irow;
+ indxc[i] = icol;
+ if (a.get(icol, icol) === 0.0)
+ return false;
- for (ll = 0; ll < n; ll++) {
- if (ll !== icol) {
- dum = a.get(ll, icol);
- a.set(ll, icol, 0.0);
- for (l = 0; l < n; l++)
- a.set(ll, l, a.get(ll, l) - a.get(icol, l) * dum);
+ pivinv = 1.0 / a.get(icol, icol);
+ a.set(icol, icol, 1.0);
+ for (l = 0; l < n; l++)
+ a.set(icol, l, a.get(icol, l) * pivinv);
- for (l = 0; l < m; l++)
- b.set(ll, l, a.get(ll, l) - b.get(icol, l) * dum);
- }
+ for (l = 0; l < m; l++)
+ b.set(icol, l, b.get(icol, l) * pivinv);
+
+ for (ll = 0; ll < n; ll++) {
+ if (ll !== icol) {
+ dum = a.get(ll, icol);
+ a.set(ll, icol, 0.0);
+ for (l = 0; l < n; l++)
+ a.set(ll, l, a.get(ll, l) - a.get(icol, l) * dum);
+
+ for (l = 0; l < m; l++)
+ b.set(ll, l, a.get(ll, l) - b.get(icol, l) * dum);
}
}
- // This is the end of the main loop over columns of the reduction. It only remains to unscram-
- // ble the solution in view of the column interchanges. We do this by interchanging pairs of
- // columns in the reverse order that the permutation was built up.
- for (l = n - 1; l >= 0; l--) {
- if (indxr[l] !== indxc[l]) {
- for (k = 0; k < n; k++)
- a.swap(k, indxr[l], k, indxc[l]);
- }
+ }
+ // This is the end of the main loop over columns of the reduction. It only remains to unscram-
+ // ble the solution in view of the column interchanges. We do this by interchanging pairs of
+ // columns in the reverse order that the permutation was built up.
+ for (l = n - 1; l >= 0; l--) {
+ if (indxr[l] !== indxc[l]) {
+ for (k = 0; k < n; k++)
+ a.swap(k, indxr[l], k, indxc[l]);
}
+ }
+ return true;
+};
+
+var identityMatrix = new cc.math.Matrix4().identity();
+/**
+ * Calculates the inverse of pM and stores the result in pOut.
+ * Please use matrix4's inverse function instead.
+ * @Return Returns NULL if there is no inverse, else pOut
+ */
+cc.math.mat4Inverse = function (pOut, pM) {
+ var inv = new cc.math.Matrix4(pM);
+ var tmp = new cc.math.Matrix4(identityMatrix);
+ if (cc.math.Matrix4._gaussj(inv, tmp) === false)
+ return null;
+ pOut.assignFrom(inv);
+ return pOut;
+};
+
+/**
+ * Calculates the inverse of current matrix.
+ * @returns {cc.math.Matrix4} Returns null if there is no inverse, else returns a new inverse matrix object
+ */
+proto.inverse = function(){ //cc.kmMat4Inverse
+ var inv = new cc.math.Matrix4(this);
+ var tmp = new cc.math.Matrix4(identityMatrix);
+ if (cc.math.Matrix4._gaussj(inv, tmp) === false)
+ return null;
+ return inv;
+};
+
+/**
+ * Returns true if current matrix is an identity matrix, false otherwise
+ */
+proto.isIdentity = function () { // cc.kmMat4IsIdentity
+ var mat = this.mat;
+ return (mat[0] === 1 && mat[1] === 0 && mat[2] === 0 && mat[3] === 0
+ && mat[4] === 0 && mat[5] === 1 && mat[6] === 0 && mat[7] === 0
+ && mat[8] === 0 && mat[9] === 0 && mat[10] === 1 && mat[11] === 0
+ && mat[12] === 0 && mat[13] === 0 && mat[14] === 0 && mat[15] === 1);
+};
+
+/**
+ * transpose the current matrix
+ */
+proto.transpose = function() { // cc.kmMat4Transpose
+ var mat = this.mat;
+ var m1 = mat[1], m2 = mat[2], m3 = mat[3],
+ m4 = mat[4], m6 = mat[6], m7 = mat[7],
+ m8 = mat[8], m9 = mat[9], m11 = mat[11],
+ m12 = mat[12], m13 = mat[13], m14 = mat[14];
+ mat[1] = m4;
+ mat[2] = m8;
+ mat[3] = m12;
+
+ mat[4] = m1;
+ mat[6] = m9;
+ mat[7] = m13;
+
+ mat[8] = m2;
+ mat[9] = m6;
+ mat[11] = m14;
+
+ mat[12] = m3;
+ mat[13] = m7;
+ mat[14] = m11;
+ return this;
+};
+
+/**
+ * Multiplies pM1 with pM2, stores the result in pOut, returns pOut
+ */
+cc.math.mat4Multiply = function (pOut, pM1, pM2) {
+ // Cache the matrix values (makes for huge speed increases!)
+ var outArray = pOut.mat, mat1 = pM1.mat, mat2 = pM2.mat;
+ var a00 = mat1[0], a01 = mat1[1], a02 = mat1[2], a03 = mat1[3];
+ var a10 = mat1[4], a11 = mat1[5], a12 = mat1[6], a13 = mat1[7];
+ var a20 = mat1[8], a21 = mat1[9], a22 = mat1[10], a23 = mat1[11];
+ var a30 = mat1[12], a31 = mat1[13], a32 = mat1[14], a33 = mat1[15];
+
+ var b00 = mat2[0], b01 = mat2[1], b02 = mat2[2], b03 = mat2[3];
+ var b10 = mat2[4], b11 = mat2[5], b12 = mat2[6], b13 = mat2[7];
+ var b20 = mat2[8], b21 = mat2[9], b22 = mat2[10], b23 = mat2[11];
+ var b30 = mat2[12], b31 = mat2[13], b32 = mat2[14], b33 = mat2[15];
+
+ outArray[0] = b00 * a00 + b01 * a10 + b02 * a20 + b03 * a30;
+ outArray[1] = b00 * a01 + b01 * a11 + b02 * a21 + b03 * a31;
+ outArray[2] = b00 * a02 + b01 * a12 + b02 * a22 + b03 * a32;
+ outArray[3] = b00 * a03 + b01 * a13 + b02 * a23 + b03 * a33;
+ outArray[4] = b10 * a00 + b11 * a10 + b12 * a20 + b13 * a30;
+ outArray[5] = b10 * a01 + b11 * a11 + b12 * a21 + b13 * a31;
+ outArray[6] = b10 * a02 + b11 * a12 + b12 * a22 + b13 * a32;
+ outArray[7] = b10 * a03 + b11 * a13 + b12 * a23 + b13 * a33;
+ outArray[8] = b20 * a00 + b21 * a10 + b22 * a20 + b23 * a30;
+ outArray[9] = b20 * a01 + b21 * a11 + b22 * a21 + b23 * a31;
+ outArray[10] = b20 * a02 + b21 * a12 + b22 * a22 + b23 * a32;
+ outArray[11] = b20 * a03 + b21 * a13 + b22 * a23 + b23 * a33;
+ outArray[12] = b30 * a00 + b31 * a10 + b32 * a20 + b33 * a30;
+ outArray[13] = b30 * a01 + b31 * a11 + b32 * a21 + b33 * a31;
+ outArray[14] = b30 * a02 + b31 * a12 + b32 * a22 + b33 * a32;
+ outArray[15] = b30 * a03 + b31 * a13 + b32 * a23 + b33 * a33;
+ return pOut;
+};
+
+/**
+ * current matrix multiplies with other matrix mat4
+ * @param {cc.math.Matrix4} mat4
+ * @returns {cc.math.Matrix4}
+ */
+proto.multiply = function(mat4){
+ // Cache the matrix values (makes for huge speed increases!)
+ var mat = this.mat, mat2 = mat4.mat;
+ var a00 = mat[0], a01 = mat[1], a02 = mat[2], a03 = mat[3];
+ var a10 = mat[4], a11 = mat[5], a12 = mat[6], a13 = mat[7];
+ var a20 = mat[8], a21 = mat[9], a22 = mat[10], a23 = mat[11];
+ var a30 = mat[12], a31 = mat[13], a32 = mat[14], a33 = mat[15];
+
+ var b00 = mat2[0], b01 = mat2[1], b02 = mat2[2], b03 = mat2[3];
+ var b10 = mat2[4], b11 = mat2[5], b12 = mat2[6], b13 = mat2[7];
+ var b20 = mat2[8], b21 = mat2[9], b22 = mat2[10], b23 = mat2[11];
+ var b30 = mat2[12], b31 = mat2[13], b32 = mat2[14], b33 = mat2[15];
+
+ mat[0] = b00 * a00 + b01 * a10 + b02 * a20 + b03 * a30;
+ mat[1] = b00 * a01 + b01 * a11 + b02 * a21 + b03 * a31;
+ mat[2] = b00 * a02 + b01 * a12 + b02 * a22 + b03 * a32;
+ mat[3] = b00 * a03 + b01 * a13 + b02 * a23 + b03 * a33;
+ mat[4] = b10 * a00 + b11 * a10 + b12 * a20 + b13 * a30;
+ mat[5] = b10 * a01 + b11 * a11 + b12 * a21 + b13 * a31;
+ mat[6] = b10 * a02 + b11 * a12 + b12 * a22 + b13 * a32;
+ mat[7] = b10 * a03 + b11 * a13 + b12 * a23 + b13 * a33;
+ mat[8] = b20 * a00 + b21 * a10 + b22 * a20 + b23 * a30;
+ mat[9] = b20 * a01 + b21 * a11 + b22 * a21 + b23 * a31;
+ mat[10] = b20 * a02 + b21 * a12 + b22 * a22 + b23 * a32;
+ mat[11] = b20 * a03 + b21 * a13 + b22 * a23 + b23 * a33;
+ mat[12] = b30 * a00 + b31 * a10 + b32 * a20 + b33 * a30;
+ mat[13] = b30 * a01 + b31 * a11 + b32 * a21 + b33 * a31;
+ mat[14] = b30 * a02 + b31 * a12 + b32 * a22 + b33 * a32;
+ mat[15] = b30 * a03 + b31 * a13 + b32 * a23 + b33 * a33;
+ return this;
+};
+
+cc.math.getMat4MultiplyValue = function (pM1, pM2) {
+ var m1 = pM1.mat, m2 = pM2.mat;
+ var mat = new Float32Array(16);
+
+ mat[0] = m1[0] * m2[0] + m1[4] * m2[1] + m1[8] * m2[2] + m1[12] * m2[3];
+ mat[1] = m1[1] * m2[0] + m1[5] * m2[1] + m1[9] * m2[2] + m1[13] * m2[3];
+ mat[2] = m1[2] * m2[0] + m1[6] * m2[1] + m1[10] * m2[2] + m1[14] * m2[3];
+ mat[3] = m1[3] * m2[0] + m1[7] * m2[1] + m1[11] * m2[2] + m1[15] * m2[3];
+
+ mat[4] = m1[0] * m2[4] + m1[4] * m2[5] + m1[8] * m2[6] + m1[12] * m2[7];
+ mat[5] = m1[1] * m2[4] + m1[5] * m2[5] + m1[9] * m2[6] + m1[13] * m2[7];
+ mat[6] = m1[2] * m2[4] + m1[6] * m2[5] + m1[10] * m2[6] + m1[14] * m2[7];
+ mat[7] = m1[3] * m2[4] + m1[7] * m2[5] + m1[11] * m2[6] + m1[15] * m2[7];
+
+ mat[8] = m1[0] * m2[8] + m1[4] * m2[9] + m1[8] * m2[10] + m1[12] * m2[11];
+ mat[9] = m1[1] * m2[8] + m1[5] * m2[9] + m1[9] * m2[10] + m1[13] * m2[11];
+ mat[10] = m1[2] * m2[8] + m1[6] * m2[9] + m1[10] * m2[10] + m1[14] * m2[11];
+ mat[11] = m1[3] * m2[8] + m1[7] * m2[9] + m1[11] * m2[10] + m1[15] * m2[11];
+
+ mat[12] = m1[0] * m2[12] + m1[4] * m2[13] + m1[8] * m2[14] + m1[12] * m2[15];
+ mat[13] = m1[1] * m2[12] + m1[5] * m2[13] + m1[9] * m2[14] + m1[13] * m2[15];
+ mat[14] = m1[2] * m2[12] + m1[6] * m2[13] + m1[10] * m2[14] + m1[14] * m2[15];
+ mat[15] = m1[3] * m2[12] + m1[7] * m2[13] + m1[11] * m2[14] + m1[15] * m2[15];
+
+ return mat;
+};
+
+/**
+ * Assigns the value of pIn to pOut
+ */
+cc.math.mat4Assign = function (pOut, pIn) {
+ if (pOut === pIn) {
+ cc.log("cc.math.mat4Assign(): pOut equals pIn");
+ return pOut;
+ }
+
+ var outArr = pOut.mat;
+ var inArr = pIn.mat;
+
+ outArr[0] = inArr[0];
+ outArr[1] = inArr[1];
+ outArr[2] = inArr[2];
+ outArr[3] = inArr[3];
+
+ outArr[4] = inArr[4];
+ outArr[5] = inArr[5];
+ outArr[6] = inArr[6];
+ outArr[7] = inArr[7];
+
+ outArr[8] = inArr[8];
+ outArr[9] = inArr[9];
+ outArr[10] = inArr[10];
+ outArr[11] = inArr[11];
+
+ outArr[12] = inArr[12];
+ outArr[13] = inArr[13];
+ outArr[14] = inArr[14];
+ outArr[15] = inArr[15];
+ return pOut;
+};
+
+/**
+ * Assigns the value of current matrix from mat4
+ * @param {cc.math.Matrix4} mat4
+ * @returns {cc.math.Matrix4}
+ */
+proto.assignFrom = function(mat4) {
+ if (this === mat4) {
+ cc.log("cc.mat.Matrix4.assignFrom(): mat4 equals current matrix");
+ return this;
+ }
+ var outArr = this.mat, inArr = mat4.mat;
+
+ outArr[0] = inArr[0];
+ outArr[1] = inArr[1];
+ outArr[2] = inArr[2];
+ outArr[3] = inArr[3];
+
+ outArr[4] = inArr[4];
+ outArr[5] = inArr[5];
+ outArr[6] = inArr[6];
+ outArr[7] = inArr[7];
+
+ outArr[8] = inArr[8];
+ outArr[9] = inArr[9];
+ outArr[10] = inArr[10];
+ outArr[11] = inArr[11];
+
+ outArr[12] = inArr[12];
+ outArr[13] = inArr[13];
+ outArr[14] = inArr[14];
+ outArr[15] = inArr[15];
+ return this;
+};
+
+/**
+ * Returns true if current matrix equal mat4 (approximately)
+ * @param {cc.math.Matrix4} mat4
+ * @returns {boolean}
+ */
+proto.equals = function(mat4) {
+ if (this === mat4) {
+ cc.log("cc.math.Matrix4 equal: pMat1 and pMat2 are same object.");
return true;
- };
+ }
+ var matA = this.mat, matB = mat4.mat, EPSILON = cc.math.EPSILON;
+ for (var i = 0; i < 16; i++) {
+ if (!(matA[i] + EPSILON > matB[i] && matA[i] - EPSILON < matB[i]))
+ return false;
+ }
+ return true;
+};
- var identityMatrix = new cc.math.Matrix4().identity();
- /**
- * Calculates the inverse of pM and stores the result in pOut.
- * Please use matrix4's inverse function instead.
- * @Return Returns NULL if there is no inverse, else pOut
+/**
+ * Builds an X-axis rotation matrix and stores it in matrix, returns matrix, if matrix is null, create a new matrix
+ * @param {Number} radians
+ * @param {cc.math.Matrix4} [matrix]
+ * @returns {cc.math.Matrix4}
+ */
+cc.math.Matrix4.createByRotationX = function(radians, matrix) { //cc.kmMat4RotationX
+ /*
+ | 1 0 0 0 |
+ M = | 0 cos(A) -sin(A) 0 |
+ | 0 sin(A) cos(A) 0 |
+ | 0 0 0 1 |
*/
- cc.kmMat4Inverse = function (pOut, pM) {
- var inv = new cc.math.Matrix4(pM);
- var tmp = new cc.math.Matrix4(identityMatrix);
- if (cc.math.Matrix4._gaussj(inv, tmp) === false)
- return null;
- pOut.assignFrom(inv);
- return pOut;
- };
+ matrix = matrix || new cc.math.Matrix4();
+ var mat = matrix.mat;
+ mat[0] = 1.0;
+ mat[3] = mat[2] = mat[1] = 0.0;
- /**
- * Calculates the inverse of current matrix.
- * @returns {cc.math.Matrix4} Returns null if there is no inverse, else returns a new inverse matrix object
+ mat[4] = 0.0;
+ mat[5] = Math.cos(radians);
+ mat[6] = Math.sin(radians);
+ mat[7] = 0.0;
+
+ mat[8] = 0.0;
+ mat[9] = -Math.sin(radians);
+ mat[10] = Math.cos(radians);
+ mat[11] = 0.0;
+
+ mat[14] = mat[13] = mat[12] = 0.0;
+ mat[15] = 1.0;
+ return matrix;
+};
+
+/**
+ * Builds a rotation matrix using the rotation around the Y-axis, The result is stored in matrix, matrix is returned.
+ * @param {Number} radians
+ * @param {cc.math.Matrix4} [matrix]
+ * @returns {*}
+ */
+cc.math.Matrix4.createByRotationY = function(radians, matrix) { // cc.kmMat4RotationY
+ /*
+ | cos(A) 0 sin(A) 0 |
+ M = | 0 1 0 0 |
+ | -sin(A) 0 cos(A) 0 |
+ | 0 0 0 1 |
*/
- proto.inverse = function(){ //cc.kmMat4Inverse
- var inv = new cc.math.Matrix4(this);
- var tmp = new cc.math.Matrix4(identityMatrix);
- if (cc.math.Matrix4._gaussj(inv, tmp) === false)
- return null;
- return inv;
- };
+ matrix = matrix || new cc.math.Matrix4();
+ var mat = matrix.mat;
+ mat[0] = Math.cos(radians);
+ mat[1] = 0.0;
+ mat[2] = -Math.sin(radians);
+ mat[3] = 0.0;
- /**
- * Returns true if current matrix is an identity matrix, false otherwise
+ mat[7] = mat[6] = mat[4] = 0.0;
+ mat[5] = 1.0;
+
+ mat[8] = Math.sin(radians);
+ mat[9] = 0.0;
+ mat[10] = Math.cos(radians);
+ mat[11] = 0.0;
+
+ mat[14] = mat[13] = mat[12] = 0.0;
+ mat[15] = 1.0;
+ return matrix;
+};
+
+/**
+ * Builds a rotation matrix around the Z-axis. The resulting matrix is stored in matrix. matrix is returned.
+ * @param {Number} radians
+ * @param {cc.math.Matrix4} matrix
+ * @return {cc.math.Matrix4}
+ */
+cc.math.Matrix4.createByRotationZ = function(radians, matrix){ // cc.kmMat4RotationZ
+ /*
+ | cos(A) -sin(A) 0 0 |
+ M = | sin(A) cos(A) 0 0 |
+ | 0 0 1 0 |
+ | 0 0 0 1 |
*/
- proto.isIdentity = function () { // cc.kmMat4IsIdentity
- var mat = this.mat;
- return (mat[0] === 1 && mat[1] === 0 && mat[2] === 0 && mat[3] === 0
- && mat[4] === 0 && mat[5] === 1 && mat[6] === 0 && mat[7] === 0
- && mat[8] === 0 && mat[9] === 0 && mat[10] === 1 && mat[11] === 0
- && mat[12] === 0 && mat[13] === 0 && mat[14] === 0 && mat[15] === 1);
- };
-
- /**
- * transpose the current matrix
- */
- proto.transpose = function() { // cc.kmMat4Transpose
- var mat = this.mat;
- var m1 = mat[1], m2 = mat[2], m3 = mat[3],
- m4 = mat[4], m6 = mat[6], m7 = mat[7],
- m8 = mat[8], m9 = mat[9], m11 = mat[11],
- m12 = mat[12], m13 = mat[13], m14 = mat[14];
- mat[1] = m4;
- mat[2] = m8;
- mat[3] = m12;
-
- mat[4] = m1;
- mat[6] = m9;
- mat[7] = m13;
-
- mat[8] = m2;
- mat[9] = m6;
- mat[11] = m14;
-
- mat[12] = m3;
- mat[13] = m7;
- mat[14] = m11;
- return this;
- };
-
- /**
- * Multiplies pM1 with pM2, stores the result in pOut, returns pOut
- */
- cc.kmMat4Multiply = function (pOut, pM1, pM2) {
- // Cache the matrix values (makes for huge speed increases!)
- var outArray = pOut.mat, mat1 = pM1.mat, mat2 = pM2.mat;
- var a00 = mat1[0], a01 = mat1[1], a02 = mat1[2], a03 = mat1[3];
- var a10 = mat1[4], a11 = mat1[5], a12 = mat1[6], a13 = mat1[7];
- var a20 = mat1[8], a21 = mat1[9], a22 = mat1[10], a23 = mat1[11];
- var a30 = mat1[12], a31 = mat1[13], a32 = mat1[14], a33 = mat1[15];
-
- var b00 = mat2[0], b01 = mat2[1], b02 = mat2[2], b03 = mat2[3];
- var b10 = mat2[4], b11 = mat2[5], b12 = mat2[6], b13 = mat2[7];
- var b20 = mat2[8], b21 = mat2[9], b22 = mat2[10], b23 = mat2[11];
- var b30 = mat2[12], b31 = mat2[13], b32 = mat2[14], b33 = mat2[15];
-
- outArray[0] = b00 * a00 + b01 * a10 + b02 * a20 + b03 * a30;
- outArray[1] = b00 * a01 + b01 * a11 + b02 * a21 + b03 * a31;
- outArray[2] = b00 * a02 + b01 * a12 + b02 * a22 + b03 * a32;
- outArray[3] = b00 * a03 + b01 * a13 + b02 * a23 + b03 * a33;
- outArray[4] = b10 * a00 + b11 * a10 + b12 * a20 + b13 * a30;
- outArray[5] = b10 * a01 + b11 * a11 + b12 * a21 + b13 * a31;
- outArray[6] = b10 * a02 + b11 * a12 + b12 * a22 + b13 * a32;
- outArray[7] = b10 * a03 + b11 * a13 + b12 * a23 + b13 * a33;
- outArray[8] = b20 * a00 + b21 * a10 + b22 * a20 + b23 * a30;
- outArray[9] = b20 * a01 + b21 * a11 + b22 * a21 + b23 * a31;
- outArray[10] = b20 * a02 + b21 * a12 + b22 * a22 + b23 * a32;
- outArray[11] = b20 * a03 + b21 * a13 + b22 * a23 + b23 * a33;
- outArray[12] = b30 * a00 + b31 * a10 + b32 * a20 + b33 * a30;
- outArray[13] = b30 * a01 + b31 * a11 + b32 * a21 + b33 * a31;
- outArray[14] = b30 * a02 + b31 * a12 + b32 * a22 + b33 * a32;
- outArray[15] = b30 * a03 + b31 * a13 + b32 * a23 + b33 * a33;
- return pOut;
- };
-
- /**
- * current matrix multiplies with other matrix mat4
- * @param {cc.math.Matrix4} mat4
- * @returns {cc.math.Matrix4}
- */
- proto.multiply = function(mat4){
- // Cache the matrix values (makes for huge speed increases!)
- var mat = this.mat, mat2 = mat4.mat;
- var a00 = mat[0], a01 = mat[1], a02 = mat[2], a03 = mat[3];
- var a10 = mat[4], a11 = mat[5], a12 = mat[6], a13 = mat[7];
- var a20 = mat[8], a21 = mat[9], a22 = mat[10], a23 = mat[11];
- var a30 = mat[12], a31 = mat[13], a32 = mat[14], a33 = mat[15];
-
- var b00 = mat2[0], b01 = mat2[1], b02 = mat2[2], b03 = mat2[3];
- var b10 = mat2[4], b11 = mat2[5], b12 = mat2[6], b13 = mat2[7];
- var b20 = mat2[8], b21 = mat2[9], b22 = mat2[10], b23 = mat2[11];
- var b30 = mat2[12], b31 = mat2[13], b32 = mat2[14], b33 = mat2[15];
-
- mat[0] = b00 * a00 + b01 * a10 + b02 * a20 + b03 * a30;
- mat[1] = b00 * a01 + b01 * a11 + b02 * a21 + b03 * a31;
- mat[2] = b00 * a02 + b01 * a12 + b02 * a22 + b03 * a32;
- mat[3] = b00 * a03 + b01 * a13 + b02 * a23 + b03 * a33;
- mat[4] = b10 * a00 + b11 * a10 + b12 * a20 + b13 * a30;
- mat[5] = b10 * a01 + b11 * a11 + b12 * a21 + b13 * a31;
- mat[6] = b10 * a02 + b11 * a12 + b12 * a22 + b13 * a32;
- mat[7] = b10 * a03 + b11 * a13 + b12 * a23 + b13 * a33;
- mat[8] = b20 * a00 + b21 * a10 + b22 * a20 + b23 * a30;
- mat[9] = b20 * a01 + b21 * a11 + b22 * a21 + b23 * a31;
- mat[10] = b20 * a02 + b21 * a12 + b22 * a22 + b23 * a32;
- mat[11] = b20 * a03 + b21 * a13 + b22 * a23 + b23 * a33;
- mat[12] = b30 * a00 + b31 * a10 + b32 * a20 + b33 * a30;
- mat[13] = b30 * a01 + b31 * a11 + b32 * a21 + b33 * a31;
- mat[14] = b30 * a02 + b31 * a12 + b32 * a22 + b33 * a32;
- mat[15] = b30 * a03 + b31 * a13 + b32 * a23 + b33 * a33;
- return this;
- };
-
- cc.getMat4MultiplyValue = function (pM1, pM2) {
- var m1 = pM1.mat, m2 = pM2.mat;
- var mat = new Float32Array(16);
-
- mat[0] = m1[0] * m2[0] + m1[4] * m2[1] + m1[8] * m2[2] + m1[12] * m2[3];
- mat[1] = m1[1] * m2[0] + m1[5] * m2[1] + m1[9] * m2[2] + m1[13] * m2[3];
- mat[2] = m1[2] * m2[0] + m1[6] * m2[1] + m1[10] * m2[2] + m1[14] * m2[3];
- mat[3] = m1[3] * m2[0] + m1[7] * m2[1] + m1[11] * m2[2] + m1[15] * m2[3];
-
- mat[4] = m1[0] * m2[4] + m1[4] * m2[5] + m1[8] * m2[6] + m1[12] * m2[7];
- mat[5] = m1[1] * m2[4] + m1[5] * m2[5] + m1[9] * m2[6] + m1[13] * m2[7];
- mat[6] = m1[2] * m2[4] + m1[6] * m2[5] + m1[10] * m2[6] + m1[14] * m2[7];
- mat[7] = m1[3] * m2[4] + m1[7] * m2[5] + m1[11] * m2[6] + m1[15] * m2[7];
-
- mat[8] = m1[0] * m2[8] + m1[4] * m2[9] + m1[8] * m2[10] + m1[12] * m2[11];
- mat[9] = m1[1] * m2[8] + m1[5] * m2[9] + m1[9] * m2[10] + m1[13] * m2[11];
- mat[10] = m1[2] * m2[8] + m1[6] * m2[9] + m1[10] * m2[10] + m1[14] * m2[11];
- mat[11] = m1[3] * m2[8] + m1[7] * m2[9] + m1[11] * m2[10] + m1[15] * m2[11];
-
- mat[12] = m1[0] * m2[12] + m1[4] * m2[13] + m1[8] * m2[14] + m1[12] * m2[15];
- mat[13] = m1[1] * m2[12] + m1[5] * m2[13] + m1[9] * m2[14] + m1[13] * m2[15];
- mat[14] = m1[2] * m2[12] + m1[6] * m2[13] + m1[10] * m2[14] + m1[14] * m2[15];
- mat[15] = m1[3] * m2[12] + m1[7] * m2[13] + m1[11] * m2[14] + m1[15] * m2[15];
-
- return mat;
- };
-
- /**
- * Assigns the value of pIn to pOut
- */
- cc.kmMat4Assign = function (pOut, pIn) {
- if (pOut === pIn) {
- cc.log("cc.kmMat4Assign(): pOut equals pIn");
- return pOut;
- }
-
- var outArr = pOut.mat;
- var inArr = pIn.mat;
-
- outArr[0] = inArr[0];
- outArr[1] = inArr[1];
- outArr[2] = inArr[2];
- outArr[3] = inArr[3];
-
- outArr[4] = inArr[4];
- outArr[5] = inArr[5];
- outArr[6] = inArr[6];
- outArr[7] = inArr[7];
-
- outArr[8] = inArr[8];
- outArr[9] = inArr[9];
- outArr[10] = inArr[10];
- outArr[11] = inArr[11];
-
- outArr[12] = inArr[12];
- outArr[13] = inArr[13];
- outArr[14] = inArr[14];
- outArr[15] = inArr[15];
- return pOut;
- };
-
- /**
- * Assigns the value of current matrix from mat4
- * @param {cc.math.Matrix4} mat4
- * @returns {cc.math.Matrix4}
- */
- proto.assignFrom = function(mat4) {
- if (this === mat4) {
- cc.log("cc.mat.Matrix4.assignFrom(): mat4 equals current matrix");
- return this;
- }
- var outArr = this.mat, inArr = mat4.mat;
-
- outArr[0] = inArr[0];
- outArr[1] = inArr[1];
- outArr[2] = inArr[2];
- outArr[3] = inArr[3];
-
- outArr[4] = inArr[4];
- outArr[5] = inArr[5];
- outArr[6] = inArr[6];
- outArr[7] = inArr[7];
-
- outArr[8] = inArr[8];
- outArr[9] = inArr[9];
- outArr[10] = inArr[10];
- outArr[11] = inArr[11];
-
- outArr[12] = inArr[12];
- outArr[13] = inArr[13];
- outArr[14] = inArr[14];
- outArr[15] = inArr[15];
- return this;
- };
-
- /**
- * Returns true if current matrix equal mat4 (approximately)
- * @param {cc.math.Matrix4} mat4
- * @returns {boolean}
- */
- proto.equals = function(mat4) {
- if (this === mat4) {
- cc.log("cc.kmMat4AreEqual(): pMat1 and pMat2 are same object.");
- return true;
- }
- var matA = this.mat, matB = mat4.mat, EPSILON = cc.math.EPSILON;
- for (var i = 0; i < 16; i++) {
- if (!(matA[i] + EPSILON > matB[i] && matA[i] - EPSILON < matB[i]))
- return false;
- }
- return true;
- };
-
- /**
- * Builds an X-axis rotation matrix and stores it in matrix, returns matrix, if matrix is null, create a new matrix
- * @param {Number} radians
- * @param {cc.math.Matrix4} [matrix]
- * @returns {cc.math.Matrix4}
- */
- cc.math.Matrix4.createByRotationX = function(radians, matrix) { //cc.kmMat4RotationX
- /*
- | 1 0 0 0 |
- M = | 0 cos(A) -sin(A) 0 |
- | 0 sin(A) cos(A) 0 |
- | 0 0 0 1 |
- */
- matrix = matrix || new cc.math.Matrix4();
- var mat = matrix.mat;
- mat[0] = 1.0;
- mat[3] = mat[2] = mat[1] = 0.0;
-
- mat[4] = 0.0;
- mat[5] = Math.cos(radians);
- mat[6] = Math.sin(radians);
- mat[7] = 0.0;
-
- mat[8] = 0.0;
- mat[9] = -Math.sin(radians);
- mat[10] = Math.cos(radians);
- mat[11] = 0.0;
-
- mat[14] = mat[13] = mat[12] = 0.0;
- mat[15] = 1.0;
- return matrix;
- };
-
- /**
- * Builds a rotation matrix using the rotation around the Y-axis, The result is stored in matrix, matrix is returned.
- * @param {Number} radians
- * @param {cc.math.Matrix4} [matrix]
- * @returns {*}
- */
- cc.math.Matrix4.createByRotationY = function(radians, matrix) { // cc.kmMat4RotationY
- /*
- | cos(A) 0 sin(A) 0 |
- M = | 0 1 0 0 |
- | -sin(A) 0 cos(A) 0 |
- | 0 0 0 1 |
- */
- matrix = matrix || new cc.math.Matrix4();
- var mat = matrix.mat;
- mat[0] = Math.cos(radians);
- mat[1] = 0.0;
- mat[2] = -Math.sin(radians);
- mat[3] = 0.0;
-
- mat[7] = mat[6] = mat[4] = 0.0;
- mat[5] = 1.0;
-
- mat[8] = Math.sin(radians);
- mat[9] = 0.0;
- mat[10] = Math.cos(radians);
- mat[11] = 0.0;
-
- mat[14] = mat[13] = mat[12] = 0.0;
- mat[15] = 1.0;
- return matrix;
- };
-
- /**
- * Builds a rotation matrix around the Z-axis. The resulting matrix is stored in matrix. matrix is returned.
- * @param {Number} radians
- * @param {cc.math.Matrix4} matrix
- * @return {cc.math.Matrix4}
- */
- cc.math.Matrix4.createByRotationZ = function(radians, matrix){ // cc.kmMat4RotationZ
- /*
- | cos(A) -sin(A) 0 0 |
- M = | sin(A) cos(A) 0 0 |
- | 0 0 1 0 |
- | 0 0 0 1 |
- */
- matrix = matrix || new cc.math.Matrix4();
- var mat = matrix.mat;
- mat[0] = Math.cos(radians);
- mat[1] = Math.sin(radians);
- mat[3] = mat[2] = 0.0;
-
- mat[4] = -Math.sin(radians);
- mat[5] = Math.cos(radians);
- mat[7] = mat[6] = 0.0;
-
- mat[11] = mat[9] = mat[8] = 0.0;
- mat[10] = 1.0;
-
- mat[14] = mat[13] = mat[12] = 0.0;
- mat[15] = 1.0;
-
- return matrix;
- };
-
- /**
- * Builds a rotation matrix from pitch, yaw and roll. The resulting matrix is stored in parameter matrix and returns.
- * @param {Number} pitch
- * @param {Number} yaw
- * @param {Number} roll
- * @param {cc.math.Matrix4} [matrix] if matrix is undefined, creates a new matrix.
- * @returns {cc.math.Matrix4}
- */
- cc.math.Matrix4.createByPitchYawRoll = function(pitch, yaw, roll, matrix) {
- matrix = matrix || new cc.math.Matrix4();
- var cr = Math.cos(pitch), sr = Math.sin(pitch);
- var cp = Math.cos(yaw), sp = Math.sin(yaw);
- var cy = Math.cos(roll), sy = Math.sin(roll);
- var srsp = sr * sp, crsp = cr * sp;
- var mat = matrix.mat;
-
- mat[0] = cp * cy;
- mat[4] = cp * sy;
- mat[8] = -sp;
-
- mat[1] = srsp * cy - cr * sy;
- mat[5] = srsp * sy + cr * cy;
- mat[9] = sr * cp;
-
- mat[2] = crsp * cy + sr * sy;
- mat[6] = crsp * sy - sr * cy;
- mat[10] = cr * cp;
-
- mat[3] = mat[7] = mat[11] = 0.0;
- mat[15] = 1.0;
- return matrix;
- };
-
- /**
- * Builds a matrix by a quaternion.
- * @param {cc.math.Quaternion} quaternion
- * @param {cc.math.Matrix4} [matrix] if matrix is undefined, creates a new matrix.
- * @returns {cc.math.Matrix4}
- */
- cc.math.Matrix4.createByQuaternion = function(quaternion, matrix) {
- matrix = matrix || new cc.math.Matrix4();
- var mat = matrix.mat;
- mat[0] = 1.0 - 2.0 * (quaternion.y * quaternion.y + quaternion.z * quaternion.z );
- mat[1] = 2.0 * (quaternion.x * quaternion.y + quaternion.z * quaternion.w);
- mat[2] = 2.0 * (quaternion.x * quaternion.z - quaternion.y * quaternion.w);
- mat[3] = 0.0;
-
- // Second row
- mat[4] = 2.0 * ( quaternion.x * quaternion.y - quaternion.z * quaternion.w );
- mat[5] = 1.0 - 2.0 * ( quaternion.x * quaternion.x + quaternion.z * quaternion.z );
- mat[6] = 2.0 * (quaternion.z * quaternion.y + quaternion.x * quaternion.w );
- mat[7] = 0.0;
-
- // Third row
- mat[8] = 2.0 * ( quaternion.x * quaternion.z + quaternion.y * quaternion.w );
- mat[9] = 2.0 * ( quaternion.y * quaternion.z - quaternion.x * quaternion.w );
- mat[10] = 1.0 - 2.0 * ( quaternion.x * quaternion.x + quaternion.y * quaternion.y );
- mat[11] = 0.0;
-
- // Fourth row
- mat[14] = mat[13] = mat[12] = 0;
- mat[15] = 1.0;
- return matrix;
- };
-
- /**
- * Build a 4x4 OpenGL transformation matrix using a 3x3 rotation matrix, and a 3d vector representing a translation.
- * @param {cc.math.Matrix3} rotation
- * @param {cc.math.Vec3} translation
- * @param {cc.math.Matrix4} [matrix] if matrix is undefined, creates a new matrix.
- * @returns {cc.math.Matrix4}
- */
- cc.math.Matrix4.createByRotationTranslation = function(rotation, translation, matrix) {
- matrix = matrix || new cc.math.Matrix4();
- var mat = matrix.mat, rMat = rotation.mat;
- mat[0] = rMat[0];
- mat[1] = rMat[1];
- mat[2] = rMat[2];
- mat[3] = 0.0;
-
- mat[4] = rMat[3];
- mat[5] = rMat[4];
- mat[6] = rMat[5];
- mat[7] = 0.0;
-
- mat[8] = rMat[6];
- mat[9] = rMat[7];
- mat[10] = rMat[8];
- mat[11] = 0.0;
-
- mat[12] = translation.x;
- mat[13] = translation.y;
- mat[14] = translation.z;
- mat[15] = 1.0;
- return matrix;
- };
-
- /**
- * Builds a scaling matrix
- * @param {Number} x
- * @param {Number} y
- * @param {Number} z
- * @param {cc.math.Matrix4} [matrix] if matrix is undefined, creates a new matrix.
- * @returns {cc.math.Matrix4}
- */
- cc.math.Matrix4.createByScale = function(x, y, z, matrix) { //cc.kmMat4Scaling
- matrix = matrix || new cc.math.Matrix4();
- var mat = matrix.mat;
- mat[0] = x;
- mat[5] = y;
- mat[10] = z;
- mat[15] = 1.0;
- mat[1] = mat[2] = mat[3] = mat[4] = mat[6] = mat[7] =
- mat[8] = mat[9] = mat[11] = mat[12] = mat[13] = mat[14] = 0;
- return matrix;
- };
-
- /**
- * Builds a translation matrix. All other elements in the matrix
- * will be set to zero except for the diagonal which is set to 1.0
- */
- cc.kmMat4Translation = function (pOut, x, y, z) {
- //FIXME: Write a test for this
- pOut.mat[0] = pOut.mat[5] = pOut.mat[10] = pOut.mat[15] = 1.0;
- pOut.mat[1] = pOut.mat[2] = pOut.mat[3] =
- pOut.mat[4] = pOut.mat[6] = pOut.mat[7] =
- pOut.mat[8] = pOut.mat[9] = pOut.mat[11] = 0.0;
- pOut.mat[12] = x;
- pOut.mat[13] = y;
- pOut.mat[14] = z;
- return pOut;
- };
-
- /**
- * Builds a translation matrix.
- * @param {Number} x
- * @param {Number} y
- * @param {Number} z
- * @param {cc.math.Matrix4} [matrix] if matrix is undefined, creates a new matrix.
- * @returns {cc.math.Matrix4}
- */
- cc.math.Matrix4.createByTranslation = function(x, y, z, matrix){ //cc.kmMat4Translation
- matrix = matrix || new cc.math.Matrix4();
- matrix.identity();
- matrix.mat[12] = x;
- matrix.mat[13] = y;
- matrix.mat[14] = z;
- return matrix;
- };
-
- /**
- * Get the up vector from a matrix.
- * @returns {cc.math.Vec3}
- */
- proto.getUpVec3 = function() {
- var mat = this.mat;
- var ret = new cc.math.Vec3(mat[4],mat[5], mat[6]);
- return ret.normalize();
- };
-
- /**
- * Extract the right vector from a 4x4 matrix.
- * @returns {cc.math.Vec3}
- */
- proto.getRightVec3 = function(){
- var mat = this.mat;
- var ret = new cc.math.Vec3(mat[0],mat[1], mat[2]);
- return ret.normalize();
- };
-
- /**
- * Extract the forward vector from a 4x4 matrix.
- * @returns {cc.math.Vec3}
- */
- proto.getForwardVec3 = function() {
- var mat = this.mat;
- var ret = new cc.math.Vec3(mat[8],mat[9], mat[10]);
- return ret.normalize();
- };
-
- /**
- * Creates a perspective projection matrix in the
- * same way as gluPerspective
- */
- cc.kmMat4PerspectiveProjection = function (pOut, fovY, aspect, zNear, zFar) {
- var r = cc.degreesToRadians(fovY / 2);
- var deltaZ = zFar - zNear;
- var s = Math.sin(r);
-
- if (deltaZ === 0 || s === 0 || aspect === 0)
- return null;
-
- //cos(r) / sin(r) = cot(r)
- var cotangent = Math.cos(r) / s;
- pOut.identity();
- pOut.mat[0] = cotangent / aspect;
- pOut.mat[5] = cotangent;
- pOut.mat[10] = -(zFar + zNear) / deltaZ;
- pOut.mat[11] = -1;
- pOut.mat[14] = -2 * zNear * zFar / deltaZ;
- pOut.mat[15] = 0;
-
- return pOut;
- };
-
- /**
- * Creates a perspective projection matrix in the same way as gluPerspective
- * @param {Number} fovY
- * @param {Number} aspect
- * @param {Number} zNear
- * @param {Number} zFar
- * @returns {cc.math.Matrix4|Null}
- */
- cc.math.Matrix4.createPerspectiveProjection = function(fovY, aspect, zNear, zFar){
- var r = cc.degreesToRadians(fovY / 2), deltaZ = zFar - zNear;
- var s = Math.sin(r);
-
- if (deltaZ === 0 || s === 0 || aspect === 0)
- return null;
-
- //cos(r) / sin(r) = cot(r)
- var cotangent = Math.cos(r) / s;
- var matrix = new cc.math.Matrix4(), mat = matrix.mat;
- matrix.identity();
- mat[0] = cotangent / aspect;
- mat[5] = cotangent;
- mat[10] = -(zFar + zNear) / deltaZ;
- mat[11] = -1;
- mat[14] = -2 * zNear * zFar / deltaZ;
- mat[15] = 0;
- return matrix;
- };
-
- /** Creates an orthographic projection matrix like glOrtho */
- cc.kmMat4OrthographicProjection = function (pOut, left, right, bottom, top, nearVal, farVal) {
- pOut.identity();
- pOut.mat[0] = 2 / (right - left);
- pOut.mat[5] = 2 / (top - bottom);
- pOut.mat[10] = -2 / (farVal - nearVal);
- pOut.mat[12] = -((right + left) / (right - left));
- pOut.mat[13] = -((top + bottom) / (top - bottom));
- pOut.mat[14] = -((farVal + nearVal) / (farVal - nearVal));
- return pOut;
- };
-
- /**
- * Creates an orthographic projection matrix like glOrtho
- * @param {Number} left
- * @param {Number} right
- * @param {Number} bottom
- * @param {Number} top
- * @param {Number} nearVal
- * @param {Number} farVal
- * @returns {cc.math.Matrix4}
- */
- cc.math.Matrix4.createOrthographicProjection = function (left, right, bottom, top, nearVal, farVal) {
- var matrix = new cc.math.Matrix4(), mat = matrix.mat;
- matrix.identity();
- mat[0] = 2 / (right - left);
- mat[5] = 2 / (top - bottom);
- mat[10] = -2 / (farVal - nearVal);
- mat[12] = -((right + left) / (right - left));
- mat[13] = -((top + bottom) / (top - bottom));
- mat[14] = -((farVal + nearVal) / (farVal - nearVal));
- return matrix;
- };
-
- /**
- * Builds a translation matrix in the same way as gluLookAt()
- * the resulting matrix is stored in pOut. pOut is returned.
- */
- cc.kmMat4LookAt = function (pOut, pEye, pCenter, pUp) {
- var f = new cc.math.Vec3(pCenter), up = new cc.math.Vec3(pUp);
- f.subtract(pEye);
- f.normalize();
- up.normalize();
-
- var s = new cc.math.Vec3(f);
- s.cross(up);
- s.normalize();
-
- var u = new cc.math.Vec3(s);
- u.cross(f);
- s.normalize();
-
- pOut.identity();
-
- pOut.mat[0] = s.x;
- pOut.mat[4] = s.y;
- pOut.mat[8] = s.z;
-
- pOut.mat[1] = u.x;
- pOut.mat[5] = u.y;
- pOut.mat[9] = u.z;
-
- pOut.mat[2] = -f.x;
- pOut.mat[6] = -f.y;
- pOut.mat[10] = -f.z;
-
- var translate = cc.math.Matrix4.createByTranslation(-pEye.x, -pEye.y, -pEye.z);
- pOut.multiply(translate);
- return pOut;
- };
-
- var tempMatrix = new cc.math.Matrix4(); // an internal matrix
- proto.lookAt = function(eyeVec, centerVec, upVec) {
- var f = new cc.math.Vec3(centerVec), up = new cc.math.Vec3(upVec), mat = this.mat;
- f.subtract(eyeVec);
- f.normalize();
- up.normalize();
-
- var s = new cc.math.Vec3(f);
- s.cross(up);
- s.normalize();
-
- var u = new cc.math.Vec3(s);
- u.cross(f);
- s.normalize();
-
- this.identity();
- mat[0] = s.x;
- mat[4] = s.y;
- mat[8] = s.z;
-
- mat[1] = u.x;
- mat[5] = u.y;
- mat[9] = u.z;
-
- mat[2] = -f.x;
- mat[6] = -f.y;
- mat[10] = -f.z;
-
- tempMatrix = cc.math.Matrix4.createByTranslation(-eyeVec.x, -eyeVec.y, -eyeVec.z, tempMatrix);
- this.multiply(tempMatrix);
- return this;
- };
-
- /**
- * Build a rotation matrix from an axis and an angle. Result is stored in pOut.
- * pOut is returned.
- */
- cc.kmMat4RotationAxisAngle = function (pOut, axis, radians) {
- var rcos = Math.cos(radians), rsin = Math.sin(radians);
-
- var normalizedAxis = new cc.math.Vec3(axis);
- normalizedAxis.normalize();
-
- pOut.mat[0] = rcos + normalizedAxis.x * normalizedAxis.x * (1 - rcos);
- pOut.mat[1] = normalizedAxis.z * rsin + normalizedAxis.y * normalizedAxis.x * (1 - rcos);
- pOut.mat[2] = -normalizedAxis.y * rsin + normalizedAxis.z * normalizedAxis.x * (1 - rcos);
- pOut.mat[3] = 0.0;
-
- pOut.mat[4] = -normalizedAxis.z * rsin + normalizedAxis.x * normalizedAxis.y * (1 - rcos);
- pOut.mat[5] = rcos + normalizedAxis.y * normalizedAxis.y * (1 - rcos);
- pOut.mat[6] = normalizedAxis.x * rsin + normalizedAxis.z * normalizedAxis.y * (1 - rcos);
- pOut.mat[7] = 0.0;
-
- pOut.mat[8] = normalizedAxis.y * rsin + normalizedAxis.x * normalizedAxis.z * (1 - rcos);
- pOut.mat[9] = -normalizedAxis.x * rsin + normalizedAxis.y * normalizedAxis.z * (1 - rcos);
- pOut.mat[10] = rcos + normalizedAxis.z * normalizedAxis.z * (1 - rcos);
- pOut.mat[11] = 0.0;
-
- pOut.mat[12] = 0.0;
- pOut.mat[13] = 0.0;
- pOut.mat[14] = 0.0;
- pOut.mat[15] = 1.0;
-
- return pOut;
- };
-
- /**
- * Build a rotation matrix from an axis and an angle.
- * @param {cc.math.Vec3} axis
- * @param {Number} radians
- * @param {cc.math.Matrix4} [matrix]
- * @returns {cc.math.Matrix4}
- */
- cc.math.Matrix4.createByAxisAndAngle = function(axis, radians, matrix) {
- matrix = matrix || new cc.math.Matrix4();
- var mat = this.mat, rcos = Math.cos(radians), rsin = Math.sin(radians) ;
-
- var normalizedAxis = new cc.math.Vec3(axis);
- normalizedAxis.normalize();
-
- mat[0] = rcos + normalizedAxis.x * normalizedAxis.x * (1 - rcos);
- mat[1] = normalizedAxis.z * rsin + normalizedAxis.y * normalizedAxis.x * (1 - rcos);
- mat[2] = -normalizedAxis.y * rsin + normalizedAxis.z * normalizedAxis.x * (1 - rcos);
- mat[3] = 0.0;
-
- mat[4] = -normalizedAxis.z * rsin + normalizedAxis.x * normalizedAxis.y * (1 - rcos);
- mat[5] = rcos + normalizedAxis.y * normalizedAxis.y * (1 - rcos);
- mat[6] = normalizedAxis.x * rsin + normalizedAxis.z * normalizedAxis.y * (1 - rcos);
- mat[7] = 0.0;
-
- mat[8] = normalizedAxis.y * rsin + normalizedAxis.x * normalizedAxis.z * (1 - rcos);
- mat[9] = -normalizedAxis.x * rsin + normalizedAxis.y * normalizedAxis.z * (1 - rcos);
- mat[10] = rcos + normalizedAxis.z * normalizedAxis.z * (1 - rcos);
- mat[11] = 0.0;
-
- mat[12] = mat[13] = mat[14] = 0.0;
- mat[15] = 1.0;
- return matrix;
- };
-
- /**
- * Extract a 3x3 rotation matrix from the input 4x4 transformation.
- * @returns {cc.math.Matrix3}
- */
- proto.extractRotation = function(){
- var matrix = new cc.math.Matrix3(), mat4 = this.mat, mat3 = matrix.mat;
- mat3[0] = mat4[0];
- mat3[1] = mat4[1];
- mat3[2] = mat4[2];
-
- mat3[3] = mat4[4];
- mat3[4] = mat4[5];
- mat3[5] = mat4[6];
-
- mat3[6] = mat4[8];
- mat3[7] = mat4[9];
- mat3[8] = mat4[10];
- return matrix;
- };
-
- proto.extractPlane = function(planeType) {
- var plane = new cc.math.Plane(), mat = this.mat;
- switch (planeType) {
- case cc.math.Plane.RIGHT:
- plane.a = mat[3] - mat[0];
- plane.b = mat[7] - mat[4];
- plane.c = mat[11] - mat[8];
- plane.d = mat[15] - mat[12];
- break;
- case cc.math.Plane.LEFT:
- plane.a = mat[3] + mat[0];
- plane.b = mat[7] + mat[4];
- plane.c = mat[11] + mat[8];
- plane.d = mat[15] + mat[12];
- break;
- case cc.math.Plane.BOTTOM:
- plane.a = mat[3] + mat[1];
- plane.b = mat[7] + mat[5];
- plane.c = mat[11] + mat[9];
- plane.d = mat[15] + mat[13];
- break;
- case cc.math.Plane.TOP:
- plane.a = mat[3] - mat[1];
- plane.b = mat[7] - mat[5];
- plane.c = mat[11] - mat[9];
- plane.d = mat[15] - mat[13];
- break;
- case cc.math.Plane.FAR:
- plane.a = mat[3] - mat[2];
- plane.b = mat[7] - mat[6];
- plane.c = mat[11] - mat[10];
- plane.d = mat[15] - mat[14];
- break;
- case cc.math.Plane.NEAR:
- plane.a = mat[3] + mat[2];
- plane.b = mat[7] + mat[6];
- plane.c = mat[11] + mat[10];
- plane.d = mat[15] + mat[14];
- break;
- default:
- cc.log("cc.math.Matrix4.extractPlane: Invalid plane index");
- break;
- }
-
- var t = Math.sqrt(plane.a * plane.a + plane.b * plane.b + plane.c * plane.c);
- plane.a /= t;
- plane.b /= t;
- plane.c /= t;
- plane.d /= t;
- return plane;
- };
-
- /**
- * Take the rotation from a 4x4 transformation matrix, and return it as an axis and an angle (in radians)
- * @returns {*|{axis: cc.math.Vec3, angle: number}}
- */
- proto.toAxisAndAngle = function() {
- /*Surely not this easy?*/
- var rotation = this.extractRotation();
- var temp = cc.math.Quaternion.rotationMatrix(rotation);
- return temp.toAxisAndAngle();
- };
-})(cc);
-
-
-
-
+ matrix = matrix || new cc.math.Matrix4();
+ var mat = matrix.mat;
+ mat[0] = Math.cos(radians);
+ mat[1] = Math.sin(radians);
+ mat[3] = mat[2] = 0.0;
+
+ mat[4] = -Math.sin(radians);
+ mat[5] = Math.cos(radians);
+ mat[7] = mat[6] = 0.0;
+
+ mat[11] = mat[9] = mat[8] = 0.0;
+ mat[10] = 1.0;
+
+ mat[14] = mat[13] = mat[12] = 0.0;
+ mat[15] = 1.0;
+
+ return matrix;
+};
+
+/**
+ * Builds a rotation matrix from pitch, yaw and roll. The resulting matrix is stored in parameter matrix and returns.
+ * @param {Number} pitch
+ * @param {Number} yaw
+ * @param {Number} roll
+ * @param {cc.math.Matrix4} [matrix] if matrix is undefined, creates a new matrix.
+ * @returns {cc.math.Matrix4}
+ */
+cc.math.Matrix4.createByPitchYawRoll = function(pitch, yaw, roll, matrix) {
+ matrix = matrix || new cc.math.Matrix4();
+ var cr = Math.cos(pitch), sr = Math.sin(pitch);
+ var cp = Math.cos(yaw), sp = Math.sin(yaw);
+ var cy = Math.cos(roll), sy = Math.sin(roll);
+ var srsp = sr * sp, crsp = cr * sp;
+ var mat = matrix.mat;
+
+ mat[0] = cp * cy;
+ mat[4] = cp * sy;
+ mat[8] = -sp;
+
+ mat[1] = srsp * cy - cr * sy;
+ mat[5] = srsp * sy + cr * cy;
+ mat[9] = sr * cp;
+
+ mat[2] = crsp * cy + sr * sy;
+ mat[6] = crsp * sy - sr * cy;
+ mat[10] = cr * cp;
+
+ mat[3] = mat[7] = mat[11] = 0.0;
+ mat[15] = 1.0;
+ return matrix;
+};
+
+/**
+ * Builds a matrix by a quaternion.
+ * @param {cc.math.Quaternion} quaternion
+ * @param {cc.math.Matrix4} [matrix] if matrix is undefined, creates a new matrix.
+ * @returns {cc.math.Matrix4}
+ */
+cc.math.Matrix4.createByQuaternion = function(quaternion, matrix) {
+ matrix = matrix || new cc.math.Matrix4();
+ var mat = matrix.mat;
+ mat[0] = 1.0 - 2.0 * (quaternion.y * quaternion.y + quaternion.z * quaternion.z );
+ mat[1] = 2.0 * (quaternion.x * quaternion.y + quaternion.z * quaternion.w);
+ mat[2] = 2.0 * (quaternion.x * quaternion.z - quaternion.y * quaternion.w);
+ mat[3] = 0.0;
+
+ // Second row
+ mat[4] = 2.0 * ( quaternion.x * quaternion.y - quaternion.z * quaternion.w );
+ mat[5] = 1.0 - 2.0 * ( quaternion.x * quaternion.x + quaternion.z * quaternion.z );
+ mat[6] = 2.0 * (quaternion.z * quaternion.y + quaternion.x * quaternion.w );
+ mat[7] = 0.0;
+
+ // Third row
+ mat[8] = 2.0 * ( quaternion.x * quaternion.z + quaternion.y * quaternion.w );
+ mat[9] = 2.0 * ( quaternion.y * quaternion.z - quaternion.x * quaternion.w );
+ mat[10] = 1.0 - 2.0 * ( quaternion.x * quaternion.x + quaternion.y * quaternion.y );
+ mat[11] = 0.0;
+
+ // Fourth row
+ mat[14] = mat[13] = mat[12] = 0;
+ mat[15] = 1.0;
+ return matrix;
+};
+
+/**
+ * Build a 4x4 OpenGL transformation matrix using a 3x3 rotation matrix, and a 3d vector representing a translation.
+ * @param {cc.math.Matrix3} rotation
+ * @param {cc.math.Vec3} translation
+ * @param {cc.math.Matrix4} [matrix] if matrix is undefined, creates a new matrix.
+ * @returns {cc.math.Matrix4}
+ */
+cc.math.Matrix4.createByRotationTranslation = function(rotation, translation, matrix) {
+ matrix = matrix || new cc.math.Matrix4();
+ var mat = matrix.mat, rMat = rotation.mat;
+ mat[0] = rMat[0];
+ mat[1] = rMat[1];
+ mat[2] = rMat[2];
+ mat[3] = 0.0;
+
+ mat[4] = rMat[3];
+ mat[5] = rMat[4];
+ mat[6] = rMat[5];
+ mat[7] = 0.0;
+
+ mat[8] = rMat[6];
+ mat[9] = rMat[7];
+ mat[10] = rMat[8];
+ mat[11] = 0.0;
+
+ mat[12] = translation.x;
+ mat[13] = translation.y;
+ mat[14] = translation.z;
+ mat[15] = 1.0;
+ return matrix;
+};
+
+/**
+ * Builds a scaling matrix
+ * @param {Number} x
+ * @param {Number} y
+ * @param {Number} z
+ * @param {cc.math.Matrix4} [matrix] if matrix is undefined, creates a new matrix.
+ * @returns {cc.math.Matrix4}
+ */
+cc.math.Matrix4.createByScale = function(x, y, z, matrix) { //cc.kmMat4Scaling
+ matrix = matrix || new cc.math.Matrix4();
+ var mat = matrix.mat;
+ mat[0] = x;
+ mat[5] = y;
+ mat[10] = z;
+ mat[15] = 1.0;
+ mat[1] = mat[2] = mat[3] = mat[4] = mat[6] = mat[7] =
+ mat[8] = mat[9] = mat[11] = mat[12] = mat[13] = mat[14] = 0;
+ return matrix;
+};
+
+/**
+ * Builds a translation matrix. All other elements in the matrix
+ * will be set to zero except for the diagonal which is set to 1.0
+ */
+cc.math.mat4Translation = function (pOut, x, y, z) {
+ //FIXME: Write a test for this
+ pOut.mat[0] = pOut.mat[5] = pOut.mat[10] = pOut.mat[15] = 1.0;
+ pOut.mat[1] = pOut.mat[2] = pOut.mat[3] =
+ pOut.mat[4] = pOut.mat[6] = pOut.mat[7] =
+ pOut.mat[8] = pOut.mat[9] = pOut.mat[11] = 0.0;
+ pOut.mat[12] = x;
+ pOut.mat[13] = y;
+ pOut.mat[14] = z;
+ return pOut;
+};
+
+/**
+ * Builds a translation matrix.
+ * @param {Number} x
+ * @param {Number} y
+ * @param {Number} z
+ * @param {cc.math.Matrix4} [matrix] if matrix is undefined, creates a new matrix.
+ * @returns {cc.math.Matrix4}
+ */
+cc.math.Matrix4.createByTranslation = function(x, y, z, matrix){ //cc.kmMat4Translation
+ matrix = matrix || new cc.math.Matrix4();
+ matrix.identity();
+ matrix.mat[12] = x;
+ matrix.mat[13] = y;
+ matrix.mat[14] = z;
+ return matrix;
+};
+
+/**
+ * Get the up vector from a matrix.
+ * @returns {cc.math.Vec3}
+ */
+proto.getUpVec3 = function() {
+ var mat = this.mat;
+ var ret = new cc.math.Vec3(mat[4],mat[5], mat[6]);
+ return ret.normalize();
+};
+
+/**
+ * Extract the right vector from a 4x4 matrix.
+ * @returns {cc.math.Vec3}
+ */
+proto.getRightVec3 = function(){
+ var mat = this.mat;
+ var ret = new cc.math.Vec3(mat[0],mat[1], mat[2]);
+ return ret.normalize();
+};
+
+/**
+ * Extract the forward vector from a 4x4 matrix.
+ * @returns {cc.math.Vec3}
+ */
+proto.getForwardVec3 = function() {
+ var mat = this.mat;
+ var ret = new cc.math.Vec3(mat[8],mat[9], mat[10]);
+ return ret.normalize();
+};
+
+/**
+ * Creates a perspective projection matrix in the
+ * same way as gluPerspective
+ */
+cc.math.mat4PerspectiveProjection = function (pOut, fovY, aspect, zNear, zFar) {
+ var r = cc.degreesToRadians(fovY / 2);
+ var deltaZ = zFar - zNear;
+ var s = Math.sin(r);
+
+ if (deltaZ === 0 || s === 0 || aspect === 0)
+ return null;
+
+ //cos(r) / sin(r) = cot(r)
+ var cotangent = Math.cos(r) / s;
+ pOut.identity();
+ pOut.mat[0] = cotangent / aspect;
+ pOut.mat[5] = cotangent;
+ pOut.mat[10] = -(zFar + zNear) / deltaZ;
+ pOut.mat[11] = -1;
+ pOut.mat[14] = -2 * zNear * zFar / deltaZ;
+ pOut.mat[15] = 0;
+
+ return pOut;
+};
+
+/**
+ * Creates a perspective projection matrix in the same way as gluPerspective
+ * @param {Number} fovY
+ * @param {Number} aspect
+ * @param {Number} zNear
+ * @param {Number} zFar
+ * @returns {cc.math.Matrix4|Null}
+ */
+cc.math.Matrix4.createPerspectiveProjection = function(fovY, aspect, zNear, zFar){
+ var r = cc.degreesToRadians(fovY / 2), deltaZ = zFar - zNear;
+ var s = Math.sin(r);
+
+ if (deltaZ === 0 || s === 0 || aspect === 0)
+ return null;
+
+ //cos(r) / sin(r) = cot(r)
+ var cotangent = Math.cos(r) / s;
+ var matrix = new cc.math.Matrix4(), mat = matrix.mat;
+ matrix.identity();
+ mat[0] = cotangent / aspect;
+ mat[5] = cotangent;
+ mat[10] = -(zFar + zNear) / deltaZ;
+ mat[11] = -1;
+ mat[14] = -2 * zNear * zFar / deltaZ;
+ mat[15] = 0;
+ return matrix;
+};
+
+/** Creates an orthographic projection matrix like glOrtho */
+cc.math.mat4OrthographicProjection = function (pOut, left, right, bottom, top, nearVal, farVal) {
+ pOut.identity();
+ pOut.mat[0] = 2 / (right - left);
+ pOut.mat[5] = 2 / (top - bottom);
+ pOut.mat[10] = -2 / (farVal - nearVal);
+ pOut.mat[12] = -((right + left) / (right - left));
+ pOut.mat[13] = -((top + bottom) / (top - bottom));
+ pOut.mat[14] = -((farVal + nearVal) / (farVal - nearVal));
+ return pOut;
+};
+
+/**
+ * Creates an orthographic projection matrix like glOrtho
+ * @param {Number} left
+ * @param {Number} right
+ * @param {Number} bottom
+ * @param {Number} top
+ * @param {Number} nearVal
+ * @param {Number} farVal
+ * @returns {cc.math.Matrix4}
+ */
+cc.math.Matrix4.createOrthographicProjection = function (left, right, bottom, top, nearVal, farVal) {
+ var matrix = new cc.math.Matrix4(), mat = matrix.mat;
+ matrix.identity();
+ mat[0] = 2 / (right - left);
+ mat[5] = 2 / (top - bottom);
+ mat[10] = -2 / (farVal - nearVal);
+ mat[12] = -((right + left) / (right - left));
+ mat[13] = -((top + bottom) / (top - bottom));
+ mat[14] = -((farVal + nearVal) / (farVal - nearVal));
+ return matrix;
+};
+
+/**
+ * Builds a translation matrix in the same way as gluLookAt()
+ * the resulting matrix is stored in pOut. pOut is returned.
+ */
+cc.math.mat4LookAt = function (pOut, pEye, pCenter, pUp) {
+ var f = new cc.math.Vec3(pCenter), up = new cc.math.Vec3(pUp);
+ f.subtract(pEye);
+ f.normalize();
+ up.normalize();
+
+ var s = new cc.math.Vec3(f);
+ s.cross(up);
+ s.normalize();
+
+ var u = new cc.math.Vec3(s);
+ u.cross(f);
+ s.normalize();
+
+ pOut.identity();
+
+ pOut.mat[0] = s.x;
+ pOut.mat[4] = s.y;
+ pOut.mat[8] = s.z;
+
+ pOut.mat[1] = u.x;
+ pOut.mat[5] = u.y;
+ pOut.mat[9] = u.z;
+
+ pOut.mat[2] = -f.x;
+ pOut.mat[6] = -f.y;
+ pOut.mat[10] = -f.z;
+
+ var translate = cc.math.Matrix4.createByTranslation(-pEye.x, -pEye.y, -pEye.z);
+ pOut.multiply(translate);
+ return pOut;
+};
+
+var tempMatrix = new cc.math.Matrix4(); // an internal matrix
+proto.lookAt = function(eyeVec, centerVec, upVec) {
+ var f = new cc.math.Vec3(centerVec), up = new cc.math.Vec3(upVec), mat = this.mat;
+ f.subtract(eyeVec);
+ f.normalize();
+ up.normalize();
+
+ var s = new cc.math.Vec3(f);
+ s.cross(up);
+ s.normalize();
+
+ var u = new cc.math.Vec3(s);
+ u.cross(f);
+ s.normalize();
+
+ this.identity();
+ mat[0] = s.x;
+ mat[4] = s.y;
+ mat[8] = s.z;
+
+ mat[1] = u.x;
+ mat[5] = u.y;
+ mat[9] = u.z;
+
+ mat[2] = -f.x;
+ mat[6] = -f.y;
+ mat[10] = -f.z;
+
+ tempMatrix = cc.math.Matrix4.createByTranslation(-eyeVec.x, -eyeVec.y, -eyeVec.z, tempMatrix);
+ this.multiply(tempMatrix);
+ return this;
+};
+
+/**
+ * Build a rotation matrix from an axis and an angle. Result is stored in pOut.
+ * pOut is returned.
+ */
+cc.math.mat4RotationAxisAngle = function (pOut, axis, radians) {
+ var rcos = Math.cos(radians), rsin = Math.sin(radians);
+
+ var normalizedAxis = new cc.math.Vec3(axis);
+ normalizedAxis.normalize();
+
+ pOut.mat[0] = rcos + normalizedAxis.x * normalizedAxis.x * (1 - rcos);
+ pOut.mat[1] = normalizedAxis.z * rsin + normalizedAxis.y * normalizedAxis.x * (1 - rcos);
+ pOut.mat[2] = -normalizedAxis.y * rsin + normalizedAxis.z * normalizedAxis.x * (1 - rcos);
+ pOut.mat[3] = 0.0;
+
+ pOut.mat[4] = -normalizedAxis.z * rsin + normalizedAxis.x * normalizedAxis.y * (1 - rcos);
+ pOut.mat[5] = rcos + normalizedAxis.y * normalizedAxis.y * (1 - rcos);
+ pOut.mat[6] = normalizedAxis.x * rsin + normalizedAxis.z * normalizedAxis.y * (1 - rcos);
+ pOut.mat[7] = 0.0;
+
+ pOut.mat[8] = normalizedAxis.y * rsin + normalizedAxis.x * normalizedAxis.z * (1 - rcos);
+ pOut.mat[9] = -normalizedAxis.x * rsin + normalizedAxis.y * normalizedAxis.z * (1 - rcos);
+ pOut.mat[10] = rcos + normalizedAxis.z * normalizedAxis.z * (1 - rcos);
+ pOut.mat[11] = 0.0;
+
+ pOut.mat[12] = 0.0;
+ pOut.mat[13] = 0.0;
+ pOut.mat[14] = 0.0;
+ pOut.mat[15] = 1.0;
+
+ return pOut;
+};
+
+/**
+ * Build a rotation matrix from an axis and an angle.
+ * @param {cc.math.Vec3} axis
+ * @param {Number} radians
+ * @param {cc.math.Matrix4} [matrix]
+ * @returns {cc.math.Matrix4}
+ */
+cc.math.Matrix4.createByAxisAndAngle = function(axis, radians, matrix) {
+ matrix = matrix || new cc.math.Matrix4();
+ var mat = this.mat, rcos = Math.cos(radians), rsin = Math.sin(radians) ;
+
+ var normalizedAxis = new cc.math.Vec3(axis);
+ normalizedAxis.normalize();
+
+ mat[0] = rcos + normalizedAxis.x * normalizedAxis.x * (1 - rcos);
+ mat[1] = normalizedAxis.z * rsin + normalizedAxis.y * normalizedAxis.x * (1 - rcos);
+ mat[2] = -normalizedAxis.y * rsin + normalizedAxis.z * normalizedAxis.x * (1 - rcos);
+ mat[3] = 0.0;
+
+ mat[4] = -normalizedAxis.z * rsin + normalizedAxis.x * normalizedAxis.y * (1 - rcos);
+ mat[5] = rcos + normalizedAxis.y * normalizedAxis.y * (1 - rcos);
+ mat[6] = normalizedAxis.x * rsin + normalizedAxis.z * normalizedAxis.y * (1 - rcos);
+ mat[7] = 0.0;
+
+ mat[8] = normalizedAxis.y * rsin + normalizedAxis.x * normalizedAxis.z * (1 - rcos);
+ mat[9] = -normalizedAxis.x * rsin + normalizedAxis.y * normalizedAxis.z * (1 - rcos);
+ mat[10] = rcos + normalizedAxis.z * normalizedAxis.z * (1 - rcos);
+ mat[11] = 0.0;
+
+ mat[12] = mat[13] = mat[14] = 0.0;
+ mat[15] = 1.0;
+ return matrix;
+};
+
+/**
+ * Extract a 3x3 rotation matrix from the input 4x4 transformation.
+ * @returns {cc.math.Matrix3}
+ */
+proto.extractRotation = function(){
+ var matrix = new cc.math.Matrix3(), mat4 = this.mat, mat3 = matrix.mat;
+ mat3[0] = mat4[0];
+ mat3[1] = mat4[1];
+ mat3[2] = mat4[2];
+
+ mat3[3] = mat4[4];
+ mat3[4] = mat4[5];
+ mat3[5] = mat4[6];
+
+ mat3[6] = mat4[8];
+ mat3[7] = mat4[9];
+ mat3[8] = mat4[10];
+ return matrix;
+};
+
+proto.extractPlane = function(planeType) {
+ var plane = new cc.math.Plane(), mat = this.mat;
+ switch (planeType) {
+ case cc.math.Plane.RIGHT:
+ plane.a = mat[3] - mat[0];
+ plane.b = mat[7] - mat[4];
+ plane.c = mat[11] - mat[8];
+ plane.d = mat[15] - mat[12];
+ break;
+ case cc.math.Plane.LEFT:
+ plane.a = mat[3] + mat[0];
+ plane.b = mat[7] + mat[4];
+ plane.c = mat[11] + mat[8];
+ plane.d = mat[15] + mat[12];
+ break;
+ case cc.math.Plane.BOTTOM:
+ plane.a = mat[3] + mat[1];
+ plane.b = mat[7] + mat[5];
+ plane.c = mat[11] + mat[9];
+ plane.d = mat[15] + mat[13];
+ break;
+ case cc.math.Plane.TOP:
+ plane.a = mat[3] - mat[1];
+ plane.b = mat[7] - mat[5];
+ plane.c = mat[11] - mat[9];
+ plane.d = mat[15] - mat[13];
+ break;
+ case cc.math.Plane.FAR:
+ plane.a = mat[3] - mat[2];
+ plane.b = mat[7] - mat[6];
+ plane.c = mat[11] - mat[10];
+ plane.d = mat[15] - mat[14];
+ break;
+ case cc.math.Plane.NEAR:
+ plane.a = mat[3] + mat[2];
+ plane.b = mat[7] + mat[6];
+ plane.c = mat[11] + mat[10];
+ plane.d = mat[15] + mat[14];
+ break;
+ default:
+ cc.log("cc.math.Matrix4.extractPlane: Invalid plane index");
+ break;
+ }
+
+ var t = Math.sqrt(plane.a * plane.a + plane.b * plane.b + plane.c * plane.c);
+ plane.a /= t;
+ plane.b /= t;
+ plane.c /= t;
+ plane.d /= t;
+ return plane;
+};
+
+/**
+ * Take the rotation from a 4x4 transformation matrix, and return it as an axis and an angle (in radians)
+ * @returns {*|{axis: cc.math.Vec3, angle: number}}
+ */
+proto.toAxisAndAngle = function() {
+ /*Surely not this easy?*/
+ var rotation = this.extractRotation();
+ var temp = cc.math.Quaternion.rotationMatrix(rotation);
+ return temp.toAxisAndAngle();
+};
diff --git a/cocos2d/kazmath/mat4SIMD.js b/cocos2d/kazmath/mat4SIMD.js
index f716de796b..7d04020e41 100644
--- a/cocos2d/kazmath/mat4SIMD.js
+++ b/cocos2d/kazmath/mat4SIMD.js
@@ -26,403 +26,399 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-(function(cc) {
- var proto = cc.math.Matrix4.prototype;
+var proto = cc.math.Matrix4.prototype;
- cc.kmMat4InverseSIMD = function (pOut, pM) {
- pOut = pM.inverseSIMD();
+cc.math.mat4InverseSIMD = function (pOut, pM) {
+ pOut = pM.inverseSIMD();
+ return pOut;
+};
+
+proto.inverseSIMD = function(){
+ var inv = new cc.math.Matrix4();
+ var src = this.mat;
+ var dest = inv.mat;
+ var src0, src1, src2, src3;
+ var row0, row1, row2, row3;
+ var tmp1;
+ var minor0, minor1, minor2, minor3;
+ var det;
+
+ // Load the 4 rows
+ var src0 = SIMD.float32x4.load(src, 0);
+ var src1 = SIMD.float32x4.load(src, 4);
+ var src2 = SIMD.float32x4.load(src, 8);
+ var src3 = SIMD.float32x4.load(src, 12);
+
+ // Transpose the source matrix. Sort of. Not a true transpose operation
+
+ tmp1 = SIMD.float32x4.shuffle(src0, src1, 0, 1, 4, 5);
+ row1 = SIMD.float32x4.shuffle(src2, src3, 0, 1, 4, 5);
+ row0 = SIMD.float32x4.shuffle(tmp1, row1, 0, 2, 4, 6);
+ row1 = SIMD.float32x4.shuffle(row1, tmp1, 1, 3, 5, 7);
+
+ tmp1 = SIMD.float32x4.shuffle(src0, src1, 2, 3, 6, 7);
+ row3 = SIMD.float32x4.shuffle(src2, src3, 2, 3, 6, 7);
+ row2 = SIMD.float32x4.shuffle(tmp1, row3, 0, 2, 4, 6);
+ row3 = SIMD.float32x4.shuffle(row3, tmp1, 1, 3, 5, 7);
+
+ // ----
+ tmp1 = SIMD.float32x4.mul(row2, row3);
+ tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001
+ minor0 = SIMD.float32x4.mul(row1, tmp1);
+ minor1 = SIMD.float32x4.mul(row0, tmp1);
+ tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110
+ minor0 = SIMD.float32x4.sub(SIMD.float32x4.mul(row1, tmp1), minor0);
+ minor1 = SIMD.float32x4.sub(SIMD.float32x4.mul(row0, tmp1), minor1);
+ minor1 = SIMD.float32x4.swizzle(minor1, 2, 3, 0, 1); // 0x4E = 01001110
+
+ // ----
+ tmp1 = SIMD.float32x4.mul(row1, row2);
+ tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001
+ minor0 = SIMD.float32x4.add(SIMD.float32x4.mul(row3, tmp1), minor0);
+ minor3 = SIMD.float32x4.mul(row0, tmp1);
+ tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110
+ minor0 = SIMD.float32x4.sub(minor0, SIMD.float32x4.mul(row3, tmp1));
+ minor3 = SIMD.float32x4.sub(SIMD.float32x4.mul(row0, tmp1), minor3);
+ minor3 = SIMD.float32x4.swizzle(minor3, 2, 3, 0, 1); // 0x4E = 01001110
+
+ // ----
+ tmp1 = SIMD.float32x4.mul(SIMD.float32x4.swizzle(row1, 2, 3, 0, 1), row3); // 0x4E = 01001110
+ tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001
+ row2 = SIMD.float32x4.swizzle(row2, 2, 3, 0, 1); // 0x4E = 01001110
+ minor0 = SIMD.float32x4.add(SIMD.float32x4.mul(row2, tmp1), minor0);
+ minor2 = SIMD.float32x4.mul(row0, tmp1);
+ tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110
+ minor0 = SIMD.float32x4.sub(minor0, SIMD.float32x4.mul(row2, tmp1));
+ minor2 = SIMD.float32x4.sub(SIMD.float32x4.mul(row0, tmp1), minor2);
+ minor2 = SIMD.float32x4.swizzle(minor2, 2, 3, 0, 1); // 0x4E = 01001110
+
+ // ----
+ tmp1 = SIMD.float32x4.mul(row0, row1);
+ tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001
+ minor2 = SIMD.float32x4.add(SIMD.float32x4.mul(row3, tmp1), minor2);
+ minor3 = SIMD.float32x4.sub(SIMD.float32x4.mul(row2, tmp1), minor3);
+ tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110
+ minor2 = SIMD.float32x4.sub(SIMD.float32x4.mul(row3, tmp1), minor2);
+ minor3 = SIMD.float32x4.sub(minor3, SIMD.float32x4.mul(row2, tmp1));
+
+ // ----
+ tmp1 = SIMD.float32x4.mul(row0, row3);
+ tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001
+ minor1 = SIMD.float32x4.sub(minor1, SIMD.float32x4.mul(row2, tmp1));
+ minor2 = SIMD.float32x4.add(SIMD.float32x4.mul(row1, tmp1), minor2);
+ tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110
+ minor1 = SIMD.float32x4.add(SIMD.float32x4.mul(row2, tmp1), minor1);
+ minor2 = SIMD.float32x4.sub(minor2, SIMD.float32x4.mul(row1, tmp1));
+
+ // ----
+ tmp1 = SIMD.float32x4.mul(row0, row2);
+ tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001
+ minor1 = SIMD.float32x4.add(SIMD.float32x4.mul(row3, tmp1), minor1);
+ minor3 = SIMD.float32x4.sub(minor3, SIMD.float32x4.mul(row1, tmp1));
+ tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110
+ minor1 = SIMD.float32x4.sub(minor1, SIMD.float32x4.mul(row3, tmp1));
+ minor3 = SIMD.float32x4.add(SIMD.float32x4.mul(row1, tmp1), minor3);
+
+ // Compute determinant
+ det = SIMD.float32x4.mul(row0, minor0);
+ det = SIMD.float32x4.add(SIMD.float32x4.swizzle(det, 2, 3, 0, 1), det); // 0x4E = 01001110
+ det = SIMD.float32x4.add(SIMD.float32x4.swizzle(det, 1, 0, 3, 2), det); // 0xB1 = 10110001
+ tmp1 = SIMD.float32x4.reciprocalApproximation(det);
+ det = SIMD.float32x4.sub(SIMD.float32x4.add(tmp1, tmp1), SIMD.float32x4.mul(det, SIMD.float32x4.mul(tmp1, tmp1)));
+ det = SIMD.float32x4.swizzle(det, 0, 0, 0, 0);
+
+ // Compute final values by multiplying with 1/det
+ minor0 = SIMD.float32x4.mul(det, minor0);
+ minor1 = SIMD.float32x4.mul(det, minor1);
+ minor2 = SIMD.float32x4.mul(det, minor2);
+ minor3 = SIMD.float32x4.mul(det, minor3);
+
+ SIMD.float32x4.store(dest, 0, minor0);
+ SIMD.float32x4.store(dest, 4, minor1);
+ SIMD.float32x4.store(dest, 8, minor2);
+ SIMD.float32x4.store(dest, 12, minor3);
+
+ return inv;
+};
+
+var identityMatrix = new cc.math.Matrix4().identity();
+proto.isIdentitySIMD = function () {
+ var inx4 = SIMD.float32x4.load(this.mat, 0);
+ var identityx4 = SIMD.float32x4.load(identityMatrix.mat, 0);
+ var ret = SIMD.float32x4.equal(inx4, identityx4);
+ if(ret.signMask === 0x00)
+ return false;
+
+ inx4 = SIMD.float32x4.load(this.mat, 4);
+ identityx4 = SIMD.float32x4.load(identityMatrix.mat, 4);
+ ret = SIMD.float32x4.equal(inx4, identityx4);
+ if(ret.signMask === 0x00)
+ return false;
+
+ inx4 = SIMD.float32x4.load(this.mat, 8);
+ identityx4 = SIMD.float32x4.load(identityMatrix.mat, 8);
+ ret = SIMD.float32x4.equal(inx4, identityx4);
+ if(ret.signMask === 0x00)
+ return false;
+
+ inx4 = SIMD.float32x4.load(this.mat, 12);
+ identityx4 = SIMD.float32x4.load(identityMatrix.mat, 12);
+ ret = SIMD.float32x4.equal(inx4, identityx4);
+ if(ret.signMask === 0x00)
+ return false;
+ return true;
+};
+
+proto.transposeSIMD = function () {
+ var outArr = this.mat, inArr = this.mat;
+ var src0 = SIMD.float32x4.load(inArr, 0);
+ var src1 = SIMD.float32x4.load(inArr, 4);
+ var src2 = SIMD.float32x4.load(inArr, 8);
+ var src3 = SIMD.float32x4.load(inArr, 12);
+ var dst0;
+ var dst1;
+ var dst2;
+ var dst3;
+ var tmp01;
+ var tmp23;
+
+ tmp01 = SIMD.float32x4.shuffle(src0, src1, 0, 1, 4, 5);
+ tmp23 = SIMD.float32x4.shuffle(src2, src3, 0, 1, 4, 5);
+ dst0 = SIMD.float32x4.shuffle(tmp01, tmp23, 0, 2, 4, 6);
+ dst1 = SIMD.float32x4.shuffle(tmp01, tmp23, 1, 3, 5, 7);
+
+ tmp01 = SIMD.float32x4.shuffle(src0, src1, 2, 3, 6, 7);
+ tmp23 = SIMD.float32x4.shuffle(src2, src3, 2, 3, 6, 7);
+ dst2 = SIMD.float32x4.shuffle(tmp01, tmp23, 0, 2, 4, 6);
+ dst3 = SIMD.float32x4.shuffle(tmp01, tmp23, 1, 3, 5, 7);
+
+ SIMD.float32x4.store(outArr, 0, dst0);
+ SIMD.float32x4.store(outArr, 4, dst1);
+ SIMD.float32x4.store(outArr, 8, dst2);
+ SIMD.float32x4.store(outArr, 12, dst3);
+ return this;
+};
+
+cc.math.mat4MultiplySIMD = function (pOut, pM1, pM2) {
+ pOut = new cc.math.Matrix4(pM1);
+ return pOut.multiplySIMD(pM2);
+};
+
+proto.multiplySIMD = function(mat4) {
+ var a = this.mat;
+ var b = mat4.mat;
+ var out = this.mat;
+
+ var a0 = SIMD.float32x4.load(a,0);
+ var a1 = SIMD.float32x4.load(a,4);
+ var a2 = SIMD.float32x4.load(a,8);
+ var a3 = SIMD.float32x4.load(a,12);
+ var b0 = SIMD.float32x4.load(b, 0);
+ SIMD.float32x4.store(out, 0, SIMD.float32x4.add(
+ SIMD.float32x4.mul(
+ SIMD.float32x4.swizzle(b0, 0, 0, 0, 0), a0),
+ SIMD.float32x4.add(
+ SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 1, 1, 1, 1), a1),
+ SIMD.float32x4.add(
+ SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 2, 2, 2, 2), a2),
+ SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 3, 3, 3, 3), a3)))));
+ var b1 = SIMD.float32x4.load(b, 4);
+ SIMD.float32x4.store(out, 4, SIMD.float32x4.add(
+ SIMD.float32x4.mul(
+ SIMD.float32x4.swizzle(b1, 0, 0, 0, 0), a0),
+ SIMD.float32x4.add(
+ SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 1, 1, 1, 1), a1),
+ SIMD.float32x4.add(
+ SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 2, 2, 2, 2), a2),
+ SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 3, 3, 3, 3), a3)))));
+ var b2 = SIMD.float32x4.load(b, 8);
+ SIMD.float32x4.store(out, 8, SIMD.float32x4.add(
+ SIMD.float32x4.mul(
+ SIMD.float32x4.swizzle(b2, 0, 0, 0, 0), a0),
+ SIMD.float32x4.add(
+ SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 1, 1, 1, 1), a1),
+ SIMD.float32x4.add(
+ SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 2, 2, 2, 2), a2),
+ SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 3, 3, 3, 3), a3)))));
+ var b3 = SIMD.float32x4.load(b, 12);
+ SIMD.float32x4.store(out, 12, SIMD.float32x4.add(
+ SIMD.float32x4.mul(
+ SIMD.float32x4.swizzle(b3, 0, 0, 0, 0), a0),
+ SIMD.float32x4.add(
+ SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 1, 1, 1, 1), a1),
+ SIMD.float32x4.add(
+ SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 2, 2, 2, 2), a2),
+ SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 3, 3, 3, 3), a3)))));
+
+ return this;
+};
+
+cc.math.getMat4MultiplyValueSIMD = function (pM1, pM2) {
+ var mat = new cc.math.Matrix4(pM1);
+ return mat.multiplySIMD(pM2);
+};
+
+cc.math.mat4AssignSIMD = function (pOut, pIn) {
+ if(pOut == pIn) {
+ cc.log("cc.math.mat4Assign(): pOut equals pIn");//TODO: ADD SIMD?
return pOut;
- };
+ }
- proto.inverseSIMD = function(){
- var inv = new cc.math.Matrix4();
- var src = this.mat;
- var dest = inv.mat;
- var src0, src1, src2, src3;
- var row0, row1, row2, row3;
- var tmp1;
- var minor0, minor1, minor2, minor3;
- var det;
+ return pOut.assignFromSIMD(pIn);
+};
- // Load the 4 rows
- var src0 = SIMD.float32x4.load(src, 0);
- var src1 = SIMD.float32x4.load(src, 4);
- var src2 = SIMD.float32x4.load(src, 8);
- var src3 = SIMD.float32x4.load(src, 12);
+proto.assignFromSIMD = function (mat4) {
+ if(this == mat4) {
+ cc.log("cc.mat.Matrix4.assignFrom(): mat4 equals current matrix");//TODO: ADD SIMD?
+ return this;
+ }
- // Transpose the source matrix. Sort of. Not a true transpose operation
+ var outArr = this.mat;
+ var inArr = mat4.mat;
- tmp1 = SIMD.float32x4.shuffle(src0, src1, 0, 1, 4, 5);
- row1 = SIMD.float32x4.shuffle(src2, src3, 0, 1, 4, 5);
- row0 = SIMD.float32x4.shuffle(tmp1, row1, 0, 2, 4, 6);
- row1 = SIMD.float32x4.shuffle(row1, tmp1, 1, 3, 5, 7);
+ SIMD.float32x4.store(outArr, 0, SIMD.float32x4.load(inArr, 0));
+ SIMD.float32x4.store(outArr, 4, SIMD.float32x4.load(inArr, 4));
+ SIMD.float32x4.store(outArr, 8, SIMD.float32x4.load(inArr, 8));
+ SIMD.float32x4.store(outArr, 12, SIMD.float32x4.load(inArr, 12));
- tmp1 = SIMD.float32x4.shuffle(src0, src1, 2, 3, 6, 7);
- row3 = SIMD.float32x4.shuffle(src2, src3, 2, 3, 6, 7);
- row2 = SIMD.float32x4.shuffle(tmp1, row3, 0, 2, 4, 6);
- row3 = SIMD.float32x4.shuffle(row3, tmp1, 1, 3, 5, 7);
+ return this;
+};
- // ----
- tmp1 = SIMD.float32x4.mul(row2, row3);
- tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001
- minor0 = SIMD.float32x4.mul(row1, tmp1);
- minor1 = SIMD.float32x4.mul(row0, tmp1);
- tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110
- minor0 = SIMD.float32x4.sub(SIMD.float32x4.mul(row1, tmp1), minor0);
- minor1 = SIMD.float32x4.sub(SIMD.float32x4.mul(row0, tmp1), minor1);
- minor1 = SIMD.float32x4.swizzle(minor1, 2, 3, 0, 1); // 0x4E = 01001110
-
- // ----
- tmp1 = SIMD.float32x4.mul(row1, row2);
- tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001
- minor0 = SIMD.float32x4.add(SIMD.float32x4.mul(row3, tmp1), minor0);
- minor3 = SIMD.float32x4.mul(row0, tmp1);
- tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110
- minor0 = SIMD.float32x4.sub(minor0, SIMD.float32x4.mul(row3, tmp1));
- minor3 = SIMD.float32x4.sub(SIMD.float32x4.mul(row0, tmp1), minor3);
- minor3 = SIMD.float32x4.swizzle(minor3, 2, 3, 0, 1); // 0x4E = 01001110
-
- // ----
- tmp1 = SIMD.float32x4.mul(SIMD.float32x4.swizzle(row1, 2, 3, 0, 1), row3); // 0x4E = 01001110
- tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001
- row2 = SIMD.float32x4.swizzle(row2, 2, 3, 0, 1); // 0x4E = 01001110
- minor0 = SIMD.float32x4.add(SIMD.float32x4.mul(row2, tmp1), minor0);
- minor2 = SIMD.float32x4.mul(row0, tmp1);
- tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110
- minor0 = SIMD.float32x4.sub(minor0, SIMD.float32x4.mul(row2, tmp1));
- minor2 = SIMD.float32x4.sub(SIMD.float32x4.mul(row0, tmp1), minor2);
- minor2 = SIMD.float32x4.swizzle(minor2, 2, 3, 0, 1); // 0x4E = 01001110
-
- // ----
- tmp1 = SIMD.float32x4.mul(row0, row1);
- tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001
- minor2 = SIMD.float32x4.add(SIMD.float32x4.mul(row3, tmp1), minor2);
- minor3 = SIMD.float32x4.sub(SIMD.float32x4.mul(row2, tmp1), minor3);
- tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110
- minor2 = SIMD.float32x4.sub(SIMD.float32x4.mul(row3, tmp1), minor2);
- minor3 = SIMD.float32x4.sub(minor3, SIMD.float32x4.mul(row2, tmp1));
-
- // ----
- tmp1 = SIMD.float32x4.mul(row0, row3);
- tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001
- minor1 = SIMD.float32x4.sub(minor1, SIMD.float32x4.mul(row2, tmp1));
- minor2 = SIMD.float32x4.add(SIMD.float32x4.mul(row1, tmp1), minor2);
- tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110
- minor1 = SIMD.float32x4.add(SIMD.float32x4.mul(row2, tmp1), minor1);
- minor2 = SIMD.float32x4.sub(minor2, SIMD.float32x4.mul(row1, tmp1));
-
- // ----
- tmp1 = SIMD.float32x4.mul(row0, row2);
- tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001
- minor1 = SIMD.float32x4.add(SIMD.float32x4.mul(row3, tmp1), minor1);
- minor3 = SIMD.float32x4.sub(minor3, SIMD.float32x4.mul(row1, tmp1));
- tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110
- minor1 = SIMD.float32x4.sub(minor1, SIMD.float32x4.mul(row3, tmp1));
- minor3 = SIMD.float32x4.add(SIMD.float32x4.mul(row1, tmp1), minor3);
-
- // Compute determinant
- det = SIMD.float32x4.mul(row0, minor0);
- det = SIMD.float32x4.add(SIMD.float32x4.swizzle(det, 2, 3, 0, 1), det); // 0x4E = 01001110
- det = SIMD.float32x4.add(SIMD.float32x4.swizzle(det, 1, 0, 3, 2), det); // 0xB1 = 10110001
- tmp1 = SIMD.float32x4.reciprocalApproximation(det);
- det = SIMD.float32x4.sub(SIMD.float32x4.add(tmp1, tmp1), SIMD.float32x4.mul(det, SIMD.float32x4.mul(tmp1, tmp1)));
- det = SIMD.float32x4.swizzle(det, 0, 0, 0, 0);
-
- // Compute final values by multiplying with 1/det
- minor0 = SIMD.float32x4.mul(det, minor0);
- minor1 = SIMD.float32x4.mul(det, minor1);
- minor2 = SIMD.float32x4.mul(det, minor2);
- minor3 = SIMD.float32x4.mul(det, minor3);
-
- SIMD.float32x4.store(dest, 0, minor0);
- SIMD.float32x4.store(dest, 4, minor1);
- SIMD.float32x4.store(dest, 8, minor2);
- SIMD.float32x4.store(dest, 12, minor3);
-
- return inv;
- };
-
- var identityMatrix = new cc.math.Matrix4().identity();
- proto.isIdentitySIMD = function () {
- var inx4 = SIMD.float32x4.load(this.mat, 0);
- var identityx4 = SIMD.float32x4.load(identityMatrix.mat, 0);
- var ret = SIMD.float32x4.equal(inx4, identityx4);
- if(ret.signMask === 0x00)
- return false;
-
- inx4 = SIMD.float32x4.load(this.mat, 4);
- identityx4 = SIMD.float32x4.load(identityMatrix.mat, 4);
- ret = SIMD.float32x4.equal(inx4, identityx4);
- if(ret.signMask === 0x00)
- return false;
-
- inx4 = SIMD.float32x4.load(this.mat, 8);
- identityx4 = SIMD.float32x4.load(identityMatrix.mat, 8);
- ret = SIMD.float32x4.equal(inx4, identityx4);
- if(ret.signMask === 0x00)
- return false;
-
- inx4 = SIMD.float32x4.load(this.mat, 12);
- identityx4 = SIMD.float32x4.load(identityMatrix.mat, 12);
- ret = SIMD.float32x4.equal(inx4, identityx4);
- if(ret.signMask === 0x00)
- return false;
+proto.equalsSIMD = function (mat4) {
+ if(this === mat4){
+ cc.log("cc.math.Matrix4 equals: pMat1 and pMat2 are same object.");
return true;
- };
+ }
+ var m10 = SIMD.float32x4.load(this.mat, 0);
+ var m20 = SIMD.float32x4.load(mat4.mat, 0);
- proto.transposeSIMD = function () {
- var outArr = this.mat, inArr = this.mat;
- var src0 = SIMD.float32x4.load(inArr, 0);
- var src1 = SIMD.float32x4.load(inArr, 4);
- var src2 = SIMD.float32x4.load(inArr, 8);
- var src3 = SIMD.float32x4.load(inArr, 12);
- var dst0;
- var dst1;
- var dst2;
- var dst3;
- var tmp01;
- var tmp23;
+ var epsilon = SIMD.float32x4.splat(cc.math.EPSILON);
- tmp01 = SIMD.float32x4.shuffle(src0, src1, 0, 1, 4, 5);
- tmp23 = SIMD.float32x4.shuffle(src2, src3, 0, 1, 4, 5);
- dst0 = SIMD.float32x4.shuffle(tmp01, tmp23, 0, 2, 4, 6);
- dst1 = SIMD.float32x4.shuffle(tmp01, tmp23, 1, 3, 5, 7);
+ var ret = SIMD.float32x4.lessThanOrEqual(SIMD.float32x4.abs(SIMD.float32x4.sub(m10, m20)), epsilon);
+ if (ret.signMask === 0)
+ return false;
- tmp01 = SIMD.float32x4.shuffle(src0, src1, 2, 3, 6, 7);
- tmp23 = SIMD.float32x4.shuffle(src2, src3, 2, 3, 6, 7);
- dst2 = SIMD.float32x4.shuffle(tmp01, tmp23, 0, 2, 4, 6);
- dst3 = SIMD.float32x4.shuffle(tmp01, tmp23, 1, 3, 5, 7);
+ var m11 = SIMD.float32x4.load(this.mat, 4);
+ var m21 = SIMD.float32x4.load(mat4.mat, 4);
+ ret = SIMD.float32x4.lessThanOrEqual(SIMD.float32x4.abs(SIMD.float32x4.sub(m11, m21)), epsilon);
+ if (ret.signMask === 0)
+ return false;
- SIMD.float32x4.store(outArr, 0, dst0);
- SIMD.float32x4.store(outArr, 4, dst1);
- SIMD.float32x4.store(outArr, 8, dst2);
- SIMD.float32x4.store(outArr, 12, dst3);
- return this;
- };
+ var m12 = SIMD.float32x4.load(this.mat, 8);
+ var m22 = SIMD.float32x4.load(mat4.mat, 8);
+ ret = SIMD.float32x4.lessThanOrEqual(SIMD.float32x4.abs(SIMD.float32x4.sub(m12, m22)), epsilon);
+ if (ret.signMask === 0)
+ return false;
- cc.kmMat4MultiplySIMD = function (pOut, pM1, pM2) {
- pOut = new cc.math.Matrix4(pM1);
- return pOut.multiplySIMD(pM2);
- };
+ var m13 = SIMD.float32x4.load(this.mat, 12);
+ var m23 = SIMD.float32x4.load(mat4.mat, 12);
+ ret = SIMD.float32x4.lessThanOrEqual(SIMD.float32x4.abs(SIMD.float32x4.sub(m13, m23)), epsilon);
+ if (ret.signMask === 0)
+ return false;
+ return true;
+};
- proto.multiplySIMD = function(mat4) {
- var a = this.mat;
- var b = mat4.mat;
- var out = this.mat;
+cc.math.mat4LookAtSIMD = function (pOut, pEye, pCenter, pUp) {
+ return pOut.lookAtSIMD(pEye, pCenter, pUp);
+};
- var a0 = SIMD.float32x4.load(a,0);
- var a1 = SIMD.float32x4.load(a,4);
- var a2 = SIMD.float32x4.load(a,8);
- var a3 = SIMD.float32x4.load(a,12);
- var b0 = SIMD.float32x4.load(b, 0);
- SIMD.float32x4.store(out, 0, SIMD.float32x4.add(
- SIMD.float32x4.mul(
- SIMD.float32x4.swizzle(b0, 0, 0, 0, 0), a0),
+proto.lookAtSIMD = function(eyeVec, centerVec, upVec) {
+ var out = this.mat;
+
+ var center = SIMD.float32x4(centerVec.x, centerVec.y, centerVec.z, 0.0);
+ var eye = SIMD.float32x4(eyeVec.x, eyeVec.y, eyeVec.z, 0.0);
+ var up = SIMD.float32x4(upVec.x, upVec.y, upVec.z, 0.0);
+
+ // cc.math.Vec3Subtract(f, pCenter, pEye);
+ var f = SIMD.float32x4.sub(center, eye);
+ // cc.math.Vec3Normalize(f, f);
+ var tmp = SIMD.float32x4.mul(f, f);
+ tmp = SIMD.float32x4.add(tmp, SIMD.float32x4.add(SIMD.float32x4.swizzle(tmp, 1, 2, 0, 3), SIMD.float32x4.swizzle(tmp, 2, 0, 1, 3)));
+ f = SIMD.float32x4.mul(f, SIMD.float32x4.reciprocalSqrtApproximation(tmp));
+
+ // cc.math.Vec3Assign(up, pUp);
+ // cc.math.Vec3Normalize(up, up);
+ tmp = SIMD.float32x4.mul(up, up);
+ tmp = SIMD.float32x4.add(tmp, SIMD.float32x4.add(SIMD.float32x4.swizzle(tmp, 1, 2, 0, 3), SIMD.float32x4.swizzle(tmp, 2, 0, 1, 3)));
+ up = SIMD.float32x4.mul(up, SIMD.float32x4.reciprocalSqrtApproximation(tmp));
+
+ // cc.math.Vec3Cross(s, f, up);
+ var s = SIMD.float32x4.sub(SIMD.float32x4.mul(SIMD.float32x4.swizzle(f, 1, 2, 0, 3), SIMD.float32x4.swizzle(up, 2, 0, 1, 3)),
+ SIMD.float32x4.mul(SIMD.float32x4.swizzle(f, 2, 0, 1, 3), SIMD.float32x4.swizzle(up, 1, 2, 0, 3)));
+ // cc.math.Vec3Normalize(s, s);
+ tmp = SIMD.float32x4.mul(s, s);
+ tmp = SIMD.float32x4.add(tmp, SIMD.float32x4.add(SIMD.float32x4.swizzle(tmp, 1, 2, 0, 3), SIMD.float32x4.swizzle(tmp, 2, 0, 1, 3)));
+ s = SIMD.float32x4.mul(s, SIMD.float32x4.reciprocalSqrtApproximation(tmp));
+
+ // cc.math.Vec3Cross(u, s, f);
+ var u = SIMD.float32x4.sub(SIMD.float32x4.mul(SIMD.float32x4.swizzle(s, 1, 2, 0, 3), SIMD.float32x4.swizzle(f, 2, 0, 1, 3)),
+ SIMD.float32x4.mul(SIMD.float32x4.swizzle(s, 2, 0, 1, 3), SIMD.float32x4.swizzle(f, 1, 2, 0, 3)));
+ // cc.math.Vec3Normalize(s, s);
+ tmp = SIMD.float32x4.mul(s, s);
+ tmp = SIMD.float32x4.add(tmp, SIMD.float32x4.add(SIMD.float32x4.swizzle(tmp, 1, 2, 0, 3), SIMD.float32x4.swizzle(tmp, 2, 0, 1, 3)));
+ s = SIMD.float32x4.mul(s, SIMD.float32x4.reciprocalSqrtApproximation(tmp));
+
+ //cc.math.mat4Identity(pOut);
+ //pOut.mat[0] = s.x;
+ //pOut.mat[4] = s.y;
+ //pOut.mat[8] = s.z;
+ //pOut.mat[1] = u.x;
+ //pOut.mat[5] = u.y;
+ //pOut.mat[9] = u.z;
+ //pOut.mat[2] = -f.x;
+ //pOut.mat[6] = -f.y;
+ //pOut.mat[10] = -f.z;
+ var zero = SIMD.float32x4.splat(0.0);
+ f = SIMD.float32x4.neg(f);
+ var tmp01 = SIMD.float32x4.shuffle(s, u, 0, 1, 4, 5);
+ var tmp23 = SIMD.float32x4.shuffle(f, zero, 0, 1, 4, 5);
+ var a0 = SIMD.float32x4.shuffle(tmp01, tmp23, 0, 2, 4, 6);
+ var a1 = SIMD.float32x4.shuffle(tmp01, tmp23, 1, 3, 5, 7);
+
+ var tmp01 = SIMD.float32x4.shuffle(s, u, 2, 3, 6, 7);
+ var tmp23 = SIMD.float32x4.shuffle(f, zero, 2, 3, 6, 7);
+ var a2 = SIMD.float32x4.shuffle(tmp01, tmp23, 0, 2, 4, 6);
+ var a3 = SIMD.float32x4(0.0, 0.0, 0.0, 1.0);
+
+ // cc.math.mat4Translation(translate, -pEye.x, -pEye.y, -pEye.z);
+ var b0 = SIMD.float32x4(1.0, 0.0, 0.0, 0.0);
+ var b1 = SIMD.float32x4(0.0, 1.0, 0.0, 0.0);
+ var b2 = SIMD.float32x4(0.0, 0.0, 1.0, 0.0);
+ var b3 = SIMD.float32x4.neg(eye);
+ b3 = SIMD.float32x4.withW(b3, 1.0);
+
+ // cc.math.mat4Multiply(pOut, pOut, translate);
+ SIMD.float32x4.store(out, 0, SIMD.float32x4.add(
+ SIMD.float32x4.mul(
+ SIMD.float32x4.swizzle(b0, 0, 0, 0, 0), a0),
+ SIMD.float32x4.add(
+ SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 1, 1, 1, 1), a1),
+ SIMD.float32x4.add(
+ SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 2, 2, 2, 2), a2),
+ SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 3, 3, 3, 3), a3)))));
+ SIMD.float32x4.store(out, 4, SIMD.float32x4.add(
+ SIMD.float32x4.mul(
+ SIMD.float32x4.swizzle(b1, 0, 0, 0, 0), a0),
+ SIMD.float32x4.add(
+ SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 1, 1, 1, 1), a1),
SIMD.float32x4.add(
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 1, 1, 1, 1), a1),
- SIMD.float32x4.add(
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 2, 2, 2, 2), a2),
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 3, 3, 3, 3), a3)))));
- var b1 = SIMD.float32x4.load(b, 4);
- SIMD.float32x4.store(out, 4, SIMD.float32x4.add(
- SIMD.float32x4.mul(
- SIMD.float32x4.swizzle(b1, 0, 0, 0, 0), a0),
+ SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 2, 2, 2, 2), a2),
+ SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 3, 3, 3, 3), a3)))));
+ SIMD.float32x4.store(out, 8, SIMD.float32x4.add(
+ SIMD.float32x4.mul(
+ SIMD.float32x4.swizzle(b2, 0, 0, 0, 0), a0),
+ SIMD.float32x4.add(
+ SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 1, 1, 1, 1), a1),
SIMD.float32x4.add(
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 1, 1, 1, 1), a1),
- SIMD.float32x4.add(
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 2, 2, 2, 2), a2),
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 3, 3, 3, 3), a3)))));
- var b2 = SIMD.float32x4.load(b, 8);
- SIMD.float32x4.store(out, 8, SIMD.float32x4.add(
- SIMD.float32x4.mul(
- SIMD.float32x4.swizzle(b2, 0, 0, 0, 0), a0),
+ SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 2, 2, 2, 2), a2),
+ SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 3, 3, 3, 3), a3)))));
+ SIMD.float32x4.store(out, 12, SIMD.float32x4.add(
+ SIMD.float32x4.mul(
+ SIMD.float32x4.swizzle(b3, 0, 0, 0, 0), a0),
+ SIMD.float32x4.add(
+ SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 1, 1, 1, 1), a1),
SIMD.float32x4.add(
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 1, 1, 1, 1), a1),
- SIMD.float32x4.add(
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 2, 2, 2, 2), a2),
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 3, 3, 3, 3), a3)))));
- var b3 = SIMD.float32x4.load(b, 12);
- SIMD.float32x4.store(out, 12, SIMD.float32x4.add(
- SIMD.float32x4.mul(
- SIMD.float32x4.swizzle(b3, 0, 0, 0, 0), a0),
- SIMD.float32x4.add(
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 1, 1, 1, 1), a1),
- SIMD.float32x4.add(
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 2, 2, 2, 2), a2),
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 3, 3, 3, 3), a3)))));
-
- return this;
- };
-
- cc.getMat4MultiplyValueSIMD = function (pM1, pM2) {
- var mat = new cc.math.Matrix4(pM1);
- return mat.multiplySIMD(pM2);
- };
-
- cc.kmMat4AssignSIMD = function (pOut, pIn) {
- if(pOut == pIn) {
- cc.log("cc.kmMat4Assign(): pOut equals pIn");//TODO: ADD SIMD?
- return pOut;
- }
-
- return pOut.assignFromSIMD(pIn);
- };
-
- proto.assignFromSIMD = function (mat4) {
- if(this == mat4) {
- cc.log("cc.mat.Matrix4.assignFrom(): mat4 equals current matrix");//TODO: ADD SIMD?
- return this;
- }
-
- var outArr = this.mat;
- var inArr = mat4.mat;
-
- SIMD.float32x4.store(outArr, 0, SIMD.float32x4.load(inArr, 0));
- SIMD.float32x4.store(outArr, 4, SIMD.float32x4.load(inArr, 4));
- SIMD.float32x4.store(outArr, 8, SIMD.float32x4.load(inArr, 8));
- SIMD.float32x4.store(outArr, 12, SIMD.float32x4.load(inArr, 12));
-
- return this;
- };
-
- proto.equalsSIMD = function (mat4) {
- if(this === mat4){
- cc.log("cc.kmMat4AreEqual(): pMat1 and pMat2 are same object.");
- return true;
- }
- var m10 = SIMD.float32x4.load(this.mat, 0);
- var m20 = SIMD.float32x4.load(mat4.mat, 0);
-
- var epsilon = SIMD.float32x4.splat(cc.math.EPSILON);
-
- var ret = SIMD.float32x4.lessThanOrEqual(SIMD.float32x4.abs(SIMD.float32x4.sub(m10, m20)), epsilon);
- if (ret.signMask === 0)
- return false;
-
- var m11 = SIMD.float32x4.load(this.mat, 4);
- var m21 = SIMD.float32x4.load(mat4.mat, 4);
- ret = SIMD.float32x4.lessThanOrEqual(SIMD.float32x4.abs(SIMD.float32x4.sub(m11, m21)), epsilon);
- if (ret.signMask === 0)
- return false;
-
- var m12 = SIMD.float32x4.load(this.mat, 8);
- var m22 = SIMD.float32x4.load(mat4.mat, 8);
- ret = SIMD.float32x4.lessThanOrEqual(SIMD.float32x4.abs(SIMD.float32x4.sub(m12, m22)), epsilon);
- if (ret.signMask === 0)
- return false;
-
- var m13 = SIMD.float32x4.load(this.mat, 12);
- var m23 = SIMD.float32x4.load(mat4.mat, 12);
- ret = SIMD.float32x4.lessThanOrEqual(SIMD.float32x4.abs(SIMD.float32x4.sub(m13, m23)), epsilon);
- if (ret.signMask === 0)
- return false;
- return true;
- };
-
- cc.kmMat4LookAtSIMD = function (pOut, pEye, pCenter, pUp) {
- return pOut.lookAtSIMD(pEye, pCenter, pUp);
- };
-
- proto.lookAtSIMD = function(eyeVec, centerVec, upVec) {
- var out = this.mat;
-
- var center = SIMD.float32x4(centerVec.x, centerVec.y, centerVec.z, 0.0);
- var eye = SIMD.float32x4(eyeVec.x, eyeVec.y, eyeVec.z, 0.0);
- var up = SIMD.float32x4(upVec.x, upVec.y, upVec.z, 0.0);
-
- // cc.kmVec3Subtract(f, pCenter, pEye);
- var f = SIMD.float32x4.sub(center, eye);
- // cc.kmVec3Normalize(f, f);
- var tmp = SIMD.float32x4.mul(f, f);
- tmp = SIMD.float32x4.add(tmp, SIMD.float32x4.add(SIMD.float32x4.swizzle(tmp, 1, 2, 0, 3), SIMD.float32x4.swizzle(tmp, 2, 0, 1, 3)));
- f = SIMD.float32x4.mul(f, SIMD.float32x4.reciprocalSqrtApproximation(tmp));
-
- // cc.kmVec3Assign(up, pUp);
- // cc.kmVec3Normalize(up, up);
- tmp = SIMD.float32x4.mul(up, up);
- tmp = SIMD.float32x4.add(tmp, SIMD.float32x4.add(SIMD.float32x4.swizzle(tmp, 1, 2, 0, 3), SIMD.float32x4.swizzle(tmp, 2, 0, 1, 3)));
- up = SIMD.float32x4.mul(up, SIMD.float32x4.reciprocalSqrtApproximation(tmp));
-
- // cc.kmVec3Cross(s, f, up);
- var s = SIMD.float32x4.sub(SIMD.float32x4.mul(SIMD.float32x4.swizzle(f, 1, 2, 0, 3), SIMD.float32x4.swizzle(up, 2, 0, 1, 3)),
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(f, 2, 0, 1, 3), SIMD.float32x4.swizzle(up, 1, 2, 0, 3)));
- // cc.kmVec3Normalize(s, s);
- tmp = SIMD.float32x4.mul(s, s);
- tmp = SIMD.float32x4.add(tmp, SIMD.float32x4.add(SIMD.float32x4.swizzle(tmp, 1, 2, 0, 3), SIMD.float32x4.swizzle(tmp, 2, 0, 1, 3)));
- s = SIMD.float32x4.mul(s, SIMD.float32x4.reciprocalSqrtApproximation(tmp));
-
- // cc.kmVec3Cross(u, s, f);
- var u = SIMD.float32x4.sub(SIMD.float32x4.mul(SIMD.float32x4.swizzle(s, 1, 2, 0, 3), SIMD.float32x4.swizzle(f, 2, 0, 1, 3)),
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(s, 2, 0, 1, 3), SIMD.float32x4.swizzle(f, 1, 2, 0, 3)));
- // cc.kmVec3Normalize(s, s);
- tmp = SIMD.float32x4.mul(s, s);
- tmp = SIMD.float32x4.add(tmp, SIMD.float32x4.add(SIMD.float32x4.swizzle(tmp, 1, 2, 0, 3), SIMD.float32x4.swizzle(tmp, 2, 0, 1, 3)));
- s = SIMD.float32x4.mul(s, SIMD.float32x4.reciprocalSqrtApproximation(tmp));
-
- //cc.kmMat4Identity(pOut);
- //pOut.mat[0] = s.x;
- //pOut.mat[4] = s.y;
- //pOut.mat[8] = s.z;
- //pOut.mat[1] = u.x;
- //pOut.mat[5] = u.y;
- //pOut.mat[9] = u.z;
- //pOut.mat[2] = -f.x;
- //pOut.mat[6] = -f.y;
- //pOut.mat[10] = -f.z;
- var zero = SIMD.float32x4.splat(0.0);
- f = SIMD.float32x4.neg(f);
- var tmp01 = SIMD.float32x4.shuffle(s, u, 0, 1, 4, 5);
- var tmp23 = SIMD.float32x4.shuffle(f, zero, 0, 1, 4, 5);
- var a0 = SIMD.float32x4.shuffle(tmp01, tmp23, 0, 2, 4, 6);
- var a1 = SIMD.float32x4.shuffle(tmp01, tmp23, 1, 3, 5, 7);
-
- var tmp01 = SIMD.float32x4.shuffle(s, u, 2, 3, 6, 7);
- var tmp23 = SIMD.float32x4.shuffle(f, zero, 2, 3, 6, 7);
- var a2 = SIMD.float32x4.shuffle(tmp01, tmp23, 0, 2, 4, 6);
- var a3 = SIMD.float32x4(0.0, 0.0, 0.0, 1.0);
-
- // cc.kmMat4Translation(translate, -pEye.x, -pEye.y, -pEye.z);
- var b0 = SIMD.float32x4(1.0, 0.0, 0.0, 0.0);
- var b1 = SIMD.float32x4(0.0, 1.0, 0.0, 0.0);
- var b2 = SIMD.float32x4(0.0, 0.0, 1.0, 0.0);
- var b3 = SIMD.float32x4.neg(eye);
- b3 = SIMD.float32x4.withW(b3, 1.0);
-
- // cc.kmMat4Multiply(pOut, pOut, translate);
- SIMD.float32x4.store(out, 0, SIMD.float32x4.add(
- SIMD.float32x4.mul(
- SIMD.float32x4.swizzle(b0, 0, 0, 0, 0), a0),
- SIMD.float32x4.add(
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 1, 1, 1, 1), a1),
- SIMD.float32x4.add(
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 2, 2, 2, 2), a2),
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 3, 3, 3, 3), a3)))));
- SIMD.float32x4.store(out, 4, SIMD.float32x4.add(
- SIMD.float32x4.mul(
- SIMD.float32x4.swizzle(b1, 0, 0, 0, 0), a0),
- SIMD.float32x4.add(
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 1, 1, 1, 1), a1),
- SIMD.float32x4.add(
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 2, 2, 2, 2), a2),
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 3, 3, 3, 3), a3)))));
- SIMD.float32x4.store(out, 8, SIMD.float32x4.add(
- SIMD.float32x4.mul(
- SIMD.float32x4.swizzle(b2, 0, 0, 0, 0), a0),
- SIMD.float32x4.add(
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 1, 1, 1, 1), a1),
- SIMD.float32x4.add(
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 2, 2, 2, 2), a2),
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 3, 3, 3, 3), a3)))));
- SIMD.float32x4.store(out, 12, SIMD.float32x4.add(
- SIMD.float32x4.mul(
- SIMD.float32x4.swizzle(b3, 0, 0, 0, 0), a0),
- SIMD.float32x4.add(
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 1, 1, 1, 1), a1),
- SIMD.float32x4.add(
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 2, 2, 2, 2), a2),
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 3, 3, 3, 3), a3)))));
- return this;
- };
-
-
-})(cc);
+ SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 2, 2, 2, 2), a2),
+ SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 3, 3, 3, 3), a3)))));
+ return this;
+};
diff --git a/cocos2d/kazmath/plane.js b/cocos2d/kazmath/plane.js
index 94ab4e9b71..852b5ff6d8 100644
--- a/cocos2d/kazmath/plane.js
+++ b/cocos2d/kazmath/plane.js
@@ -26,112 +26,103 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-/**
- * @ignore
- */
-(function(cc){
- cc.math.Plane = function (a, b, c, d) {
- if (a && b === undefined) {
- this.a = a.a;
- this.b = a.b;
- this.c = a.c;
- this.d = a.d;
- } else {
- this.a = a || 0;
- this.b = b || 0;
- this.c = c || 0;
- this.d = d || 0;
- }
- };
- cc.kmPlane = cc.math.Plane;
- var proto = cc.math.Plane.prototype;
+cc.math.Plane = function (a, b, c, d) {
+ if (a && b === undefined) {
+ this.a = a.a;
+ this.b = a.b;
+ this.c = a.c;
+ this.d = a.d;
+ } else {
+ this.a = a || 0;
+ this.b = b || 0;
+ this.c = c || 0;
+ this.d = d || 0;
+ }
+};
+var proto = cc.math.Plane.prototype;
- cc.math.Plane.LEFT = 0;
+cc.math.Plane.LEFT = 0;
- cc.math.Plane.RIGHT = 1;
+cc.math.Plane.RIGHT = 1;
- cc.math.Plane.BOTTOM = 2;
+cc.math.Plane.BOTTOM = 2;
- cc.math.Plane.TOP = 3;
+cc.math.Plane.TOP = 3;
- cc.math.Plane.NEAR = 4;
+cc.math.Plane.NEAR = 4;
- cc.math.Plane.FAR = 5;
+cc.math.Plane.FAR = 5;
- cc.math.Plane.POINT_INFRONT_OF_PLANE = 0;
+cc.math.Plane.POINT_INFRONT_OF_PLANE = 0;
- cc.math.Plane.POINT_BEHIND_PLANE = 1;
+cc.math.Plane.POINT_BEHIND_PLANE = 1;
- cc.math.Plane.POINT_ON_PLANE = 2;
+cc.math.Plane.POINT_ON_PLANE = 2;
- proto.dot = function(vec4){ //cc.kmPlaneDot
- return (this.a * vec4.x + this.b * vec4.y + this.c * vec4.z + this.d * vec4.w);
- };
+proto.dot = function(vec4){ //cc.kmPlaneDot
+ return (this.a * vec4.x + this.b * vec4.y + this.c * vec4.z + this.d * vec4.w);
+};
- proto.dotCoord = function(vec3) { //=cc.kmPlaneDotCoord
- return (this.a * vec3.x + this.b * vec3.y + this.c * vec3.z + this.d);
- };
+proto.dotCoord = function(vec3) { //=cc.kmPlaneDotCoord
+ return (this.a * vec3.x + this.b * vec3.y + this.c * vec3.z + this.d);
+};
- proto.dotNormal = function(vec3) { //=cc.kmPlaneDotNormal
- return (this.a * vec3.x + this.b * vec3.y + this.c * vec3.z);
- };
+proto.dotNormal = function(vec3) { //=cc.kmPlaneDotNormal
+ return (this.a * vec3.x + this.b * vec3.y + this.c * vec3.z);
+};
- cc.math.Plane.fromPointNormal = function(vec3, normal) { //cc.kmPlaneFromPointNormal
- /*
- Planea = Nx
- Planeb = Ny
- Planec = Nz
- Planed = −N⋅P
- */
- return new cc.math.Plane(normal.x, normal.y, normal.z, -normal.dot(vec3));
- };
+cc.math.Plane.fromPointNormal = function(vec3, normal) { //cc.kmPlaneFromPointNormal
+ /*
+ Planea = Nx
+ Planeb = Ny
+ Planec = Nz
+ Planed = −N⋅P
+ */
+ return new cc.math.Plane(normal.x, normal.y, normal.z, -normal.dot(vec3));
+};
- cc.math.Plane.fromPoints = function(vec1, vec2, vec3) { //cc.kmPlaneFromPoints
- /*
- v = (B − A) × (C − A)
- n = 1⁄|v| v
- Outa = nx
- Outb = ny
- Outc = nz
- Outd = −n⋅A
- */
- var v1 = new cc.math.Vec3(vec2), v2 = new cc.math.Vec3(vec3), plane = new cc.math.Plane();
- v1.subtract(vec1); //Create the vectors for the 2 sides of the triangle
- v2.subtract(vec1);
- v1.cross(v2); // Use the cross product to get the normal
- v1.normalize(); //Normalize it and assign to pOut.m_N
+cc.math.Plane.fromPoints = function(vec1, vec2, vec3) { //cc.kmPlaneFromPoints
+ /*
+ v = (B − A) × (C − A)
+ n = 1⁄|v| v
+ Outa = nx
+ Outb = ny
+ Outc = nz
+ Outd = −n⋅A
+ */
+ var v1 = new cc.math.Vec3(vec2), v2 = new cc.math.Vec3(vec3), plane = new cc.math.Plane();
+ v1.subtract(vec1); //Create the vectors for the 2 sides of the triangle
+ v2.subtract(vec1);
+ v1.cross(v2); // Use the cross product to get the normal
+ v1.normalize(); //Normalize it and assign to pOut.m_N
- plane.a = v1.x;
- plane.b = v1.y;
- plane.c = v1.z;
- plane.d = v1.scale(-1.0).dot(vec1);
- return plane;
- };
-
- proto.normalize = function(){ //cc.kmPlaneNormalize
- var n = new cc.math.Vec3(this.a, this.b, this.c), l = 1.0 / n.length(); //Get 1/length
- n.normalize(); //Normalize the vector and assign to pOut
- this.a = n.x;
- this.b = n.y;
- this.c = n.z;
- this.d = this.d * l; //Scale the D value and assign to pOut
- return this;
- };
-
- proto.classifyPoint = function(vec3) {
- // This function will determine if a point is on, in front of, or behind
- // the plane. First we store the dot product of the plane and the point.
- var distance = this.a * vec3.x + this.b * vec3.y + this.c * vec3.z + this.d;
-
- // Simply put if the dot product is greater than 0 then it is infront of it.
- // If it is less than 0 then it is behind it. And if it is 0 then it is on it.
- if(distance > 0.001)
- return cc.math.Plane.POINT_INFRONT_OF_PLANE;
- if(distance < -0.001)
- return cc.math.Plane.POINT_BEHIND_PLANE;
- return cc.math.Plane.POINT_ON_PLANE;
- };
-})(cc);
+ plane.a = v1.x;
+ plane.b = v1.y;
+ plane.c = v1.z;
+ plane.d = v1.scale(-1.0).dot(vec1);
+ return plane;
+};
+proto.normalize = function(){ //cc.kmPlaneNormalize
+ var n = new cc.math.Vec3(this.a, this.b, this.c), l = 1.0 / n.length(); //Get 1/length
+ n.normalize(); //Normalize the vector and assign to pOut
+ this.a = n.x;
+ this.b = n.y;
+ this.c = n.z;
+ this.d = this.d * l; //Scale the D value and assign to pOut
+ return this;
+};
+proto.classifyPoint = function(vec3) {
+ // This function will determine if a point is on, in front of, or behind
+ // the plane. First we store the dot product of the plane and the point.
+ var distance = this.a * vec3.x + this.b * vec3.y + this.c * vec3.z + this.d;
+ // Simply put if the dot product is greater than 0 then it is infront of it.
+ // If it is less than 0 then it is behind it. And if it is 0 then it is on it.
+ if(distance > 0.001)
+ return cc.math.Plane.POINT_INFRONT_OF_PLANE;
+ if(distance < -0.001)
+ return cc.math.Plane.POINT_BEHIND_PLANE;
+ return cc.math.Plane.POINT_ON_PLANE;
+};
diff --git a/cocos2d/kazmath/quaternion.js b/cocos2d/kazmath/quaternion.js
index fcbd652da9..ebead45e44 100644
--- a/cocos2d/kazmath/quaternion.js
+++ b/cocos2d/kazmath/quaternion.js
@@ -26,434 +26,418 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-(function(cc) {
- /**
- * The Quaternion class
- * @param {Number|cc.math.Quaternion} [x=0]
- * @param {Number} [y=0]
- * @param {Number} [z=0]
- * @param {Number} [w=0]
- * @constructor
- */
- cc.math.Quaternion = function (x, y, z, w) {
- if (x && y === undefined) {
- this.x = x.x;
- this.y = x.y;
- this.z = x.z;
- this.w = x.w;
- } else {
- this.x = x || 0;
- this.y = y || 0;
- this.z = z || 0;
- this.w = w || 0;
- }
- };
- cc.kmQuaternion = cc.math.Quaternion;
- var proto = cc.math.Quaternion.prototype;
+/**
+ * The Quaternion class
+ * @param {Number|cc.math.Quaternion} [x=0]
+ * @param {Number} [y=0]
+ * @param {Number} [z=0]
+ * @param {Number} [w=0]
+ * @constructor
+ */
+cc.math.Quaternion = function (x, y, z, w) {
+ if (x && y === undefined) {
+ this.x = x.x;
+ this.y = x.y;
+ this.z = x.z;
+ this.w = x.w;
+ } else {
+ this.x = x || 0;
+ this.y = y || 0;
+ this.z = z || 0;
+ this.w = w || 0;
+ }
+};
+var proto = cc.math.Quaternion.prototype;
- /**
- * Sets the conjugate of quaternion to self
- * @param {cc.math.Quaternion} quaternion
- */
- proto.conjugate = function (quaternion) { //= cc.kmQuaternionConjugate
- this.x = -quaternion.x;
- this.y = -quaternion.y;
- this.z = -quaternion.z;
- this.w = quaternion.w;
- return this;
- };
+/**
+ * Sets the conjugate of quaternion to self
+ * @param {cc.math.Quaternion} quaternion
+ */
+proto.conjugate = function (quaternion) { //= cc.kmQuaternionConjugate
+ this.x = -quaternion.x;
+ this.y = -quaternion.y;
+ this.z = -quaternion.z;
+ this.w = quaternion.w;
+ return this;
+};
- /**
- * Returns the dot product of the current quaternion and parameter quaternion
- * @param quaternion
- * @returns {number}
- */
- proto.dot = function(quaternion) { // = cc.kmQuaternionDot
- // A dot B = B dot A = AtBt + AxBx + AyBy + AzBz
- return (this.w * quaternion.w + this.x * quaternion.x + this.y * quaternion.y + this.z * quaternion.z);
- };
+/**
+ * Returns the dot product of the current quaternion and parameter quaternion
+ * @param quaternion
+ * @returns {number}
+ */
+proto.dot = function(quaternion) { // = cc.kmQuaternionDot
+ // A dot B = B dot A = AtBt + AxBx + AyBy + AzBz
+ return (this.w * quaternion.w + this.x * quaternion.x + this.y * quaternion.y + this.z * quaternion.z);
+};
- /**
- * Returns the exponential of the quaternion, this function doesn't implemented.
- * @returns {cc.math.Quaternion}
- */
- proto.exponential = function(){ //=cc.kmQuaternionExp
- return this;
- };
+/**
+ * Returns the exponential of the quaternion, this function doesn't implemented.
+ * @returns {cc.math.Quaternion}
+ */
+proto.exponential = function(){ //=cc.kmQuaternionExp
+ return this;
+};
- /**
- * Makes the current quaternion an identity quaternion
- */
- proto.identity = function(){ //=cc.kmQuaternionIdentity
+/**
+ * Makes the current quaternion an identity quaternion
+ */
+proto.identity = function(){ //=cc.kmQuaternionIdentity
+ this.x = 0.0;
+ this.y = 0.0;
+ this.z = 0.0;
+ this.w = 1.0;
+ return this;
+};
+
+/**
+ * Inverses the value of current Quaternion
+ */
+proto.inverse = function(){ //=cc.kmQuaternionInverse
+ var len = this.length();
+ if (Math.abs(len) > cc.math.EPSILON) {
this.x = 0.0;
this.y = 0.0;
this.z = 0.0;
- this.w = 1.0;
+ this.w = 0.0;
return this;
- };
+ }
- /**
- * Inverses the value of current Quaternion
- */
- proto.inverse = function(){ //=cc.kmQuaternionInverse
- var len = this.length();
- if (Math.abs(len) > cc.math.EPSILON) {
- this.x = 0.0;
- this.y = 0.0;
- this.z = 0.0;
- this.w = 0.0;
- return this;
- }
+ ///Get the conjugute and divide by the length
+ this.conjugate(this).scale(1.0 / len);
+ return this;
+};
- ///Get the conjugute and divide by the length
- this.conjugate(this).scale(1.0 / len);
- return this;
- };
+/**
+ * Returns true if the quaternion is an identity quaternion
+ * @returns {boolean}
+ */
+proto.isIdentity = function(){ //=cc.kmQuaternionIsIdentity
+ return (this.x === 0.0 && this.y === 0.0 && this.z === 0.0 && this.w === 1.0);
+};
- /**
- * Returns true if the quaternion is an identity quaternion
- * @returns {boolean}
- */
- proto.isIdentity = function(){ //=cc.kmQuaternionIsIdentity
- return (this.x === 0.0 && this.y === 0.0 && this.z === 0.0 && this.w === 1.0);
- };
+/**
+ * Returns the length of the quaternion
+ * @returns {number}
+ */
+proto.length = function() { //=cc.kmQuaternionLength
+ return Math.sqrt(this.lengthSq());
+};
- /**
- * Returns the length of the quaternion
- * @returns {number}
- */
- proto.length = function() { //=cc.kmQuaternionLength
- return Math.sqrt(this.lengthSq());
- };
+/**
+ * Returns the length of the quaternion squared (prevents a sqrt)
+ * @returns {number}
+ */
+proto.lengthSq = function() { //=cc.kmQuaternionLengthSq
+ return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
+};
- /**
- * Returns the length of the quaternion squared (prevents a sqrt)
- * @returns {number}
- */
- proto.lengthSq = function() { //=cc.kmQuaternionLengthSq
- return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
- };
+/**
+ * Uses current quaternion multiplies other quaternion.
+ * @param {cc.math.Quaternion} quaternion
+ * @returns {cc.math.Quaternion}
+ */
+proto.multiply = function(quaternion) { //cc.kmQuaternionMultiply
+ var x = this.x, y = this.y, z = this.z, w = this.w;
+ this.w = w * quaternion.w - x * quaternion.x - y * quaternion.y - z * quaternion.z;
+ this.x = w * quaternion.x + x * quaternion.w + y * quaternion.z - z * quaternion.y;
+ this.y = w * quaternion.y + y * quaternion.w + z * quaternion.x - x * quaternion.z;
+ this.z = w * quaternion.z + z * quaternion.w + x * quaternion.y - y * quaternion.x;
+ return this;
+};
- /**
- * Uses current quaternion multiplies other quaternion.
- * @param {cc.math.Quaternion} quaternion
- * @returns {cc.math.Quaternion}
- */
- proto.multiply = function(quaternion) { //cc.kmQuaternionMultiply
- var x = this.x, y = this.y, z = this.z, w = this.w;
- this.w = w * quaternion.w - x * quaternion.x - y * quaternion.y - z * quaternion.z;
- this.x = w * quaternion.x + x * quaternion.w + y * quaternion.z - z * quaternion.y;
- this.y = w * quaternion.y + y * quaternion.w + z * quaternion.x - x * quaternion.z;
- this.z = w * quaternion.z + z * quaternion.w + x * quaternion.y - y * quaternion.x;
- return this;
- };
+/**
+ * Normalizes a quaternion
+ * @returns {cc.math.Quaternion}
+ */
+proto.normalize = function(){ //=cc.kmQuaternionNormalize
+ var length = this.length();
+ if (Math.abs(length) <= cc.math.EPSILON)
+ throw new Error("current quaternion is an invalid value");
+ this.scale(1.0 / length);
+ return this;
+};
- /**
- * Normalizes a quaternion
- * @returns {cc.math.Quaternion}
- */
- proto.normalize = function(){ //=cc.kmQuaternionNormalize
- var length = this.length();
- if (Math.abs(length) <= cc.math.EPSILON)
- throw new Error("current quaternion is an invalid value");
- this.scale(1.0 / length);
- return this;
- };
+/**
+ * Rotates a quaternion around an axis and an angle
+ * @param {cc.math.Vec3} axis
+ * @param {Number} angle
+ */
+proto.rotationAxis = function(axis, angle){ //cc.kmQuaternionRotationAxis
+ var rad = angle * 0.5, scale = Math.sin(rad);
+ this.w = Math.cos(rad);
+ this.x = axis.x * scale;
+ this.y = axis.y * scale;
+ this.z = axis.z * scale;
+ return this;
+};
- /**
- * Rotates a quaternion around an axis and an angle
- * @param {cc.math.Vec3} axis
- * @param {Number} angle
- */
- proto.rotationAxis = function(axis, angle){ //cc.kmQuaternionRotationAxis
- var rad = angle * 0.5, scale = Math.sin(rad);
- this.w = Math.cos(rad);
- this.x = axis.x * scale;
- this.y = axis.y * scale;
- this.z = axis.z * scale;
- return this;
- };
+/**
+ * Creates a quaternion from a rotation matrix
+ * @param mat3
+ * @returns {*}
+ */
+cc.math.Quaternion.rotationMatrix = function (mat3) { //cc.kmQuaternionRotationMatrix
+ if (!mat3)
+ return null;
- /**
- * Creates a quaternion from a rotation matrix
- * @param mat3
- * @returns {*}
- */
- cc.math.Quaternion.rotationMatrix = function (mat3) { //cc.kmQuaternionRotationMatrix
- if (!mat3)
- return null;
+ var x, y, z, w;
+ var m4x4 = [], mat = mat3.mat, scale = 0.0;
- var x, y, z, w;
- var m4x4 = [], mat = mat3.mat, scale = 0.0;
+ /* 0 3 6
+ 1 4 7
+ 2 5 8
- /* 0 3 6
- 1 4 7
- 2 5 8
+ 0 1 2 3
+ 4 5 6 7
+ 8 9 10 11
+ 12 13 14 15*/
+ m4x4[0] = mat[0];
+ m4x4[1] = mat[3];
+ m4x4[2] = mat[6];
+ m4x4[4] = mat[1];
+ m4x4[5] = mat[4];
+ m4x4[6] = mat[7];
+ m4x4[8] = mat[2];
+ m4x4[9] = mat[5];
+ m4x4[10] = mat[8];
+ m4x4[15] = 1;
+ var pMatrix = m4x4[0];
- 0 1 2 3
- 4 5 6 7
- 8 9 10 11
- 12 13 14 15*/
- m4x4[0] = mat[0];
- m4x4[1] = mat[3];
- m4x4[2] = mat[6];
- m4x4[4] = mat[1];
- m4x4[5] = mat[4];
- m4x4[6] = mat[7];
- m4x4[8] = mat[2];
- m4x4[9] = mat[5];
- m4x4[10] = mat[8];
- m4x4[15] = 1;
- var pMatrix = m4x4[0];
+ var diagonal = pMatrix[0] + pMatrix[5] + pMatrix[10] + 1;
+ if (diagonal > cc.math.EPSILON) {
+ // Calculate the scale of the diagonal
+ scale = Math.sqrt(diagonal) * 2;
- var diagonal = pMatrix[0] + pMatrix[5] + pMatrix[10] + 1;
- if (diagonal > cc.math.EPSILON) {
- // Calculate the scale of the diagonal
- scale = Math.sqrt(diagonal) * 2;
+ // Calculate the x, y, x and w of the quaternion through the respective equation
+ x = ( pMatrix[9] - pMatrix[6] ) / scale;
+ y = ( pMatrix[2] - pMatrix[8] ) / scale;
+ z = ( pMatrix[4] - pMatrix[1] ) / scale;
+ w = 0.25 * scale;
+ } else {
+ // If the first element of the diagonal is the greatest value
+ if (pMatrix[0] > pMatrix[5] && pMatrix[0] > pMatrix[10]) {
+ // Find the scale according to the first element, and double that value
+ scale = Math.sqrt(1.0 + pMatrix[0] - pMatrix[5] - pMatrix[10]) * 2.0;
// Calculate the x, y, x and w of the quaternion through the respective equation
- x = ( pMatrix[9] - pMatrix[6] ) / scale;
- y = ( pMatrix[2] - pMatrix[8] ) / scale;
- z = ( pMatrix[4] - pMatrix[1] ) / scale;
- w = 0.25 * scale;
+ x = 0.25 * scale;
+ y = (pMatrix[4] + pMatrix[1] ) / scale;
+ z = (pMatrix[2] + pMatrix[8] ) / scale;
+ w = (pMatrix[9] - pMatrix[6] ) / scale;
+ }
+ // Else if the second element of the diagonal is the greatest value
+ else if (pMatrix[5] > pMatrix[10]) {
+ // Find the scale according to the second element, and double that value
+ scale = Math.sqrt(1.0 + pMatrix[5] - pMatrix[0] - pMatrix[10]) * 2.0;
+
+ // Calculate the x, y, x and w of the quaternion through the respective equation
+ x = (pMatrix[4] + pMatrix[1] ) / scale;
+ y = 0.25 * scale;
+ z = (pMatrix[9] + pMatrix[6] ) / scale;
+ w = (pMatrix[2] - pMatrix[8] ) / scale;
} else {
- // If the first element of the diagonal is the greatest value
- if (pMatrix[0] > pMatrix[5] && pMatrix[0] > pMatrix[10]) {
- // Find the scale according to the first element, and double that value
- scale = Math.sqrt(1.0 + pMatrix[0] - pMatrix[5] - pMatrix[10]) * 2.0;
+ // Else the third element of the diagonal is the greatest value
- // Calculate the x, y, x and w of the quaternion through the respective equation
- x = 0.25 * scale;
- y = (pMatrix[4] + pMatrix[1] ) / scale;
- z = (pMatrix[2] + pMatrix[8] ) / scale;
- w = (pMatrix[9] - pMatrix[6] ) / scale;
- }
- // Else if the second element of the diagonal is the greatest value
- else if (pMatrix[5] > pMatrix[10]) {
- // Find the scale according to the second element, and double that value
- scale = Math.sqrt(1.0 + pMatrix[5] - pMatrix[0] - pMatrix[10]) * 2.0;
+ // Find the scale according to the third element, and double that value
+ scale = Math.sqrt(1.0 + pMatrix[10] - pMatrix[0] - pMatrix[5]) * 2.0;
- // Calculate the x, y, x and w of the quaternion through the respective equation
- x = (pMatrix[4] + pMatrix[1] ) / scale;
- y = 0.25 * scale;
- z = (pMatrix[9] + pMatrix[6] ) / scale;
- w = (pMatrix[2] - pMatrix[8] ) / scale;
- } else {
- // Else the third element of the diagonal is the greatest value
-
- // Find the scale according to the third element, and double that value
- scale = Math.sqrt(1.0 + pMatrix[10] - pMatrix[0] - pMatrix[5]) * 2.0;
-
- // Calculate the x, y, x and w of the quaternion through the respective equation
- x = (pMatrix[2] + pMatrix[8] ) / scale;
- y = (pMatrix[9] + pMatrix[6] ) / scale;
- z = 0.25 * scale;
- w = (pMatrix[4] - pMatrix[1] ) / scale;
- }
+ // Calculate the x, y, x and w of the quaternion through the respective equation
+ x = (pMatrix[2] + pMatrix[8] ) / scale;
+ y = (pMatrix[9] + pMatrix[6] ) / scale;
+ z = 0.25 * scale;
+ w = (pMatrix[4] - pMatrix[1] ) / scale;
}
- return new cc.math.Quaternion(x, y, z, w);
- };
+ }
+ return new cc.math.Quaternion(x, y, z, w);
+};
- /**
- * Create a quaternion from yaw, pitch and roll
- * @param yaw
- * @param pitch
- * @param roll
- * @returns {cc.math.Quaternion}
- */
- cc.math.Quaternion.rotationYawPitchRoll = function (yaw, pitch, roll) { //cc.kmQuaternionRotationYawPitchRoll
- var ex, ey, ez; // temp half euler angles
- var cr, cp, cy, sr, sp, sy, cpcy, spsy; // temp vars in roll,pitch yaw
+/**
+ * Create a quaternion from yaw, pitch and roll
+ * @param yaw
+ * @param pitch
+ * @param roll
+ * @returns {cc.math.Quaternion}
+ */
+cc.math.Quaternion.rotationYawPitchRoll = function (yaw, pitch, roll) { //cc.kmQuaternionRotationYawPitchRoll
+ var ex, ey, ez; // temp half euler angles
+ var cr, cp, cy, sr, sp, sy, cpcy, spsy; // temp vars in roll,pitch yaw
- ex = cc.degreesToRadians(pitch) / 2.0; // convert to rads and half them
- ey = cc.degreesToRadians(yaw) / 2.0;
- ez = cc.degreesToRadians(roll) / 2.0;
+ ex = cc.degreesToRadians(pitch) / 2.0; // convert to rads and half them
+ ey = cc.degreesToRadians(yaw) / 2.0;
+ ez = cc.degreesToRadians(roll) / 2.0;
- cr = Math.cos(ex);
- cp = Math.cos(ey);
- cy = Math.cos(ez);
+ cr = Math.cos(ex);
+ cp = Math.cos(ey);
+ cy = Math.cos(ez);
- sr = Math.sin(ex);
- sp = Math.sin(ey);
- sy = Math.sin(ez);
+ sr = Math.sin(ex);
+ sp = Math.sin(ey);
+ sy = Math.sin(ez);
- cpcy = cp * cy;
- spsy = sp * sy;
+ cpcy = cp * cy;
+ spsy = sp * sy;
- var ret = new cc.math.Quaternion();
- ret.w = cr * cpcy + sr * spsy;
- ret.x = sr * cpcy - cr * spsy;
- ret.y = cr * sp * cy + sr * cp * sy;
- ret.z = cr * cp * sy - sr * sp * cy;
- ret.normalize();
- return ret;
- };
+ var ret = new cc.math.Quaternion();
+ ret.w = cr * cpcy + sr * spsy;
+ ret.x = sr * cpcy - cr * spsy;
+ ret.y = cr * sp * cy + sr * cp * sy;
+ ret.z = cr * cp * sy - sr * sp * cy;
+ ret.normalize();
+ return ret;
+};
- /**
- * Interpolate with other quaternions
- * @param {cc.math.Quaternion} quaternion
- * @param {Number} t
- * @returns {cc.math.Quaternion}
- */
- proto.slerp = function(quaternion, t) { //=cc.kmQuaternionSlerp
- if (this.x === quaternion.x && this.y === quaternion.y && this.z === quaternion.z && this.w === quaternion.w) {
- return this;
- }
- var ct = this.dot(quaternion), theta = Math.acos(ct), st = Math.sqrt(1.0 - cc.math.square(ct));
- var stt = Math.sin(t * theta) / st, somt = Math.sin((1.0 - t) * theta) / st;
- var temp2 = new cc.math.Quaternion(quaternion);
- this.scale(somt);
- temp2.scale(stt);
- this.add(temp2);
+/**
+ * Interpolate with other quaternions
+ * @param {cc.math.Quaternion} quaternion
+ * @param {Number} t
+ * @returns {cc.math.Quaternion}
+ */
+proto.slerp = function(quaternion, t) { //=cc.kmQuaternionSlerp
+ if (this.x === quaternion.x && this.y === quaternion.y && this.z === quaternion.z && this.w === quaternion.w) {
return this;
- };
+ }
+ var ct = this.dot(quaternion), theta = Math.acos(ct), st = Math.sqrt(1.0 - cc.math.square(ct));
+ var stt = Math.sin(t * theta) / st, somt = Math.sin((1.0 - t) * theta) / st;
+ var temp2 = new cc.math.Quaternion(quaternion);
+ this.scale(somt);
+ temp2.scale(stt);
+ this.add(temp2);
+ return this;
+};
- /**
- * Get the axis and angle of rotation from a quaternion
- * @returns {{axis: cc.math.Vec3, angle: number}}
- */
- proto.toAxisAndAngle = function(){ //=cc.kmQuaternionToAxisAngle
- var tempAngle; // temp angle
- var scale; // temp vars
- var retAngle, retAxis = new cc.math.Vec3();
+/**
+ * Get the axis and angle of rotation from a quaternion
+ * @returns {{axis: cc.math.Vec3, angle: number}}
+ */
+proto.toAxisAndAngle = function(){ //=cc.kmQuaternionToAxisAngle
+ var tempAngle; // temp angle
+ var scale; // temp vars
+ var retAngle, retAxis = new cc.math.Vec3();
- tempAngle = Math.acos(this.w);
- scale = Math.sqrt(cc.math.square(this.x) + cc.math.square(this.y) + cc.math.square(this.z));
+ tempAngle = Math.acos(this.w);
+ scale = Math.sqrt(cc.math.square(this.x) + cc.math.square(this.y) + cc.math.square(this.z));
- if (((scale > -cc.math.EPSILON) && scale < cc.math.EPSILON)
- || (scale < 2 * Math.PI + cc.math.EPSILON && scale > 2 * Math.PI - cc.math.EPSILON)) { // angle is 0 or 360 so just simply set axis to 0,0,1 with angle 0
- retAngle = 0.0;
- retAxis.x = 0.0;
- retAxis.y = 0.0;
- retAxis.z = 1.0;
- } else {
- retAngle = tempAngle * 2.0; // angle in radians
- retAxis.x = this.x / scale;
- retAxis.y = this.y / scale;
- retAxis.z = this.z / scale;
- retAxis.normalize();
- }
- return {axis: retAxis, angle: retAngle};
- };
+ if (((scale > -cc.math.EPSILON) && scale < cc.math.EPSILON)
+ || (scale < 2 * Math.PI + cc.math.EPSILON && scale > 2 * Math.PI - cc.math.EPSILON)) { // angle is 0 or 360 so just simply set axis to 0,0,1 with angle 0
+ retAngle = 0.0;
+ retAxis.x = 0.0;
+ retAxis.y = 0.0;
+ retAxis.z = 1.0;
+ } else {
+ retAngle = tempAngle * 2.0; // angle in radians
+ retAxis.x = this.x / scale;
+ retAxis.y = this.y / scale;
+ retAxis.z = this.z / scale;
+ retAxis.normalize();
+ }
+ return {axis: retAxis, angle: retAngle};
+};
- /**
- * Scale a quaternion
- * @param {Number} scale
- */
- proto.scale = function(scale) { //cc.kmQuaternionScale
- this.x *= scale;
- this.y *= scale;
- this.z *= scale;
- this.w *= scale;
- return this;
- };
+/**
+ * Scale a quaternion
+ * @param {Number} scale
+ */
+proto.scale = function(scale) { //cc.kmQuaternionScale
+ this.x *= scale;
+ this.y *= scale;
+ this.z *= scale;
+ this.w *= scale;
+ return this;
+};
- /**
- * Assign current quaternion value from a quaternion.
- * @param {cc.math.Quaternion} quaternion
- * @returns {cc.math.Quaternion} current quaternion
- */
- proto.assignFrom = function(quaternion){ //=cc.kmQuaternionAssign
- this.x = quaternion.x;
- this.y = quaternion.y;
- this.z = quaternion.z;
- this.w = quaternion.w;
- return this;
- };
+/**
+ * Assign current quaternion value from a quaternion.
+ * @param {cc.math.Quaternion} quaternion
+ * @returns {cc.math.Quaternion} current quaternion
+ */
+proto.assignFrom = function(quaternion){ //=cc.kmQuaternionAssign
+ this.x = quaternion.x;
+ this.y = quaternion.y;
+ this.z = quaternion.z;
+ this.w = quaternion.w;
+ return this;
+};
- /**
- * Adds other quaternion
- * @param {cc.math.Quaternion} quaternion
- * @returns {cc.math.Quaternion}
- */
- proto.add = function(quaternion) { //cc.kmQuaternionAdd
- this.x += quaternion.x;
- this.y += quaternion.y;
- this.z += quaternion.z;
- this.w += quaternion.w;
- return this;
- };
+/**
+ * Adds other quaternion
+ * @param {cc.math.Quaternion} quaternion
+ * @returns {cc.math.Quaternion}
+ */
+proto.add = function(quaternion) { //cc.kmQuaternionAdd
+ this.x += quaternion.x;
+ this.y += quaternion.y;
+ this.z += quaternion.z;
+ this.w += quaternion.w;
+ return this;
+};
- /**
- *
- * Adapted from the OGRE engine!
- * Gets the shortest arc quaternion to rotate this vector to the destination vector.
- * @remarks
- * If you call this with a destination vector that is close to the inverse
- * of this vector, we will rotate 180 degrees around the 'fallbackAxis'
- * (if specified, or a generated axis if not) since in this case ANY axis of rotation is valid.
- *
- * @param {cc.math.Vec3} vec1
- * @param {cc.math.Vec3} vec2
- * @param {cc.math.Vec3} fallback
- * @returns {cc.math.Quaternion}
- */
- cc.math.Quaternion.rotationBetweenVec3 = function(vec1, vec2, fallback) { //cc.kmQuaternionRotationBetweenVec3
- var v1 = new cc.math.Vec3(vec1), v2 = new cc.math.Vec3(vec2);
- v1.normalize();
- v2.normalize();
- var a = v1.dot(v2), quaternion = new cc.math.Quaternion();
+/**
+ *
+ * Adapted from the OGRE engine!
+ * Gets the shortest arc quaternion to rotate this vector to the destination vector.
+ * @remarks
+ * If you call this with a destination vector that is close to the inverse
+ * of this vector, we will rotate 180 degrees around the 'fallbackAxis'
+ * (if specified, or a generated axis if not) since in this case ANY axis of rotation is valid.
+ *
+ * @param {cc.math.Vec3} vec1
+ * @param {cc.math.Vec3} vec2
+ * @param {cc.math.Vec3} fallback
+ * @returns {cc.math.Quaternion}
+ */
+cc.math.Quaternion.rotationBetweenVec3 = function(vec1, vec2, fallback) { //cc.kmQuaternionRotationBetweenVec3
+ var v1 = new cc.math.Vec3(vec1), v2 = new cc.math.Vec3(vec2);
+ v1.normalize();
+ v2.normalize();
+ var a = v1.dot(v2), quaternion = new cc.math.Quaternion();
- if (a >= 1.0) {
- quaternion.identity();
- return quaternion;
- }
-
- if (a < (1e-6 - 1.0)) {
- if (Math.abs(fallback.lengthSq()) < cc.math.EPSILON) {
- quaternion.rotationAxis(fallback, Math.PI);
- } else {
- var axis = new cc.math.Vec3(1.0, 0.0, 0.0);
- axis.cross(vec1);
-
- //If axis is zero
- if (Math.abs(axis.lengthSq()) < cc.math.EPSILON) {
- axis.fill(0.0, 1.0, 0.0);
- axis.cross(vec1);
- }
- axis.normalize();
- quaternion.rotationAxis(axis, Math.PI);
- }
- } else {
- var s = Math.sqrt((1 + a) * 2), invs = 1 / s;
- v1.cross(v2);
- quaternion.x = v1.x * invs;
- quaternion.y = v1.y * invs;
- quaternion.z = v1.z * invs;
- quaternion.w = s * 0.5;
- quaternion.normalize();
- }
+ if (a >= 1.0) {
+ quaternion.identity();
return quaternion;
- };
-
- /**
- * Current quaternion multiplies a vec3
- * @param {cc.math.Vec3} vec
- * @returns {cc.math.Vec3}
- */
- proto.multiplyVec3 = function(vec){ //=cc.kmQuaternionMultiplyVec3
- var x = this.x, y = this.y, z = this.z, retVec = new cc.math.Vec3(vec);
- var uv = new cc.math.Vec3(x, y, z), uuv = new cc.math.Vec3(x, y, z);
- uv.cross(vec);
- uuv.cross(uv);
- uv.scale((2.0 * q.w));
- uuv.scale(2.0);
-
- retVec.add(uv);
- retVec.add(uuv);
- return retVec;
- };
-})(cc);
-
-
-
-
-
-
-
-
-
+ }
+ if (a < (1e-6 - 1.0)) {
+ if (Math.abs(fallback.lengthSq()) < cc.math.EPSILON) {
+ quaternion.rotationAxis(fallback, Math.PI);
+ } else {
+ var axis = new cc.math.Vec3(1.0, 0.0, 0.0);
+ axis.cross(vec1);
+ //If axis is zero
+ if (Math.abs(axis.lengthSq()) < cc.math.EPSILON) {
+ axis.fill(0.0, 1.0, 0.0);
+ axis.cross(vec1);
+ }
+ axis.normalize();
+ quaternion.rotationAxis(axis, Math.PI);
+ }
+ } else {
+ var s = Math.sqrt((1 + a) * 2), invs = 1 / s;
+ v1.cross(v2);
+ quaternion.x = v1.x * invs;
+ quaternion.y = v1.y * invs;
+ quaternion.z = v1.z * invs;
+ quaternion.w = s * 0.5;
+ quaternion.normalize();
+ }
+ return quaternion;
+};
+/**
+ * Current quaternion multiplies a vec3
+ * @param {cc.math.Vec3} vec
+ * @returns {cc.math.Vec3}
+ */
+proto.multiplyVec3 = function(vec){ //=cc.kmQuaternionMultiplyVec3
+ var x = this.x, y = this.y, z = this.z, retVec = new cc.math.Vec3(vec);
+ var uv = new cc.math.Vec3(x, y, z), uuv = new cc.math.Vec3(x, y, z);
+ uv.cross(vec);
+ uuv.cross(uv);
+ uv.scale((2.0 * q.w));
+ uuv.scale(2.0);
+ retVec.add(uv);
+ retVec.add(uuv);
+ return retVec;
+};
diff --git a/cocos2d/kazmath/ray2.js b/cocos2d/kazmath/ray2.js
index 5a29794e88..1c39326214 100644
--- a/cocos2d/kazmath/ray2.js
+++ b/cocos2d/kazmath/ray2.js
@@ -26,115 +26,113 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-(function(cc){
- cc.math.Ray2 = function (start, dir) { // = cc.kmRay2
- this.start = start || new cc.math.Vec2();
- this.dir = dir || new cc.math.Vec2();
- };
+cc.math.Ray2 = function (start, dir) { // = cc.kmRay2
+ this.start = start || new cc.math.Vec2();
+ this.dir = dir || new cc.math.Vec2();
+};
- cc.math.Ray2.prototype.fill = function (px, py, vx, vy) { // = cc.kmRay2Fill
- this.start.x = px;
- this.start.y = py;
- this.dir.x = vx;
- this.dir.y = vy;
- };
+cc.math.Ray2.prototype.fill = function (px, py, vx, vy) { // = cc.kmRay2Fill
+ this.start.x = px;
+ this.start.y = py;
+ this.dir.x = vx;
+ this.dir.y = vy;
+};
- cc.math.Ray2.prototype.intersectLineSegment = function (p1, p2, intersection) { // = cc.kmRay2IntersectLineSegment
- var x1 = this.start.x, y1 = this.start.y;
- var x2 = this.start.x + this.dir.x, y2 = this.start.y + this.dir.y;
- var x3 = p1.x, y3 = p1.y;
- var x4 = p2.x, y4 = p2.y;
+cc.math.Ray2.prototype.intersectLineSegment = function (p1, p2, intersection) { // = cc.kmRay2IntersectLineSegment
+ var x1 = this.start.x, y1 = this.start.y;
+ var x2 = this.start.x + this.dir.x, y2 = this.start.y + this.dir.y;
+ var x3 = p1.x, y3 = p1.y;
+ var x4 = p2.x, y4 = p2.y;
- var denom = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
- var ua, x, y;
- //If denom is zero, the lines are parallel
- if (denom > -cc.math.EPSILON && denom < cc.math.EPSILON)
- return false;
+ var denom = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
+ var ua, x, y;
+ //If denom is zero, the lines are parallel
+ if (denom > -cc.math.EPSILON && denom < cc.math.EPSILON)
+ return false;
- ua = ((x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3)) / denom;
- //var ub = ((x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3)) / denom;
+ ua = ((x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3)) / denom;
+ //var ub = ((x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3)) / denom;
- x = x1 + ua * (x2 - x1);
- y = y1 + ua * (y2 - y1);
+ x = x1 + ua * (x2 - x1);
+ y = y1 + ua * (y2 - y1);
- if (x < Math.min(p1.x, p2.x) - cc.math.EPSILON ||
- x > Math.max(p1.x, p2.x) + cc.math.EPSILON ||
- y < Math.min(p1.y, p2.y) - cc.math.EPSILON ||
- y > Math.max(p1.y, p2.y) + cc.math.EPSILON) {
- //Outside of line
- //printf("Outside of line, %f %f (%f %f)(%f, %f)\n", x, y, p1.x, p1.y, p2.x, p2.y);
- return false;
- }
-
- if (x < Math.min(x1, x2) - cc.math.EPSILON ||
- x > Math.max(x1, x2) + cc.math.EPSILON ||
- y < Math.min(y1, y2) - cc.math.EPSILON ||
- y > Math.max(y1, y2) + cc.math.EPSILON) {
- //printf("Outside of ray, %f %f (%f %f)(%f, %f)\n", x, y, x1, y1, x2, y2);
- return false;
- }
-
- intersection.x = x;
- intersection.y = y;
- return true;
- };
-
- function calculate_line_normal(p1, p2, normalOut){
- var tmp = new cc.math.Vec2(p2);
- tmp.subtract(p1);
-
- normalOut.x = -tmp.y;
- normalOut.y = tmp.x;
- normalOut.normalize();
- //TODO: should check that the normal is pointing out of the triangle
+ if (x < Math.min(p1.x, p2.x) - cc.math.EPSILON ||
+ x > Math.max(p1.x, p2.x) + cc.math.EPSILON ||
+ y < Math.min(p1.y, p2.y) - cc.math.EPSILON ||
+ y > Math.max(p1.y, p2.y) + cc.math.EPSILON) {
+ //Outside of line
+ //printf("Outside of line, %f %f (%f %f)(%f, %f)\n", x, y, p1.x, p1.y, p2.x, p2.y);
+ return false;
}
- cc.math.Ray2.prototype.intersectTriangle = function(p1, p2, p3, intersection, normal_out){
- var intersect = new cc.math.Vec2(), final_intersect = new cc.math.Vec2();
- var normal = new cc.math.Vec2(), distance = 10000.0, intersected = false;
- var this_distance;
+ if (x < Math.min(x1, x2) - cc.math.EPSILON ||
+ x > Math.max(x1, x2) + cc.math.EPSILON ||
+ y < Math.min(y1, y2) - cc.math.EPSILON ||
+ y > Math.max(y1, y2) + cc.math.EPSILON) {
+ //printf("Outside of ray, %f %f (%f %f)(%f, %f)\n", x, y, x1, y1, x2, y2);
+ return false;
+ }
- if(this.intersectLineSegment(p1, p2, intersect)) {
- intersected = true;
- this_distance = intersect.subtract(this.start).length();
- if(this_distance < distance) {
- final_intersect.x = intersect.x;
- final_intersect.y = intersect.y;
- distance = this_distance;
- calculate_line_normal(p1, p2, normal);
- }
- }
+ intersection.x = x;
+ intersection.y = y;
+ return true;
+};
- if(this.intersectLineSegment(p2, p3, intersect)) {
- intersected = true;
- this_distance = intersect.subtract(this.start).length();
- if(this_distance < distance) {
- final_intersect.x = intersect.x;
- final_intersect.y = intersect.y;
- distance = this_distance;
- calculate_line_normal(p2, p3, normal);
- }
- }
+function calculate_line_normal(p1, p2, normalOut){
+ var tmp = new cc.math.Vec2(p2);
+ tmp.subtract(p1);
- if(this.intersectLineSegment(p3, p1, intersect)) {
- intersected = true;
- this_distance = intersect.subtract(this.start).length();
- if(this_distance < distance) {
- final_intersect.x = intersect.x;
- final_intersect.y = intersect.y;
- distance = this_distance;
- calculate_line_normal(p3, p1, normal);
- }
- }
+ normalOut.x = -tmp.y;
+ normalOut.y = tmp.x;
+ normalOut.normalize();
+ //TODO: should check that the normal is pointing out of the triangle
+}
- if(intersected) {
- intersection.x = final_intersect.x;
- intersection.y = final_intersect.y;
- if(normal_out) {
- normal_out.x = normal.x;
- normal_out.y = normal.y;
- }
+cc.math.Ray2.prototype.intersectTriangle = function(p1, p2, p3, intersection, normal_out){
+ var intersect = new cc.math.Vec2(), final_intersect = new cc.math.Vec2();
+ var normal = new cc.math.Vec2(), distance = 10000.0, intersected = false;
+ var this_distance;
+
+ if(this.intersectLineSegment(p1, p2, intersect)) {
+ intersected = true;
+ this_distance = intersect.subtract(this.start).length();
+ if(this_distance < distance) {
+ final_intersect.x = intersect.x;
+ final_intersect.y = intersect.y;
+ distance = this_distance;
+ calculate_line_normal(p1, p2, normal);
}
- return intersected;
- };
-})(cc);
+ }
+
+ if(this.intersectLineSegment(p2, p3, intersect)) {
+ intersected = true;
+ this_distance = intersect.subtract(this.start).length();
+ if(this_distance < distance) {
+ final_intersect.x = intersect.x;
+ final_intersect.y = intersect.y;
+ distance = this_distance;
+ calculate_line_normal(p2, p3, normal);
+ }
+ }
+
+ if(this.intersectLineSegment(p3, p1, intersect)) {
+ intersected = true;
+ this_distance = intersect.subtract(this.start).length();
+ if(this_distance < distance) {
+ final_intersect.x = intersect.x;
+ final_intersect.y = intersect.y;
+ distance = this_distance;
+ calculate_line_normal(p3, p1, normal);
+ }
+ }
+
+ if(intersected) {
+ intersection.x = final_intersect.x;
+ intersection.y = final_intersect.y;
+ if(normal_out) {
+ normal_out.x = normal.x;
+ normal_out.y = normal.y;
+ }
+ }
+ return intersected;
+};
diff --git a/cocos2d/kazmath/simd_benchmark/kmMat4AreEqual.js b/cocos2d/kazmath/simd_benchmark/kmMat4AreEqual.js
index a3dee727ac..8d7c48ba60 100644
--- a/cocos2d/kazmath/simd_benchmark/kmMat4AreEqual.js
+++ b/cocos2d/kazmath/simd_benchmark/kmMat4AreEqual.js
@@ -16,10 +16,10 @@
benchmarks.add(new Benchmark(kernelConfig));
// Benchmark data, initialization and kernel functions
- var T1 = new cc.kmMat4();
- var T2 = new cc.kmMat4();
- var T1x4 = new cc.kmMat4();
- var T2x4 = new cc.kmMat4();
+ var T1 = new cc.math.Matrix4();
+ var T2 = new cc.math.Matrix4();
+ var T1x4 = new cc.math.Matrix4();
+ var T2x4 = new cc.math.Matrix4();
var areEqual, areEqualSIMD;
function equals(A, B) {
diff --git a/cocos2d/kazmath/simd_benchmark/kmMat4Assign.js b/cocos2d/kazmath/simd_benchmark/kmMat4Assign.js
index e8e386f781..47b6bb7f1f 100644
--- a/cocos2d/kazmath/simd_benchmark/kmMat4Assign.js
+++ b/cocos2d/kazmath/simd_benchmark/kmMat4Assign.js
@@ -16,10 +16,10 @@
benchmarks.add(new Benchmark(kernelConfig));
// Benchmark data, initialization and kernel functions
- var T1 = new cc.kmMat4();
- var T2 = new cc.kmMat4();
- var T1x4 = new cc.kmMat4();
- var T2x4 = new cc.kmMat4();
+ var T1 = new cc.math.Matrix4();
+ var T2 = new cc.math.Matrix4();
+ var T1x4 = new cc.math.Matrix4();
+ var T2x4 = new cc.math.Matrix4();
function equals(A, B) {
for (var i = 0; i < 16; ++i) {
@@ -53,14 +53,14 @@
function nonSimd(n) {
for (var i = 0; i < n; i++) {
- //cc.kmMat4Assign(T2, T1);
+ //cc.math.mat4Assign(T2, T1);
T2.assignFrom(T1);
}
}
function simd(n) {
for (var i = 0; i < n; i++) {
- //cc.kmMat4AssignSIMD(T2x4, T1x4);
+ //cc.math.mat4AssignSIMD(T2x4, T1x4);
T2x4.assignFromSIMD(T1x4);
}
}
diff --git a/cocos2d/kazmath/simd_benchmark/kmMat4Inverse.js b/cocos2d/kazmath/simd_benchmark/kmMat4Inverse.js
index 212dff1af1..ca2723d565 100644
--- a/cocos2d/kazmath/simd_benchmark/kmMat4Inverse.js
+++ b/cocos2d/kazmath/simd_benchmark/kmMat4Inverse.js
@@ -16,10 +16,10 @@
benchmarks.add(new Benchmark(kernelConfig));
// Benchmark data, initialization and kernel functions
- var src = new cc.kmMat4();
- var dst = new cc.kmMat4();
- var srcx4 = new cc.kmMat4();
- var dstx4 = new cc.kmMat4();
+ var src = new cc.math.Matrix4();
+ var dst = new cc.math.Matrix4();
+ var srcx4 = new cc.math.Matrix4();
+ var dstx4 = new cc.math.Matrix4();
var ident = new Float32Array(
[1,0,0,0,
0,1,0,0,
@@ -101,14 +101,14 @@
function nonSimd(n) {
for (var i = 0; i < n; i++) {
- //cc.kmMat4Inverse(dst, src);
+ //cc.math.mat4Inverse(dst, src);
dst = src.inverse();
}
}
function simd(n) {
for (var i = 0; i < n; i++) {
- //cc.kmMat4InverseSIMD(dstx4, srcx4);
+ //cc.math.mat4InverseSIMD(dstx4, srcx4);
dstx4 = srcx4.inverseSIMD();
}
}
diff --git a/cocos2d/kazmath/simd_benchmark/kmMat4IsIdentity.js b/cocos2d/kazmath/simd_benchmark/kmMat4IsIdentity.js
index 9ab17ac744..703fad5303 100644
--- a/cocos2d/kazmath/simd_benchmark/kmMat4IsIdentity.js
+++ b/cocos2d/kazmath/simd_benchmark/kmMat4IsIdentity.js
@@ -16,8 +16,8 @@
benchmarks.add(new Benchmark(kernelConfig));
// Benchmark data, initialization and kernel functions
- var T1 = new cc.kmMat4();
- var T1x4 = new cc.kmMat4();
+ var T1 = new cc.math.Matrix4();
+ var T1x4 = new cc.math.Matrix4();
var isIdentity, isIdentitySIMD;
function equals(A, B) {
diff --git a/cocos2d/kazmath/simd_benchmark/kmMat4LookAt.js b/cocos2d/kazmath/simd_benchmark/kmMat4LookAt.js
index 1015ad14eb..d214bd6edb 100644
--- a/cocos2d/kazmath/simd_benchmark/kmMat4LookAt.js
+++ b/cocos2d/kazmath/simd_benchmark/kmMat4LookAt.js
@@ -16,10 +16,10 @@
benchmarks.add(new Benchmark(kernelConfig));
// Benchmark data, initialization and kernel functions
- var eye = new cc.kmVec3(), center = new cc.kmVec3(), up = new cc.kmVec3();
- var T1 = new cc.kmMat4();
- var eye1 = new cc.kmVec3(), center1 = new cc.kmVec3(), up1 = new cc.kmVec3();
- var T1x4 = new cc.kmMat4();
+ var eye = new cc.math.Vec3(), center = new cc.math.Vec3(), up = new cc.math.Vec3();
+ var T1 = new cc.math.Matrix4();
+ var eye1 = new cc.math.Vec3(), center1 = new cc.math.Vec3(), up1 = new cc.math.Vec3();
+ var T1x4 = new cc.math.Matrix4();
function printMatrix(matrix) {
print('--------matrix----------');
@@ -79,14 +79,14 @@
function nonSimd(n) {
for (var i = 0; i < n; i++) {
- //cc.kmMat4LookAt(T1, eye, center, up);
+ //cc.math.mat4LookAt(T1, eye, center, up);
T1.lookAt(eye, center, up);
}
}
function simd(n) {
for (var i = 0; i < n; i++) {
- //cc.kmMat4LookAtSIMD(T1x4, eye1, center1, up1);
+ //cc.math.mat4LookAtSIMD(T1x4, eye1, center1, up1);
T1x4.lookAtSIMD(eye1, center1, up1);
}
}
diff --git a/cocos2d/kazmath/simd_benchmark/kmMat4Multiply.js b/cocos2d/kazmath/simd_benchmark/kmMat4Multiply.js
index 325b6f95bf..5082d921df 100644
--- a/cocos2d/kazmath/simd_benchmark/kmMat4Multiply.js
+++ b/cocos2d/kazmath/simd_benchmark/kmMat4Multiply.js
@@ -16,10 +16,10 @@
benchmarks.add(new Benchmark(kernelConfig));
// Benchmark data, initialization and kernel functions
- var T1 = new cc.kmMat4();
- var T2 = new cc.kmMat4();
- var T1x4 = new cc.kmMat4();
- var T2x4 = new cc.kmMat4();
+ var T1 = new cc.math.Matrix4();
+ var T2 = new cc.math.Matrix4();
+ var T1x4 = new cc.math.Matrix4();
+ var T2x4 = new cc.math.Matrix4();
function equals(A, B) {
for (var i = 0; i < 16; ++i) {
diff --git a/cocos2d/kazmath/simd_benchmark/kmMat4Transpose.js b/cocos2d/kazmath/simd_benchmark/kmMat4Transpose.js
index cd1b776bf0..2892ba95da 100644
--- a/cocos2d/kazmath/simd_benchmark/kmMat4Transpose.js
+++ b/cocos2d/kazmath/simd_benchmark/kmMat4Transpose.js
@@ -16,10 +16,10 @@
benchmarks.add(new Benchmark(kernelConfig));
// Benchmark data, initialization and kernel functions
- var T1 = new cc.kmMat4();
- var T2 = new cc.kmMat4();
- var T1x4 = new cc.kmMat4();
- var T2x4 = new cc.kmMat4();
+ var T1 = new cc.math.Matrix4();
+ var T2 = new cc.math.Matrix4();
+ var T1x4 = new cc.math.Matrix4();
+ var T2x4 = new cc.math.Matrix4();
function equals(A, B) {
for (var i = 0; i < 16; ++i) {
diff --git a/cocos2d/kazmath/simd_benchmark/kmVec3TransformCoord.js b/cocos2d/kazmath/simd_benchmark/kmVec3TransformCoord.js
index 541a926c9d..0bb25e8e12 100644
--- a/cocos2d/kazmath/simd_benchmark/kmVec3TransformCoord.js
+++ b/cocos2d/kazmath/simd_benchmark/kmVec3TransformCoord.js
@@ -16,12 +16,12 @@
benchmarks.add(new Benchmark(kernelConfig));
// Benchmark data, initialization and kernel functions
- var V = new cc.kmVec3();
- var T = new cc.kmMat4();
- var Out = new cc.kmVec3();
- var Vx4 = new cc.kmVec3();
- var Tx4 = new cc.kmMat4();
- var Outx4 = new cc.kmVec3();
+ var V = new cc.math.Vec3();
+ var T = new cc.math.Matrix4();
+ var Out = new cc.math.Vec3();
+ var Vx4 = new cc.math.Vec3();
+ var Tx4 = new cc.math.Matrix4();
+ var Outx4 = new cc.math.Vec3();
function init() {
T.mat[0] = 1.0;
diff --git a/cocos2d/kazmath/utility.js b/cocos2d/kazmath/utility.js
index 2ffe652038..f3f8ab188f 100644
--- a/cocos2d/kazmath/utility.js
+++ b/cocos2d/kazmath/utility.js
@@ -35,9 +35,9 @@
*/
cc.math = cc.math || {};
-//cc.kmPIOver180 = 0.017453; please use cc.Macro.RAD
+//cc.kmPIOver180 = 0.017453; please use cc.macro.RAD
-//cc.kmPIUnder180 = 57.295779; please use cc.Macro.DEG
+//cc.kmPIUnder180 = 57.295779; please use cc.macro.DEG
cc.math.EPSILON = 1.0 / 64.0; //cc.kmEpsilon
diff --git a/cocos2d/kazmath/vec2.js b/cocos2d/kazmath/vec2.js
index a682bc4853..a0650c92eb 100644
--- a/cocos2d/kazmath/vec2.js
+++ b/cocos2d/kazmath/vec2.js
@@ -26,88 +26,86 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-(function(cc){
- cc.math.Vec2 = function (x, y) {
- if(y === undefined){
- this.x = x.x;
- this.y = x.y;
- }else{
- this.x = x || 0;
- this.y = y || 0;
- }
- };
+cc.math.Vec2 = function (x, y) {
+ if(y === undefined){
+ this.x = x.x;
+ this.y = x.y;
+ }else{
+ this.x = x || 0;
+ this.y = y || 0;
+ }
+};
- var proto = cc.math.Vec2.prototype;
- proto.fill = function(x, y){ // = cc.kmVec2Fill
- this.x = x;
- this.y = y;
- };
+var proto = cc.math.Vec2.prototype;
+proto.fill = function(x, y){ // = cc.kmVec2Fill
+ this.x = x;
+ this.y = y;
+};
- proto.length = function(){ // = cc.kmVec2Length
- return Math.sqrt(cc.math.square(this.x) + cc.math.square(this.y));
- };
+proto.length = function(){ // = cc.kmVec2Length
+ return Math.sqrt(cc.math.square(this.x) + cc.math.square(this.y));
+};
- proto.lengthSq = function(){ // = cc.kmVec2LengthSq
- return cc.math.square(this.x) + cc.math.square(this.y);
- };
+proto.lengthSq = function(){ // = cc.kmVec2LengthSq
+ return cc.math.square(this.x) + cc.math.square(this.y);
+};
- proto.normalize = function(){ // = cc.kmVec2Normalize
- var l = 1.0 / this.length();
- this.x *= l;
- this.y *= l;
- return this;
- };
+proto.normalize = function(){ // = cc.kmVec2Normalize
+ var l = 1.0 / this.length();
+ this.x *= l;
+ this.y *= l;
+ return this;
+};
- cc.math.Vec2.add = function (pOut, pV1, pV2) { // = cc.kmVec2Add
- pOut.x = pV1.x + pV2.x;
- pOut.y = pV1.y + pV2.y;
- return pOut
- };
+cc.math.Vec2.add = function (pOut, pV1, pV2) { // = cc.kmVec2Add
+ pOut.x = pV1.x + pV2.x;
+ pOut.y = pV1.y + pV2.y;
+ return pOut
+};
- proto.add = function(vec){ // = cc.kmVec2Add
- this.x += vec.x;
- this.y += vec.y;
- return this;
- };
+proto.add = function(vec){ // = cc.kmVec2Add
+ this.x += vec.x;
+ this.y += vec.y;
+ return this;
+};
- proto.dot = function (vec) { //cc.kmVec2Dot
- return this.x * vec.x + this.y * vec.y;
- };
+proto.dot = function (vec) { //cc.kmVec2Dot
+ return this.x * vec.x + this.y * vec.y;
+};
- cc.math.Vec2.subtract = function (pOut, pV1, pV2) { // = cc.kmVec2Subtract
- pOut.x = pV1.x - pV2.x;
- pOut.y = pV1.y - pV2.y;
- return pOut;
- };
+cc.math.Vec2.subtract = function (pOut, pV1, pV2) { // = cc.kmVec2Subtract
+ pOut.x = pV1.x - pV2.x;
+ pOut.y = pV1.y - pV2.y;
+ return pOut;
+};
- proto.subtract = function(vec){ // = cc.kmVec2Subtract
- this.x -= vec.x;
- this.y -= vec.y;
- return this;
- };
+proto.subtract = function(vec){ // = cc.kmVec2Subtract
+ this.x -= vec.x;
+ this.y -= vec.y;
+ return this;
+};
- proto.transform = function (mat3) { // = cc.kmVec2Transform
- var x = this.x, y = this.y;
- this.x = x * mat3.mat[0] + y * mat3.mat[3] + mat3.mat[6];
- this.y = x * mat3.mat[1] + y * mat3.mat[4] + mat3.mat[7];
- return this;
- };
+proto.transform = function (mat3) { // = cc.kmVec2Transform
+ var x = this.x, y = this.y;
+ this.x = x * mat3.mat[0] + y * mat3.mat[3] + mat3.mat[6];
+ this.y = x * mat3.mat[1] + y * mat3.mat[4] + mat3.mat[7];
+ return this;
+};
- cc.math.Vec2.scale = function (pOut, pIn, s) { // = cc.kmVec2Scale
- pOut.x = pIn.x * s;
- pOut.y = pIn.y * s;
- return pOut;
- };
+cc.math.Vec2.scale = function (pOut, pIn, s) { // = cc.kmVec2Scale
+ pOut.x = pIn.x * s;
+ pOut.y = pIn.y * s;
+ return pOut;
+};
- proto.scale = function(s) { // = cc.kmVec2Scale
- this.x *= s;
- this.y *= s;
- return this;
- };
+proto.scale = function(s) { // = cc.kmVec2Scale
+ this.x *= s;
+ this.y *= s;
+ return this;
+};
- proto.equals = function (vec) { // = cc.kmVec2AreEqual
- return (this.x < vec.x + cc.math.EPSILON && this.x > vec.x - cc.math.EPSILON) &&
- (this.y < vec.y + cc.math.EPSILON && this.y > vec.y - cc.math.EPSILON);
- };
-})(cc);
+proto.equals = function (vec) { // = cc.kmVec2AreEqual
+ return (this.x < vec.x + cc.math.EPSILON && this.x > vec.x - cc.math.EPSILON) &&
+ (this.y < vec.y + cc.math.EPSILON && this.y > vec.y - cc.math.EPSILON);
+};
diff --git a/cocos2d/kazmath/vec3.js b/cocos2d/kazmath/vec3.js
index 282b34aaae..a1918b981a 100644
--- a/cocos2d/kazmath/vec3.js
+++ b/cocos2d/kazmath/vec3.js
@@ -26,176 +26,164 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-(function(cc) {
- cc.kmVec3 = cc.math.Vec3 = function (x, y, z) {
- if(x && y === undefined){
- this.x = x.x;
- this.y = x.y;
- this.z = x.z;
- } else {
- this.x = x || 0;
- this.y = y || 0;
- this.z = z || 0;
- }
- };
+cc.math.Vec3 = cc.math.Vec3 = function (x, y, z) {
+ if(x && y === undefined){
+ this.x = x.x;
+ this.y = x.y;
+ this.z = x.z;
+ } else {
+ this.x = x || 0;
+ this.y = y || 0;
+ this.z = z || 0;
+ }
+};
- cc.math.vec3 = function(x, y, z){
- return new cc.math.Vec3(x, y, z);
- };
+cc.math.vec3 = function(x, y, z){
+ return new cc.math.Vec3(x, y, z);
+};
- var proto = cc.math.Vec3.prototype;
+var proto = cc.math.Vec3.prototype;
- proto.fill = function (x, y, z) { // =cc.kmVec3Fill
- if (x && y === undefined) {
- this.x = x.x;
- this.y = x.y;
- this.z = x.z;
- } else {
- this.x = x;
- this.y = y;
- this.z = z;
- }
+proto.fill = function (x, y, z) { // =cc.math.Vec3Fill
+ if (x && y === undefined) {
+ this.x = x.x;
+ this.y = x.y;
+ this.z = x.z;
+ } else {
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ }
+ return this;
+};
+
+proto.length = function () { //=cc.math.Vec3Length
+ return Math.sqrt(cc.math.square(this.x) + cc.math.square(this.y) + cc.math.square(this.z));
+};
+
+proto.lengthSq = function () { //=cc.math.Vec3LengthSq
+ return cc.math.square(this.x) + cc.math.square(this.y) + cc.math.square(this.z)
+};
+
+proto.normalize = function () { //= cc.math.Vec3Normalize
+ var l = 1.0 / this.length();
+ this.x *= l;
+ this.y *= l;
+ this.z *= l;
+ return this;
+};
+
+proto.cross = function (vec3) { //= cc.math.Vec3Cross
+ var x = this.x, y = this.y, z = this.z;
+ this.x = (y * vec3.z) - (z * vec3.y);
+ this.y = (z * vec3.x) - (x * vec3.z);
+ this.z = (x * vec3.y) - (y * vec3.x);
+ return this;
+};
+
+proto.dot = function (vec) { //= cc.math.Vec3Dot
+ return ( this.x * vec.x + this.y * vec.y + this.z * vec.z );
+};
+
+proto.add = function(vec){ //= cc.math.Vec3Add
+ this.x += vec.x;
+ this.y += vec.y;
+ this.z += vec.z;
+ return this;
+};
+
+proto.subtract = function (vec) { // = cc.math.Vec3Subtract
+ this.x -= vec.x;
+ this.y -= vec.y;
+ this.z -= vec.z;
+ return this;
+};
+
+proto.transform = function (mat4) { // = cc.math.Vec3Transform
+ var x = this.x, y = this.y, z = this.z, mat = mat4.mat;
+ this.x = x * mat[0] + y * mat[4] + z * mat[8] + mat[12];
+ this.y = x * mat[1] + y * mat[5] + z * mat[9] + mat[13];
+ this.z = x * mat[2] + y * mat[6] + z * mat[10] + mat[14];
+ return this;
+};
+
+proto.transformNormal = function(mat4){
+ /*
+ a = (Vx, Vy, Vz, 0)
+ b = (a×M)T
+ Out = (bx, by, bz)
+ */
+ //Omits the translation, only scaling + rotating
+ var x = this.x, y = this.y, z = this.z, mat = mat4.mat;
+ this.x = x * mat[0] + y * mat[4] + z * mat[8];
+ this.y = x * mat[1] + y * mat[5] + z * mat[9];
+ this.z = x * mat[2] + y * mat[6] + z * mat[10];
+ return this;
+};
+
+proto.transformCoord = function(mat4){ // = cc.math.Vec3TransformCoord
+ /*
+ a = (Vx, Vy, Vz, 1)
+ b = (a×M)T
+ Out = 1⁄bw(bx, by, bz)
+ */
+ var v = new cc.math.Vec4(this.x, this.y, this.z, 1.0);
+ v.transform(mat4);
+ this.x = v.x / v.w;
+ this.y = v.y / v.w;
+ this.z = v.z / v.w;
+ return this;
+};
+
+proto.scale = function(scale){ // = cc.math.Vec3Scale
+ this.x *= scale;
+ this.y *= scale;
+ this.z *= scale;
+ return this;
+};
+
+proto.equals = function(vec){ // = cc.math.Vec3AreEqual
+ var EPSILON = cc.math.EPSILON;
+ return (this.x < (vec.x + EPSILON) && this.x > (vec.x - EPSILON)) &&
+ (this.y < (vec.y + EPSILON) && this.y > (vec.y - EPSILON)) &&
+ (this.z < (vec.z + EPSILON) && this.z > (vec.z - EPSILON));
+};
+
+proto.inverseTransform = function(mat4){ //= cc.math.Vec3InverseTransform
+ var mat = mat4.mat;
+ var v1 = new cc.math.Vec3(this.x - mat[12], this.y - mat[13], this.z - mat[14]);
+ this.x = v1.x * mat[0] + v1.y * mat[1] + v1.z * mat[2];
+ this.y = v1.x * mat[4] + v1.y * mat[5] + v1.z * mat[6];
+ this.z = v1.x * mat[8] + v1.y * mat[9] + v1.z * mat[10];
+ return this;
+};
+
+proto.inverseTransformNormal = function(mat4){ // = cc.math.Vec3InverseTransformNormal
+ var x = this.x, y = this.y, z = this.z, mat = mat4.mat;
+ this.x = x * mat[0] + y * mat[1] + z * mat[2];
+ this.y = x * mat[4] + y * mat[5] + z * mat[6];
+ this.z = x * mat[8] + y * mat[9] + z * mat[10];
+ return this;
+};
+
+proto.assignFrom = function(vec){
+ if(!vec)
return this;
- };
-
- proto.length = function () { //=cc.kmVec3Length
- return Math.sqrt(cc.math.square(this.x) + cc.math.square(this.y) + cc.math.square(this.z));
- };
-
- proto.lengthSq = function () { //=cc.kmVec3LengthSq
- return cc.math.square(this.x) + cc.math.square(this.y) + cc.math.square(this.z)
- };
-
- proto.normalize = function () { //= cc.kmVec3Normalize
- var l = 1.0 / this.length();
- this.x *= l;
- this.y *= l;
- this.z *= l;
- return this;
- };
-
- proto.cross = function (vec3) { //= cc.kmVec3Cross
- var x = this.x, y = this.y, z = this.z;
- this.x = (y * vec3.z) - (z * vec3.y);
- this.y = (z * vec3.x) - (x * vec3.z);
- this.z = (x * vec3.y) - (y * vec3.x);
- return this;
- };
-
- proto.dot = function (vec) { //= cc.kmVec3Dot
- return ( this.x * vec.x + this.y * vec.y + this.z * vec.z );
- };
-
- proto.add = function(vec){ //= cc.kmVec3Add
- this.x += vec.x;
- this.y += vec.y;
- this.z += vec.z;
- return this;
- };
-
- proto.subtract = function (vec) { // = cc.kmVec3Subtract
- this.x -= vec.x;
- this.y -= vec.y;
- this.z -= vec.z;
- return this;
- };
-
- proto.transform = function (mat4) { // = cc.kmVec3Transform
- var x = this.x, y = this.y, z = this.z, mat = mat4.mat;
- this.x = x * mat[0] + y * mat[4] + z * mat[8] + mat[12];
- this.y = x * mat[1] + y * mat[5] + z * mat[9] + mat[13];
- this.z = x * mat[2] + y * mat[6] + z * mat[10] + mat[14];
- return this;
- };
-
- proto.transformNormal = function(mat4){
- /*
- a = (Vx, Vy, Vz, 0)
- b = (a×M)T
- Out = (bx, by, bz)
- */
- //Omits the translation, only scaling + rotating
- var x = this.x, y = this.y, z = this.z, mat = mat4.mat;
- this.x = x * mat[0] + y * mat[4] + z * mat[8];
- this.y = x * mat[1] + y * mat[5] + z * mat[9];
- this.z = x * mat[2] + y * mat[6] + z * mat[10];
- return this;
- };
-
- proto.transformCoord = function(mat4){ // = cc.kmVec3TransformCoord
- /*
- a = (Vx, Vy, Vz, 1)
- b = (a×M)T
- Out = 1⁄bw(bx, by, bz)
- */
- var v = new cc.math.Vec4(this.x, this.y, this.z, 1.0);
- v.transform(mat4);
- this.x = v.x / v.w;
- this.y = v.y / v.w;
- this.z = v.z / v.w;
- return this;
- };
-
- proto.scale = function(scale){ // = cc.kmVec3Scale
- this.x *= scale;
- this.y *= scale;
- this.z *= scale;
- return this;
- };
-
- proto.equals = function(vec){ // = cc.kmVec3AreEqual
- var EPSILON = cc.math.EPSILON;
- return (this.x < (vec.x + EPSILON) && this.x > (vec.x - EPSILON)) &&
- (this.y < (vec.y + EPSILON) && this.y > (vec.y - EPSILON)) &&
- (this.z < (vec.z + EPSILON) && this.z > (vec.z - EPSILON));
- };
-
- proto.inverseTransform = function(mat4){ //= cc.kmVec3InverseTransform
- var mat = mat4.mat;
- var v1 = new cc.math.Vec3(this.x - mat[12], this.y - mat[13], this.z - mat[14]);
- this.x = v1.x * mat[0] + v1.y * mat[1] + v1.z * mat[2];
- this.y = v1.x * mat[4] + v1.y * mat[5] + v1.z * mat[6];
- this.z = v1.x * mat[8] + v1.y * mat[9] + v1.z * mat[10];
- return this;
- };
-
- proto.inverseTransformNormal = function(mat4){ // = cc.kmVec3InverseTransformNormal
- var x = this.x, y = this.y, z = this.z, mat = mat4.mat;
- this.x = x * mat[0] + y * mat[1] + z * mat[2];
- this.y = x * mat[4] + y * mat[5] + z * mat[6];
- this.z = x * mat[8] + y * mat[9] + z * mat[10];
- return this;
- };
-
- proto.assignFrom = function(vec){
- if(!vec)
- return this;
- this.x = vec.x;
- this.y = vec.y;
- this.z = vec.z;
- return this;
- };
-
- cc.math.Vec3.zero = function(vec){ // = cc.kmVec3Zero
- vec.x = vec.y = vec.z = 0.0;
- return vec;
- };
-
- proto.toTypeArray = function(){ //cc.kmVec3ToTypeArray
- var tyArr = new Float32Array(3);
- tyArr[0] = this.x;
- tyArr[1] = this.y;
- tyArr[2] = this.z;
- return tyArr;
- };
-})(cc);
-
-
-
-
-
-
-
-
+ this.x = vec.x;
+ this.y = vec.y;
+ this.z = vec.z;
+ return this;
+};
+cc.math.Vec3.zero = function(vec){ // = cc.math.Vec3Zero
+ vec.x = vec.y = vec.z = 0.0;
+ return vec;
+};
+proto.toTypeArray = function(){ //cc.math.Vec3ToTypeArray
+ var tyArr = new Float32Array(3);
+ tyArr[0] = this.x;
+ tyArr[1] = this.y;
+ tyArr[2] = this.z;
+ return tyArr;
+};
diff --git a/cocos2d/kazmath/vec3SIMD.js b/cocos2d/kazmath/vec3SIMD.js
index 0bf4ff4b87..31dcbcd715 100644
--- a/cocos2d/kazmath/vec3SIMD.js
+++ b/cocos2d/kazmath/vec3SIMD.js
@@ -26,26 +26,26 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
- (function(cc) {
- var proto = cc.math.Vec3.prototype;
+require('./vec3');
- proto.transformCoordSIMD = function(mat4){
- var vec = SIMD.float32x4(this.x, this.y, this.z, 0.0);
- var mat0 = SIMD.float32x4.load(mat4.mat, 0);
- var mat1 = SIMD.float32x4.load(mat4.mat, 4);
- var mat2 = SIMD.float32x4.load(mat4.mat, 8);
- var mat3 = SIMD.float32x4.load(mat4.mat, 12);
+var proto = cc.math.Vec3.prototype;
- //cc.kmVec4Transform(v, inV,pM);
- var out = SIMD.float32x4.add(
- SIMD.float32x4.add(SIMD.float32x4.mul(mat0, SIMD.float32x4.swizzle(vec, 0, 0, 0, 0)),
- SIMD.float32x4.mul(mat1, SIMD.float32x4.swizzle(vec, 1, 1, 1, 1))),
- SIMD.float32x4.add(SIMD.float32x4.mul(mat2, SIMD.float32x4.swizzle(vec, 2, 2, 2, 2)),
- mat3));
+proto.transformCoordSIMD = function(mat4){
+ var vec = SIMD.float32x4(this.x, this.y, this.z, 0.0);
+ var mat0 = SIMD.float32x4.load(mat4.mat, 0);
+ var mat1 = SIMD.float32x4.load(mat4.mat, 4);
+ var mat2 = SIMD.float32x4.load(mat4.mat, 8);
+ var mat3 = SIMD.float32x4.load(mat4.mat, 12);
- out = SIMD.float32x4.div(out, SIMD.float32x4.swizzle(out, 3, 3, 3, 3));
- this.fill(out);
+ //cc.kmVec4Transform(v, inV,pM);
+ var out = SIMD.float32x4.add(
+ SIMD.float32x4.add(SIMD.float32x4.mul(mat0, SIMD.float32x4.swizzle(vec, 0, 0, 0, 0)),
+ SIMD.float32x4.mul(mat1, SIMD.float32x4.swizzle(vec, 1, 1, 1, 1))),
+ SIMD.float32x4.add(SIMD.float32x4.mul(mat2, SIMD.float32x4.swizzle(vec, 2, 2, 2, 2)),
+ mat3));
- return this;
- };
-})(cc);
+ out = SIMD.float32x4.div(out, SIMD.float32x4.swizzle(out, 3, 3, 3, 3));
+ this.fill(out);
+
+ return this;
+};
diff --git a/cocos2d/kazmath/vec4.js b/cocos2d/kazmath/vec4.js
index fb2e376380..3761f4acb9 100644
--- a/cocos2d/kazmath/vec4.js
+++ b/cocos2d/kazmath/vec4.js
@@ -26,133 +26,128 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-(function(cc) {
- cc.math.Vec4 = function (x, y, z, w) {
- if (x && y === undefined) {
- this.x = x.x;
- this.y = x.y;
- this.z = x.z;
- this.w = x.w;
- } else {
- this.x = x || 0;
- this.y = y || 0;
- this.z = z || 0;
- this.w = w || 0;
- }
- };
- cc.kmVec4 = cc.math.Vec4;
- var proto = cc.math.Vec4.prototype;
+cc.math.Vec4 = function (x, y, z, w) {
+ if (x && y === undefined) {
+ this.x = x.x;
+ this.y = x.y;
+ this.z = x.z;
+ this.w = x.w;
+ } else {
+ this.x = x || 0;
+ this.y = y || 0;
+ this.z = z || 0;
+ this.w = w || 0;
+ }
+};
+var proto = cc.math.Vec4.prototype;
- proto.fill = function (x, y, z, w) { //=cc.kmVec4Fill
- if (x && y === undefined) {
- this.x = x.x;
- this.y = x.y;
- this.z = x.z;
- this.w = x.w;
- } else {
- this.x = x;
- this.y = y;
- this.z = z;
- this.w = w;
- }
- };
+proto.fill = function (x, y, z, w) { //=cc.kmVec4Fill
+ if (x && y === undefined) {
+ this.x = x.x;
+ this.y = x.y;
+ this.z = x.z;
+ this.w = x.w;
+ } else {
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ this.w = w;
+ }
+};
- proto.add = function(vec) { //cc.kmVec4Add
- if(!vec)
- return this;
- this.x += vec.x;
- this.y += vec.y;
- this.z += vec.z;
- this.w += vec.w;
+proto.add = function(vec) { //cc.kmVec4Add
+ if(!vec)
return this;
- };
+ this.x += vec.x;
+ this.y += vec.y;
+ this.z += vec.z;
+ this.w += vec.w;
+ return this;
+};
- proto.dot = function(vec){ //cc.kmVec4Dot
- return ( this.x * vec.x + this.y * vec.y + this.z * vec.z + this.w * vec.w );
- };
+proto.dot = function(vec){ //cc.kmVec4Dot
+ return ( this.x * vec.x + this.y * vec.y + this.z * vec.z + this.w * vec.w );
+};
- proto.length = function(){ //=cc.kmVec4Length
- return Math.sqrt(cc.math.square(this.x) + cc.math.square(this.y) + cc.math.square(this.z) + cc.math.square(this.w));
- };
+proto.length = function(){ //=cc.kmVec4Length
+ return Math.sqrt(cc.math.square(this.x) + cc.math.square(this.y) + cc.math.square(this.z) + cc.math.square(this.w));
+};
- proto.lengthSq = function(){ //=cc.kmVec4LengthSq
- return cc.math.square(this.x) + cc.math.square(this.y) + cc.math.square(this.z) + cc.math.square(this.w);
- };
+proto.lengthSq = function(){ //=cc.kmVec4LengthSq
+ return cc.math.square(this.x) + cc.math.square(this.y) + cc.math.square(this.z) + cc.math.square(this.w);
+};
- proto.lerp = function(vec, t){ //= cc.kmVec4Lerp
- //not implemented
- return this;
- };
+proto.lerp = function(vec, t){ //= cc.kmVec4Lerp
+ //not implemented
+ return this;
+};
- proto.normalize = function() { // cc.kmVec4Normalize
- var l = 1.0 / this.length();
- this.x *= l;
- this.y *= l;
- this.z *= l;
- this.w *= l;
- return this;
- };
+proto.normalize = function() { // cc.kmVec4Normalize
+ var l = 1.0 / this.length();
+ this.x *= l;
+ this.y *= l;
+ this.z *= l;
+ this.w *= l;
+ return this;
+};
- proto.scale = function(scale){ //= cc.kmVec4Scale
- /// Scales a vector to the required length. This performs a Normalize before multiplying by S.
- this.normalize();
- this.x *= scale;
- this.y *= scale;
- this.z *= scale;
- this.w *= scale;
- return this;
- };
+proto.scale = function(scale){ //= cc.kmVec4Scale
+ /// Scales a vector to the required length. This performs a Normalize before multiplying by S.
+ this.normalize();
+ this.x *= scale;
+ this.y *= scale;
+ this.z *= scale;
+ this.w *= scale;
+ return this;
+};
- proto.subtract = function(vec) {
- this.x -= vec.x;
- this.y -= vec.y;
- this.z -= vec.z;
- this.w -= vec.w;
- };
+proto.subtract = function(vec) {
+ this.x -= vec.x;
+ this.y -= vec.y;
+ this.z -= vec.z;
+ this.w -= vec.w;
+};
- proto.transform = function(mat4) {
- var x = this.x, y = this.y, z = this.z, w = this.w, mat = mat4.mat;
- this.x = x * mat[0] + y * mat[4] + z * mat[8] + w * mat[12];
- this.y = x * mat[1] + y * mat[5] + z * mat[9] + w * mat[13];
- this.z = x * mat[2] + y * mat[6] + z * mat[10] + w * mat[14];
- this.w = x * mat[3] + y * mat[7] + z * mat[11] + w * mat[15];
- return this;
- };
+proto.transform = function(mat4) {
+ var x = this.x, y = this.y, z = this.z, w = this.w, mat = mat4.mat;
+ this.x = x * mat[0] + y * mat[4] + z * mat[8] + w * mat[12];
+ this.y = x * mat[1] + y * mat[5] + z * mat[9] + w * mat[13];
+ this.z = x * mat[2] + y * mat[6] + z * mat[10] + w * mat[14];
+ this.w = x * mat[3] + y * mat[7] + z * mat[11] + w * mat[15];
+ return this;
+};
- cc.math.Vec4.transformArray = function(vecArray, mat4){
- var retArray = [];
- for (var i = 0; i < vecArray.length; i++) {
- var selVec = new cc.math.Vec4(vecArray[i]);
- selVec.transform(mat4);
- retArray.push(selVec);
- }
- return retArray;
- };
+cc.math.Vec4.transformArray = function(vecArray, mat4){
+ var retArray = [];
+ for (var i = 0; i < vecArray.length; i++) {
+ var selVec = new cc.math.Vec4(vecArray[i]);
+ selVec.transform(mat4);
+ retArray.push(selVec);
+ }
+ return retArray;
+};
- proto.equals = function(vec){ //=cc.kmVec4AreEqual
- var EPSILON = cc.math.EPSILON;
- return (this.x < vec.x + EPSILON && this.x > vec.x - EPSILON) &&
- (this.y < vec.y + EPSILON && this.y > vec.y - EPSILON) &&
- (this.z < vec.z + EPSILON && this.z > vec.z - EPSILON) &&
- (this.w < vec.w + EPSILON && this.w > vec.w - EPSILON);
- };
-
- proto.assignFrom = function(vec) { //= cc.kmVec4Assign
- this.x = vec.x;
- this.y = vec.y;
- this.z = vec.z;
- this.w = vec.w;
- return this;
- };
-
- proto.toTypeArray = function(){ //cc.kmVec4ToTypeArray
- var tyArr = new Float32Array(4);
- tyArr[0] = this.x;
- tyArr[1] = this.y;
- tyArr[2] = this.z;
- tyArr[3] = this.w;
- return tyArr;
- };
-})(cc);
+proto.equals = function(vec){ //=cc.kmVec4AreEqual
+ var EPSILON = cc.math.EPSILON;
+ return (this.x < vec.x + EPSILON && this.x > vec.x - EPSILON) &&
+ (this.y < vec.y + EPSILON && this.y > vec.y - EPSILON) &&
+ (this.z < vec.z + EPSILON && this.z > vec.z - EPSILON) &&
+ (this.w < vec.w + EPSILON && this.w > vec.w - EPSILON);
+};
+proto.assignFrom = function(vec) { //= cc.kmVec4Assign
+ this.x = vec.x;
+ this.y = vec.y;
+ this.z = vec.z;
+ this.w = vec.w;
+ return this;
+};
+proto.toTypeArray = function(){ //cc.kmVec4ToTypeArray
+ var tyArr = new Float32Array(4);
+ tyArr[0] = this.x;
+ tyArr[1] = this.y;
+ tyArr[2] = this.z;
+ tyArr[3] = this.w;
+ return tyArr;
+};
diff --git a/cocos2d/labels/CCLabelAtlasWebGLRenderCmd.js b/cocos2d/labels/CCLabelAtlasWebGLRenderCmd.js
index 3e0b3bccc7..d6bf60bf63 100644
--- a/cocos2d/labels/CCLabelAtlasWebGLRenderCmd.js
+++ b/cocos2d/labels/CCLabelAtlasWebGLRenderCmd.js
@@ -39,7 +39,7 @@
proto.rendering = function(ctx){
cc.AtlasNode.WebGLRenderCmd.prototype.rendering.call(this, ctx);
- if (cc.Macro.LABELATLAS_DEBUG_DRAW) {
+ if (cc.macro.LABELATLAS_DEBUG_DRAW) {
var node = this._node;
var s = node.getContentSize();
var locRect = node.getBoundingBoxToWorld();
@@ -82,7 +82,7 @@
cr++;
var left, right, top, bottom;
- if (cc.Macro.FIX_ARTIFACTS_BY_STRECHING_TEXEL) {
+ if (cc.macro.FIX_ARTIFACTS_BY_STRECHING_TEXEL) {
// Issue #938. Don't use texStepX & texStepY
left = (2 * row * itemWidth + 1) / (2 * textureWide);
right = left + (itemWidth * 2 - 2) / (2 * textureWide);
diff --git a/cocos2d/labels/CCLabelBMFontWebGLRenderCmd.js b/cocos2d/labels/CCLabelBMFontWebGLRenderCmd.js
index 37031c5b6a..9c5f202817 100644
--- a/cocos2d/labels/CCLabelBMFontWebGLRenderCmd.js
+++ b/cocos2d/labels/CCLabelBMFontWebGLRenderCmd.js
@@ -71,7 +71,7 @@
var node = this._node;
//LabelBMFont - Debug draw
- if (cc.Macro.LABELBMFONT_DEBUG_DRAW) {
+ if (cc.macro.LABELBMFONT_DEBUG_DRAW) {
var size = node.getContentSize();
var pos = cc.p(0 | ( -this._anchorPointInPoints.x), 0 | ( -this._anchorPointInPoints.y));
var vertices = [cc.p(pos.x, pos.y), cc.p(pos.x + size.width, pos.y), cc.p(pos.x + size.width, pos.y + size.height), cc.p(pos.x, pos.y + size.height)];
diff --git a/cocos2d/menus/CCMenuItem.js b/cocos2d/menus/CCMenuItem.js
index 7a6ee83580..0774672245 100644
--- a/cocos2d/menus/CCMenuItem.js
+++ b/cocos2d/menus/CCMenuItem.js
@@ -24,7 +24,7 @@
THE SOFTWARE.
****************************************************************************/
-cc._globalFontSize = cc.Macro.ITEM_SIZE;
+cc._globalFontSize = cc.macro.ITEM_SIZE;
cc._globalFontName = "Arial";
cc._globalFontNameRelease = false;
@@ -362,14 +362,14 @@ cc.MenuItemLabel = cc.MenuItem.extend(/** @lends cc.MenuItemLabel# */{
if (this._enabled) {
cc.MenuItem.prototype.selected.call(this);
- var action = this.getActionByTag(cc.Macro.ZOOM_ACTION_TAG);
+ var action = this.getActionByTag(cc.macro.ZOOM_ACTION_TAG);
if (action)
this.stopAction(action);
else
this._originalScale = this.scale;
var zoomAction = cc.scaleTo(0.1, this._originalScale * 1.2);
- zoomAction.setTag(cc.Macro.ZOOM_ACTION_TAG);
+ zoomAction.setTag(cc.macro.ZOOM_ACTION_TAG);
this.runAction(zoomAction);
}
},
@@ -380,9 +380,9 @@ cc.MenuItemLabel = cc.MenuItem.extend(/** @lends cc.MenuItemLabel# */{
unselected: function () {
if (this._enabled) {
cc.MenuItem.prototype.unselected.call(this);
- this.stopActionByTag(cc.Macro.ZOOM_ACTION_TAG);
+ this.stopActionByTag(cc.macro.ZOOM_ACTION_TAG);
var zoomAction = cc.scaleTo(0.1, this._originalScale);
- zoomAction.setTag(cc.Macro.ZOOM_ACTION_TAG);
+ zoomAction.setTag(cc.macro.ZOOM_ACTION_TAG);
this.runAction(zoomAction);
}
}
@@ -732,7 +732,7 @@ cc.MenuItemSprite = cc.MenuItem.extend(/** @lends cc.MenuItemSprite# */{
return;
}
if (normalImage) {
- this.addChild(normalImage, 0, cc.Macro.NORMAL_TAG);
+ this.addChild(normalImage, 0, cc.macro.NORMAL_TAG);
normalImage.anchorX = 0;
normalImage.anchorY = 0;
}
@@ -773,7 +773,7 @@ cc.MenuItemSprite = cc.MenuItem.extend(/** @lends cc.MenuItemSprite# */{
return;
if (selectedImage) {
- this.addChild(selectedImage, 0, cc.Macro.SELECTED_TAG);
+ this.addChild(selectedImage, 0, cc.macro.SELECTED_TAG);
selectedImage.anchorX = 0;
selectedImage.anchorY = 0;
}
@@ -803,7 +803,7 @@ cc.MenuItemSprite = cc.MenuItem.extend(/** @lends cc.MenuItemSprite# */{
return;
if (disabledImage) {
- this.addChild(disabledImage, 0, cc.Macro.DISABLE_TAG);
+ this.addChild(disabledImage, 0, cc.macro.DISABLE_TAG);
disabledImage.anchorX = 0;
disabledImage.anchorY = 0;
}
@@ -1180,12 +1180,12 @@ cc.MenuItemToggle = cc.MenuItem.extend(/** @lends cc.MenuItemToggle# */{
setSelectedIndex: function (SelectedIndex) {
if (SelectedIndex !== this._selectedIndex) {
this._selectedIndex = SelectedIndex;
- var currItem = this.getChildByTag(cc.Macro.CURRENT_ITEM);
+ var currItem = this.getChildByTag(cc.macro.CURRENT_ITEM);
if (currItem)
currItem.removeFromParent(false);
var item = this.subItems[this._selectedIndex];
- this.addChild(item, 0, cc.Macro.CURRENT_ITEM);
+ this.addChild(item, 0, cc.macro.CURRENT_ITEM);
var w = item.width, h = item.height;
this.width = w;
this.height = h;
@@ -1235,7 +1235,7 @@ cc.MenuItemToggle = cc.MenuItem.extend(/** @lends cc.MenuItemToggle# */{
if (args[i])
locSubItems.push(args[i]);
}
- this._selectedIndex = cc.Macro.UINT_MAX;
+ this._selectedIndex = cc.macro.UINT_MAX;
this.setSelectedIndex(0);
this.setCascadeColorEnabled(true);
diff --git a/cocos2d/motion-streak/CCMotionStreak.js b/cocos2d/motion-streak/CCMotionStreak.js
index 66d533c48d..17bcbb59c4 100644
--- a/cocos2d/motion-streak/CCMotionStreak.js
+++ b/cocos2d/motion-streak/CCMotionStreak.js
@@ -84,7 +84,7 @@ cc.MotionStreak = _ccsg.Node.extend(/** @lends cc.MotionStreak# */{
ctor: function (fade, minSeg, stroke, color, texture) {
_ccsg.Node.prototype.ctor.call(this);
this._positionR = cc.p(0, 0);
- this._blendFunc = new cc.BlendFunc(cc.Macro.SRC_ALPHA, cc.Macro.ONE_MINUS_SRC_ALPHA);
+ this._blendFunc = new cc.BlendFunc(cc.macro.SRC_ALPHA, cc.macro.ONE_MINUS_SRC_ALPHA);
this.fastMode = false;
this.startingPositionInitialized = false;
diff --git a/cocos2d/motion-streak/CCMotionStreakWebGLRenderCmd.js b/cocos2d/motion-streak/CCMotionStreakWebGLRenderCmd.js
index b47388541a..25ab3c3058 100644
--- a/cocos2d/motion-streak/CCMotionStreakWebGLRenderCmd.js
+++ b/cocos2d/motion-streak/CCMotionStreakWebGLRenderCmd.js
@@ -25,7 +25,7 @@
cc.MotionStreak.WebGLRenderCmd = function(renderableObject){
_ccsg.Node.WebGLRenderCmd.call(this, renderableObject);
this._needDraw = true;
- this._shaderProgram = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLOR);
+ this._shaderProgram = cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLOR);
};
cc.MotionStreak.WebGLRenderCmd.prototype = Object.create(_ccsg.Node.WebGLRenderCmd.prototype);
@@ -40,7 +40,7 @@ cc.MotionStreak.WebGLRenderCmd.prototype.rendering = function(ctx){
ctx = ctx || cc._renderContext;
this._shaderProgram.use();
this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix);
- cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
+ cc.glEnableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst);
cc.glBindTexture2D(node.texture);
@@ -48,17 +48,17 @@ cc.MotionStreak.WebGLRenderCmd.prototype.rendering = function(ctx){
//position
ctx.bindBuffer(ctx.ARRAY_BUFFER, node._verticesBuffer);
ctx.bufferData(ctx.ARRAY_BUFFER, node._vertices, ctx.DYNAMIC_DRAW);
- ctx.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, ctx.FLOAT, false, 0, 0);
+ ctx.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_POSITION, 2, ctx.FLOAT, false, 0, 0);
//texcoords
ctx.bindBuffer(ctx.ARRAY_BUFFER, node._texCoordsBuffer);
ctx.bufferData(ctx.ARRAY_BUFFER, node._texCoords, ctx.DYNAMIC_DRAW);
- ctx.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_TEX_COORDS, 2, ctx.FLOAT, false, 0, 0);
+ ctx.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_TEX_COORDS, 2, ctx.FLOAT, false, 0, 0);
//colors
ctx.bindBuffer(ctx.ARRAY_BUFFER, node._colorPointerBuffer);
ctx.bufferData(ctx.ARRAY_BUFFER, node._colorPointer, ctx.DYNAMIC_DRAW);
- ctx.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_COLOR, 4, ctx.UNSIGNED_BYTE, true, 0, 0);
+ ctx.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_COLOR, 4, ctx.UNSIGNED_BYTE, true, 0, 0);
ctx.drawArrays(ctx.TRIANGLE_STRIP, 0, node._nuPoints * 2);
cc.g_NumberOfDraws++;
diff --git a/cocos2d/node-grid/CCNodeGrid.js b/cocos2d/node-grid/CCNodeGrid.js
index efa4bcd0dd..0e59aa5904 100644
--- a/cocos2d/node-grid/CCNodeGrid.js
+++ b/cocos2d/node-grid/CCNodeGrid.js
@@ -101,7 +101,7 @@ cc.NodeGrid = _ccsg.Node.extend({
t4x4Mat[14] = this._vertexZ;
//optimize performance for Javascript
- topMat4.multiply(t4x4) ; // = cc.kmGLMultMatrix(this._transform4x4);
+ topMat4.multiply(t4x4) ; // = cc.math.glMultMatrix(this._transform4x4);
// XXX: Expensive calls. Camera should be integrated into the cached affine matrix
if (this._camera !== null && !(this.grid && this.grid.isActive())) {
@@ -109,7 +109,7 @@ cc.NodeGrid = _ccsg.Node.extend({
apx = app.x, apy = app.y,
translate = (apx !== 0.0 || apy !== 0.0);
if (translate) {
- if(!cc.Macro.SPRITEBATCHNODE_RENDER_SUBPIXEL) {
+ if(!cc.macro.SPRITEBATCHNODE_RENDER_SUBPIXEL) {
apx = 0 | apx;
apy = 0 | apy;
}
diff --git a/cocos2d/node-grid/CCNodeGridWebGLRenderCmd.js b/cocos2d/node-grid/CCNodeGridWebGLRenderCmd.js
index 3bf8e9e7a4..5ac176e37d 100644
--- a/cocos2d/node-grid/CCNodeGridWebGLRenderCmd.js
+++ b/cocos2d/node-grid/CCNodeGridWebGLRenderCmd.js
@@ -50,14 +50,14 @@
/*var beforeProjectionType = cc.director.PROJECTION_DEFAULT;
if (locGrid && locGrid._active) {
- //var backMatrix = new cc.kmMat4();
- //cc.kmMat4Assign(backMatrix, this._stackMatrix);
+ //var backMatrix = new cc.math.Matrix4();
+ //cc.math.mat4Assign(backMatrix, this._stackMatrix);
beforeProjectionType = cc.director.getProjection();
//locGrid.set2DProjection();
//reset this._stackMatrix to current_stack.top
- //cc.kmMat4Assign(currentStack.top, backMatrix);
+ //cc.math.mat4Assign(currentStack.top, backMatrix);
}*/
cc.renderer.pushRenderCommand(this._gridBeginCommand);
diff --git a/cocos2d/particle/CCParticleBatchNode.js b/cocos2d/particle/CCParticleBatchNode.js
index daff2faf5b..505c738357 100644
--- a/cocos2d/particle/CCParticleBatchNode.js
+++ b/cocos2d/particle/CCParticleBatchNode.js
@@ -93,7 +93,7 @@ cc.ParticleBatchNode = _ccsg.Node.extend(/** @lends cc.ParticleBatchNode# */{
*/
ctor:function (fileImage, capacity) {
_ccsg.Node.prototype.ctor.call(this);
- this._blendFunc = {src:cc.Macro.BLEND_SRC, dst:cc.Macro.BLEND_DST};
+ this._blendFunc = {src:cc.macro.BLEND_SRC, dst:cc.macro.BLEND_DST};
if (cc.js.isString(fileImage)) {
this.init(fileImage, capacity);
} else if (fileImage instanceof cc.Texture2D) {
@@ -350,9 +350,9 @@ cc.ParticleBatchNode = _ccsg.Node.extend(/** @lends cc.ParticleBatchNode# */{
// If the new texture has No premultiplied alpha, AND the blendFunc hasn't been changed, then update it
var locBlendFunc = this._blendFunc;
- if (texture && !texture.hasPremultipliedAlpha() && ( locBlendFunc.src === cc.Macro.BLEND_SRC && locBlendFunc.dst === cc.Macro.BLEND_DST )) {
- locBlendFunc.src = cc.Macro.SRC_ALPHA;
- locBlendFunc.dst = cc.Macro.ONE_MINUS_SRC_ALPHA;
+ if (texture && !texture.hasPremultipliedAlpha() && ( locBlendFunc.src === cc.macro.BLEND_SRC && locBlendFunc.dst === cc.macro.BLEND_DST )) {
+ locBlendFunc.src = cc.macro.SRC_ALPHA;
+ locBlendFunc.dst = cc.macro.ONE_MINUS_SRC_ALPHA;
}
},
@@ -485,8 +485,8 @@ cc.ParticleBatchNode = _ccsg.Node.extend(/** @lends cc.ParticleBatchNode# */{
_updateBlendFunc:function () {
if (!this.textureAtlas.texture.hasPremultipliedAlpha()) {
- this._blendFunc.src = cc.Macro.SRC_ALPHA;
- this._blendFunc.dst = cc.Macro.ONE_MINUS_SRC_ALPHA;
+ this._blendFunc.src = cc.macro.SRC_ALPHA;
+ this._blendFunc.dst = cc.macro.ONE_MINUS_SRC_ALPHA;
}
},
diff --git a/cocos2d/particle/CCParticleBatchNodeWebGLRenderCmd.js b/cocos2d/particle/CCParticleBatchNodeWebGLRenderCmd.js
index ba8caa0ab9..669d30d764 100644
--- a/cocos2d/particle/CCParticleBatchNodeWebGLRenderCmd.js
+++ b/cocos2d/particle/CCParticleBatchNodeWebGLRenderCmd.js
@@ -46,7 +46,7 @@
};
proto._initWithTexture = function(){
- this._shaderProgram = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLOR);
+ this._shaderProgram = cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLOR);
};
proto.visit = function(parentCmd){
@@ -69,6 +69,6 @@
cc.renderer.pushRenderCommand(this);
this._dirtyFlag = 0;
- cc.kmGLPopMatrix();
+ cc.math.glPopMatrix();
};
})();
\ No newline at end of file
diff --git a/cocos2d/particle/CCSGParticleSystem.js b/cocos2d/particle/CCSGParticleSystem.js
index c05f659798..1c04be344f 100644
--- a/cocos2d/particle/CCSGParticleSystem.js
+++ b/cocos2d/particle/CCSGParticleSystem.js
@@ -290,7 +290,7 @@ _ccsg.ParticleSystem = _ccsg.Node.extend({
this.emitterMode = _ccsg.ParticleSystem.Mode.GRAVITY;
this.modeA = new _ccsg.ParticleSystem.ModeA();
this.modeB = new _ccsg.ParticleSystem.ModeB();
- this._blendFunc = {src:cc.Macro.BLEND_SRC, dst:cc.Macro.BLEND_DST};
+ this._blendFunc = {src:cc.macro.BLEND_SRC, dst:cc.macro.BLEND_DST};
this._particles = [];
this._sourcePosition = cc.p(0, 0);
@@ -1128,8 +1128,8 @@ _ccsg.ParticleSystem = _ccsg.Node.extend({
* dest blend function = GL_ONE;
*/
isBlendAdditive:function () {
- return (( this._blendFunc.src === cc.Macro.SRC_ALPHA && this._blendFunc.dst === cc.Macro.ONE) ||
- (this._blendFunc.src === cc.Macro.ONE && this._blendFunc.dst === cc.Macro.ONE));
+ return (( this._blendFunc.src === cc.macro.SRC_ALPHA && this._blendFunc.dst === cc.macro.ONE) ||
+ (this._blendFunc.src === cc.macro.ONE && this._blendFunc.dst === cc.macro.ONE));
},
/**
@@ -1141,8 +1141,8 @@ _ccsg.ParticleSystem = _ccsg.Node.extend({
setBlendAdditive:function (isBlendAdditive) {
var locBlendFunc = this._blendFunc;
if (isBlendAdditive) {
- locBlendFunc.src = cc.Macro.SRC_ALPHA;
- locBlendFunc.dst = cc.Macro.ONE;
+ locBlendFunc.src = cc.macro.SRC_ALPHA;
+ locBlendFunc.dst = cc.macro.ONE;
} else {
this._renderCmd._setBlendAdditive();
}
@@ -1445,8 +1445,8 @@ _ccsg.ParticleSystem = _ccsg.Node.extend({
this._isActive = true;
// default blend function
- this._blendFunc.src = cc.Macro.BLEND_SRC;
- this._blendFunc.dst = cc.Macro.BLEND_DST;
+ this._blendFunc.src = cc.macro.BLEND_SRC;
+ this._blendFunc.dst = cc.macro.BLEND_DST;
// default movement type;
this.positionType = _ccsg.ParticleSystem.Type.FREE;
@@ -1831,12 +1831,12 @@ _ccsg.ParticleSystem = _ccsg.Node.extend({
if (locTexture && locTexture instanceof cc.Texture2D) {
this._opacityModifyRGB = false;
var locBlendFunc = this._blendFunc;
- if (locBlendFunc.src === cc.Macro.BLEND_SRC && locBlendFunc.dst === cc.Macro.BLEND_DST) {
+ if (locBlendFunc.src === cc.macro.BLEND_SRC && locBlendFunc.dst === cc.macro.BLEND_DST) {
if (locTexture.hasPremultipliedAlpha()) {
this._opacityModifyRGB = true;
} else {
- locBlendFunc.src = cc.Macro.SRC_ALPHA;
- locBlendFunc.dst = cc.Macro.ONE_MINUS_SRC_ALPHA;
+ locBlendFunc.src = cc.macro.SRC_ALPHA;
+ locBlendFunc.dst = cc.macro.ONE_MINUS_SRC_ALPHA;
}
}
}
diff --git a/cocos2d/particle/CCSGParticleSystemCanvasRenderCmd.js b/cocos2d/particle/CCSGParticleSystemCanvasRenderCmd.js
index b206c2a3ff..67c2e52945 100644
--- a/cocos2d/particle/CCSGParticleSystemCanvasRenderCmd.js
+++ b/cocos2d/particle/CCSGParticleSystemCanvasRenderCmd.js
@@ -182,8 +182,8 @@
proto._setBlendAdditive = function(){
var locBlendFunc = this._node._blendFunc;
- locBlendFunc.src = cc.Macro.BLEND_SRC;
- locBlendFunc.dst = cc.Macro.BLEND_DST;
+ locBlendFunc.src = cc.macro.BLEND_SRC;
+ locBlendFunc.dst = cc.macro.BLEND_DST;
};
proto._initWithTotalParticles = function(totalParticles){};
diff --git a/cocos2d/particle/CCSGParticleSystemWebGLRenderCmd.js b/cocos2d/particle/CCSGParticleSystemWebGLRenderCmd.js
index 48c7834c18..caa6f99d02 100644
--- a/cocos2d/particle/CCSGParticleSystemWebGLRenderCmd.js
+++ b/cocos2d/particle/CCSGParticleSystemWebGLRenderCmd.js
@@ -195,12 +195,12 @@
//
// Using VBO without VAO
//
- cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
+ cc.glEnableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
gl.bindBuffer(gl.ARRAY_BUFFER, this._buffersVBO[0]);
- gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 3, gl.FLOAT, false, 24, 0); // vertices
- gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_COLOR, 4, gl.UNSIGNED_BYTE, true, 24, 12); // colors
- gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_TEX_COORDS, 2, gl.FLOAT, false, 24, 16); // tex coords
+ gl.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_POSITION, 3, gl.FLOAT, false, 24, 0); // vertices
+ gl.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_COLOR, 4, gl.UNSIGNED_BYTE, true, 24, 12); // colors
+ gl.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_TEX_COORDS, 2, gl.FLOAT, false, 24, 16); // tex coords
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._buffersVBO[1]);
gl.drawElements(gl.TRIANGLES, node._particleIdx * 6, gl.UNSIGNED_SHORT, 0);
@@ -219,7 +219,7 @@
}
var left, bottom, right, top;
- if (cc.Macro.FIX_ARTIFACTS_BY_STRECHING_TEXEL) {
+ if (cc.macro.FIX_ARTIFACTS_BY_STRECHING_TEXEL) {
left = (pointRect.x * 2 + 1) / (wide * 2);
bottom = (pointRect.y * 2 + 1) / (high * 2);
right = left + (pointRect.width * 2 - 2) / (wide * 2);
@@ -365,11 +365,11 @@
proto._setBlendAdditive = function(){
var locBlendFunc = this._node._blendFunc;
if (this._texture && !this._texture.hasPremultipliedAlpha()) {
- locBlendFunc.src = cc.Macro.SRC_ALPHA;
- locBlendFunc.dst = cc.Macro.ONE_MINUS_SRC_ALPHA;
+ locBlendFunc.src = cc.macro.SRC_ALPHA;
+ locBlendFunc.dst = cc.macro.ONE_MINUS_SRC_ALPHA;
} else {
- locBlendFunc.src = cc.Macro.BLEND_SRC;
- locBlendFunc.dst = cc.Macro.BLEND_DST;
+ locBlendFunc.src = cc.macro.BLEND_SRC;
+ locBlendFunc.dst = cc.macro.BLEND_DST;
}
};
@@ -381,7 +381,7 @@
this.initIndices(totalParticles);
this._setupVBO();
- this._shaderProgram = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLOR);
+ this._shaderProgram = cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLOR);
};
proto._updateDeltaColor = function (selParticle, dt) {
diff --git a/cocos2d/progress-timer/CCProgressTimerWebGLRenderCmd.js b/cocos2d/progress-timer/CCProgressTimerWebGLRenderCmd.js
index 47406e3808..58a7a53b7b 100644
--- a/cocos2d/progress-timer/CCProgressTimerWebGLRenderCmd.js
+++ b/cocos2d/progress-timer/CCProgressTimerWebGLRenderCmd.js
@@ -51,7 +51,7 @@
var blendFunc = node._sprite._blendFunc;
cc.glBlendFunc(blendFunc.src, blendFunc.dst);
- cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
+ cc.glEnableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
cc.glBindTexture2D(node._sprite.texture);
@@ -61,9 +61,9 @@
this._vertexDataDirty = false;
}
var locVertexDataLen = cc.V2F_C4B_T2F.BYTES_PER_ELEMENT;
- context.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, context.FLOAT, false, locVertexDataLen, 0);
- context.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_COLOR, 4, context.UNSIGNED_BYTE, true, locVertexDataLen, 8);
- context.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_TEX_COORDS, 2, context.FLOAT, false, locVertexDataLen, 12);
+ context.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_POSITION, 2, context.FLOAT, false, locVertexDataLen, 0);
+ context.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_COLOR, 4, context.UNSIGNED_BYTE, true, locVertexDataLen, 8);
+ context.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_TEX_COORDS, 2, context.FLOAT, false, locVertexDataLen, 12);
if (node._type === cc.ProgressTimer.Type.RADIAL)
context.drawArrays(context.TRIANGLE_FAN, 0, this._vertexDataCount);
@@ -169,7 +169,7 @@
this._vertexDataCount = 0;
//shader program
- this._shaderProgram = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLOR);
+ this._shaderProgram = cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLOR);
};
proto._updateProgress = function(){
@@ -342,7 +342,7 @@
// intersection point
// We loop through five points since the top is split in half
- var min_t = cc.Macro.FLT_MAX;
+ var min_t = cc.macro.FLT_MAX;
var locProTextCoordsCount = cc.ProgressTimer.TEXTURE_COORDS_COUNT;
for (i = 0; i <= locProTextCoordsCount; ++i) {
var pIndex = (i + (locProTextCoordsCount - 1)) % locProTextCoordsCount;
diff --git a/cocos2d/render-texture/CCRenderTextureCanvasRenderCmd.js b/cocos2d/render-texture/CCRenderTextureCanvasRenderCmd.js
index 7172765279..1e31fdbc46 100644
--- a/cocos2d/render-texture/CCRenderTextureCanvasRenderCmd.js
+++ b/cocos2d/render-texture/CCRenderTextureCanvasRenderCmd.js
@@ -59,7 +59,7 @@
texture.handleLoadedTexture();
var locSprite = node.sprite = new _ccsg.Sprite(texture);
- locSprite.setBlendFunc(cc.Macro.ONE, cc.Macro.ONE_MINUS_SRC_ALPHA);
+ locSprite.setBlendFunc(cc.macro.ONE, cc.macro.ONE_MINUS_SRC_ALPHA);
// Disabled by default.
node.autoDraw = false;
// add sprite for backward compatibility
diff --git a/cocos2d/render-texture/CCRenderTextureWebGLRenderCmd.js b/cocos2d/render-texture/CCRenderTextureWebGLRenderCmd.js
index e35ce64b97..c59ebe7655 100644
--- a/cocos2d/render-texture/CCRenderTextureWebGLRenderCmd.js
+++ b/cocos2d/render-texture/CCRenderTextureWebGLRenderCmd.js
@@ -222,10 +222,10 @@
proto.begin = function(){
var node = this._node;
// Save the current matrix
- cc.kmGLMatrixMode(cc.KM_GL_PROJECTION);
- cc.kmGLPushMatrix();
- cc.kmGLMatrixMode(cc.KM_GL_MODELVIEW);
- cc.kmGLPushMatrix();
+ cc.math.glMatrixMode(cc.math.KM_GL_PROJECTION);
+ cc.math.glPushMatrix();
+ cc.math.glMatrixMode(cc.math.KM_GL_MODELVIEW);
+ cc.math.glPushMatrix();
var gl = cc._renderContext;
@@ -241,7 +241,7 @@
var orthoMatrix = cc.math.Matrix4.createOrthographicProjection(-1.0 / widthRatio, 1.0 / widthRatio,
-1.0 / heightRatio, 1.0 / heightRatio, -1, 1);
- cc.kmGLMultMatrix(orthoMatrix);
+ cc.math.glMultMatrix(orthoMatrix);
//calculate viewport
var viewport = new cc.Rect(0, 0, 0, 0);
@@ -321,10 +321,10 @@
//restore viewport
director.setViewport();
- cc.kmGLMatrixMode(cc.KM_GL_PROJECTION);
- cc.kmGLPopMatrix();
- cc.kmGLMatrixMode(cc.KM_GL_MODELVIEW);
- cc.kmGLPopMatrix();
+ cc.math.glMatrixMode(cc.math.KM_GL_PROJECTION);
+ cc.math.glPopMatrix();
+ cc.math.glMatrixMode(cc.math.KM_GL_MODELVIEW);
+ cc.math.glPopMatrix();
/* var size = director.getWinSizeInPixels();
@@ -382,6 +382,6 @@
locGrid.afterDraw(this);*/
this._dirtyFlag = 0;
- cc.kmGLPopMatrix();
+ cc.math.glPopMatrix();
};
})();
\ No newline at end of file
diff --git a/cocos2d/shaders/CCGLProgram.js b/cocos2d/shaders/CCGLProgram.js
index 0cd2f84931..1f35ee6a89 100644
--- a/cocos2d/shaders/CCGLProgram.js
+++ b/cocos2d/shaders/CCGLProgram.js
@@ -26,12 +26,15 @@
THE SOFTWARE.
****************************************************************************/
-cc.HashUniformEntry = function (value, location, hh) {
+var HashUniformEntry = function (value, location, hh) {
this.value = value;
this.location = location;
this.hh = hh || {};
};
+var math = cc.math;
+var macro = cc.macro;
+
/**
* Class that implements a WebGL program
* @class
@@ -58,7 +61,7 @@ cc.GLProgram = cc._Class.extend(/** @lends cc.GLProgram# */{
element = this._hashForUniforms[i];
if (!element) {
- element = new cc.HashUniformEntry();
+ element = new HashUniformEntry();
// key
element.location = location;
// value
@@ -261,27 +264,27 @@ cc.GLProgram = cc._Class.extend(/** @lends cc.GLProgram# */{
/**
* It will create 4 uniforms:
- * cc.Macro.UNIFORM_PMATRIX
- * cc.Macro.UNIFORM_MVMATRIX
- * cc.Macro.UNIFORM_MVPMATRIX
- * cc.Macro.UNIFORM_SAMPLER
+ * cc.macro.UNIFORM_PMATRIX
+ * cc.macro.UNIFORM_MVMATRIX
+ * cc.macro.UNIFORM_MVPMATRIX
+ * cc.macro.UNIFORM_SAMPLER
*/
updateUniforms: function () {
- this._uniforms[cc.Macro.UNIFORM_PMATRIX] = this._glContext.getUniformLocation(this._programObj, cc.Macro.UNIFORM_PMATRIX_S);
- this._uniforms[cc.Macro.UNIFORM_MVMATRIX] = this._glContext.getUniformLocation(this._programObj, cc.Macro.UNIFORM_MVMATRIX_S);
- this._uniforms[cc.Macro.UNIFORM_MVPMATRIX] = this._glContext.getUniformLocation(this._programObj, cc.Macro.UNIFORM_MVPMATRIX_S);
- this._uniforms[cc.Macro.UNIFORM_TIME] = this._glContext.getUniformLocation(this._programObj, cc.Macro.UNIFORM_TIME_S);
- this._uniforms[cc.Macro.UNIFORM_SINTIME] = this._glContext.getUniformLocation(this._programObj, cc.Macro.UNIFORM_SINTIME_S);
- this._uniforms[cc.Macro.UNIFORM_COSTIME] = this._glContext.getUniformLocation(this._programObj, cc.Macro.UNIFORM_COSTIME_S);
+ this._uniforms[macro.UNIFORM_PMATRIX] = this._glContext.getUniformLocation(this._programObj, macro.UNIFORM_PMATRIX_S);
+ this._uniforms[macro.UNIFORM_MVMATRIX] = this._glContext.getUniformLocation(this._programObj, macro.UNIFORM_MVMATRIX_S);
+ this._uniforms[macro.UNIFORM_MVPMATRIX] = this._glContext.getUniformLocation(this._programObj, macro.UNIFORM_MVPMATRIX_S);
+ this._uniforms[macro.UNIFORM_TIME] = this._glContext.getUniformLocation(this._programObj, macro.UNIFORM_TIME_S);
+ this._uniforms[macro.UNIFORM_SINTIME] = this._glContext.getUniformLocation(this._programObj, macro.UNIFORM_SINTIME_S);
+ this._uniforms[macro.UNIFORM_COSTIME] = this._glContext.getUniformLocation(this._programObj, macro.UNIFORM_COSTIME_S);
- this._usesTime = (this._uniforms[cc.Macro.UNIFORM_TIME] != null || this._uniforms[cc.Macro.UNIFORM_SINTIME] != null || this._uniforms[cc.Macro.UNIFORM_COSTIME] != null);
+ this._usesTime = (this._uniforms[macro.UNIFORM_TIME] != null || this._uniforms[macro.UNIFORM_SINTIME] != null || this._uniforms[macro.UNIFORM_COSTIME] != null);
- this._uniforms[cc.Macro.UNIFORM_RANDOM01] = this._glContext.getUniformLocation(this._programObj, cc.Macro.UNIFORM_RANDOM01_S);
- this._uniforms[cc.Macro.UNIFORM_SAMPLER] = this._glContext.getUniformLocation(this._programObj, cc.Macro.UNIFORM_SAMPLER_S);
+ this._uniforms[macro.UNIFORM_RANDOM01] = this._glContext.getUniformLocation(this._programObj, macro.UNIFORM_RANDOM01_S);
+ this._uniforms[macro.UNIFORM_SAMPLER] = this._glContext.getUniformLocation(this._programObj, macro.UNIFORM_SAMPLER_S);
this.use();
// Since sample most probably won't change, set it to 0 now.
- this.setUniformLocationWith1i(this._uniforms[cc.Macro.UNIFORM_SAMPLER], 0);
+ this.setUniformLocationWith1i(this._uniforms[macro.UNIFORM_SAMPLER], 0);
},
/**
@@ -303,7 +306,7 @@ cc.GLProgram = cc._Class.extend(/** @lends cc.GLProgram# */{
* @returns {WebGLUniformLocation}
*/
getUniformMVPMatrix: function () {
- return this._uniforms[cc.Macro.UNIFORM_MVPMATRIX];
+ return this._uniforms[macro.UNIFORM_MVPMATRIX];
},
/**
@@ -311,7 +314,7 @@ cc.GLProgram = cc._Class.extend(/** @lends cc.GLProgram# */{
* @returns {WebGLUniformLocation}
*/
getUniformSampler: function () {
- return this._uniforms[cc.Macro.UNIFORM_SAMPLER];
+ return this._uniforms[macro.UNIFORM_SAMPLER];
},
/**
@@ -543,18 +546,18 @@ cc.GLProgram = cc._Class.extend(/** @lends cc.GLProgram# */{
* will update the builtin uniforms if they are different than the previous call for this same shader program.
*/
setUniformsForBuiltins: function () {
- var matrixP = new cc.math.Matrix4();
- var matrixMV = new cc.math.Matrix4();
- var matrixMVP = new cc.math.Matrix4();
+ var matrixP = new math.Matrix4();
+ var matrixMV = new math.Matrix4();
+ var matrixMVP = new math.Matrix4();
- cc.kmGLGetMatrix(cc.KM_GL_PROJECTION, matrixP);
- cc.kmGLGetMatrix(cc.KM_GL_MODELVIEW, matrixMV);
+ math.glGetMatrix(math.KM_GL_PROJECTION, matrixP);
+ math.glGetMatrix(math.KM_GL_MODELVIEW, matrixMV);
- cc.kmMat4Multiply(matrixMVP, matrixP, matrixMV);
+ math.mat4Multiply(matrixMVP, matrixP, matrixMV);
- this.setUniformLocationWithMatrix4fv(this._uniforms[cc.Macro.UNIFORM_PMATRIX], matrixP.mat, 1);
- this.setUniformLocationWithMatrix4fv(this._uniforms[cc.Macro.UNIFORM_MVMATRIX], matrixMV.mat, 1);
- this.setUniformLocationWithMatrix4fv(this._uniforms[cc.Macro.UNIFORM_MVPMATRIX], matrixMVP.mat, 1);
+ this.setUniformLocationWithMatrix4fv(this._uniforms[macro.UNIFORM_PMATRIX], matrixP.mat, 1);
+ this.setUniformLocationWithMatrix4fv(this._uniforms[macro.UNIFORM_MVMATRIX], matrixMV.mat, 1);
+ this.setUniformLocationWithMatrix4fv(this._uniforms[macro.UNIFORM_MVPMATRIX], matrixMVP.mat, 1);
if (this._usesTime) {
var director = cc.director;
@@ -563,31 +566,31 @@ cc.GLProgram = cc._Class.extend(/** @lends cc.GLProgram# */{
// Getting Mach time per frame per shader using time could be extremely expensive.
var time = director.getTotalFrames() * director.getAnimationInterval();
- this.setUniformLocationWith4f(this._uniforms[cc.Macro.UNIFORM_TIME], time / 10.0, time, time * 2, time * 4);
- this.setUniformLocationWith4f(this._uniforms[cc.Macro.UNIFORM_SINTIME], time / 8.0, time / 4.0, time / 2.0, Math.sin(time));
- this.setUniformLocationWith4f(this._uniforms[cc.Macro.UNIFORM_COSTIME], time / 8.0, time / 4.0, time / 2.0, Math.cos(time));
+ this.setUniformLocationWith4f(this._uniforms[macro.UNIFORM_TIME], time / 10.0, time, time * 2, time * 4);
+ this.setUniformLocationWith4f(this._uniforms[macro.UNIFORM_SINTIME], time / 8.0, time / 4.0, time / 2.0, Math.sin(time));
+ this.setUniformLocationWith4f(this._uniforms[macro.UNIFORM_COSTIME], time / 8.0, time / 4.0, time / 2.0, Math.cos(time));
}
- if (this._uniforms[cc.Macro.UNIFORM_RANDOM01] !== -1)
- this.setUniformLocationWith4f(this._uniforms[cc.Macro.UNIFORM_RANDOM01], Math.random(), Math.random(), Math.random(), Math.random());
+ if (this._uniforms[macro.UNIFORM_RANDOM01] !== -1)
+ this.setUniformLocationWith4f(this._uniforms[macro.UNIFORM_RANDOM01], Math.random(), Math.random(), Math.random(), Math.random());
},
_setUniformsForBuiltinsForRenderer: function (node) {
if(!node || !node._renderCmd)
return;
- var matrixP = new cc.math.Matrix4();
- //var matrixMV = new cc.kmMat4();
- var matrixMVP = new cc.math.Matrix4();
+ var matrixP = new math.Matrix4();
+ //var matrixMV = new math.Matrix4();
+ var matrixMVP = new math.Matrix4();
- cc.kmGLGetMatrix(cc.KM_GL_PROJECTION, matrixP);
- //cc.kmGLGetMatrix(cc.KM_GL_MODELVIEW, node._stackMatrix);
+ math.glGetMatrix(math.KM_GL_PROJECTION, matrixP);
+ //math.glGetMatrix(math.KM_GL_MODELVIEW, node._stackMatrix);
- cc.kmMat4Multiply(matrixMVP, matrixP, node._renderCmd._stackMatrix);
+ math.mat4Multiply(matrixMVP, matrixP, node._renderCmd._stackMatrix);
- this.setUniformLocationWithMatrix4fv(this._uniforms[cc.Macro.UNIFORM_PMATRIX], matrixP.mat, 1);
- this.setUniformLocationWithMatrix4fv(this._uniforms[cc.Macro.UNIFORM_MVMATRIX], node._renderCmd._stackMatrix.mat, 1);
- this.setUniformLocationWithMatrix4fv(this._uniforms[cc.Macro.UNIFORM_MVPMATRIX], matrixMVP.mat, 1);
+ this.setUniformLocationWithMatrix4fv(this._uniforms[macro.UNIFORM_PMATRIX], matrixP.mat, 1);
+ this.setUniformLocationWithMatrix4fv(this._uniforms[macro.UNIFORM_MVMATRIX], node._renderCmd._stackMatrix.mat, 1);
+ this.setUniformLocationWithMatrix4fv(this._uniforms[macro.UNIFORM_MVPMATRIX], matrixMVP.mat, 1);
if (this._usesTime) {
var director = cc.director;
@@ -596,38 +599,38 @@ cc.GLProgram = cc._Class.extend(/** @lends cc.GLProgram# */{
// Getting Mach time per frame per shader using time could be extremely expensive.
var time = director.getTotalFrames() * director.getAnimationInterval();
- this.setUniformLocationWith4f(this._uniforms[cc.Macro.UNIFORM_TIME], time / 10.0, time, time * 2, time * 4);
- this.setUniformLocationWith4f(this._uniforms[cc.Macro.UNIFORM_SINTIME], time / 8.0, time / 4.0, time / 2.0, Math.sin(time));
- this.setUniformLocationWith4f(this._uniforms[cc.Macro.UNIFORM_COSTIME], time / 8.0, time / 4.0, time / 2.0, Math.cos(time));
+ this.setUniformLocationWith4f(this._uniforms[macro.UNIFORM_TIME], time / 10.0, time, time * 2, time * 4);
+ this.setUniformLocationWith4f(this._uniforms[macro.UNIFORM_SINTIME], time / 8.0, time / 4.0, time / 2.0, Math.sin(time));
+ this.setUniformLocationWith4f(this._uniforms[macro.UNIFORM_COSTIME], time / 8.0, time / 4.0, time / 2.0, Math.cos(time));
}
- if (this._uniforms[cc.Macro.UNIFORM_RANDOM01] !== -1)
- this.setUniformLocationWith4f(this._uniforms[cc.Macro.UNIFORM_RANDOM01], Math.random(), Math.random(), Math.random(), Math.random());
+ if (this._uniforms[macro.UNIFORM_RANDOM01] !== -1)
+ this.setUniformLocationWith4f(this._uniforms[macro.UNIFORM_RANDOM01], Math.random(), Math.random(), Math.random(), Math.random());
},
/**
* will update the MVP matrix on the MVP uniform if it is different than the previous call for this same shader program.
*/
setUniformForModelViewProjectionMatrix: function () {
- this._glContext.uniformMatrix4fv(this._uniforms[cc.Macro.UNIFORM_MVPMATRIX], false,
- cc.getMat4MultiplyValue(cc.projection_matrix_stack.top, cc.modelview_matrix_stack.top));
+ this._glContext.uniformMatrix4fv(this._uniforms[macro.UNIFORM_MVPMATRIX], false,
+ math.getMat4MultiplyValue(math.projection_matrix_stack.top, math.modelview_matrix_stack.top));
},
setUniformForModelViewProjectionMatrixWithMat4: function (swapMat4) {
- cc.kmMat4Multiply(swapMat4, cc.projection_matrix_stack.top, cc.modelview_matrix_stack.top);
- this._glContext.uniformMatrix4fv(this._uniforms[cc.Macro.UNIFORM_MVPMATRIX], false, swapMat4.mat);
+ math.mat4Multiply(swapMat4, math.projection_matrix_stack.top, math.modelview_matrix_stack.top);
+ this._glContext.uniformMatrix4fv(this._uniforms[macro.UNIFORM_MVPMATRIX], false, swapMat4.mat);
},
setUniformForModelViewAndProjectionMatrixWithMat4: function () {
- this._glContext.uniformMatrix4fv(this._uniforms[cc.Macro.UNIFORM_MVMATRIX], false, cc.modelview_matrix_stack.top.mat);
- this._glContext.uniformMatrix4fv(this._uniforms[cc.Macro.UNIFORM_PMATRIX], false, cc.projection_matrix_stack.top.mat);
+ this._glContext.uniformMatrix4fv(this._uniforms[macro.UNIFORM_MVMATRIX], false, math.modelview_matrix_stack.top.mat);
+ this._glContext.uniformMatrix4fv(this._uniforms[macro.UNIFORM_PMATRIX], false, math.projection_matrix_stack.top.mat);
},
_setUniformForMVPMatrixWithMat4: function(modelViewMatrix){
if(!modelViewMatrix)
throw new Error("modelView matrix is undefined.");
- this._glContext.uniformMatrix4fv(this._uniforms[cc.Macro.UNIFORM_MVMATRIX], false, modelViewMatrix.mat);
- this._glContext.uniformMatrix4fv(this._uniforms[cc.Macro.UNIFORM_PMATRIX], false, cc.projection_matrix_stack.top.mat);
+ this._glContext.uniformMatrix4fv(this._uniforms[macro.UNIFORM_MVMATRIX], false, modelViewMatrix.mat);
+ this._glContext.uniformMatrix4fv(this._uniforms[macro.UNIFORM_PMATRIX], false, math.projection_matrix_stack.top.mat);
},
/**
@@ -753,7 +756,7 @@ cc.GLProgram._isHighpSupported = function(){
* @param {_ccsg.Node} node
* @param {cc.GLProgram} program The shader program which fetches from CCShaderCache.
* @example
- * cc.setGLProgram(node, cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLOR));
+ * cc.setGLProgram(node, cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLOR));
*/
cc.setProgram = function (node, program) {
node.shaderProgram = program;
diff --git a/cocos2d/shaders/CCGLStateCache.js b/cocos2d/shaders/CCGLStateCache.js
index 70b1387591..ea2442c61d 100644
--- a/cocos2d/shaders/CCGLStateCache.js
+++ b/cocos2d/shaders/CCGLStateCache.js
@@ -29,7 +29,9 @@ cc._vertexAttribPosition = false;
cc._vertexAttribColor = false;
cc._vertexAttribTexCoords = false;
-var ENABLE_GL_STATE_CACHE = cc.Macro.ENABLE_GL_STATE_CACHE;
+var macro = cc.macro;
+
+var ENABLE_GL_STATE_CACHE = macro.ENABLE_GL_STATE_CACHE;
if (ENABLE_GL_STATE_CACHE) {
cc.MAX_ACTIVETEXTURE = 16;
@@ -39,7 +41,7 @@ if (ENABLE_GL_STATE_CACHE) {
cc._blendingSource = -1;
cc._blendingDest = -1;
cc._GLServerState = 0;
- if(cc.Macro.TEXTURE_ATLAS_USE_VAO)
+ if(macro.TEXTURE_ATLAS_USE_VAO)
cc._uVAO = 0;
}
@@ -47,11 +49,11 @@ if (ENABLE_GL_STATE_CACHE) {
/**
* Invalidates the GL state cache.
- * If cc.Macro.ENABLE_GL_STATE_CACHE it will reset the GL state cache.
+ * If cc.macro.ENABLE_GL_STATE_CACHE it will reset the GL state cache.
* @function
*/
cc.glInvalidateStateCache = function () {
- cc.kmGLFreeAll();
+ cc.math.glFreeAll();
cc._currentProjectionMatrix = -1;
cc._vertexAttribPosition = false;
cc._vertexAttribColor = false;
@@ -69,7 +71,7 @@ cc.glInvalidateStateCache = function () {
/**
* Uses the GL program in case program is different than the current one.
- * If cc.Macro.ENABLE_GL_STATE_CACHE is disabled, it will the glUseProgram() directly.
+ * If cc.macro.ENABLE_GL_STATE_CACHE is disabled, it will the glUseProgram() directly.
* @function
* @param {WebGLProgram} program
*/
@@ -88,7 +90,7 @@ if(!ENABLE_GL_STATE_CACHE){
/**
* Deletes the GL program. If it is the one that is being used, it invalidates it.
- * If cc.Macro.ENABLE_GL_STATE_CACHE is disabled, it will the glDeleteProgram() directly.
+ * If cc.macro.ENABLE_GL_STATE_CACHE is disabled, it will the glDeleteProgram() directly.
* @function
* @param {WebGLProgram} program
*/
@@ -102,7 +104,7 @@ cc.glDeleteProgram = function (program) {
/**
* Uses a blending function in case it not already used.
- * If cc.Macro.ENABLE_GL_STATE_CACHE is disabled, it will the glBlendFunc() directly.
+ * If cc.macro.ENABLE_GL_STATE_CACHE is disabled, it will the glBlendFunc() directly.
* @function
* @param {Number} sfactor
* @param {Number} dfactor
@@ -158,7 +160,7 @@ if(!ENABLE_GL_STATE_CACHE){
/**
* Resets the blending mode back to the cached state in case you used glBlendFuncSeparate() or glBlendEquation().
- * If cc.Macro.ENABLE_GL_STATE_CACHE is disabled, it will just set the default blending mode using GL_FUNC_ADD.
+ * If cc.macro.ENABLE_GL_STATE_CACHE is disabled, it will just set the default blending mode using GL_FUNC_ADD.
* @function
*/
cc.glBlendResetToCache = function () {
@@ -182,51 +184,51 @@ cc.setProjectionMatrixDirty = function () {
*
* Will enable the vertex attribs that are passed as flags.
* Possible flags:
- * cc.Macro.VERTEX_ATTRIB_FLAG_POSITION
- * cc.Macro.VERTEX_ATTRIB_FLAG_COLOR
- * cc.Macro.VERTEX_ATTRIB_FLAG_TEX_COORDS
+ * cc.macro.VERTEX_ATTRIB_FLAG_POSITION
+ * cc.macro.VERTEX_ATTRIB_FLAG_COLOR
+ * cc.macro.VERTEX_ATTRIB_FLAG_TEX_COORDS
*
* These flags can be ORed. The flags that are not present, will be disabled.
*
* @function
- * @param {cc.Macro.VERTEX_ATTRIB_FLAG_POSITION | cc.Macro.VERTEX_ATTRIB_FLAG_COLOR | cc.Macro.VERTEX_ATTRIB_FLAG_TEX_OORDS} flags
+ * @param {cc.macro.VERTEX_ATTRIB_FLAG_POSITION | cc.macro.VERTEX_ATTRIB_FLAG_COLOR | cc.macro.VERTEX_ATTRIB_FLAG_TEX_OORDS} flags
*/
cc.glEnableVertexAttribs = function (flags) {
/* Position */
var ctx = cc._renderContext;
- var enablePosition = ( flags & cc.Macro.VERTEX_ATTRIB_FLAG_POSITION );
+ var enablePosition = ( flags & macro.VERTEX_ATTRIB_FLAG_POSITION );
if (enablePosition !== cc._vertexAttribPosition) {
if (enablePosition)
- ctx.enableVertexAttribArray(cc.Macro.VERTEX_ATTRIB_POSITION);
+ ctx.enableVertexAttribArray(macro.VERTEX_ATTRIB_POSITION);
else
- ctx.disableVertexAttribArray(cc.Macro.VERTEX_ATTRIB_POSITION);
+ ctx.disableVertexAttribArray(macro.VERTEX_ATTRIB_POSITION);
cc._vertexAttribPosition = enablePosition;
}
/* Color */
- var enableColor = (flags & cc.Macro.VERTEX_ATTRIB_FLAG_COLOR);
+ var enableColor = (flags & macro.VERTEX_ATTRIB_FLAG_COLOR);
if (enableColor !== cc._vertexAttribColor) {
if (enableColor)
- ctx.enableVertexAttribArray(cc.Macro.VERTEX_ATTRIB_COLOR);
+ ctx.enableVertexAttribArray(macro.VERTEX_ATTRIB_COLOR);
else
- ctx.disableVertexAttribArray(cc.Macro.VERTEX_ATTRIB_COLOR);
+ ctx.disableVertexAttribArray(macro.VERTEX_ATTRIB_COLOR);
cc._vertexAttribColor = enableColor;
}
/* Tex Coords */
- var enableTexCoords = (flags & cc.Macro.VERTEX_ATTRIB_FLAG_TEX_COORDS);
+ var enableTexCoords = (flags & macro.VERTEX_ATTRIB_FLAG_TEX_COORDS);
if (enableTexCoords !== cc._vertexAttribTexCoords) {
if (enableTexCoords)
- ctx.enableVertexAttribArray(cc.Macro.VERTEX_ATTRIB_TEX_COORDS);
+ ctx.enableVertexAttribArray(macro.VERTEX_ATTRIB_TEX_COORDS);
else
- ctx.disableVertexAttribArray(cc.Macro.VERTEX_ATTRIB_TEX_COORDS);
+ ctx.disableVertexAttribArray(macro.VERTEX_ATTRIB_TEX_COORDS);
cc._vertexAttribTexCoords = enableTexCoords;
}
};
/**
* If the texture is not already bound, it binds it.
- * If cc.Macro.ENABLE_GL_STATE_CACHE is disabled, it will call glBindTexture() directly.
+ * If cc.macro.ENABLE_GL_STATE_CACHE is disabled, it will call glBindTexture() directly.
* @function
* @param {cc.Texture2D} textureId
*/
@@ -236,7 +238,7 @@ cc.glBindTexture2D = function (textureId) {
/**
* If the texture is not already bound to a given unit, it binds it.
- * If cc.Macro.ENABLE_GL_STATE_CACHE is disabled, it will call glBindTexture() directly.
+ * If cc.macro.ENABLE_GL_STATE_CACHE is disabled, it will call glBindTexture() directly.
* @function
* @param {Number} textureUnit
* @param {cc.Texture2D} textureId
@@ -266,7 +268,7 @@ if (!ENABLE_GL_STATE_CACHE){
/**
* It will delete a given texture. If the texture was bound, it will invalidate the cached.
- * If cc.Macro.ENABLE_GL_STATE_CACHE is disabled, it will call glDeleteTextures() directly.
+ * If cc.macro.ENABLE_GL_STATE_CACHE is disabled, it will call glDeleteTextures() directly.
* @function
* @param {cc.Texture2D} textureId
*/
@@ -276,7 +278,7 @@ cc.glDeleteTexture2D = function (textureId) {
/**
* It will delete a given texture. If the texture was bound, it will invalidate the cached for the given texture unit.
- * If cc.Macro.ENABLE_GL_STATE_CACHE is disabled, it will call glDeleteTextures() directly.
+ * If cc.macro.ENABLE_GL_STATE_CACHE is disabled, it will call glDeleteTextures() directly.
* @function
* @param {Number} textureUnit
* @param {cc.Texture2D} textureId
@@ -291,12 +293,12 @@ cc.glDeleteTexture2DN = function (textureUnit, textureId) {
/**
* If the vertex array is not already bound, it binds it.
- * If cc.Macro.ENABLE_GL_STATE_CACHE is disabled, it will call glBindVertexArray() directly.
+ * If cc.macro.ENABLE_GL_STATE_CACHE is disabled, it will call glBindVertexArray() directly.
* @function
* @param {Number} vaoId
*/
cc.glBindVAO = function (vaoId) {
- if (!cc.Macro.TEXTURE_ATLAS_USE_VAO)
+ if (!macro.TEXTURE_ATLAS_USE_VAO)
return;
if (ENABLE_GL_STATE_CACHE) {
@@ -312,7 +314,7 @@ cc.glBindVAO = function (vaoId) {
/**
* It will enable / disable the server side GL states.
- * If cc.Macro.ENABLE_GL_STATE_CACHE is disabled, it will call glEnable() directly.
+ * If cc.macro.ENABLE_GL_STATE_CACHE is disabled, it will call glEnable() directly.
* @function
* @param {Number} flags
*/
diff --git a/cocos2d/shaders/CCShaderCache.js b/cocos2d/shaders/CCShaderCache.js
index 6183feeca9..c004f2a359 100644
--- a/cocos2d/shaders/CCShaderCache.js
+++ b/cocos2d/shaders/CCShaderCache.js
@@ -24,6 +24,9 @@
THE SOFTWARE.
****************************************************************************/
+var shaders = cc.PresetShaders;
+var macro = cc.macro;
+
/**
* cc.shaderCache is a singleton object that stores manages GL shaders
* @class
@@ -96,54 +99,54 @@ cc.shaderCache = /** @lends cc.shaderCache# */{
_loadDefaultShader: function (program, type) {
switch (type) {
case this.TYPE_POSITION_TEXTURECOLOR:
- program.initWithVertexShaderByteArray(cc.Shaders.POSITION_TEXTURE_COLOR_VERT, cc.Shaders.POSITION_TEXTURE_COLOR_FRAG);
+ program.initWithVertexShaderByteArray(shaders.POSITION_TEXTURE_COLOR_VERT, shaders.POSITION_TEXTURE_COLOR_FRAG);
- program.addAttribute(cc.Macro.ATTRIBUTE_NAME_POSITION, cc.Macro.VERTEX_ATTRIB_POSITION);
- program.addAttribute(cc.Macro.ATTRIBUTE_NAME_COLOR, cc.Macro.VERTEX_ATTRIB_COLOR);
- program.addAttribute(cc.Macro.ATTRIBUTE_NAME_TEX_COORD, cc.Macro.VERTEX_ATTRIB_TEX_COORDS);
+ program.addAttribute(macro.ATTRIBUTE_NAME_POSITION, macro.VERTEX_ATTRIB_POSITION);
+ program.addAttribute(macro.ATTRIBUTE_NAME_COLOR, macro.VERTEX_ATTRIB_COLOR);
+ program.addAttribute(macro.ATTRIBUTE_NAME_TEX_COORD, macro.VERTEX_ATTRIB_TEX_COORDS);
break;
case this.TYPE_POSITION_TEXTURECOLOR_ALPHATEST:
- program.initWithVertexShaderByteArray(cc.Shaders.POSITION_TEXTURE_COLOR_VERT, cc.Shaders.POSITION_TEXTURE_COLOR_ALPHATEST_FRAG);
+ program.initWithVertexShaderByteArray(shaders.POSITION_TEXTURE_COLOR_VERT, shaders.POSITION_TEXTURE_COLOR_ALPHATEST_FRAG);
- program.addAttribute(cc.Macro.ATTRIBUTE_NAME_POSITION, cc.Macro.VERTEX_ATTRIB_POSITION);
- program.addAttribute(cc.Macro.ATTRIBUTE_NAME_COLOR, cc.Macro.VERTEX_ATTRIB_COLOR);
- program.addAttribute(cc.Macro.ATTRIBUTE_NAME_TEX_COORD, cc.Macro.VERTEX_ATTRIB_TEX_COORDS);
+ program.addAttribute(macro.ATTRIBUTE_NAME_POSITION, macro.VERTEX_ATTRIB_POSITION);
+ program.addAttribute(macro.ATTRIBUTE_NAME_COLOR, macro.VERTEX_ATTRIB_COLOR);
+ program.addAttribute(macro.ATTRIBUTE_NAME_TEX_COORD, macro.VERTEX_ATTRIB_TEX_COORDS);
break;
case this.TYPE_POSITION_COLOR:
- program.initWithVertexShaderByteArray(cc.Shaders.POSITION_COLOR_VERT, cc.Shaders.POSITION_COLOR_FRAG);
+ program.initWithVertexShaderByteArray(shaders.POSITION_COLOR_VERT, shaders.POSITION_COLOR_FRAG);
- program.addAttribute(cc.Macro.ATTRIBUTE_NAME_POSITION, cc.Macro.VERTEX_ATTRIB_POSITION);
- program.addAttribute(cc.Macro.ATTRIBUTE_NAME_COLOR, cc.Macro.VERTEX_ATTRIB_COLOR);
+ program.addAttribute(macro.ATTRIBUTE_NAME_POSITION, macro.VERTEX_ATTRIB_POSITION);
+ program.addAttribute(macro.ATTRIBUTE_NAME_COLOR, macro.VERTEX_ATTRIB_COLOR);
break;
case this.TYPE_POSITION_TEXTURE:
- program.initWithVertexShaderByteArray(cc.Shaders.POSITION_TEXTURE_VERT, cc.Shaders.POSITION_TEXTURE_FRAG);
+ program.initWithVertexShaderByteArray(shaders.POSITION_TEXTURE_VERT, shaders.POSITION_TEXTURE_FRAG);
- program.addAttribute(cc.Macro.ATTRIBUTE_NAME_POSITION, cc.Macro.VERTEX_ATTRIB_POSITION);
- program.addAttribute(cc.Macro.ATTRIBUTE_NAME_TEX_COORD, cc.Macro.VERTEX_ATTRIB_TEX_COORDS);
+ program.addAttribute(macro.ATTRIBUTE_NAME_POSITION, macro.VERTEX_ATTRIB_POSITION);
+ program.addAttribute(macro.ATTRIBUTE_NAME_TEX_COORD, macro.VERTEX_ATTRIB_TEX_COORDS);
break;
case this.TYPE_POSITION_TEXTURE_UCOLOR:
- program.initWithVertexShaderByteArray(cc.Shaders.POSITION_TEXTURE_UCOLOR_VERT, cc.Shaders.POSITION_TEXTURE_UCOLOR_FRAG);
+ program.initWithVertexShaderByteArray(shaders.POSITION_TEXTURE_UCOLOR_VERT, shaders.POSITION_TEXTURE_UCOLOR_FRAG);
- program.addAttribute(cc.Macro.ATTRIBUTE_NAME_POSITION, cc.Macro.VERTEX_ATTRIB_POSITION);
- program.addAttribute(cc.Macro.ATTRIBUTE_NAME_TEX_COORD, cc.Macro.VERTEX_ATTRIB_TEX_COORDS);
+ program.addAttribute(macro.ATTRIBUTE_NAME_POSITION, macro.VERTEX_ATTRIB_POSITION);
+ program.addAttribute(macro.ATTRIBUTE_NAME_TEX_COORD, macro.VERTEX_ATTRIB_TEX_COORDS);
break;
case this.TYPE_POSITION_TEXTURE_A8COLOR:
- program.initWithVertexShaderByteArray(cc.Shaders.POSITION_TEXTURE_A8COLOR_VERT, cc.Shaders.POSITION_TEXTURE_A8COLOR_FRAG);
+ program.initWithVertexShaderByteArray(shaders.POSITION_TEXTURE_A8COLOR_VERT, shaders.POSITION_TEXTURE_A8COLOR_FRAG);
- program.addAttribute(cc.Macro.ATTRIBUTE_NAME_POSITION, cc.Macro.VERTEX_ATTRIB_POSITION);
- program.addAttribute(cc.Macro.ATTRIBUTE_NAME_COLOR, cc.Macro.VERTEX_ATTRIB_COLOR);
- program.addAttribute(cc.Macro.ATTRIBUTE_NAME_TEX_COORD, cc.Macro.VERTEX_ATTRIB_TEX_COORDS);
+ program.addAttribute(macro.ATTRIBUTE_NAME_POSITION, macro.VERTEX_ATTRIB_POSITION);
+ program.addAttribute(macro.ATTRIBUTE_NAME_COLOR, macro.VERTEX_ATTRIB_COLOR);
+ program.addAttribute(macro.ATTRIBUTE_NAME_TEX_COORD, macro.VERTEX_ATTRIB_TEX_COORDS);
break;
case this.TYPE_POSITION_UCOLOR:
- program.initWithVertexShaderByteArray(cc.Shaders.POSITION_UCOLOR_VERT, cc.Shaders.POSITION_UCOLOR_FRAG);
- program.addAttribute("aVertex", cc.Macro.VERTEX_ATTRIB_POSITION);
+ program.initWithVertexShaderByteArray(shaders.POSITION_UCOLOR_VERT, shaders.POSITION_UCOLOR_FRAG);
+ program.addAttribute("aVertex", macro.VERTEX_ATTRIB_POSITION);
break;
case this.TYPE_POSITION_LENGTH_TEXTURECOLOR:
- program.initWithVertexShaderByteArray(cc.Shaders.POSITION_COLOR_LENGTH_TEXTURE_VERT, cc.Shaders.POSITION_COLOR_LENGTH_TEXTURE_FRAG);
+ program.initWithVertexShaderByteArray(shaders.POSITION_COLOR_LENGTH_TEXTURE_VERT, shaders.POSITION_COLOR_LENGTH_TEXTURE_FRAG);
- program.addAttribute(cc.Macro.ATTRIBUTE_NAME_POSITION, cc.Macro.VERTEX_ATTRIB_POSITION);
- program.addAttribute(cc.Macro.ATTRIBUTE_NAME_TEX_COORD, cc.Macro.VERTEX_ATTRIB_TEX_COORDS);
- program.addAttribute(cc.Macro.ATTRIBUTE_NAME_COLOR, cc.Macro.VERTEX_ATTRIB_COLOR);
+ program.addAttribute(macro.ATTRIBUTE_NAME_POSITION, macro.VERTEX_ATTRIB_POSITION);
+ program.addAttribute(macro.ATTRIBUTE_NAME_TEX_COORD, macro.VERTEX_ATTRIB_TEX_COORDS);
+ program.addAttribute(macro.ATTRIBUTE_NAME_COLOR, macro.VERTEX_ATTRIB_COLOR);
break;
default:
cc.log("cocos2d: cc.shaderCache._loadDefaultShader, error shader type");
@@ -163,13 +166,13 @@ cc.shaderCache = /** @lends cc.shaderCache# */{
// Position Texture Color shader
var program = new cc.GLProgram();
this._loadDefaultShader(program, this.TYPE_POSITION_TEXTURECOLOR);
- this._programs[cc.Macro.SHADER_POSITION_TEXTURECOLOR] = program;
+ this._programs[macro.SHADER_POSITION_TEXTURECOLOR] = program;
this._programs["ShaderPositionTextureColor"] = program;
// Position Texture Color alpha test
program = new cc.GLProgram();
this._loadDefaultShader(program, this.TYPE_POSITION_TEXTURECOLOR_ALPHATEST);
- this._programs[cc.Macro.SHADER_POSITION_TEXTURECOLORALPHATEST] = program;
+ this._programs[macro.SHADER_POSITION_TEXTURECOLORALPHATEST] = program;
this._programs["ShaderPositionTextureColorAlphaTest"] = program;
//
@@ -177,7 +180,7 @@ cc.shaderCache = /** @lends cc.shaderCache# */{
//
program = new cc.GLProgram();
this._loadDefaultShader(program, this.TYPE_POSITION_COLOR);
- this._programs[cc.Macro.SHADER_POSITION_COLOR] = program;
+ this._programs[macro.SHADER_POSITION_COLOR] = program;
this._programs["ShaderPositionColor"] = program;
//
@@ -185,7 +188,7 @@ cc.shaderCache = /** @lends cc.shaderCache# */{
//
program = new cc.GLProgram();
this._loadDefaultShader(program, this.TYPE_POSITION_TEXTURE);
- this._programs[cc.Macro.SHADER_POSITION_TEXTURE] = program;
+ this._programs[macro.SHADER_POSITION_TEXTURE] = program;
this._programs["ShaderPositionTexture"] = program;
//
@@ -193,7 +196,7 @@ cc.shaderCache = /** @lends cc.shaderCache# */{
//
program = new cc.GLProgram();
this._loadDefaultShader(program, this.TYPE_POSITION_TEXTURE_UCOLOR);
- this._programs[cc.Macro.SHADER_POSITION_TEXTURE_UCOLOR] = program;
+ this._programs[macro.SHADER_POSITION_TEXTURE_UCOLOR] = program;
this._programs["ShaderPositionTextureUColor"] = program;
//
@@ -201,7 +204,7 @@ cc.shaderCache = /** @lends cc.shaderCache# */{
//
program = new cc.GLProgram();
this._loadDefaultShader(program, this.TYPE_POSITION_TEXTURE_A8COLOR);
- this._programs[cc.Macro.SHADER_POSITION_TEXTUREA8COLOR] = program;
+ this._programs[macro.SHADER_POSITION_TEXTUREA8COLOR] = program;
this._programs["ShaderPositionTextureA8Color"] = program;
//
@@ -209,7 +212,7 @@ cc.shaderCache = /** @lends cc.shaderCache# */{
//
program = new cc.GLProgram();
this._loadDefaultShader(program, this.TYPE_POSITION_UCOLOR);
- this._programs[cc.Macro.SHADER_POSITION_UCOLOR] = program;
+ this._programs[macro.SHADER_POSITION_UCOLOR] = program;
this._programs["ShaderPositionUColor"] = program;
//
@@ -217,7 +220,7 @@ cc.shaderCache = /** @lends cc.shaderCache# */{
//
program = new cc.GLProgram();
this._loadDefaultShader(program, this.TYPE_POSITION_LENGTH_TEXTURECOLOR);
- this._programs[cc.Macro.SHADER_POSITION_LENGTHTEXTURECOLOR] = program;
+ this._programs[macro.SHADER_POSITION_LENGTHTEXTURECOLOR] = program;
this._programs["ShaderPositionLengthTextureColor"] = program;
},
@@ -228,47 +231,47 @@ cc.shaderCache = /** @lends cc.shaderCache# */{
// reset all programs and reload them
// Position Texture Color shader
- var program = this.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLOR);
+ var program = this.programForKey(macro.SHADER_POSITION_TEXTURECOLOR);
program.reset();
this._loadDefaultShader(program, this.TYPE_POSITION_TEXTURECOLOR);
// Position Texture Color alpha test
- program = this.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLORALPHATEST);
+ program = this.programForKey(macro.SHADER_POSITION_TEXTURECOLORALPHATEST);
program.reset();
this._loadDefaultShader(program, this.TYPE_POSITION_TEXTURECOLOR_ALPHATEST);
//
// Position, Color shader
//
- program = this.programForKey(cc.Macro.SHADER_POSITION_COLOR);
+ program = this.programForKey(macro.SHADER_POSITION_COLOR);
program.reset();
this._loadDefaultShader(program, this.TYPE_POSITION_COLOR);
//
// Position Texture shader
//
- program = this.programForKey(cc.Macro.SHADER_POSITION_TEXTURE);
+ program = this.programForKey(macro.SHADER_POSITION_TEXTURE);
program.reset();
this._loadDefaultShader(program, this.TYPE_POSITION_TEXTURE);
//
// Position, Texture attribs, 1 Color as uniform shader
//
- program = this.programForKey(cc.Macro.SHADER_POSITION_TEXTURE_UCOLOR);
+ program = this.programForKey(macro.SHADER_POSITION_TEXTURE_UCOLOR);
program.reset();
this._loadDefaultShader(program, this.TYPE_POSITION_TEXTURE_UCOLOR);
//
// Position Texture A8 Color shader
//
- program = this.programForKey(cc.Macro.SHADER_POSITION_TEXTUREA8COLOR);
+ program = this.programForKey(macro.SHADER_POSITION_TEXTUREA8COLOR);
program.reset();
this._loadDefaultShader(program, this.TYPE_POSITION_TEXTURE_A8COLOR);
//
// Position and 1 color passed as a uniform (to similate glColor4ub )
//
- program = this.programForKey(cc.Macro.SHADER_POSITION_UCOLOR);
+ program = this.programForKey(macro.SHADER_POSITION_UCOLOR);
program.reset();
this._loadDefaultShader(program, this.TYPE_POSITION_UCOLOR);
},
diff --git a/cocos2d/shaders/CCShaders.js b/cocos2d/shaders/CCShaders.js
index 393e6b7c56..974f3c9c0a 100644
--- a/cocos2d/shaders/CCShaders.js
+++ b/cocos2d/shaders/CCShaders.js
@@ -28,13 +28,13 @@
/**
* Predefined constants
- * @property Shaders
+ * @class PresetShaders
* @readonly
* @type {Object}
* @static
* @namespace cc
*/
-cc.Shaders = {
+cc.PresetShaders = {
/**
* @property POSITION_UCOLOR_FRAG
* @type {String}
diff --git a/cocos2d/shape-nodes/CCDrawNode.js b/cocos2d/shape-nodes/CCDrawNode.js
index ee4a0febf4..9622a74b41 100644
--- a/cocos2d/shape-nodes/CCDrawNode.js
+++ b/cocos2d/shape-nodes/CCDrawNode.js
@@ -198,7 +198,7 @@ cc.game.once(cc.game.EVENT_RENDERER_INITED, function () {
var locCmd = this._renderCmd;
locCmd._buffer = this._buffer = [];
locCmd._drawColor = this._drawColor = cc.color(255, 255, 255, 255);
- locCmd._blendFunc = this._blendFunc = new cc.BlendFunc(cc.Macro.SRC_ALPHA, cc.Macro.ONE_MINUS_SRC_ALPHA);
+ locCmd._blendFunc = this._blendFunc = new cc.BlendFunc(cc.macro.SRC_ALPHA, cc.macro.ONE_MINUS_SRC_ALPHA);
this.init();
},
@@ -527,7 +527,7 @@ cc.game.once(cc.game.EVENT_RENDERER_INITED, function () {
ctor:function () {
_ccsg.Node.prototype.ctor.call(this);
this._buffer = [];
- this._blendFunc = new cc.BlendFunc(cc.Macro.SRC_ALPHA, cc.Macro.ONE_MINUS_SRC_ALPHA);
+ this._blendFunc = new cc.BlendFunc(cc.macro.SRC_ALPHA, cc.macro.ONE_MINUS_SRC_ALPHA);
this._drawColor = new cc.WebGLColor(255,255,255,255);
this.init();
@@ -535,7 +535,7 @@ cc.game.once(cc.game.EVENT_RENDERER_INITED, function () {
init:function () {
if (_ccsg.Node.prototype.init.call(this)) {
- this.shaderProgram = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_LENGTHTEXTURECOLOR);
+ this.shaderProgram = cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_LENGTHTEXTURECOLOR);
this._ensureCapacity(64);
this._trianglesWebBuffer = cc._renderContext.createBuffer();
this._dirty = true;
@@ -649,7 +649,7 @@ cc.game.once(cc.game.EVENT_RENDERER_INITED, function () {
_render:function () {
var gl = cc._renderContext;
- cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
+ cc.glEnableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
gl.bindBuffer(gl.ARRAY_BUFFER, this._trianglesWebBuffer);
if (this._dirty) {
gl.bufferData(gl.ARRAY_BUFFER, this._trianglesArrayBuffer, gl.STREAM_DRAW);
@@ -658,11 +658,11 @@ cc.game.once(cc.game.EVENT_RENDERER_INITED, function () {
var triangleSize = cc.V2F_C4B_T2F.BYTES_PER_ELEMENT;
// vertex
- gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, triangleSize, 0);
+ gl.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, triangleSize, 0);
// color
- gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_COLOR, 4, gl.UNSIGNED_BYTE, true, triangleSize, 8);
+ gl.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_COLOR, 4, gl.UNSIGNED_BYTE, true, triangleSize, 8);
// texcood
- gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_TEX_COORDS, 2, gl.FLOAT, false, triangleSize, 12);
+ gl.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_TEX_COORDS, 2, gl.FLOAT, false, triangleSize, 12);
gl.drawArrays(gl.TRIANGLES, 0, this._buffer.length * 3);
cc.incrementGLDraws(1);
diff --git a/cocos2d/shape-nodes/CCDrawNodeCanvasRenderCmd.js b/cocos2d/shape-nodes/CCDrawNodeCanvasRenderCmd.js
index eb3af4bd14..e244adfd1a 100644
--- a/cocos2d/shape-nodes/CCDrawNodeCanvasRenderCmd.js
+++ b/cocos2d/shape-nodes/CCDrawNodeCanvasRenderCmd.js
@@ -45,7 +45,7 @@
//context.save();
wrapper.setGlobalAlpha(alpha);
- if ((this._blendFunc && (this._blendFunc.src === cc.Macro.SRC_ALPHA) && (this._blendFunc.dst === cc.Macro.ONE)))
+ if ((this._blendFunc && (this._blendFunc.src === cc.macro.SRC_ALPHA) && (this._blendFunc.dst === cc.macro.ONE)))
wrapper.setCompositeOperation('lighter'); //todo: need refactor
var locBuffer = this._buffer;
for (var i = 0, len = locBuffer.length; i < len; i++) {
diff --git a/cocos2d/tilemap/CCSGTMXLayer.js b/cocos2d/tilemap/CCSGTMXLayer.js
index 54ab7da302..26d349f679 100644
--- a/cocos2d/tilemap/CCSGTMXLayer.js
+++ b/cocos2d/tilemap/CCSGTMXLayer.js
@@ -766,8 +766,8 @@ _ccsg.TMXLayer = cc.SpriteBatchNode.extend(/** @lends _ccsg.TMXLayer# */{
alphaFuncValue = parseFloat(alphaFuncVal);
if (cc._renderType === cc.game.RENDER_TYPE_WEBGL) { //todo: need move to WebGL render cmd
- this.shaderProgram = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLORALPHATEST);
- var alphaValueLocation = cc._renderContext.getUniformLocation(this.shaderProgram.getProgram(), cc.Macro.UNIFORM_ALPHA_TEST_VALUE_S);
+ this.shaderProgram = cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLORALPHATEST);
+ var alphaValueLocation = cc._renderContext.getUniformLocation(this.shaderProgram.getProgram(), cc.macro.UNIFORM_ALPHA_TEST_VALUE_S);
// NOTE: alpha test shader is hard-coded to use the equivalent of a glAlphaFunc(GL_GREATER) comparison
this.shaderProgram.use();
this.shaderProgram.setUniformLocationWith1f(alphaValueLocation, alphaFuncValue);
diff --git a/cocos2d/transitions/CCTransition.js b/cocos2d/transitions/CCTransition.js
index b041faf0f3..c586437d66 100644
--- a/cocos2d/transitions/CCTransition.js
+++ b/cocos2d/transitions/CCTransition.js
@@ -1518,8 +1518,8 @@ cc.TransitionCrossFade = cc.TransitionScene.extend(/** @lends cc.TransitionCross
this._outScene.visit();
outTexture.end();
- inTexture.sprite.setBlendFunc(cc.Macro.ONE, cc.Macro.ONE); // inScene will lay on background and will not be used with alpha
- outTexture.sprite.setBlendFunc(cc.Macro.SRC_ALPHA, cc.Macro.ONE_MINUS_SRC_ALPHA); // we are going to blend outScene via alpha
+ inTexture.sprite.setBlendFunc(cc.macro.ONE, cc.macro.ONE); // inScene will lay on background and will not be used with alpha
+ outTexture.sprite.setBlendFunc(cc.macro.SRC_ALPHA, cc.macro.ONE_MINUS_SRC_ALPHA); // we are going to blend outScene via alpha
// add render textures to the layer
layer.addChild(inTexture);
diff --git a/extensions/ccui/base-classes/CCProtectedNode.js b/extensions/ccui/base-classes/CCProtectedNode.js
index bcc046a1da..889240886b 100644
--- a/extensions/ccui/base-classes/CCProtectedNode.js
+++ b/extensions/ccui/base-classes/CCProtectedNode.js
@@ -85,7 +85,7 @@ cc.ProtectedNode = _ccsg.Node.extend(/** @lends cc.ProtectedNode# */{
* @return {_ccsg.Node} a Node object whose tag equals to the input parameter
*/
getProtectedChildByTag: function(tag){
- cc.assert(tag !== cc.NODE_TAG_INVALID, "Invalid tag");
+ cc.assert(tag !== cc.macro.NODE_TAG_INVALID, "Invalid tag");
var locChildren = this._protectedChildren;
for(var i = 0, len = locChildren.length; i < len; i++)
if(locChildren.getTag() === tag)
@@ -129,7 +129,7 @@ cc.ProtectedNode = _ccsg.Node.extend(/** @lends cc.ProtectedNode# */{
* @param {Boolean} [cleanup=true]
*/
removeProtectedChildByTag: function(tag, cleanup){
- cc.assert( tag !== cc.NODE_TAG_INVALID, "Invalid tag");
+ cc.assert( tag !== cc.macro.NODE_TAG_INVALID, "Invalid tag");
if(cleanup == null)
cleanup = true;
diff --git a/extensions/ccui/base-classes/CCProtectedNodeWebGLRenderCmd.js b/extensions/ccui/base-classes/CCProtectedNodeWebGLRenderCmd.js
index 66e763a55b..322c0ae571 100644
--- a/extensions/ccui/base-classes/CCProtectedNodeWebGLRenderCmd.js
+++ b/extensions/ccui/base-classes/CCProtectedNodeWebGLRenderCmd.js
@@ -117,7 +117,7 @@
t4x4Mat[14] = node._vertexZ;
//optimize performance for Javascript
- cc.kmMat4Multiply(stackMatrix, parentMatrix, t4x4);
+ cc.math.mat4Multiply(stackMatrix, parentMatrix, t4x4);
var i, len, locChildren = node._children;
if(recursive && locChildren && locChildren.length !== 0){
diff --git a/extensions/ccui/layouts/UILayout.js b/extensions/ccui/layouts/UILayout.js
index de88174cc3..8b3269143e 100644
--- a/extensions/ccui/layouts/UILayout.js
+++ b/extensions/ccui/layouts/UILayout.js
@@ -936,7 +936,7 @@ ccui.Layout = ccui.Widget.extend(/** @lends ccui.Layout# */{
var index = 0, locChildren = this.getChildren();
var count = locChildren.length, widgetPosition;
- var distance = cc.Macro.FLT_MAX, found = 0;
+ var distance = cc.macro.FLT_MAX, found = 0;
if (direction === ccui.Widget.LEFT || direction === ccui.Widget.RIGHT || direction === ccui.Widget.DOWN || direction === ccui.Widget.UP) {
widgetPosition = this._getWorldCenterPoint(baseWidget);
while (index < count) {
@@ -972,7 +972,7 @@ ccui.Layout = ccui.Widget.extend(/** @lends ccui.Layout# */{
var index = 0, locChildren = this.getChildren();
var count = locChildren.length;
- var distance = -cc.Macro.FLT_MAX, found = 0;
+ var distance = -cc.macro.FLT_MAX, found = 0;
if (direction === ccui.Widget.LEFT || direction === ccui.Widget.RIGHT || direction === ccui.Widget.DOWN || direction === ccui.Widget.UP) {
var widgetPosition = this._getWorldCenterPoint(baseWidget);
while (index < count) {
@@ -1000,7 +1000,7 @@ ccui.Layout = ccui.Widget.extend(/** @lends ccui.Layout# */{
* @private
*/
_calculateNearestDistance: function(baseWidget){
- var distance = cc.Macro.FLT_MAX;
+ var distance = cc.macro.FLT_MAX;
var widgetPosition = this._getWorldCenterPoint(baseWidget);
var locChildren = this._children;
@@ -1027,7 +1027,7 @@ ccui.Layout = ccui.Widget.extend(/** @lends ccui.Layout# */{
* @private
*/
_calculateFarthestDistance:function(baseWidget){
- var distance = -cc.Macro.FLT_MAX;
+ var distance = -cc.macro.FLT_MAX;
var widgetPosition = this._getWorldCenterPoint(baseWidget);
var locChildren = this._children;
diff --git a/extensions/ccui/layouts/UILayoutWebGLRenderCmd.js b/extensions/ccui/layouts/UILayoutWebGLRenderCmd.js
index 5a487135ee..1b6a1d535b 100644
--- a/extensions/ccui/layouts/UILayoutWebGLRenderCmd.js
+++ b/extensions/ccui/layouts/UILayoutWebGLRenderCmd.js
@@ -144,17 +144,17 @@
proto._drawFullScreenQuadClearStencil = function(){
// draw a fullscreen solid rectangle to clear the stencil buffer
- cc.kmGLMatrixMode(cc.KM_GL_PROJECTION);
- cc.kmGLPushMatrix();
- cc.kmGLLoadIdentity();
- cc.kmGLMatrixMode(cc.KM_GL_MODELVIEW);
- cc.kmGLPushMatrix();
- cc.kmGLLoadIdentity();
+ cc.math.glMatrixMode(cc.math.KM_GL_PROJECTION);
+ cc.math.glPushMatrix();
+ cc.math.glLoadIdentity();
+ cc.math.glMatrixMode(cc.math.KM_GL_MODELVIEW);
+ cc.math.glPushMatrix();
+ cc.math.glLoadIdentity();
cc._drawingUtil.drawSolidRect(cc.p(-1,-1), cc.p(1,1), cc.color(255, 255, 255, 255));
- cc.kmGLMatrixMode(cc.KM_GL_PROJECTION);
- cc.kmGLPopMatrix();
- cc.kmGLMatrixMode(cc.KM_GL_MODELVIEW);
- cc.kmGLPopMatrix();
+ cc.math.glMatrixMode(cc.math.KM_GL_PROJECTION);
+ cc.math.glPopMatrix();
+ cc.math.glMatrixMode(cc.math.KM_GL_MODELVIEW);
+ cc.math.glPopMatrix();
};
proto.rebindStencilRendering = function(stencil){};
diff --git a/extensions/cocostudio/action/CCActionObject.js b/extensions/cocostudio/action/CCActionObject.js
index a78f0f7b41..bb8959c86b 100644
--- a/extensions/cocostudio/action/CCActionObject.js
+++ b/extensions/cocostudio/action/CCActionObject.js
@@ -200,7 +200,7 @@ ccs.ActionObject = ccs.Class.extend(/** @lends ccs.ActionObject# */{
locActionNodeList[i].playAction(fun);
}
if (this._loop)
- this._scheduler.schedule(this.simulationActionUpdate, this, 0, cc.Macro.REPEAT_FOREVER, 0, false, this.__instanceId + "");
+ this._scheduler.schedule(this.simulationActionUpdate, this, 0, cc.macro.REPEAT_FOREVER, 0, false, this.__instanceId + "");
if(fun !== undefined)
this._callback = fun;
},
diff --git a/extensions/cocostudio/armature/CCArmature.js b/extensions/cocostudio/armature/CCArmature.js
index 8030a42a5c..41778fc45b 100644
--- a/extensions/cocostudio/armature/CCArmature.js
+++ b/extensions/cocostudio/armature/CCArmature.js
@@ -68,7 +68,7 @@ ccs.Armature = ccs.Node.extend(/** @lends ccs.Armature# */{
this._armatureIndexDic = {};
this._offsetPoint = cc.p(0, 0);
this._armatureTransformDirty = true;
- this._blendFunc = {src: cc.Macro.BLEND_SRC, dst: cc.Macro.BLEND_DST};
+ this._blendFunc = {src: cc.macro.BLEND_SRC, dst: cc.macro.BLEND_DST};
name && ccs.Armature.prototype.init.call(this, name, parentBone);
},
diff --git a/extensions/cocostudio/armature/CCArmatureWebGLRenderCmd.js b/extensions/cocostudio/armature/CCArmatureWebGLRenderCmd.js
index 9f4e8f6aaa..b282271316 100644
--- a/extensions/cocostudio/armature/CCArmatureWebGLRenderCmd.js
+++ b/extensions/cocostudio/armature/CCArmatureWebGLRenderCmd.js
@@ -39,9 +39,9 @@
var node = this._node;
if(!dontChangeMatrix){
- cc.kmGLMatrixMode(cc.KM_GL_MODELVIEW);
- cc.kmGLPushMatrix();
- cc.kmGLLoadMatrix(this._stackMatrix);
+ cc.math.glMatrixMode(cc.math.KM_GL_MODELVIEW);
+ cc.math.glPushMatrix();
+ cc.math.glLoadMatrix(this._stackMatrix);
}
var locChildren = node._children;
@@ -88,11 +88,11 @@
}
}
if(!dontChangeMatrix)
- cc.kmGLPopMatrix();
+ cc.math.glPopMatrix();
};
proto.initShaderCache = function(){
- this._shaderProgram = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLOR);
+ this._shaderProgram = cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLOR);
};
proto.setShaderProgram = function(shaderProgram){
diff --git a/extensions/cocostudio/armature/CCBone.js b/extensions/cocostudio/armature/CCBone.js
index 38c5f123a7..0d256735fb 100644
--- a/extensions/cocostudio/armature/CCBone.js
+++ b/extensions/cocostudio/armature/CCBone.js
@@ -78,7 +78,7 @@ ccs.Bone = ccs.Node.extend(/** @lends ccs.Bone# */{
this._worldTransform = cc.affineTransformMake(1, 0, 0, 1, 0, 0);
this._boneTransformDirty = true;
- this._blendFunc = new cc.BlendFunc(cc.Macro.BLEND_SRC, cc.Macro.BLEND_DST);
+ this._blendFunc = new cc.BlendFunc(cc.macro.BLEND_SRC, cc.macro.BLEND_DST);
this.blendDirty = false;
this._worldInfo = null;
diff --git a/extensions/cocostudio/armature/datas/CCDatas.js b/extensions/cocostudio/armature/datas/CCDatas.js
index 5bd84bf0a1..4526071f81 100644
--- a/extensions/cocostudio/armature/datas/CCDatas.js
+++ b/extensions/cocostudio/armature/datas/CCDatas.js
@@ -557,7 +557,7 @@ ccs.FrameData = ccs.BaseData.extend(/** @lends ccs.FrameData# */{
this.event = "";
this.sound = "";
this.soundEffect = "";
- this.blendFunc = new cc.BlendFunc(cc.Macro.BLEND_SRC, cc.Macro.BLEND_DST);
+ this.blendFunc = new cc.BlendFunc(cc.macro.BLEND_SRC, cc.macro.BLEND_DST);
this.frameID = 0;
this.isTween = true;
},
diff --git a/extensions/cocostudio/armature/display/CCBatchNode.js b/extensions/cocostudio/armature/display/CCBatchNode.js
index 504678a179..99a626ffb6 100644
--- a/extensions/cocostudio/armature/display/CCBatchNode.js
+++ b/extensions/cocostudio/armature/display/CCBatchNode.js
@@ -40,7 +40,7 @@ ccs.BatchNode = _ccsg.Node.extend(/** @lends ccs.BatchNode# */{
init:function () {
var ret = _ccsg.Node.prototype.init.call(this);
- this.setShaderProgram(cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURE_UCOLOR));
+ this.setShaderProgram(cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURE_UCOLOR));
return ret;
},
@@ -70,7 +70,7 @@ ccs.BatchNode = _ccsg.Node.extend(/** @lends ccs.BatchNode# */{
// IMPORTANT:
// To ease the migration to v3.0, we still support the kmGL stack,
// but it is deprecated and your code should not rely on it
- cc.kmGLPushMatrixWitMat4(this._stackMatrix);
+ cc.math.glPushMatrixWitMat4(this._stackMatrix);
if (this.grid && this.grid.isActive())
this.grid.beforeDraw();
@@ -81,7 +81,7 @@ ccs.BatchNode = _ccsg.Node.extend(/** @lends ccs.BatchNode# */{
if (this.grid && this.grid.isActive())
this.grid.afterDraw(this);
- cc.kmGLPopMatrix();
+ cc.math.glPopMatrix();
},
draw:function (renderer, transform, transformUpdated) {
diff --git a/extensions/cocostudio/armature/display/CCSkinWebGLRenderCmd.js b/extensions/cocostudio/armature/display/CCSkinWebGLRenderCmd.js
index f804e6a3aa..0b5f6ae06a 100644
--- a/extensions/cocostudio/armature/display/CCSkinWebGLRenderCmd.js
+++ b/extensions/cocostudio/armature/display/CCSkinWebGLRenderCmd.js
@@ -65,7 +65,7 @@
var dy = x1 * sr + y2 * cr2 + y;
var locVertexZ = node._vertexZ;
- if(!cc.Macro.SPRITEBATCHNODE_RENDER_SUBPIXEL) {
+ if(!cc.macro.SPRITEBATCHNODE_RENDER_SUBPIXEL) {
ax = 0 | ax;
ay = 0 | ay;
bx = 0 | bx;
@@ -106,25 +106,25 @@
cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst);
//optimize performance for javascript
cc.glBindTexture2DN(0, locTexture); // = cc.glBindTexture2D(locTexture);
- cc.glEnableVertexAttribs(cc.Macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
+ cc.glEnableVertexAttribs(cc.macro.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
gl.bindBuffer(gl.ARRAY_BUFFER, this._quadWebBuffer);
if (this._quadDirty) {
gl.bufferData(gl.ARRAY_BUFFER, this._quad.arrayBuffer, gl.DYNAMIC_DRAW);
this._quadDirty = false;
}
- gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 24, 0); //cc.Macro.VERTEX_ATTRIB_POSITION
- gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, true, 24, 12); //cc.Macro.VERTEX_ATTRIB_COLOR
- gl.vertexAttribPointer(2, 2, gl.FLOAT, false, 24, 16); //cc.Macro.VERTEX_ATTRIB_TEX_COORDS
+ gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 24, 0); //cc.macro.VERTEX_ATTRIB_POSITION
+ gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, true, 24, 12); //cc.macro.VERTEX_ATTRIB_COLOR
+ gl.vertexAttribPointer(2, 2, gl.FLOAT, false, 24, 16); //cc.macro.VERTEX_ATTRIB_TEX_COORDS
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
}
cc.g_NumberOfDraws++;
- if (cc.Macro.SPRITE_DEBUG_DRAW === 0 && !node._showNode)
+ if (cc.macro.SPRITE_DEBUG_DRAW === 0 && !node._showNode)
return;
- if (cc.Macro.SPRITE_DEBUG_DRAW === 1 || node._showNode) {
+ if (cc.macro.SPRITE_DEBUG_DRAW === 1 || node._showNode) {
// draw bounding box
var locQuad = this._quad;
var verticesG1 = [
@@ -134,7 +134,7 @@
cc.p(locQuad.tr.vertices.x, locQuad.tr.vertices.y)
];
cc._drawingUtil.drawPoly(verticesG1, 4, true);
- } else if (cc.Macro.SPRITE_DEBUG_DRAW === 2) {
+ } else if (cc.macro.SPRITE_DEBUG_DRAW === 2) {
// draw texture box
var drawRectG2 = node.getTextureRect();
var offsetPixG2 = node.getOffsetPosition();
diff --git a/extensions/cocostudio/armature/utils/CCDataReaderHelper.js b/extensions/cocostudio/armature/utils/CCDataReaderHelper.js
index 99c837dde9..329382ae6f 100644
--- a/extensions/cocostudio/armature/utils/CCDataReaderHelper.js
+++ b/extensions/cocostudio/armature/utils/CCDataReaderHelper.js
@@ -847,24 +847,24 @@ ccs.dataReaderHelper = /** @lends ccs.dataReaderHelper# */{
var blendFunc = frameData.blendFunc;
switch (blendType) {
case ccs.BLEND_TYPE_NORMAL:
- blendFunc.src = cc.Macro.BLEND_SRC;
- blendFunc.dst = cc.Macro.BLEND_DST;
+ blendFunc.src = cc.macro.BLEND_SRC;
+ blendFunc.dst = cc.macro.BLEND_DST;
break;
case ccs.BLEND_TYPE_ADD:
- blendFunc.src = cc.Macro.SRC_ALPHA;
- blendFunc.dst = cc.Macro.ONE;
+ blendFunc.src = cc.macro.SRC_ALPHA;
+ blendFunc.dst = cc.macro.ONE;
break;
case ccs.BLEND_TYPE_MULTIPLY:
- blendFunc.src = cc.Macro.DST_COLOR;
- blendFunc.dst = cc.Macro.ONE_MINUS_SRC_ALPHA;
+ blendFunc.src = cc.macro.DST_COLOR;
+ blendFunc.dst = cc.macro.ONE_MINUS_SRC_ALPHA;
break;
case ccs.BLEND_TYPE_SCREEN:
- blendFunc.src = cc.Macro.ONE;
- blendFunc.dst = cc.Macro.ONE_MINUS_DST_COLOR;
+ blendFunc.src = cc.macro.ONE;
+ blendFunc.dst = cc.macro.ONE_MINUS_DST_COLOR;
break;
default:
- frameData.blendFunc.src = cc.Macro.BLEND_SRC;
- frameData.blendFunc.dst = cc.Macro.BLEND_DST;
+ frameData.blendFunc.src = cc.macro.BLEND_SRC;
+ frameData.blendFunc.dst = cc.macro.BLEND_DST;
break;
}
}
@@ -937,8 +937,8 @@ ccs.dataReaderHelper = /** @lends ccs.dataReaderHelper# */{
frameData.tweenEasing = json[ccs.CONST_A_TWEEN_EASING] || ccs.TweenType.LINEAR;
frameData.displayIndex = json[ccs.CONST_A_DISPLAY_INDEX];
- var bd_src = json[ccs.CONST_A_BLEND_SRC] == null ? cc.Macro.BLEND_SRC : json[ccs.CONST_A_BLEND_SRC];
- var bd_dst = json[ccs.CONST_A_BLEND_DST] == null ? cc.Macro.BLEND_DST : json[ccs.CONST_A_BLEND_DST];
+ var bd_src = json[ccs.CONST_A_BLEND_SRC] == null ? cc.macro.BLEND_SRC : json[ccs.CONST_A_BLEND_SRC];
+ var bd_dst = json[ccs.CONST_A_BLEND_DST] == null ? cc.macro.BLEND_DST : json[ccs.CONST_A_BLEND_DST];
frameData.blendFunc.src = bd_src;
frameData.blendFunc.dst = bd_dst;
frameData.isTween = json[ccs.CONST_A_TWEEN_FRAME] == null ? true : json[ccs.CONST_A_TWEEN_FRAME];
diff --git a/extensions/gui/control-extension/CCControlStepper.js b/extensions/gui/control-extension/CCControlStepper.js
index fb0e8c97eb..a94c8c11d9 100644
--- a/extensions/gui/control-extension/CCControlStepper.js
+++ b/extensions/gui/control-extension/CCControlStepper.js
@@ -221,7 +221,7 @@ cc.ControlStepper = cc.Control.extend(/** @lends cc.ControlStepper# */{
startAutorepeat:function () {
this._autorepeatCount = -1;
- this.schedule(this.update, cc.AUTOREPEAT_DELTATIME, cc.Macro.REPEAT_FOREVER, cc.AUTOREPEAT_DELTATIME * 3);
+ this.schedule(this.update, cc.AUTOREPEAT_DELTATIME, cc.macro.REPEAT_FOREVER, cc.AUTOREPEAT_DELTATIME * 3);
},
/** Stop the autorepeat. */
diff --git a/extensions/gui/scrollview/CCScrollViewWebGLRenderCmd.js b/extensions/gui/scrollview/CCScrollViewWebGLRenderCmd.js
index 7098f1a825..674e326e42 100644
--- a/extensions/gui/scrollview/CCScrollViewWebGLRenderCmd.js
+++ b/extensions/gui/scrollview/CCScrollViewWebGLRenderCmd.js
@@ -104,6 +104,6 @@
}
this._dirtyFlag = 0;
- cc.kmGLPopMatrix();
+ cc.math.glPopMatrix();
};
})();
\ No newline at end of file
diff --git a/extensions/gui/scrollview/CCSorting.js b/extensions/gui/scrollview/CCSorting.js
index d9e43b88c1..e0064ccf16 100644
--- a/extensions/gui/scrollview/CCSorting.js
+++ b/extensions/gui/scrollview/CCSorting.js
@@ -108,7 +108,7 @@ cc.ArrayForObjectSorting = cc._Class.extend(/** @lends cc.ArrayForObjectSorting#
}
var idx = this.indexOfSortedObject(delObject);
- if (idx < this.count() && idx !== cc.Macro.INVALID_INDEX) {
+ if (idx < this.count() && idx !== cc.macro.INVALID_INDEX) {
var foundObj = this.objectAtIndex(idx);
if (foundObj.getObjectID() === delObject.getObjectID()) {
this.removeObjectAtIndex(idx);
@@ -129,7 +129,7 @@ cc.ArrayForObjectSorting = cc._Class.extend(/** @lends cc.ArrayForObjectSorting#
*/
setObjectID_ofSortedObject:function (tag, setObject) {
var idx = this.indexOfSortedObject(setObject);
- if (idx < this.count() && idx !== cc.Macro.INVALID_INDEX) {
+ if (idx < this.count() && idx !== cc.macro.INVALID_INDEX) {
var foundObj = this.objectAtIndex(idx);
if (foundObj.getObjectID() === setObject.getObjectID()) {
this.removeObjectAtIndex(idx);
@@ -147,7 +147,7 @@ cc.ArrayForObjectSorting = cc._Class.extend(/** @lends cc.ArrayForObjectSorting#
foundObj.setObjectID(tag);
var idx = this.indexOfSortedObject(foundObj);
- if (idx < this.count() && idx !== cc.Macro.INVALID_INDEX) {
+ if (idx < this.count() && idx !== cc.macro.INVALID_INDEX) {
foundObj = this.objectAtIndex(idx);
if (foundObj.getObjectID() !== tag)
foundObj = null;
@@ -201,7 +201,7 @@ cc.ArrayForObjectSorting = cc._Class.extend(/** @lends cc.ArrayForObjectSorting#
idx++;
}
} else {
- idx = cc.Macro.INVALID_INDEX;
+ idx = cc.macro.INVALID_INDEX;
}
return idx;
},
diff --git a/extensions/gui/scrollview/CCTableView.js b/extensions/gui/scrollview/CCTableView.js
index f3992593e5..961fb014a6 100644
--- a/extensions/gui/scrollview/CCTableView.js
+++ b/extensions/gui/scrollview/CCTableView.js
@@ -65,7 +65,7 @@ cc.TableViewCell = _ccsg.Node.extend(/** @lends cc.TableViewCell# */{
* Cleans up any resources linked to this cell and resets idx property.
*/
reset:function () {
- this._idx = cc.Macro.INVALID_INDEX;
+ this._idx = cc.macro.INVALID_INDEX;
},
setObjectID:function (idx) {
@@ -257,7 +257,7 @@ cc.TableView = cc.ScrollView.extend(/** @lends cc.TableView# */{
if (index !== -1) {
index = Math.max(0, index);
if (index > maxIdx)
- index = cc.Macro.INVALID_INDEX;
+ index = cc.macro.INVALID_INDEX;
}
return index;
},
@@ -428,7 +428,7 @@ cc.TableView = cc.ScrollView.extend(/** @lends cc.TableView# */{
* @param idx index to find a cell
*/
updateCellAtIndex:function (idx) {
- if (idx === cc.Macro.INVALID_INDEX || idx > this._dataSource.numberOfCellsInTableView(this) - 1)
+ if (idx === cc.macro.INVALID_INDEX || idx > this._dataSource.numberOfCellsInTableView(this) - 1)
return;
var cell = this.cellAtIndex(idx);
@@ -446,7 +446,7 @@ cc.TableView = cc.ScrollView.extend(/** @lends cc.TableView# */{
* @param idx location to insert
*/
insertCellAtIndex:function (idx) {
- if (idx === cc.Macro.INVALID_INDEX || idx > this._dataSource.numberOfCellsInTableView(this) - 1)
+ if (idx === cc.macro.INVALID_INDEX || idx > this._dataSource.numberOfCellsInTableView(this) - 1)
return;
var newIdx, locCellsUsed = this._cellsUsed;
@@ -474,7 +474,7 @@ cc.TableView = cc.ScrollView.extend(/** @lends cc.TableView# */{
* @param idx index to find a cell
*/
removeCellAtIndex:function (idx) {
- if (idx === cc.Macro.INVALID_INDEX || idx > this._dataSource.numberOfCellsInTableView(this) - 1)
+ if (idx === cc.macro.INVALID_INDEX || idx > this._dataSource.numberOfCellsInTableView(this) - 1)
return;
var cell = this.cellAtIndex(idx);
@@ -569,7 +569,7 @@ cc.TableView = cc.ScrollView.extend(/** @lends cc.TableView# */{
if (this._vOrdering === cc.TABLEVIEW_FILL_TOPDOWN)
offset.y = offset.y + locViewSize.height/locContainer.getScaleY();
var startIdx = this._indexFromOffset(offset);
- if (startIdx === cc.Macro.INVALID_INDEX)
+ if (startIdx === cc.macro.INVALID_INDEX)
startIdx = countOfItems - 1;
if (this._vOrdering === cc.TABLEVIEW_FILL_TOPDOWN)
@@ -579,7 +579,7 @@ cc.TableView = cc.ScrollView.extend(/** @lends cc.TableView# */{
offset.x += locViewSize.width/locContainer.getScaleX();
var endIdx = this._indexFromOffset(offset);
- if (endIdx === cc.Macro.INVALID_INDEX)
+ if (endIdx === cc.macro.INVALID_INDEX)
endIdx = countOfItems - 1;
var cell, locCellsUsed = this._cellsUsed;
@@ -656,7 +656,7 @@ cc.TableView = cc.ScrollView.extend(/** @lends cc.TableView# */{
point = this.getContainer().convertTouchToNodeSpace(touch);
index = this._indexFromOffset(point);
- if (index === cc.Macro.INVALID_INDEX)
+ if (index === cc.macro.INVALID_INDEX)
this._touchedCell = null;
else
this._touchedCell = this.cellAtIndex(index);
diff --git a/extensions/spine/SGSkeleton.js b/extensions/spine/SGSkeleton.js
index d96a50c93a..bc98f63f89 100644
--- a/extensions/spine/SGSkeleton.js
+++ b/extensions/spine/SGSkeleton.js
@@ -40,7 +40,7 @@ sp._SGSkeleton = _ccsg.Node.extend({
ctor: function(skeletonDataFile, atlasFile, scale) {
_ccsg.Node.prototype.ctor.call(this);
- this._blendFunc = {src: cc.Macro.BLEND_SRC, dst: cc.Macro.BLEND_DST};
+ this._blendFunc = {src: cc.macro.BLEND_SRC, dst: cc.macro.BLEND_DST};
if(arguments.length === 0)
this.init();
@@ -58,8 +58,8 @@ sp._SGSkeleton = _ccsg.Node.extend({
init: function () {
_ccsg.Node.prototype.init.call(this);
//this.setOpacityModifyRGB(true);
- this._blendFunc.src = cc.Macro.ONE;
- this._blendFunc.dst = cc.Macro.ONE_MINUS_SRC_ALPHA;
+ this._blendFunc.src = cc.macro.ONE;
+ this._blendFunc.dst = cc.macro.ONE_MINUS_SRC_ALPHA;
this.scheduleUpdate();
},
@@ -148,7 +148,7 @@ sp._SGSkeleton = _ccsg.Node.extend({
* @returns {cc.Rect}
*/
getBoundingBox: function () {
- var minX = cc.Macro.FLT_MAX, minY = cc.Macro.FLT_MAX, maxX = cc.Macro.FLT_MIN, maxY = cc.Macro.FLT_MIN;
+ var minX = cc.macro.FLT_MAX, minY = cc.macro.FLT_MAX, maxX = cc.macro.FLT_MIN, maxY = cc.macro.FLT_MIN;
var scaleX = this.getScaleX(), scaleY = this.getScaleY(), vertices = [],
slots = this._skeleton.slots, VERTEX = sp.VERTEX_INDEX;
diff --git a/extensions/spine/SGSkeletonWebGLRenderCmd.js b/extensions/spine/SGSkeletonWebGLRenderCmd.js
index 524065302e..e611be7e07 100644
--- a/extensions/spine/SGSkeletonWebGLRenderCmd.js
+++ b/extensions/spine/SGSkeletonWebGLRenderCmd.js
@@ -28,7 +28,7 @@ var spine = sp.spine;
sp._SGSkeleton.WebGLRenderCmd = function (renderableObject) {
_ccsg.Node.WebGLRenderCmd.call(this, renderableObject);
this._needDraw = true;
- this.setShaderProgram(cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLOR));
+ this.setShaderProgram(cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLOR));
this._tmpQuad = new cc.V3F_C4B_T2F_Quad();
};
@@ -86,13 +86,13 @@ proto.rendering = function (ctx) {
blendMode = slot.data.blendMode;
switch (blendMode) {
case spine.BlendMode.additive:
- cc.glBlendFunc(premultiAlpha ? cc.Macro.ONE : cc.Macro.SRC_ALPHA, cc.Macro.ONE);
+ cc.glBlendFunc(premultiAlpha ? cc.macro.ONE : cc.macro.SRC_ALPHA, cc.macro.ONE);
break;
case spine.BlendMode.multiply:
- cc.glBlendFunc(cc.Macro.DST_COLOR, cc.Macro.ONE_MINUS_SRC_ALPHA);
+ cc.glBlendFunc(cc.macro.DST_COLOR, cc.macro.ONE_MINUS_SRC_ALPHA);
break;
case spine.BlendMode.screen:
- cc.glBlendFunc(cc.Macro.ONE, cc.Macro.ONE_MINUS_SRC_COLOR);
+ cc.glBlendFunc(cc.macro.ONE, cc.macro.ONE_MINUS_SRC_COLOR);
break;
default:
cc.glBlendFunc(locBlendFunc.src, locBlendFunc.dst);
@@ -120,8 +120,8 @@ proto.rendering = function (ctx) {
}
if (node._debugBones || node._debugSlots) {
- cc.kmGLMatrixMode(cc.KM_GL_MODELVIEW);
- //cc.kmGLPushMatrixWitMat4(this._stackMatrix);
+ cc.math.glMatrixMode(cc.math.KM_GL_MODELVIEW);
+ //cc.math.glPushMatrixWitMat4(this._stackMatrix);
cc.current_stack.stack.push(cc.current_stack.top);
cc.current_stack.top = this._stackMatrix;
var drawingUtil = cc._drawingUtil;
@@ -173,7 +173,7 @@ proto.rendering = function (ctx) {
}
}
}
- cc.kmGLPopMatrix();
+ cc.math.glPopMatrix();
}
};
diff --git a/external/gaf/Library/GAFShaderManager.js b/external/gaf/Library/GAFShaderManager.js
index 4bb314ce0a..1de8a28667 100644
--- a/external/gaf/Library/GAFShaderManager.js
+++ b/external/gaf/Library/GAFShaderManager.js
@@ -14,9 +14,9 @@ gaf._glShaderInit = function() {
var program = new cc.GLProgram();
var result = program.initWithVertexShaderByteArray(vs, fs);
cc.assert(result, "Shader init error");
- program.addAttribute(cc.Macro.ATTRIBUTE_NAME_POSITION, cc.Macro.VERTEX_ATTRIB_POSITION);
- program.addAttribute(cc.Macro.ATTRIBUTE_NAME_COLOR, cc.Macro.VERTEX_ATTRIB_COLOR);
- program.addAttribute(cc.Macro.ATTRIBUTE_NAME_TEX_COORD, cc.Macro.VERTEX_ATTRIB_TEX_COORDS);
+ program.addAttribute(cc.macro.ATTRIBUTE_NAME_POSITION, cc.macro.VERTEX_ATTRIB_POSITION);
+ program.addAttribute(cc.macro.ATTRIBUTE_NAME_COLOR, cc.macro.VERTEX_ATTRIB_COLOR);
+ program.addAttribute(cc.macro.ATTRIBUTE_NAME_TEX_COORD, cc.macro.VERTEX_ATTRIB_TEX_COORDS);
result = program.link();
cc.assert(result, "Shader linking error");
program.updateUniforms();
@@ -24,7 +24,7 @@ gaf._glShaderInit = function() {
};
gaf._shaderCreateAlpha = function () {
- var program = gaf._shaderCreate(gaf.SHADER_COLOR_MATRIX_FRAG, cc.Shaders.POSITION_TEXTURE_COLOR_VERT);
+ var program = gaf._shaderCreate(gaf.SHADER_COLOR_MATRIX_FRAG, cc.PresetShaders.POSITION_TEXTURE_COLOR_VERT);
gaf._Uniforms.ColorTransformMult = program.getUniformLocationForName(gaf.UNIFORM_ALPHA_TINT_MULT);
gaf._Uniforms.ColorTransformOffset = program.getUniformLocationForName(gaf.UNIFORM_ALPHA_TINT_OFFSET);
gaf._Uniforms.ColorMatrixBody = program.getUniformLocationForName(gaf.UNIFORM_ALPHA_COLOR_MATRIX_BODY);
@@ -33,14 +33,14 @@ gaf._glShaderInit = function() {
};
gaf._shaderCreateBlur = function () {
- var program = gaf._shaderCreate(gaf.SHADER_GAUSSIAN_BLUR_FRAG, cc.Shaders.POSITION_TEXTURE_COLOR_VERT);
+ var program = gaf._shaderCreate(gaf.SHADER_GAUSSIAN_BLUR_FRAG, cc.PresetShaders.POSITION_TEXTURE_COLOR_VERT);
gaf._Uniforms.BlurTexelOffset = program._glContext.getUniformLocation(program._programObj, gaf.UNIFORM_BLUR_TEXEL_OFFSET);
return program;
};
gaf._shaderCreateGlow = function () {
- var program = gaf._shaderCreate(gaf.SHADER_GLOW_FRAG, cc.Shaders.POSITION_TEXTURE_COLOR_VERT);
+ var program = gaf._shaderCreate(gaf.SHADER_GLOW_FRAG, cc.PresetShaders.POSITION_TEXTURE_COLOR_VERT);
gaf._Uniforms.GlowTexelOffset = program._glContext.getUniformLocation(program._programObj, gaf.UNIFORM_GLOW_TEXEL_OFFSET);
gaf._Uniforms.GlowColor = program._glContext.getUniformLocation(program._programObj, gaf.UNIFORM_GLOW_COLOR);
return program;
diff --git a/external/gaf/Library/GAFSpriteWebGLRenderCmd.js b/external/gaf/Library/GAFSpriteWebGLRenderCmd.js
index 127d2a7f6a..de1f92b8d3 100644
--- a/external/gaf/Library/GAFSpriteWebGLRenderCmd.js
+++ b/external/gaf/Library/GAFSpriteWebGLRenderCmd.js
@@ -2,7 +2,7 @@
(function(){
gaf.Sprite.WebGLRenderCmd = function (renderable) {
_ccsg.Sprite.WebGLRenderCmd.call(this, renderable);
- this._defualtShader = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLOR);
+ this._defualtShader = cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLOR);
this._customShader = gaf._Shaders.Alpha;
//this._shaderProgram = this._defualtShader;
diff --git a/gulp/tasks/build-cocos2d.js b/gulp/tasks/build-cocos2d.js
index b2b9ff65bd..6f792684af 100644
--- a/gulp/tasks/build-cocos2d.js
+++ b/gulp/tasks/build-cocos2d.js
@@ -32,25 +32,11 @@ var es = require('event-stream');
var sourcemaps = require('gulp-sourcemaps');
var srcs = [
- './Base64Images.js',
'./CCBoot.js',
'./cocos2d/core/platform/CCSAXParser.js',
- './cocos2d/core/platform/miniFramework.js',
'./cocos2d/core/platform/CCEGLView.js',
'./cocos2d/core/platform/CCScreen.js',
- './cocos2d/core/platform/CCVisibleRect.js',
-
- './cocos2d/core/support/CCVertex.js',
- './cocos2d/core/support/TransformUtils.js',
-
- './cocos2d/core/event-manager/CCTouch.js',
- './cocos2d/core/event-manager/CCSystemEvent.js',
- './cocos2d/core/event-manager/CCEventListener.js',
- './cocos2d/core/event-manager/CCEventManager.js',
-
- './cocos2d/core/renderer/RendererCanvas.js',
- './cocos2d/core/renderer/RendererWebGL.js',
'./cocos2d/core/base-nodes/BaseNodesPropertyDefine.js',
'./cocos2d/core/base-nodes/CCSGNode.js',
@@ -69,9 +55,6 @@ var srcs = [
'./cocos2d/core/sprites/CCSGSpriteCanvasRenderCmd.js',
'./cocos2d/core/sprites/CCSGSpriteWebGLRenderCmd.js',
'./cocos2d/core/sprites/CCBakeSprite.js',
- './cocos2d/core/sprites/CCAnimation.js',
- './cocos2d/core/sprites/CCAnimationCache.js',
- './cocos2d/core/sprites/CCSpriteFrameCache.js',
'./cocos2d/core/sprites/CCSpriteBatchNode.js',
'./cocos2d/core/sprites/CCSpriteBatchNodeCanvasRenderCmd.js',
'./cocos2d/core/sprites/CCSpriteBatchNodeWebGLRenderCmd.js',
@@ -81,7 +64,6 @@ var srcs = [
'./cocos2d/core/sprites/CCScale9SpriteWebGLRenderCmd.js',
'./cocos2d/core/CCConfiguration.js',
- './cocos2d/core/CCCamera.js',
'./cocos2d/core/CCScheduler.js',
'./cocos2d/core/CCDrawingPrimitivesCanvas.js',
@@ -94,19 +76,6 @@ var srcs = [
'./cocos2d/core/editbox/CCSGEditBox.js',
'./cocos2d/core/editBox/CCdomNode.js',
- './cocos2d/kazmath/utility.js',
- './cocos2d/kazmath/vec2.js',
- './cocos2d/kazmath/vec3.js',
- './cocos2d/kazmath/vec4.js',
- './cocos2d/kazmath/ray2.js',
- './cocos2d/kazmath/mat3.js',
- './cocos2d/kazmath/mat4.js',
- './cocos2d/kazmath/plane.js',
- './cocos2d/kazmath/quaternion.js',
- './cocos2d/kazmath/aabb.js',
- './cocos2d/kazmath/gl/mat4stack.js',
- './cocos2d/kazmath/gl/matrix.js',
-
'./cocos2d/shaders/CCShaders.js',
'./cocos2d/shaders/CCShaderCache.js',
'./cocos2d/shaders/CCGLProgram.js',
@@ -126,11 +95,6 @@ var srcs = [
'./cocos2d/core/CCActionManager.js',
- './cocos2d/progress-timer/CCProgressTimer.js',
- './cocos2d/progress-timer/CCProgressTimerCanvasRenderCmd.js',
- './cocos2d/progress-timer/CCProgressTimerWebGLRenderCmd.js',
- './cocos2d/progress-timer/CCActionProgressTimer.js',
-
'./cocos2d/compression/ZipUtils.js',
'./cocos2d/compression/base64.js',
'./cocos2d/compression/gzip.js',
diff --git a/jsb/jsb-tex-sprite-frame.js b/jsb/jsb-tex-sprite-frame.js
index 2340ccefa9..de595c9025 100644
--- a/jsb/jsb-tex-sprite-frame.js
+++ b/jsb/jsb-tex-sprite-frame.js
@@ -25,8 +25,8 @@
'use strict';
-cc.spriteFrameAnimationCache = cc.animationCache;
-cc.SpriteFrameAnimation = cc.Animation;
+// cc.spriteFrameAnimationCache = cc.animationCache;
+// cc.SpriteFrameAnimation = cc.Animation;
// cc.textureCache.cacheImage
cc.textureCache._textures = {};
diff --git a/predefine.js b/predefine.js
index da92d6de01..0d29782fe2 100644
--- a/predefine.js
+++ b/predefine.js
@@ -59,13 +59,19 @@ require('./cocos2d/core/event');
require('./cocos2d/core/platform/CCSys');
require('./cocos2d/core/platform/CCMacro');
require('./cocos2d/core/load-pipeline');
-require('./cocos2d/core/CCDirector');
-require('./cocos2d/core/CCDirectorWebGL');
-require('./cocos2d/core/CCDirectorCanvas');
require('./cocos2d/core/textures');
if (!CC_JSB) {
- require('./cocos2d/actions');
+ require('./cocos2d/kazmath');
+ require('./cocos2d/core/CCDirector');
+ require('./cocos2d/core/CCDirectorWebGL');
+ require('./cocos2d/core/CCDirectorCanvas');
+
+ if (!(CC_EDITOR && Editor.isCoreLevel)) {
+ require('./cocos2d/actions');
+ require('./cocos2d/core/event-manager');
+ require('./cocos2d/core/renderer');
+ }
}
ccui = {};
diff --git a/test/visual-tests/src/ClippingNodeTest/ClippingNodeTest.js b/test/visual-tests/src/ClippingNodeTest/ClippingNodeTest.js
index e6b4d72a31..7c307790ed 100644
--- a/test/visual-tests/src/ClippingNodeTest/ClippingNodeTest.js
+++ b/test/visual-tests/src/ClippingNodeTest/ClippingNodeTest.js
@@ -534,20 +534,20 @@ var RawStencilBufferTest = BaseClippingNodeTest.extend({
cc._drawingUtil.drawSolidRect(cc.p(0, 0), stencilPoint, cc.color(255, 255, 255, 255));
- cc.kmGLPushMatrix();
+ cc.math.glPushMatrix();
this.transform();
this._sprite.visit();
- cc.kmGLPopMatrix();
+ cc.math.glPopMatrix();
this.setupStencilForDrawingOnPlane(i);
//cc.checkGLErrorDebug();
cc._drawingUtil.drawSolidRect(cc.p(0, 0), winPoint, _planeColor[i]);
- cc.kmGLPushMatrix();
+ cc.math.glPushMatrix();
this.transform();
this._sprite.visit();
- cc.kmGLPopMatrix();
+ cc.math.glPopMatrix();
}
gl.disable(gl.STENCIL_TEST);
@@ -620,8 +620,8 @@ var RawStencilBufferTest4 = RawStencilBufferTest.extend({
this._super(plane);
gl.depthMask(false);
- var program = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLORALPHATEST);
- var alphaValueLocation = gl.getUniformLocation(program.getProgram(),cc.Macro.UNIFORM_ALPHA_TEST_VALUE_S);
+ var program = cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLORALPHATEST);
+ var alphaValueLocation = gl.getUniformLocation(program.getProgram(),cc.macro.UNIFORM_ALPHA_TEST_VALUE_S);
cc.glUseProgram(program.getProgram());
program.setUniformLocationWith1f(alphaValueLocation, _alphaThreshold);
this._sprite.shaderProgram = program;
@@ -644,8 +644,8 @@ var RawStencilBufferTest5 = RawStencilBufferTest.extend({
gl.disable(gl.DEPTH_TEST);
gl.depthMask(false);
- var program = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLORALPHATEST);
- var alphaValueLocation = gl.getUniformLocation(program.getProgram(), cc.Macro.UNIFORM_ALPHA_TEST_VALUE_S);
+ var program = cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLORALPHATEST);
+ var alphaValueLocation = gl.getUniformLocation(program.getProgram(), cc.macro.UNIFORM_ALPHA_TEST_VALUE_S);
cc.glUseProgram(program.getProgram());
program.setUniformLocationWith1f(alphaValueLocation, _alphaThreshold);
this._sprite.shaderProgram = program;
@@ -680,8 +680,8 @@ var RawStencilBufferTest6 = RawStencilBufferTest.extend({
gl.disable(gl.DEPTH_TEST);
gl.depthMask(false);
- var program = cc.shaderCache.programForKey(cc.Macro.SHADER_POSITION_TEXTURECOLORALPHATEST);
- var alphaValueLocation = gl.getUniformLocation(program.getProgram(), cc.Macro.UNIFORM_ALPHA_TEST_VALUE_S);
+ var program = cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLORALPHATEST);
+ var alphaValueLocation = gl.getUniformLocation(program.getProgram(), cc.macro.UNIFORM_ALPHA_TEST_VALUE_S);
cc.glUseProgram(program.getProgram());
program.setUniformLocationWith1f(alphaValueLocation, _alphaThreshold);
this._sprite.shaderProgram = program;
diff --git a/test/visual-tests/src/CocosNodeTest/CocosNodeTest.js b/test/visual-tests/src/CocosNodeTest/CocosNodeTest.js
index f11089f687..fa9cb14caf 100644
--- a/test/visual-tests/src/CocosNodeTest/CocosNodeTest.js
+++ b/test/visual-tests/src/CocosNodeTest/CocosNodeTest.js
@@ -740,7 +740,7 @@ var NodeOpaqueTest = TestNodeDemo.extend({
var background;
for (var i = 0; i < 50; i++) {
background = new _ccsg.Sprite(s_back1);
- background.setBlendFunc(cc.Macro.ONE, cc.Macro.ONE_MINUS_SRC_ALPHA);
+ background.setBlendFunc(cc.macro.ONE, cc.macro.ONE_MINUS_SRC_ALPHA);
background.x = winSize.width / 2;
background.y = winSize.height / 2;
this.addChild(background);
@@ -765,7 +765,7 @@ var NodeNonOpaqueTest = TestNodeDemo.extend({
var background;
for (var i = 0; i < 50; i++) {
background = new _ccsg.Sprite(s_back1);
- background.setBlendFunc(cc.Macro.ONE, cc.Macro.ZERO);
+ background.setBlendFunc(cc.macro.ONE, cc.macro.ZERO);
background.x = winSize.width / 2;
background.y = winSize.height / 2;
this.addChild(background);
diff --git a/test/visual-tests/src/LabelTest/LabelTest.js b/test/visual-tests/src/LabelTest/LabelTest.js
index 883fa2fe37..dd18e17111 100644
--- a/test/visual-tests/src/LabelTest/LabelTest.js
+++ b/test/visual-tests/src/LabelTest/LabelTest.js
@@ -2006,11 +2006,11 @@ var WrapAlgorithmTest = AtlasDemo.extend({
},
onEnter: function(){
this._super();
- cc.Macro.SPRITE_DEBUG_DRAW = 1;
+ cc.macro.SPRITE_DEBUG_DRAW = 1;
},
onExit: function(){
this._super();
- cc.Macro.SPRITE_DEBUG_DRAW = 0;
+ cc.macro.SPRITE_DEBUG_DRAW = 0;
}
});
diff --git a/test/visual-tests/src/LayerTest/LayerTest.js b/test/visual-tests/src/LayerTest/LayerTest.js
index e73f979a73..d61faa9f7a 100644
--- a/test/visual-tests/src/LayerTest/LayerTest.js
+++ b/test/visual-tests/src/LayerTest/LayerTest.js
@@ -428,11 +428,11 @@ var LayerTestBlend = LayerTest.extend({
var dst;
if (this._blend) {
- src = cc.Macro.SRC_ALPHA;
- dst = cc.Macro.ONE_MINUS_SRC_ALPHA;
+ src = cc.macro.SRC_ALPHA;
+ dst = cc.macro.ONE_MINUS_SRC_ALPHA;
} else {
- src = cc.Macro.ONE_MINUS_DST_COLOR;
- dst = cc.Macro.ZERO;
+ src = cc.macro.ONE_MINUS_DST_COLOR;
+ dst = cc.macro.ZERO;
}
layer.setBlendFunc( src, dst );
this._blend = ! this._blend;
diff --git a/test/visual-tests/src/OpenGLTest/OpenGLTest.js b/test/visual-tests/src/OpenGLTest/OpenGLTest.js
index ba5eba2b31..4fba806585 100644
--- a/test/visual-tests/src/OpenGLTest/OpenGLTest.js
+++ b/test/visual-tests/src/OpenGLTest/OpenGLTest.js
@@ -43,13 +43,13 @@ cc.GLNode = cc.GLNode || _ccsg.Node.extend({
init:function(){
this._renderCmd._needDraw = true;
this._renderCmd.rendering = function(ctx){
- cc.kmGLMatrixMode(cc.KM_GL_MODELVIEW);
- cc.kmGLPushMatrix();
- cc.kmGLLoadMatrix(this._stackMatrix);
+ cc.math.glMatrixMode(cc.math.KM_GL_MODELVIEW);
+ cc.math.glPushMatrix();
+ cc.math.glLoadMatrix(this._stackMatrix);
this._node.draw(ctx);
- cc.kmGLPopMatrix();
+ cc.math.glPopMatrix();
};
},
draw:function(ctx){
@@ -458,23 +458,23 @@ var GLNodeCCAPITest = OpenGLTestLayer.extend({
this.shader.use();
this.shader.setUniformsForBuiltins();
- cc.glEnableVertexAttribs( cc.Macro.VERTEX_ATTRIB_FLAG_COLOR | cc.Macro.VERTEX_ATTRIB_FLAG_POSITION);
+ cc.glEnableVertexAttribs( cc.macro.VERTEX_ATTRIB_FLAG_COLOR | cc.macro.VERTEX_ATTRIB_FLAG_POSITION);
// Draw fullscreen Square
gl.bindBuffer(gl.ARRAY_BUFFER, this.squareVertexPositionBuffer);
- gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, 0, 0);
+ gl.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, 0, 0);
gl.bindBuffer(gl.ARRAY_BUFFER, this.squareVertexColorBuffer);
- gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_COLOR, 4, gl.FLOAT, false, 0, 0);
+ gl.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_COLOR, 4, gl.FLOAT, false, 0, 0);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
// Draw fullscreen Triangle
gl.bindBuffer(gl.ARRAY_BUFFER, this.triangleVertexPositionBuffer);
- gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, 0, 0);
+ gl.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, 0, 0);
gl.bindBuffer(gl.ARRAY_BUFFER, this.triangleVertexColorBuffer);
- gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_COLOR, 4, gl.FLOAT, false, 0, 0);
+ gl.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_COLOR, 4, gl.FLOAT, false, 0, 0);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 3);
@@ -574,7 +574,7 @@ var ShaderNode = cc.GLNode.extend({
this.shader = cc.GLProgram.create(vertexShader, framentShader);
this.shader.retain();
- this.shader.addAttribute("aVertex", cc.Macro.VERTEX_ATTRIB_POSITION);
+ this.shader.addAttribute("aVertex", cc.macro.VERTEX_ATTRIB_POSITION);
this.shader.link();
this.shader.updateUniforms();
@@ -604,11 +604,11 @@ var ShaderNode = cc.GLNode.extend({
this.shader.setUniformLocationF32( this.uniformCenter, centerx, centery);
this.shader.setUniformLocationF32( this.uniformResolution, 256, 256);
- cc.glEnableVertexAttribs( cc.Macro.VERTEX_ATTRIB_FLAG_POSITION );
+ cc.glEnableVertexAttribs( cc.macro.VERTEX_ATTRIB_FLAG_POSITION );
// Draw fullscreen Square
gl.bindBuffer(gl.ARRAY_BUFFER, this.squareVertexPositionBuffer);
- gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, 0, 0);
+ gl.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, 0, 0);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
gl.bindBuffer(gl.ARRAY_BUFFER, null);
@@ -879,9 +879,9 @@ var ShaderOutlineEffect = OpenGLTestLayer.extend({
}
else{
this.shader = new cc.GLProgram("res/Shaders/example_Outline.vsh", "res/Shaders/example_Outline.fsh");
- this.shader.addAttribute(cc.Macro.ATTRIBUTE_NAME_POSITION, cc.Macro.VERTEX_ATTRIB_POSITION);
- this.shader.addAttribute(cc.Macro.ATTRIBUTE_NAME_TEX_COORD, cc.Macro.VERTEX_ATTRIB_TEX_COORDS);
- this.shader.addAttribute(cc.Macro.ATTRIBUTE_NAME_COLOR, cc.Macro.VERTEX_ATTRIB_COLOR);
+ this.shader.addAttribute(cc.macro.ATTRIBUTE_NAME_POSITION, cc.macro.VERTEX_ATTRIB_POSITION);
+ this.shader.addAttribute(cc.macro.ATTRIBUTE_NAME_TEX_COORD, cc.macro.VERTEX_ATTRIB_TEX_COORDS);
+ this.shader.addAttribute(cc.macro.ATTRIBUTE_NAME_COLOR, cc.macro.VERTEX_ATTRIB_COLOR);
this.shader.link();
this.shader.updateUniforms();
@@ -950,8 +950,8 @@ var ShaderRetroEffect = OpenGLTestLayer.extend({
if( 'opengl' in cc.sys.capabilities ) {
var program = new cc.GLProgram("res/Shaders/example_ColorBars.vsh", "res/Shaders/example_ColorBars.fsh");
- program.addAttribute(cc.Macro.ATTRIBUTE_NAME_POSITION, cc.Macro.VERTEX_ATTRIB_POSITION);
- program.addAttribute(cc.Macro.ATTRIBUTE_NAME_TEX_COORD, cc.Macro.VERTEX_ATTRIB_TEX_COORDS);
+ program.addAttribute(cc.macro.ATTRIBUTE_NAME_POSITION, cc.macro.VERTEX_ATTRIB_POSITION);
+ program.addAttribute(cc.macro.ATTRIBUTE_NAME_TEX_COORD, cc.macro.VERTEX_ATTRIB_TEX_COORDS);
program.link();
program.updateUniforms();
@@ -1088,14 +1088,14 @@ var TexImage2DTest = OpenGLTestLayer.extend({
this.shader.setUniformsForBuiltins();
gl.bindTexture(gl.TEXTURE_2D, this.my_texture);
- cc.glEnableVertexAttribs( cc.Macro.VERTEX_ATTRIB_FLAG_TEX_COORDS | cc.Macro.VERTEX_ATTRIB_FLAG_POSITION);
+ cc.glEnableVertexAttribs( cc.macro.VERTEX_ATTRIB_FLAG_TEX_COORDS | cc.macro.VERTEX_ATTRIB_FLAG_POSITION);
// Draw fullscreen Square
gl.bindBuffer(gl.ARRAY_BUFFER, this.squareVertexPositionBuffer);
- gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, 0, 0);
+ gl.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, 0, 0);
gl.bindBuffer(gl.ARRAY_BUFFER, this.squareVertexTextureBuffer);
- gl.vertexAttribPointer(cc.Macro.VERTEX_ATTRIB_TEX_COORDS, 2, gl.FLOAT, false, 0, 0);
+ gl.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_TEX_COORDS, 2, gl.FLOAT, false, 0, 0);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
diff --git a/test/visual-tests/src/SchedulerTest/SchedulerTest.js b/test/visual-tests/src/SchedulerTest/SchedulerTest.js
index 050f7be692..916208139f 100644
--- a/test/visual-tests/src/SchedulerTest/SchedulerTest.js
+++ b/test/visual-tests/src/SchedulerTest/SchedulerTest.js
@@ -496,7 +496,7 @@ var ScheduleUsingSchedulerTest = SchedulerTestLayer.extend({
scheduler.scheduleUpdateForTarget(this, priority, paused);
var interval = 0.25; // every 1/4 of second
- var repeat = cc.Macro.REPEAT_FOREVER; // how many repeats. cc.Macro.REPEAT_FOREVER means forever
+ var repeat = cc.macro.REPEAT_FOREVER; // how many repeats. cc.macro.REPEAT_FOREVER means forever
var delay = 2; // start after 2 seconds;
paused = false; // not paused. queue it now.
scheduler.scheduleCallbackForTarget(this, this.onSchedUpdate, interval, repeat, delay, paused);
diff --git a/test/visual-tests/src/SpriteTest/SpriteTest.js b/test/visual-tests/src/SpriteTest/SpriteTest.js
index ef6e0606bf..cd15652482 100644
--- a/test/visual-tests/src/SpriteTest/SpriteTest.js
+++ b/test/visual-tests/src/SpriteTest/SpriteTest.js
@@ -994,7 +994,7 @@ var SpriteZVertex = SpriteTestDemo.extend({
//
var alphaTestShader = cc.shaderCache.getProgram("ShaderPositionTextureColorAlphaTest");
var glprogram = alphaTestShader.getProgram();
- var alphaValueLocation = gl.getUniformLocation(glprogram, cc.Macro.UNIFORM_ALPHA_TEST_VALUE_S);
+ var alphaValueLocation = gl.getUniformLocation(glprogram, cc.macro.UNIFORM_ALPHA_TEST_VALUE_S);
// set alpha test value
// NOTE: alpha test shader is hard-coded to use the equivalent of a glAlphaFunc(GL_GREATER) comparison
@@ -1118,7 +1118,7 @@ var SpriteBatchNodeZVertex = SpriteTestDemo.extend({
//
var alphaTestShader = cc.shaderCache.getProgram("ShaderPositionTextureColorAlphaTest");
var glprogram = alphaTestShader.getProgram();
- var alphaValueLocation = gl.getUniformLocation(glprogram, cc.Macro.UNIFORM_ALPHA_TEST_VALUE_S);
+ var alphaValueLocation = gl.getUniformLocation(glprogram, cc.macro.UNIFORM_ALPHA_TEST_VALUE_S);
// set alpha test value
// NOTE: alpha test shader is hard-coded to use the equivalent of a glAlphaFunc(GL_GREATER) comparison
@@ -5200,7 +5200,7 @@ var TextureRotatedSpriteFrame = SpriteTestDemo.extend({
var SpriteWithRepeatingTexture = SpriteTestDemo.extend({
_title:"Sprite with Repeating texture",
- _subtitle:"aTexture.setTexParameters(cc.Macro.LINEAR, cc.Macro.LINEAR, cc.Texture2D.WrapMode.REPEAT, cc.Texture2D.WrapMode.REPEAT);",
+ _subtitle:"aTexture.setTexParameters(cc.macro.LINEAR, cc.macro.LINEAR, cc.Texture2D.WrapMode.REPEAT, cc.Texture2D.WrapMode.REPEAT);",
ctor:function () {
//----start58----ctor
@@ -5212,7 +5212,7 @@ var SpriteWithRepeatingTexture = SpriteTestDemo.extend({
block.setTextureRect(cc.rect(0,0, 320,240));
block.setPosition(x, y);
- block.getTexture().setTexParameters(cc.Macro.LINEAR, cc.Macro.LINEAR, cc.Texture2D.WrapMode.REPEAT, cc.Texture2D.WrapMode.REPEAT);
+ block.getTexture().setTexParameters(cc.macro.LINEAR, cc.macro.LINEAR, cc.Texture2D.WrapMode.REPEAT, cc.Texture2D.WrapMode.REPEAT);
this.addChild(block);
//----end58----
}
@@ -5227,8 +5227,8 @@ var SpriteBlendFuncTest = SpriteTestDemo.extend({
//----start59----ctor
this._super();
- var destFactors = [cc.Macro.ZERO, cc.Macro.ONE, cc.Macro.DST_COLOR, cc.Macro.ONE_MINUS_DST_COLOR, cc.Macro.DST_ALPHA, cc.Macro.ONE_MINUS_DST_ALPHA],
- srcFactors = [cc.Macro.ZERO, cc.Macro.ONE, cc.Macro.SRC_COLOR, cc.Macro.ONE_MINUS_SRC_COLOR, cc.Macro.SRC_ALPHA, cc.Macro.ONE_MINUS_SRC_ALPHA];
+ var destFactors = [cc.macro.ZERO, cc.macro.ONE, cc.macro.DST_COLOR, cc.macro.ONE_MINUS_DST_COLOR, cc.macro.DST_ALPHA, cc.macro.ONE_MINUS_DST_ALPHA],
+ srcFactors = [cc.macro.ZERO, cc.macro.ONE, cc.macro.SRC_COLOR, cc.macro.ONE_MINUS_SRC_COLOR, cc.macro.SRC_ALPHA, cc.macro.ONE_MINUS_SRC_ALPHA];
var destTitles = ["ZERO", "ONE", "DST_COLOR", "ONE_MINUS_DST_COLOR", "DST_ALPHA", "ONE_MINUS_DST_ALPHA"],
srcTitles = ["ZERO", "ONE", "SRC_COLOR", "ONE_MINUS_SRC_COLOR", "SRC_ALPHA", "ONE_MINUS_SRC_ALPHA"];