replaced matrix

This commit is contained in:
Mat Groves 2014-01-31 00:04:32 +00:00
parent b8a9a82680
commit c3b9c96200
14 changed files with 804 additions and 251 deletions

File diff suppressed because it is too large Load diff

View file

@ -454,8 +454,8 @@ PIXI.InteractionManager.prototype.hitTest = function(item, interactionData)
var isSprite = (item instanceof PIXI.Sprite),
worldTransform = item.worldTransform,
a00 = worldTransform[0], a01 = worldTransform[1], a02 = worldTransform[2],
a10 = worldTransform[3], a11 = worldTransform[4], a12 = worldTransform[5],
a00 = worldTransform.a, a01 = worldTransform.b, a02 = worldTransform.tx,
a10 = worldTransform.c, a11 = worldTransform.d, a12 = worldTransform.ty,
id = 1 / (a00 * a11 + a01 * -a10),
x = a11 * id * global.x + -a01 * id * global.y + (a12 * a01 - a02 * a11) * id,
y = a00 * id * global.y + -a10 * id * global.x + (-a12 * a00 + a02 * a10) * id;

View file

@ -12,7 +12,7 @@ PIXI.determineMatrixArrayType = function() {
return (typeof Float32Array !== 'undefined') ? Float32Array : Array;
};
PIXI.Matrix = PIXI.determineMatrixArrayType();
PIXI.Matrix2 = PIXI.determineMatrixArrayType();
/**
@ -33,7 +33,7 @@ PIXI.mat3 = {};
*/
PIXI.mat3.create = function()
{
var matrix = new PIXI.Matrix(9);
var matrix = new PIXI.Matrix2(9);
matrix[0] = 1;
matrix[1] = 0;
@ -118,7 +118,7 @@ PIXI.mat3.multiply = function (mat, mat2, dest)
*/
PIXI.mat3.clone = function(mat)
{
var matrix = new PIXI.Matrix(9);
var matrix = new PIXI.Matrix2(9);
matrix[0] = mat[0];
matrix[1] = mat[1];
@ -217,7 +217,7 @@ PIXI.mat3.toMat4 = function (mat, dest)
*/
PIXI.mat4.create = function()
{
var matrix = new PIXI.Matrix(16);
var matrix = new PIXI.Matrix2(16);
matrix[0] = 1;
matrix[1] = 0;
@ -350,3 +350,60 @@ PIXI.mat4.multiply = function (mat, mat2, dest)
PIXI.identityMatrix = PIXI.mat3.create();
PIXI.tempMatrix = PIXI.mat3.create();
PIXI.Matrix = function()
{
this.a = 1;
this.b = 0;
this.c = 0;
this.d = 1;
this.tx = 0;
this.ty = 0;
}
PIXI.Matrix.prototype.fromArray = function(array)
{
this.a = array[0];
this.b = array[1];
this.c = array[3];
this.d = array[4];
this.tx = array[2];
this.ty = array[5];
}
PIXI.Matrix.prototype.toArray = function(transpose)
{
if(!this.array)this.array = new Float32Array(9);
var array = this.array;
if(transpose)
{
this.array[0] = this.a;
this.array[1] = this.c;
this.array[2] = 0;
this.array[3] = this.b;
this.array[4] = this.d;
this.array[5] = 0;
this.array[6] = this.tx;
this.array[7] = this.ty;
this.array[8] = 1;
}
else
{
this.array[0] = this.a;
this.array[1] = this.b;
this.array[2] = this.tx;
this.array[3] = this.c;
this.array[4] = this.d;
this.array[5] = this.ty;
this.array[6] = 0;
this.array[7] = 0;
this.array[8] = 1;
}
return array;//[this.a, this.b, this.tx, this.c, this.d, this.ty, 0, 0, 1];
}

View file

@ -139,7 +139,7 @@ PIXI.DisplayObject = function()
* @readOnly
* @private
*/
this.worldTransform = PIXI.mat3.create(); //mat3.identity();
this.worldTransform = new PIXI.Matrix()//PIXI.mat3.create(); //mat3.identity();
/**
* [read-only] Current transform of the object locally
@ -149,7 +149,7 @@ PIXI.DisplayObject = function()
* @readOnly
* @private
*/
this.localTransform = PIXI.mat3.create(); //mat3.identity();
this.localTransform = new PIXI.Matrix()//PIXI.mat3.create(); //mat3.identity();
/**
* [NYI] Unknown
@ -407,40 +407,30 @@ PIXI.DisplayObject.prototype.updateTransform = function()
this._cr = Math.cos(this.rotation);
}
var localTransform = this.localTransform;
var parentTransform = this.parent.worldTransform;
var worldTransform = this.worldTransform;
// var localTransform = this.localTransform//.toArray();
var parentTransform = this.parent.worldTransform//.toArray();
var worldTransform = this.worldTransform//.toArray();
//console.log(localTransform)
localTransform[0] = this._cr * this.scale.x;
localTransform[1] = -this._sr * this.scale.y;
localTransform[3] = this._sr * this.scale.x;
localTransform[4] = this._cr * this.scale.y;
// TODO --> do we even need a local matrix???
var px = this.pivot.x;
var py = this.pivot.y;
// Cache the matrix values (makes for huge speed increases!)
var a00 = localTransform[0], a01 = localTransform[1], a02 = this.position.x - localTransform[0] * px - py * localTransform[1],
a10 = localTransform[3], a11 = localTransform[4], a12 = this.position.y - localTransform[4] * py - px * localTransform[3],
var a00 = this._cr * this.scale.x,
a01 = -this._sr * this.scale.y,
a10 = this._sr * this.scale.x,
a11 = this._cr * this.scale.y,
a02 = this.position.x + a00 * px - py * a01,
a12 = this.position.y + a11 * py - px * a10,
b00 = parentTransform.a, b01 = parentTransform.b, b02 = parentTransform.tx,
b10 = parentTransform.c, b11 = parentTransform.d, b12 = parentTransform.ty;
b00 = parentTransform[0], b01 = parentTransform[1], b02 = parentTransform[2],
b10 = parentTransform[3], b11 = parentTransform[4], b12 = parentTransform[5];
worldTransform.a = b00 * a00 + b01 * a10;
worldTransform.b = b00 * a01 + b01 * a11;
worldTransform.tx = b00 * a02 + b01 * a12 + b02;
localTransform[2] = a02;
localTransform[5] = a12;
worldTransform.c = b10 * a00 + b11 * a10;
worldTransform.d = b10 * a01 + b11 * a11;
worldTransform.ty = b10 * a02 + b11 * a12 + b12;
worldTransform[0] = b00 * a00 + b01 * a10;
worldTransform[1] = b00 * a01 + b01 * a11;
worldTransform[2] = b00 * a02 + b01 * a12 + b02;
worldTransform[3] = b10 * a00 + b11 * a10;
worldTransform[4] = b10 * a01 + b11 * a11;
worldTransform[5] = b10 * a02 + b11 * a12 + b12;
// because we are using affine transformation, we can optimise the matrix concatenation process.. wooo!
// mat3.multiply(this.localTransform, this.parent.worldTransform, this.worldTransform);
this.worldAlpha = this.alpha * this.parent.worldAlpha;
};

View file

@ -184,12 +184,12 @@ PIXI.Sprite.prototype.getBounds = function()
var worldTransform = this.worldTransform;
var a = worldTransform[0];
var b = worldTransform[3];
var c = worldTransform[1];
var d = worldTransform[4];
var tx = worldTransform[2];
var ty = worldTransform[5];
var a = worldTransform.a;
var b = worldTransform.c;
var c = worldTransform.b;
var d = worldTransform.d;
var tx = worldTransform.tx;
var ty = worldTransform.ty;
var x1 = a * w1 + c * h1 + tx;
var y1 = d * h1 + b * w1 + ty;
@ -345,7 +345,7 @@ PIXI.Sprite.prototype._renderCanvas = function(renderSession)
// allow for trimming
context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]);
context.setTransform(transform.a, transform.c, transform.b, transform.d, transform.tx, transform.ty);
//if smoothingEnabled is supported and we need to change the smoothing property for this texture
if(renderSession.smoothProperty && renderSession.scaleMode !== this.texture.baseTexture.scaleMode) {

View file

@ -93,7 +93,7 @@ PIXI.SpriteBatch.prototype._renderCanvas = function(renderSession)
// alow for trimming
context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]);
context.setTransform(transform.a, transform.c, transform.b, transform.d, transform.tx, transform.ty);
context.save();
for (var i = 0; i < this.children.length; i++) {
@ -123,7 +123,7 @@ PIXI.SpriteBatch.prototype._renderCanvas = function(renderSession)
PIXI.DisplayObject.prototype.updateTransform.call(child);
transform = child.localTransform;
context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]);
context.setTransform(transform.a, transform.c, transform.b, transform.d, transform.tx, transform.ty);
context.drawImage(texture.baseTexture.source,
frame.x,

View file

@ -30,7 +30,7 @@ PIXI.Stage = function(backgroundColor)
* @readOnly
* @private
*/
this.worldTransform = PIXI.mat3.create();
this.worldTransform = new PIXI.Matrix()//PIXI.mat3.create();
/**
* Whether or not the stage is interactive

View file

@ -198,7 +198,7 @@ PIXI.TilingSprite.prototype._renderCanvas = function(renderSession)
// allow for trimming
context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]);
context.setTransform(transform.a, transform.c, transform.b, transform.d, transform.tx, transform.ty);
if(!this.__tilePattern)
@ -256,12 +256,12 @@ PIXI.TilingSprite.prototype.getBounds = function()
var worldTransform = this.worldTransform;
var a = worldTransform[0];
var b = worldTransform[3];
var c = worldTransform[1];
var d = worldTransform[4];
var tx = worldTransform[2];
var ty = worldTransform[5];
var a = worldTransform.a;
var b = worldTransform.c;
var c = worldTransform.b;
var d = worldTransform.d;
var tx = worldTransform.tx;
var ty = worldTransform.ty;
var x1 = a * w1 + c * h1 + tx;
var y1 = d * h1 + b * w1 + ty;

View file

@ -422,7 +422,7 @@ PIXI.Graphics.prototype._renderCanvas = function(renderSession)
context.globalCompositeOperation = PIXI.blendModesCanvas[renderSession.currentBlendMode];
}
context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]);
context.setTransform(transform.a, transform.c, transform.b, transform.d, transform.tx, transform.ty);
PIXI.CanvasGraphics.renderGraphics(this, context);
// simple render children!
@ -450,12 +450,12 @@ PIXI.Graphics.prototype.getBounds = function()
var worldTransform = this.worldTransform;
var a = worldTransform[0];
var b = worldTransform[3];
var c = worldTransform[1];
var d = worldTransform[4];
var tx = worldTransform[2];
var ty = worldTransform[5];
var a = worldTransform.a;
var b = worldTransform.c;
var c = worldTransform.b;
var d = worldTransform.d;
var tx = worldTransform.tx;
var ty = worldTransform.ty;
var x1 = a * w1 + c * h1 + tx;
var y1 = d * h1 + b * w1 + ty;

View file

@ -30,7 +30,7 @@ PIXI.CanvasMaskManager.prototype.pushMask = function(maskData, context)
var cacheAlpha = maskData.alpha;
var transform = maskData.worldTransform;
context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]);
context.setTransform(transform.a, transform.c, transform.b, transform.d, transform.tx, transform.ty);
PIXI.CanvasGraphics.renderGraphicsMask(maskData, context);

View file

@ -52,7 +52,7 @@ PIXI.WebGLFastSpriteBatch = function(gl)
this.shader = null;
this.tempMatrix = PIXI.mat3.create();
this.matrix
this.setContext(gl);
};
@ -83,7 +83,9 @@ PIXI.WebGLFastSpriteBatch.prototype.begin = function(spriteBatch, renderSession)
this.renderSession = renderSession;
this.shader = this.renderSession.shaderManager.fastShader;
PIXI.mat3.transpose(spriteBatch.worldTransform, this.tempMatrix);
// PIXI.mat3.transpose(spriteBatch.worldTransform.toArray(), this.tempMatrix);
this.matrix = spriteBatch.worldTransform.toArray(true)
// console.log(this.tempMatrix)
this.start();
@ -179,8 +181,8 @@ PIXI.WebGLFastSpriteBatch.prototype.renderSprite = function(sprite)
verticies[index++] = sprite.rotation;
// uv
verticies[index++] = uvs[0];
verticies[index++] = uvs[1];
verticies[index++] = uvs.x0;
verticies[index++] = uvs.y1;
// color
verticies[index++] = sprite.alpha;
@ -200,8 +202,8 @@ PIXI.WebGLFastSpriteBatch.prototype.renderSprite = function(sprite)
verticies[index++] = sprite.rotation;
// uv
verticies[index++] = uvs[2];
verticies[index++] = uvs[3];
verticies[index++] = uvs.x1;
verticies[index++] = uvs.y1;
// color
verticies[index++] = sprite.alpha;
@ -221,8 +223,8 @@ PIXI.WebGLFastSpriteBatch.prototype.renderSprite = function(sprite)
verticies[index++] = sprite.rotation;
// uv
verticies[index++] = uvs[4];
verticies[index++] = uvs[5];
verticies[index++] = uvs.x2;
verticies[index++] = uvs.y2;
// color
verticies[index++] = sprite.alpha;
@ -244,8 +246,8 @@ PIXI.WebGLFastSpriteBatch.prototype.renderSprite = function(sprite)
verticies[index++] = sprite.rotation;
// uv
verticies[index++] = uvs[6];
verticies[index++] = uvs[7];
verticies[index++] = uvs.x3;
verticies[index++] = uvs.y3;
// color
verticies[index++] = sprite.alpha;
@ -260,6 +262,7 @@ PIXI.WebGLFastSpriteBatch.prototype.renderSprite = function(sprite)
PIXI.WebGLFastSpriteBatch.prototype.flush = function()
{
// If the batch is length 0 then return as there is nothing to draw
if (this.currentBatchSize===0)return;
@ -318,7 +321,7 @@ PIXI.WebGLFastSpriteBatch.prototype.start = function()
gl.uniform2f(this.shader.projectionVector, projection.x, projection.y);
// set the matrix
gl.uniformMatrix3fv(this.shader.uMatrix, false, this.tempMatrix);
gl.uniformMatrix3fv(this.shader.uMatrix, false, this.matrix);
// set the pointers
var stride = this.vertSize * 4;

View file

@ -58,12 +58,10 @@ PIXI.WebGLGraphics.renderGraphics = function(graphics, renderSession)//projectio
// This could be speeded up for sure!
// var m = PIXI.mat3.clone(graphics.worldTransform);
PIXI.mat3.transpose(graphics.worldTransform, PIXI.tempMatrix);
// set the matrix transform
gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
gl.uniformMatrix3fv(shader.translationMatrix, false, PIXI.tempMatrix);
gl.uniformMatrix3fv(shader.translationMatrix, false, graphics.worldTransform.toArray(true));
gl.uniform2f(shader.projectionVector, projection.x, -projection.y);
gl.uniform2f(shader.offsetVector, -offset.x, -offset.y);

View file

@ -194,21 +194,21 @@ PIXI.WebGLSpriteBatch.prototype.render = function(sprite)
var index = this.currentBatchSize * 4 * this.vertSize;
var worldTransform = sprite.worldTransform;
var worldTransform = sprite.worldTransform;//.toArray();
var a = worldTransform[0];
var b = worldTransform[3];
var c = worldTransform[1];
var d = worldTransform[4];
var tx = worldTransform[2];
var ty = worldTransform[5];
var a = worldTransform.a//[0];
var b = worldTransform.c//[3];
var c = worldTransform.b//[1];
var d = worldTransform.d//[4];
var tx = worldTransform.tx//[2];
var ty = worldTransform.ty///[5];
// xy
verticies[index++] = a * w1 + c * h1 + tx;
verticies[index++] = d * h1 + b * w1 + ty;
// uv
verticies[index++] = uvs[0];
verticies[index++] = uvs[1];
verticies[index++] = uvs.x0;
verticies[index++] = uvs.y0;
// color
verticies[index++] = alpha;
verticies[index++] = tint;
@ -217,8 +217,8 @@ PIXI.WebGLSpriteBatch.prototype.render = function(sprite)
verticies[index++] = a * w0 + c * h1 + tx;
verticies[index++] = d * h1 + b * w0 + ty;
// uv
verticies[index++] = uvs[2];
verticies[index++] = uvs[3];
verticies[index++] = uvs.x1;
verticies[index++] = uvs.y1;
// color
verticies[index++] = alpha;
verticies[index++] = tint;
@ -227,8 +227,8 @@ PIXI.WebGLSpriteBatch.prototype.render = function(sprite)
verticies[index++] = a * w0 + c * h0 + tx;
verticies[index++] = d * h0 + b * w0 + ty;
// uv
verticies[index++] = uvs[4];
verticies[index++] = uvs[5];
verticies[index++] = uvs.x2;
verticies[index++] = uvs.y2;
// color
verticies[index++] = alpha;
verticies[index++] = tint;
@ -237,8 +237,8 @@ PIXI.WebGLSpriteBatch.prototype.render = function(sprite)
verticies[index++] = a * w1 + c * h0 + tx;
verticies[index++] = d * h0 + b * w1 + ty;
// uv
verticies[index++] = uvs[6];
verticies[index++] = uvs[7];
verticies[index++] = uvs.x3;
verticies[index++] = uvs.y3;
// color
verticies[index++] = alpha;
verticies[index++] = tint;

View file

@ -128,23 +128,23 @@ PIXI.Texture.prototype.setFrame = function(frame)
PIXI.Texture.prototype._updateWebGLuvs = function()
{
if(!this._uvs)this._uvs = new Float32Array(8);
if(!this._uvs)this._uvs = new PIXI.TextureUvs();
var frame = this.frame;
var tw = this.baseTexture.width;
var th = this.baseTexture.height;
this._uvs[0] = frame.x / tw;
this._uvs[1] = frame.y / th;
this._uvs.x0 = frame.x / tw;
this._uvs.y0 = frame.y / th;
this._uvs[2] = (frame.x + frame.width) / tw;
this._uvs[3] = frame.y / th;
this._uvs.x1 = (frame.x + frame.width) / tw;
this._uvs.y1 = frame.y / th;
this._uvs[4] = (frame.x + frame.width) / tw;
this._uvs[5] = (frame.y + frame.height) / th;
this._uvs.x2 = (frame.x + frame.width) / tw;
this._uvs.y2 = (frame.y + frame.height) / th;
this._uvs[6] = frame.x / tw;
this._uvs[7] = (frame.y + frame.height) / th;
this._uvs.x3 = frame.x / tw;
this._uvs.y3 = (frame.y + frame.height) / th;
};
/**
@ -234,3 +234,25 @@ PIXI.Texture.removeTextureFromCache = function(id)
// this is more for webGL.. it contains updated frames..
PIXI.Texture.frameUpdates = [];
PIXI.TextureUvs = function()
{
this.x0 = 0;
this.y0 = 0;
this.x1 = 0;
this.y1 = 0;
this.x2 = 0;
this.y2 = 0;
this.x3 = 0;
this.y4 = 0;
}