Merge pull request #470 from pandamicro/v1.0

清理 Core 模块
This commit is contained in:
pandamicro
2016-03-14 12:00:26 +08:00
130 changed files with 3959 additions and 4345 deletions
-32
View File
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -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)
+1 -1
View File
@@ -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;
+3 -3
View File
@@ -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;
@@ -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);
+2 -2
View File
@@ -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;
};
+2 -2
View File
@@ -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("")
+1 -1
View File
@@ -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();
},
-8
View File
@@ -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;
}
}
});
+33 -30
View File
@@ -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();
};
+2 -2
View File
@@ -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();
+21 -19
View File
@@ -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);
+4 -4
View File
@@ -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.<br/>
* If 'interval' is 0, it will be called every frame, but if so, it recommended to use 'scheduleUpdateForTarget:' instead.<br/>
* If the callback function is already scheduled, then only the interval parameter will be updated without re-scheduling it again.<br/>
* repeat let the action be repeated repeat + 1 times, use cc.Macro.REPEAT_FOREVER to let the action run continuously<br/>
* repeat let the action be repeated repeat + 1 times, use cc.macro.REPEAT_FOREVER to let the action run continuously<br/>
* delay is the amount of time the action will wait before it'll start<br/>
* </p>
* @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;
}
}
+1 -1
View File
@@ -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);
},
@@ -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]);
+11 -28
View File
@@ -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: '', ///<a string label, an user defined string to identify this node
@@ -1233,7 +1226,7 @@ _ccsg.Node = cc.Class({
* @see _ccsg.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);
@@ -1564,27 +1557,27 @@ _ccsg.Node = cc.Class({
if(len === 1){
//callback
interval = 0;
repeat = cc.Macro.REPEAT_FOREVER;
repeat = cc.macro.REPEAT_FOREVER;
delay = 0;
key = this.__instanceId;
}else if(len === 2){
if(typeof interval === "number"){
//callback, interval
repeat = cc.Macro.REPEAT_FOREVER;
repeat = cc.macro.REPEAT_FOREVER;
delay = 0;
key = this.__instanceId;
}else{
//callback, key
key = interval;
interval = 0;
repeat = cc.Macro.REPEAT_FOREVER;
repeat = cc.macro.REPEAT_FOREVER;
delay = 0;
}
}else if(len === 3){
if(typeof repeat === "string"){
//callback, interval, key
key = repeat;
repeat = cc.Macro.REPEAT_FOREVER;
repeat = cc.macro.REPEAT_FOREVER;
}else{
//callback, interval, repeat
key = this.__instanceId;
@@ -1599,10 +1592,10 @@ _ccsg.Node = cc.Class({
//selector, interval, repeat, delay
if(len === 1){
interval = 0;
repeat = cc.Macro.REPEAT_FOREVER;
repeat = cc.macro.REPEAT_FOREVER;
delay = 0;
}else if(len === 2){
repeat = cc.Macro.REPEAT_FOREVER;
repeat = cc.macro.REPEAT_FOREVER;
delay = 0;
}
}
@@ -1611,7 +1604,7 @@ _ccsg.Node = cc.Class({
cc.assert(interval >= 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");
@@ -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";
@@ -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;
};
+2 -2
View File
@@ -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);
-13
View File
@@ -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;
+1 -25
View File
@@ -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();
};
cc._EventListenerKeyboard.LISTENER_ID = "__cc_keyboard";
+5 -5
View File
@@ -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)
+29
View File
@@ -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');
+4
View File
@@ -26,6 +26,10 @@
require('./platform');
require('./assets');
if (!CC_JSB) {
require('./sprites/CCSpriteFrameCache');
}
if (!CC_EDITOR || !Editor.isCoreLevel) {
require('./CCNode');
require('./CCScene');
+7 -7
View File
@@ -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;
@@ -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);
}
+3 -3
View File
@@ -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";
+3 -49
View File
@@ -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();
};
/**
* <p>
* CCLayerColor is a subclass of CCLayer that implements the CCRGBAProtocol protocol. <br/>
@@ -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));
};
});
+6 -6
View File
@@ -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);
+20 -31
View File
@@ -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({
/**
* <p>
* Sets view's target-densitydpi for android mobile browser. it can be set to: <br/>
* 1. cc.DENSITYDPI_DEVICE, value is "device-dpi" <br/>
* 2. cc.DENSITYDPI_HIGH, value is "high-dpi" (default value) <br/>
* 3. cc.DENSITYDPI_MEDIUM, value is "medium-dpi" (browser's default value) <br/>
* 4. cc.DENSITYDPI_LOW, value is "low-dpi" <br/>
* 1. cc.macro.DENSITYDPI_DEVICE, value is "device-dpi" <br/>
* 2. cc.macro.DENSITYDPI_HIGH, value is "high-dpi" (default value) <br/>
* 3. cc.macro.DENSITYDPI_MEDIUM, value is "medium-dpi" (browser's default value) <br/>
* 4. cc.macro.DENSITYDPI_LOW, value is "low-dpi" <br/>
* 5. Custom value, e.g: "480" <br/>
* </p>
*
@@ -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);
}
},
+21 -7
View File
@@ -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;
};
/**
+5
View File
@@ -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');
}
+1
View File
@@ -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() {
+1 -1
View File
@@ -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;
+27
View File
@@ -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');
-9
View File
@@ -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();
};
+1 -1
View File
@@ -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"];
+5 -38
View File
@@ -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
+448 -448
View File
@@ -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();
};
})();
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();
};
+5 -32
View File
@@ -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};
/**
@@ -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();
+3 -26
View File
@@ -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;
/**
* <p>
* creates a cc.SpriteBatchNodeCanvas with a file image (.png, .jpg etc) with a default capacity of 29 children.<br/>
* The capacity will be increased in 33% in runtime if it run out of space.<br/>
* The file will be loaded using the TextureMgr.<br/>
* </p>
* @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;
cc.SpriteBatchNode.DEFAULT_CAPACITY = 29;
@@ -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;
}
};
-28
View File
@@ -466,31 +466,3 @@ proto.copyWithZone = proto.clone;
*/
proto.copy = proto.clone;
/**
* <p>
* Create a cc.SpriteFrame with a texture filename, rect, rotated, offset and originalSize in pixels.<br/>
* The originalSize is the size in pixels of the frame before being trimmed.
* </p>
* 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);
};
+1 -1
View File
@@ -25,7 +25,7 @@
****************************************************************************/
// init CCSpriteFrame
require("../cocos2d/core/sprites/CCSpriteFrame");
require("./CCSpriteFrame");
+3 -3
View File
@@ -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];
-65
View File
@@ -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
+6 -6
View File
@@ -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);
+1 -1
View File
@@ -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);
};
+3 -3
View File
@@ -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;
}
},
+2 -2
View File
@@ -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);
+10 -10
View File
@@ -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;
+1 -1
View File
@@ -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) {
+13 -50
View File
@@ -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 <br/>
* 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);
};
+42 -44
View File
@@ -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);
cc.defineGetterSetter(cc.sys, "useSIMD", _isEnabledSIMD, _enableSIMD);
+42 -64
View File
@@ -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);
};
+116 -117
View File
@@ -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;
}
};
+12
View File
@@ -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');
+300 -307
View File
@@ -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();
}
+951 -958
View File
File diff suppressed because it is too large Load Diff
+377 -381
View File
@@ -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;
};
+82 -91
View File
@@ -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;
};
+367 -383
View File
@@ -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;
};
/**
* <p>
* Adapted from the OGRE engine! <br/>
* Gets the shortest arc quaternion to rotate this vector to the destination vector. <br/>
* @remarks <br/>
* If you call this with a destination vector that is close to the inverse <br/>
* of this vector, we will rotate 180 degrees around the 'fallbackAxis' <br/>
* (if specified, or a generated axis if not) since in this case ANY axis of rotation is valid.
* </p>
* @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();
/**
* <p>
* Adapted from the OGRE engine! <br/>
* Gets the shortest arc quaternion to rotate this vector to the destination vector. <br/>
* @remarks <br/>
* If you call this with a destination vector that is close to the inverse <br/>
* of this vector, we will rotate 180 degrees around the 'fallbackAxis' <br/>
* (if specified, or a generated axis if not) since in this case ANY axis of rotation is valid.
* </p>
* @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;
};
+97 -99
View File
@@ -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;
};
@@ -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) {
@@ -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);
}
}
@@ -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();
}
}
@@ -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) {
@@ -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);
}
}
@@ -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) {
@@ -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) {
@@ -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;
+2 -2
View File
@@ -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
+69 -71
View File
@@ -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);
};
+155 -167
View File
@@ -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;
};
+19 -19
View File
@@ -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;
};
+110 -115
View File
@@ -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;
};
+2 -2
View File
@@ -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);
@@ -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)];
+11 -11
View File
@@ -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);
+1 -1
View File
@@ -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;
@@ -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++;
+2 -2
View File
@@ -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;
}
@@ -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);
+6 -6
View File
@@ -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;
}
},
@@ -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();
};
})();
+10 -10
View File
@@ -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;
}
}
}
@@ -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){};
@@ -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) {
@@ -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;
@@ -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
@@ -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();
};
})();
+58 -55
View File
@@ -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;
+30 -28
View File
@@ -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.<br/>
* 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.<br/>
* 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.<br/>
* 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.<br/>
* 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().<br/>
* 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 () {
* <p>
* Will enable the vertex attribs that are passed as flags. <br/>
* Possible flags: <br/>
* cc.Macro.VERTEX_ATTRIB_FLAG_POSITION <br/>
* cc.Macro.VERTEX_ATTRIB_FLAG_COLOR <br/>
* cc.Macro.VERTEX_ATTRIB_FLAG_TEX_COORDS <br/>
* cc.macro.VERTEX_ATTRIB_FLAG_POSITION <br/>
* cc.macro.VERTEX_ATTRIB_FLAG_COLOR <br/>
* cc.macro.VERTEX_ATTRIB_FLAG_TEX_COORDS <br/>
* <br/>
* These flags can be ORed. The flags that are not present, will be disabled.
* </p>
* @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.<br/>
* 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.<br/>
* 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. <br/>
* 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.<br/>
* 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.<br/>
* 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.<br/>
* 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
*/
+45 -42
View File
@@ -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);
},
+2 -2
View File
@@ -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}
+7 -7
View File
@@ -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);
@@ -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++) {
+2 -2
View File
@@ -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);
+2 -2
View File
@@ -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);

Some files were not shown because too many files have changed in this diff Show More