Commit ee6d36de authored by GoshaZotov's avatar GoshaZotov

change functions(for multiply matrix)

parent d3d8345f
......@@ -103,6 +103,7 @@ function Processor3D(width, height, left, right, bottom, top, chartSpace, charts
this.matrixRotateOy = null;
this.matrixRotateAllAxis = null;
this.matrixShearXY = null;
this.projectMatrix = null;
}
Processor3D.prototype.calaculate3DProperties = function(baseDepth, gapDepth, bIsCheck)
......@@ -690,6 +691,20 @@ Processor3D.prototype.calculatePropertiesForPieCharts = function()
//***functions for matrix transformation***
Processor3D.prototype._shearXY = function()
{
if(null === this.matrixShearXY)
{
this.matrixShearXY = new Matrix4D();
this.matrixShearXY.a31 = Math.sin(-this.angleOy);
this.matrixShearXY.a32 = Math.sin(this.angleOx);
this.matrixShearXY.a33 = 0;
this.matrixShearXY.a44 = 0;
}
return this.matrixShearXY;
};
Processor3D.prototype._shearXY2 = function()
{
if(null === this.matrixShearXY)
{
......@@ -712,7 +727,7 @@ Processor3D.prototype._getMatrixRotateAllAxis = function()
if(null === this.matrixRotateAllAxis)
{
this.matrixRotateAllAxis = Point3D.prototype.multiplyMatrix(matrixRotateOY, matrixRotateOX);
this.matrixRotateAllAxis = matrixRotateOY.multiply(matrixRotateOX);
}
return this.matrixRotateAllAxis;
......@@ -723,7 +738,16 @@ Processor3D.prototype._getMatrixRotateOx = function()
//todo посмотреть возможность заменить массивы на Float32Array
if(null === this.matrixRotateOx)
{
this.matrixRotateOx = [[1, 0, 0, 0], [0, Math.cos(-this.angleOx), Math.sin(-this.angleOx), 0], [0, - Math.sin(-this.angleOx), Math.cos(-this.angleOx), 1], [0, 0, 0, 1]];
this.matrixRotateOx = new Matrix4D()/*[[1, 0, 0, 0], [0, Math.cos(-this.angleOx), Math.sin(-this.angleOx), 0], [0, - Math.sin(-this.angleOx), Math.cos(-this.angleOx), 1], [0, 0, 0, 1]]*/;
var cos = Math.cos(-this.angleOx);
var sin = Math.sin(-this.angleOx);
this.matrixRotateOx.a22 = cos;
this.matrixRotateOx.a23 = sin;
this.matrixRotateOx.a32 = -sin;
this.matrixRotateOx.a33 = cos;
this.matrixRotateOx.a34 = 1;
}
return this.matrixRotateOx;
......@@ -733,18 +757,85 @@ Processor3D.prototype._getMatrixRotateOy = function()
{
if(null === this.matrixRotateOy)
{
this.matrixRotateOy = [[Math.cos(-this.angleOy), 0, -Math.sin(-this.angleOy), 0], [0, 1, 0, 0], [Math.sin(-this.angleOy), 0, Math.cos(-this.angleOy), 1], [0, 0, 0, 1]];
this.matrixRotateOy = new Matrix4D()/*[[Math.cos(-this.angleOy), 0, -Math.sin(-this.angleOy), 0], [0, 1, 0, 0], [Math.sin(-this.angleOy), 0, Math.cos(-this.angleOy), 1], [0, 0, 0, 1]]*/;
var cos = Math.cos(-this.angleOy);
var sin = Math.sin(-this.angleOy);
this.matrixRotateOy.a11 = cos;
this.matrixRotateOy.a13 = -sin;
this.matrixRotateOy.a31 = sin;
this.matrixRotateOy.a33 = cos;
this.matrixRotateOy.a34 = 1;
}
return this.matrixRotateOy;
};
Processor3D.prototype._getMatrixRotateAllAxis2 = function()
{
var matrixRotateOY = this._getMatrixRotateOy2();
var matrixRotateOX = this._getMatrixRotateOx2();
/*итоговая матрица
|cosOy 0 sinOy 0|
|sinOx * sinOy cosOx -sinOx * cosOy 0|
|-sinOy * cosOx sinOx cosOy * cosOx 0|
|-sinOy 0 (cosOy + 1) 1|*/
if(!this.matrixRotateAllAxis2)
{
this.matrixRotateAllAxis2 = Point3D.prototype.multiplyMatrix(matrixRotateOY, matrixRotateOX);
}
return this.matrixRotateAllAxis2;
};
Processor3D.prototype._getMatrixRotateOx2 = function()
{
//todo посмотреть возможность заменить массивы на Float32Array
if(!this.matrixRotateOx2)
{
this.matrixRotateOx2 = [[1, 0, 0, 0], [0, Math.cos(-this.angleOx), Math.sin(-this.angleOx), 0], [0, - Math.sin(-this.angleOx), Math.cos(-this.angleOx), 1], [0, 0, 0, 1]];
}
return this.matrixRotateOx2;
};
Processor3D.prototype._getMatrixRotateOy2 = function()
{
if(!this.matrixRotateOy2)
{
this.matrixRotateOy2 = [[Math.cos(-this.angleOy), 0, -Math.sin(-this.angleOy), 0], [0, 1, 0, 0], [Math.sin(-this.angleOy), 0, Math.cos(-this.angleOy), 1], [0, 0, 0, 1]];
}
return this.matrixRotateOy2;
};
Processor3D.prototype._getMatrixRotateOz = function()
{
return [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1], [0, 0, 0, 1]];
};
Processor3D.prototype._getPerspectiveProjectionMatrix = function(fov)
{
/*var zf = this.rPerspective + this.depthPerspective;
var zn = this.rPerspective;
var q = zf / (zf - zn);
return [[1 / Math.tan(this.rPerspective / 2), 0, 0, 0], [0, 1 / Math.tan(this.rPerspective / 2), 0, 0], [0, 0, q, 1], [0, 0, -q * zn, 0]];*/
//[[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1 / fov], [0, 0, 0, 1]]
if(null === this.projectMatrix)
{
this.projectMatrix = new Matrix4D();
this.projectMatrix.a33 = 0;
this.projectMatrix.a34 = 1 / fov;
}
return this.projectMatrix;
};
Processor3D.prototype._getPerspectiveProjectionMatrix2 = function(fov)
{
/*var zf = this.rPerspective + this.depthPerspective;
var zn = this.rPerspective;
......@@ -2368,6 +2459,8 @@ function Point3D(x, y, z, chartsDrawer)
this.x = x;
this.y = y;
this.z = z;
this.t = 1;
if(chartsDrawer)
{
this.chartProp = chartsDrawer.calcProp;
......@@ -2407,11 +2500,11 @@ Point3D.prototype =
project: function(matrix)
{
//умножаем
var projectPoint = this.multiplyPointOnMatrix(matrix);
var projectPoint = matrix.multiplyPoint(this);
//делим на 4 коэффициэнт
var newX = projectPoint[0][0] / projectPoint[0][3];
var newY = projectPoint[0][1] / projectPoint[0][3];
var newX = projectPoint.x / projectPoint.t;
var newY = projectPoint.y / projectPoint.t;
this.x = newX;
this.y = newY;
......@@ -2437,24 +2530,25 @@ Point3D.prototype =
return this;
},
multiplyPointOnMatrix: function(matrix)
multiplyPointOnMatrix1: function(matrix)
{
var pointMatrix = [[this.x, this.y, this.z, 1]];
return this.multiplyMatrix(pointMatrix , matrix);
var multiplyMatrix = matrix.multiplyPoint(this);
this.x = multiplyMatrix.x;
this.y = multiplyMatrix.y;
this.z = multiplyMatrix.z;
},
multiplyPointOnMatrix1: function(matrix)
multiplyPointOnMatrix12: function(matrix)
{
var pointMatrix = [[this.x, this.y, this.z, 1]];
var multiplyMatrix = this.multiplyMatrix(pointMatrix , matrix);
var multiplyMatrix = this.multiplyMatrix(pointMatrix , matrix, true);
this.x = multiplyMatrix[0][0];
this.y = multiplyMatrix[0][1];
this.z = multiplyMatrix[0][2];
},
multiplyMatrix: function(A, B)
multiplyMatrix2: function(A, B)
{
var rowsA = A.length, colsA = A[0].length,
rowsB = B.length, colsB = B[0].length,
......@@ -2481,7 +2575,7 @@ Point3D.prototype =
return C;
},
multiplyMatrix2: function(A, B, pointOnMatrtix)
multiplyMatrix: function(A, B, pointOnMatrtix)
{
var C = [];
......@@ -2542,6 +2636,91 @@ Point3D.prototype =
}
};
function Matrix4D()
{
this.a11 = 1.0;
this.a12 = 0.0;
this.a13 = 0.0;
this.a14 = 0.0;
this.a21 = 0.0;
this.a22 = 1.0;
this.a23 = 0.0;
this.a24 = 0.0;
this.a31 = 0.0;
this.a32 = 0.0;
this.a33 = 1.0;
this.a34 = 0.0;
this.a41 = 0.0;
this.a42 = 0.0;
this.a43 = 0.0;
this.a44 = 1.0;
return this;
}
Matrix4D.prototype.reset = function ()
{
this.a11 = 1.0;
this.a12 = 0.0;
this.a13 = 0.0;
this.a14 = 0.0;
this.a21 = 0.0;
this.a22 = 1.0;
this.a23 = 0.0;
this.a24 = 0.0;
this.a31 = 0.0;
this.a32 = 0.0;
this.a33 = 1.0;
this.a34 = 0.0;
this.a41 = 0.0;
this.a42 = 0.0;
this.a43 = 0.0;
this.a44 = 1.0;
};
Matrix4D.prototype.multiply = function (m)
{
var res = new Matrix4D();
res.a11 = this.a11 * m.a11 + this.a12 * m.a21 + this.a13 * m.a31 + this.a14 * m.a41;
res.a12 = this.a11 * m.a12 + this.a12 * m.a22 + this.a13 * m.a32 + this.a14 * m.a42;
res.a13 = this.a11 * m.a13 + this.a12 * m.a23 + this.a13 * m.a33 + this.a14 * m.a43;
res.a14 = this.a11 * m.a14 + this.a12 * m.a24 + this.a13 * m.a34 + this.a14 * m.a44;
res.a21 = this.a21 * m.a11 + this.a22 * m.a21 + this.a23 * m.a31 + this.a24 * m.a41;
res.a22 = this.a21 * m.a12 + this.a22 * m.a22 + this.a23 * m.a32 + this.a24 * m.a42;
res.a23 = this.a21 * m.a13 + this.a22 * m.a23 + this.a23 * m.a33 + this.a24 * m.a43;
res.a24 = this.a21 * m.a14 + this.a22 * m.a24 + this.a23 * m.a34 + this.a24 * m.a44;
res.a31 = this.a31 * m.a11 + this.a32 * m.a21 + this.a33 * m.a31 + this.a34 * m.a41;
res.a32 = this.a31 * m.a12 + this.a32 * m.a22 + this.a33 * m.a32 + this.a34 * m.a42;
res.a33 = this.a31 * m.a13 + this.a32 * m.a23 + this.a33 * m.a33 + this.a34 * m.a43;
res.a34 = this.a31 * m.a14 + this.a32 * m.a24 + this.a33 * m.a34 + this.a34 * m.a44;
res.a41 = this.a41 * m.a11 + this.a42 * m.a21 + this.a43 * m.a31 + this.a44 * m.a41;
res.a42 = this.a41 * m.a12 + this.a42 * m.a22 + this.a43 * m.a32 + this.a44 * m.a42;
res.a43 = this.a41 * m.a13 + this.a42 * m.a23 + this.a43 * m.a33 + this.a44 * m.a43;
res.a44 = this.a41 * m.a14 + this.a42 * m.a24 + this.a43 * m.a34 + this.a44 * m.a44;
return res;
};
Matrix4D.prototype.multiplyPoint = function (p)
{
var res = new Point3D();
res.x = p.x * this.a11 + p.y * this.a21 + p.z * this.a31 + this.a41;
res.y = p.x * this.a12 + p.y * this.a22 + p.z * this.a32 + this.a42;
res.z = p.x * this.a13 + p.y * this.a23 + p.z * this.a33 + this.a43;
res.t = p.x * this.a14 + p.y * this.a24 + p.z * this.a34 + this.a44;
return res;
};
//----------------------------------------------------------export----------------------------------------------------
window['AscFormat'] = window['AscFormat'] || {};
window['AscFormat'].Processor3D = Processor3D;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment