Skip to content

Commit b7677e1

Browse files
committed
Merge pull request #2769 from dingpinglv/Iss2698_namespace
Issue #2698: corrected a mistake of cc.math.Matrix in constructor.
2 parents cbfc840 + 2ef4b2c commit b7677e1

File tree

8 files changed

+73
-39
lines changed

8 files changed

+73
-39
lines changed

cocos2d/clipping-nodes/CCClippingNodeWebGLRenderCmd.js

+22-10
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,29 @@
144144

145145
proto._drawFullScreenQuadClearStencil = function () {
146146
// draw a fullscreen solid rectangle to clear the stencil buffer
147-
cc.kmGLMatrixMode(cc.KM_GL_PROJECTION);
148-
cc.kmGLPushMatrix();
149-
cc.kmGLLoadIdentity();
150-
cc.kmGLMatrixMode(cc.KM_GL_MODELVIEW);
151-
cc.kmGLPushMatrix();
152-
cc.kmGLLoadIdentity();
147+
var projStack = cc.projection_matrix_stack;
148+
//cc.kmGLMatrixMode(cc.KM_GL_PROJECTION);
149+
//cc.kmGLPushMatrix();
150+
//cc.kmGLLoadIdentity();
151+
projStack.push();
152+
projStack.top.identity();
153+
154+
//cc.kmGLMatrixMode(cc.KM_GL_MODELVIEW);
155+
//cc.kmGLPushMatrix();
156+
//cc.kmGLLoadIdentity();
157+
var modelViewStack = cc.modelview_matrix_stack;
158+
modelViewStack.push();
159+
modelViewStack.top.identity();
160+
153161
cc._drawingUtil.drawSolidRect(cc.p(-1, -1), cc.p(1, 1), cc.color(255, 255, 255, 255));
154-
cc.kmGLMatrixMode(cc.KM_GL_PROJECTION);
155-
cc.kmGLPopMatrix();
156-
cc.kmGLMatrixMode(cc.KM_GL_MODELVIEW);
157-
cc.kmGLPopMatrix();
162+
163+
//cc.kmGLMatrixMode(cc.KM_GL_PROJECTION);
164+
//cc.kmGLPopMatrix();
165+
projStack.pop();
166+
167+
//cc.kmGLMatrixMode(cc.KM_GL_MODELVIEW);
168+
//cc.kmGLPopMatrix();
169+
modelViewStack.pop();
158170
};
159171

160172
proto._onBeforeVisit = function(ctx){

cocos2d/core/CCScheduler.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ cc.TimerTargetCallback = cc.Timer.extend({
285285
*
286286
* @example
287287
* //register a schedule to scheduler
288-
* cc.director.getScheduler().scheduleSelector(callback, this, interval, !this._isRunning);
288+
* cc.director.getScheduler().schedule(callback, this, interval, !this._isRunning);
289289
*/
290290
cc.Scheduler = cc.Class.extend(/** @lends cc.Scheduler# */{
291291
_timeScale:1.0,

cocos2d/core/cocoa/CCAffineTransform.js

+24-15
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,26 @@ cc.affineTransformMake = function (a, b, c, d, tx, ty) {
6666
* Apply the affine transformation on a point.
6767
* @function
6868
*
69-
* @param {cc.Point} point
70-
* @param {cc.AffineTransform} t
69+
* @param {cc.Point|Number} point or x
70+
* @param {cc.AffineTransform|Number} transOrY transform matrix or y
71+
* @param {cc.AffineTransform} t transform matrix or y
7172
* @return {cc.Point}
7273
*/
73-
cc.pointApplyAffineTransform = function (point, t) {
74-
return {x: t.a * point.x + t.c * point.y + t.tx, y: t.b * point.x + t.d * point.y + t.ty};
74+
cc.pointApplyAffineTransform = function (point, transOrY, t) {
75+
var x, y;
76+
if (t === undefined) {
77+
t = transOrY;
78+
x = point.x;
79+
y = point.y;
80+
} else {
81+
x = point;
82+
y = transOrY;
83+
}
84+
return {x: t.a * x + t.c * y + t.tx, y: t.b * x + t.d * y + t.ty};
7585
};
7686

77-
cc._pointApplyAffineTransform = function (x, y, t) {
78-
return {x: t.a * x + t.c * y + t.tx,
79-
y: t.b * x + t.d * y + t.ty};
87+
cc._pointApplyAffineTransform = function (x, y, t) { //it will remove.
88+
return cc.pointApplyAffineTransform(x, y, t);
8089
};
8190

8291
/**
@@ -131,10 +140,10 @@ cc.rectApplyAffineTransform = function (rect, anAffineTransform) {
131140
var right = cc.rectGetMaxX(rect);
132141
var bottom = cc.rectGetMaxY(rect);
133142

134-
var topLeft = cc._pointApplyAffineTransform(left, top, anAffineTransform);
135-
var topRight = cc._pointApplyAffineTransform(right, top, anAffineTransform);
136-
var bottomLeft = cc._pointApplyAffineTransform(left, bottom, anAffineTransform);
137-
var bottomRight = cc._pointApplyAffineTransform(right, bottom, anAffineTransform);
143+
var topLeft = cc.pointApplyAffineTransform(left, top, anAffineTransform);
144+
var topRight = cc.pointApplyAffineTransform(right, top, anAffineTransform);
145+
var bottomLeft = cc.pointApplyAffineTransform(left, bottom, anAffineTransform);
146+
var bottomRight = cc.pointApplyAffineTransform(right, bottom, anAffineTransform);
138147

139148
var minX = Math.min(topLeft.x, topRight.x, bottomLeft.x, bottomRight.x);
140149
var maxX = Math.max(topLeft.x, topRight.x, bottomLeft.x, bottomRight.x);
@@ -150,10 +159,10 @@ cc._rectApplyAffineTransformIn = function(rect, anAffineTransform){
150159
var right = cc.rectGetMaxX(rect);
151160
var bottom = cc.rectGetMaxY(rect);
152161

153-
var topLeft = cc._pointApplyAffineTransform(left, top, anAffineTransform);
154-
var topRight = cc._pointApplyAffineTransform(right, top, anAffineTransform);
155-
var bottomLeft = cc._pointApplyAffineTransform(left, bottom, anAffineTransform);
156-
var bottomRight = cc._pointApplyAffineTransform(right, bottom, anAffineTransform);
162+
var topLeft = cc.pointApplyAffineTransform(left, top, anAffineTransform);
163+
var topRight = cc.pointApplyAffineTransform(right, top, anAffineTransform);
164+
var bottomLeft = cc.pointApplyAffineTransform(left, bottom, anAffineTransform);
165+
var bottomRight = cc.pointApplyAffineTransform(right, bottom, anAffineTransform);
157166

158167
var minX = Math.min(topLeft.x, topRight.x, bottomLeft.x, bottomRight.x);
159168
var maxX = Math.max(topLeft.x, topRight.x, bottomLeft.x, bottomRight.x);

cocos2d/core/layers/CCLayer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ cc.LayerColor.create = function (color, width, height) {
313313
* @property {Number} startOpacity - Start opacity of the color gradient
314314
* @property {Number} endOpacity - End opacity of the color gradient
315315
* @property {Number} vector - Direction vector of the color gradient
316-
* @property {Number} compresseInterpolation - Indicate whether or not the interpolation will be compressed
316+
* @property {Number} compressedInterpolation - Indicate whether or not the interpolation will be compressed
317317
*/
318318
cc.LayerGradient = cc.LayerColor.extend(/** @lends cc.LayerGradient# */{
319319
_endColor: null,

cocos2d/core/layers/CCLayerWebGLRenderCmd.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,10 @@
247247
transMat = cc.affineTransformScale(transMat, tx, ty);
248248
for (i = 0; i < stopsLen; i++) {
249249
var stop = stops[i], y = stop.p * contentSize.height ;
250-
var p0 = cc._pointApplyAffineTransform(- locAnchor.x , y - locAnchor.y, transMat);
250+
var p0 = cc.pointApplyAffineTransform(- locAnchor.x , y - locAnchor.y, transMat);
251251
locVertices[i * 2].x = p0.x;
252252
locVertices[i * 2].y = p0.y;
253-
var p1 = cc._pointApplyAffineTransform(contentSize.width - locAnchor.x, y - locAnchor.y, transMat);
253+
var p1 = cc.pointApplyAffineTransform(contentSize.width - locAnchor.x, y - locAnchor.y, transMat);
254254
locVertices[i * 2 + 1].x = p1.x;
255255
locVertices[i * 2 + 1].y = p1.y;
256256
}

cocos2d/kazmath/gl/mat4stack.js

+18
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
cc.math.Matrix4Stack = function(top, stack) {
3737
this.top = top;
3838
this.stack = stack || [];
39+
//this._matrixPool = []; // use pool in next version
3940
};
4041
cc.km_mat4_stack = cc.math.Matrix4Stack;
4142
var proto = cc.math.Matrix4Stack.prototype;
@@ -61,17 +62,34 @@
6162
};
6263

6364
proto.push = function(item) {
65+
item = item || this.top;
6466
this.stack.push(this.top);
6567
this.top = new cc.math.Matrix4(item);
68+
//this.top = this._getFromPool(item);
6669
};
6770

6871
proto.pop = function() {
72+
//this._putInPool(this.top);
6973
this.top = this.stack.pop();
7074
};
7175

7276
proto.release = function(){
7377
this.stack = null;
7478
this.top = null;
79+
this._matrixPool = null;
80+
};
81+
82+
proto._getFromPool = function (item) {
83+
var pool = this._matrixPool;
84+
if (pool.length === 0)
85+
return new cc.math.Matrix4(item);
86+
var ret = pool.pop();
87+
ret.assignFrom(item);
88+
return ret;
89+
};
90+
91+
proto._putInPool = function(matrix){
92+
this._matrixPool.push(matrix);
7593
};
7694
})(cc);
7795

cocos2d/kazmath/mat3.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@
2929
var Float32Array = Float32Array || Array;
3030
(function(cc){
3131
cc.math.Matrix3 = function(mat3) {
32-
if (mat3) {
33-
this.mat = new Float32Array(mat3);
32+
if (mat3 && mat3.mat) {
33+
this.mat = new Float32Array(mat3.mat);
3434
} else {
35-
this.mat = new Float32Array([0, 0, 0,
36-
0, 0, 0,
37-
0, 0, 0]);
35+
this.mat = new Float32Array(9);
3836
}
3937
};
4038
cc.kmMat3 = cc.math.Matrix3;

cocos2d/kazmath/mat4.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,10 @@
4040
* @param {cc.math.Matrix4} [mat4]
4141
*/
4242
cc.math.Matrix4 = function (mat4) {
43-
if(mat4){
43+
if(mat4 && mat4.mat){
4444
this.mat = new Float32Array(mat4.mat);
4545
} else {
46-
this.mat = new Float32Array([0, 0, 0, 0,
47-
0, 0, 0, 0,
48-
0, 0, 0, 0,
49-
0, 0, 0, 0]);
46+
this.mat = new Float32Array(16);
5047
}
5148
};
5249
cc.kmMat4 = cc.math.Matrix4;

0 commit comments

Comments
 (0)