Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import flash.geom.Vector3D;
- import flash.geom.Matrix3D;
- var topLeft:Vector3D = new Vector3D(-20, -20, 0);
- var topRight:Vector3D = new Vector3D(100, -20, 0);
- var bottomRight:Vector3D = new Vector3D(100, 100, 0);
- var bottomLeft:Vector3D = new Vector3D(-20, 100, 0);
- function draw():void{
- graphics.beginFill(0xFF0000);
- graphics.drawCircle(topLeft.x, topLeft.y, 4);
- graphics.drawCircle(topRight.x, topRight.y, 4);
- graphics.drawCircle(bottomRight.x, bottomRight.y, 4);
- graphics.drawCircle(bottomLeft.x, bottomLeft.y, 4);
- }
- var matrix:Object = {};
- matrix.m11 = 1; matrix.m12 = 0; matrix.m13 = 0;
- matrix.m21 = 0; matrix.m22 = 1; matrix.m23 = 0;
- matrix.m31 = 0; matrix.m32 = 0; matrix.m33 = 1;
- setupScale(0.5, 0.5);
- setupRotation(10 * Math.PI / 180);
- setupTranslation(100, 100);
- topLeft = transformVector(topLeft);
- topRight = transformVector(topRight);
- bottomRight = transformVector(bottomRight);
- bottomLeft = transformVector(bottomLeft);
- draw();
- function setupScale(xScale:Number, yScale:Number):void {
- matrix.m11 *= xScale;
- matrix.m22 *= yScale;
- }
- function setupRotation(ang:Number):void {
- var sin:Number = Math.sin(ang);
- var cos:Number = Math.cos(ang);
- matrix.m11 *= cos; matrix.m12 = -sin;
- matrix.m21 = sin; matrix. m22 *= cos;
- }
- function setupTranslation(x:Number, y:Number):void{
- matrix.m31 = x; matrix.m32 = y;
- }
- function transformVector(v:Vector3D):Vector3D{
- return new Vector3D(v.x * matrix.m11 + v.y * matrix.m21 + matrix.m31, v.x * matrix.m12 + v.y * matrix.m22 + matrix.m32);
- }
Add Comment
Please, Sign In to add comment