PDA

View Full Version : Matrix


Xeef
10-16-2005, 06:20 PM
have a couple of cascaded MC's each have diferent Matrixtransformations on them

let's say for now Master & Master.Slave

now i rotate the Master by 45

so the Master & the Slave is rotated (this shoud by so)

now i wana Scale the Slave
and here coms the problem !
it's scales BUT in the coordinatesystem of the Master !
and tath shoud NOT by !!!

how can i calculate this ?????

see code for more :


_root.createEmptyMovieClip("Master", 0);
TM = new flash.geom.Transform(Master);
_bmp1 = new flash.display.BitmapData(150, 150, false, 0x00FF0000);
Master.attachBitmap(_bmp1, 0);
Master.createEmptyMovieClip("Slave", 1);
TS = new flash.geom.Transform(Master.Slave);
_bmp2 = new flash.display.BitmapData(50, 50, false, 0x000000FF);
Master.Slave.attachBitmap(_bmp2, 1);
//
M = new flash.geom.Matrix();
M.translate(100, 50);
TM.matrix = M;
//Rotate Master
M.identity();
M.rotate(45/180*Math.PI);
Tmp = TM.matrix.clone();
M.concat(Tmp);
TM.matrix = M;
//Scale Slave
M.identity();
M.scale(2, 1);
Tmp = TS.matrix.clone();
M.concat(Tmp);
TS.matrix = M;
////////////////////////////
//
//
//This is how it shoud look :
//
_root.createEmptyMovieClip("Master1", 1);
TM1 = new flash.geom.Transform(Master1);
_bmp1 = new flash.display.BitmapData(150, 150, false, 0x00FF0000);
Master1.attachBitmap(_bmp1, 0);
_root.createEmptyMovieClip("Slave1", 2);
TS1 = new flash.geom.Transform(Slave1);
_bmp2 = new flash.display.BitmapData(50, 50, false, 0x000000FF);
Slave1.attachBitmap(_bmp2, 1);
//
M = new flash.geom.Matrix();
M.translate(350, 50);
TM1.matrix = M;
TS1.matrix = M;
//
M.identity();
M.rotate(45/180*Math.PI);
Tmp = TM1.matrix.clone();
M.concat(Tmp);
TM1.matrix = M;
M.identity();
M.rotate(45/180*Math.PI);
Tmp = TS1.matrix.clone();
M.concat(Tmp);
TS1.matrix = M;
//
M.identity();
Orgmatrix = TS1.matrix.clone();
M.a = 2;
M.d = 1;
//
M.tx = Orgmatrix.tx;
M.ty = Orgmatrix.ty;
//
Orgmatrix.tx = 0;
Orgmatrix.ty = 0;
Orgmatrix.concat(M);
TS1.matrix = Orgmatrix;

senocular
10-16-2005, 06:40 PM
so what do you want to happen? You do not want it to scale in the coordinate space of the master? In the example, its not. Im confused as to what you're after

Xeef
10-16-2005, 07:03 PM
i wana Scale the Slave what's inside the Master in the Coordinate space of _root

the 1. part of the code whit the Master.Slave the scale is done in the Master Space
BUT it shoud by done in the _root Space
as the result of the 2. part looks (where BOTH are on _root this is just to demonstrate what result i wana get)

Xeef
10-16-2005, 11:31 PM
Hmmmm

this Matrix stoff is a realy hard stoff !


var cRad = Math.PI/180;
//
_root.createEmptyMovieClip("Master", 0);
Master.Matrix = new flash.geom.Transform(Master);
Master._bmp = new flash.display.BitmapData(150, 150, false, 0x00FF0000);
Master.attachBitmap(Master._bmp, 0);
Master.createEmptyMovieClip("Slave", 1);
Master.Slave.Matrix = new flash.geom.Transform(Master.Slave);
Master.Slave._bmp = new flash.display.BitmapData(50, 50, false, 0x000000FF);
Master.Slave.attachBitmap(Master.Slave._bmp, 1);
//
TempMatrix = new flash.geom.Matrix();
TempMatrix.rotate(45*cRad);
TempMatrix.translate(100, 50);
Master.Matrix.matrix = TempMatrix;
//
TempMatrix = new flash.geom.Matrix();
TempMatrix.scale(1, 2);
TempMatrix.rotate(-45*cRad);
TempMatrix.translate(80, 60);
Master.Slave.Matrix.matrix = TempMatrix;
//
//
//
//
//
//
//
Matrix_Apply = new flash.geom.Matrix();
Matrix_Apply.scale(1.5, 1);
Master.Slave.Matrix.matrix = MatrixWrap(Master.Matrix.matrix, Master.Slave.Matrix.matrix, Matrix_Apply);
//
function MatrixWrap(Matrix_Parent, Matrix_Self, Matrix_Apply) {
var Matrix_Parent = Matrix_Parent.clone();
var Matrix_Self = Matrix_Self.clone();
var Matrix_Apply = Matrix_Apply.clone();
var Matrix_Return = new flash.geom.Matrix();
//

var X = Matrix_Self.tx;
Matrix_Self.tx = Matrix_Parent.tx =0;
var Y = Matrix_Self.ty;
Matrix_Self.ty = Matrix_Parent.ty = 0;
//
Matrix_Return.concat(Matrix_Self);
Matrix_Return.concat(Matrix_Parent);
Matrix_Return.concat(Matrix_Apply);
Matrix_Parent.invert();
Matrix_Parent.tx += X;
Matrix_Parent.ty += Y;
Matrix_Return.concat(Matrix_Parent);
return Matrix_Return;
}


seams to work :confused: