The fla source (AS2):
www.leandroamano.com.br/files/3d.fla

// Perspective
ppc = perspective.value;
center = {x:0, y:0, z:0};
// Cube: Face 1
v1 = {x:-50, y:-50, z:-50};
v2 = {x:50, y:-50, z:-50};
v3 = {x:50, y:50, z:-50};
v4 = {x:-50, y:50, z:-50};
// Cube: Face 2
v5 = {x:-50, y:-50, z:50};
v6 = {x:50, y:-50, z:50};
v7 = {x:50, y:50, z:50};
v8 = {x:-50, y:50, z:50};
// plan
p1 = {x:-300, y:-225, z:-100};
p2 = {x:-275, y:-225, z:-100};
p3 = {x:-300, y:-200, z:-100};
p4 = {x:-300, y:-225, z:-125};
//---
render(p1, plan1);
pp1 = point(plan1);
var temp:MovieClip = this.createEmptyMovieClip("temp__", 500)
screen.onPress = function(Void):Void {
this._parent.temp.onEnterFrame = function(Void):Void {
 alpha = -(this._parent._ymouse-Stage.height/2)/Stage.height/2;
 beta = (this._parent._xmouse-Stage.width/2)/Stage.width/2;
 //---
 v1 = rotate(v1, center, 0, alpha, beta);
 v2 = rotate(v2, center, 0, alpha, beta);
 v3 = rotate(v3, center, 0, alpha, beta);
 v4 = rotate(v4, center, 0, alpha, beta);
 //---
 v5 = rotate(v5, center, 0, alpha, beta);
 v6 = rotate(v6, center, 0, alpha, beta);
 v7 = rotate(v7, center, 0, alpha, beta);
 v8 = rotate(v8, center, 0, alpha, beta);
 //---
 p2 = rotate(p2, p1, 0, alpha, beta);
 p3 = rotate(p3, p1, 0, alpha, beta);
 p4 = rotate(p4, p1, 0, alpha, beta);
 //---
 render(v1, vert1);
 render(v2, vert2);
 render(v3, vert3);
 render(v4, vert4);
 //---
 render(v5, vert5);
 render(v6, vert6);
 render(v7, vert7);
 render(v8, vert8);
 //---
 render(p2, plan2, 300);
 render(p3, plan3, 300);
 render(p4, plan4, 300);
 //---
 v1p = point(vert1);
 v2p = point(vert2);
 v3p = point(vert3);
 v4p = point(vert4);
 //---
 v5p = point(vert5);
 v6p = point(vert6);
 v7p = point(vert7);
 v8p = point(vert8);
 //---
 pp2 = point(plan2);
 pp3 = point(plan3);
 pp4 = point(plan4);
 //---
 z_index1 = 0;
 z_index2 = 0;
 //---
 if (v1.z>v5.z) {
  z_index1 = 1;
 } else {
  z_index2 = 1;
 }
 //---
 quad1 = this._parent.createEmptyMovieClip("quad1", z_index1);
 quad1.beginFill(0xff0000, 75);
 quad1.moveTo(v1p.x, v1p.y);
 quad1.lineTo(v2p.x, v2p.y);
 quad1.lineTo(v3p.x, v3p.y);
 quad1.lineTo(v4p.x, v4p.y);
 quad1.lineTo(v1p.x, v1p.y);
 //---
 quad2 = this._parent.createEmptyMovieClip("quad2", z_index2);
 quad2.beginFill(0x00ff00, 75);
 quad2.moveTo(v5p.x, v5p.y);
 quad2.lineTo(v6p.x, v6p.y);
 quad2.lineTo(v7p.x, v7p.y);
 quad2.lineTo(v8p.x, v8p.y);
 quad2.lineTo(v5p.x, v5p.y);
 //---
 this._parent.createEmptyMovieClip("line1", 100).drawLine(v1p, v5p);
 this._parent.createEmptyMovieClip("line2", 101).drawLine(v2p, v6p);
 this._parent.createEmptyMovieClip("line3", 102).drawLine(v3p, v7p);
 this._parent.createEmptyMovieClip("line4", 103).drawLine(v4p, v8p);
 //---
 estilo1 = {thick:2, rgb:0xff0000, alpha:100};
 estilo2 = {thick:2, rgb:0x0000ff, alpha:100};
 estilo3 = {thick:2, rgb:0x00cc00, alpha:100};
 this._parent.createEmptyMovieClip("versor_i", 201).drawLine(pp1, pp2,
estilo1);
 this._parent.createEmptyMovieClip("versor_j", 202).drawLine(pp1, pp3,
estilo2);
 this._parent.createEmptyMovieClip("versor_k", 203).drawLine(pp1, pp4,
estilo3);
};
};
screen.onRelease = function(Void):Void {
delete this._parent.temp.onEnterFrame;
};
function rotate(vert, ref, a, b, c) {
v = {x:vert.x-ref.x, y:vert.y-ref.y, z:vert.z-ref.z};
// plan XY => girar em Z
matrix1 = [];
matrix1[0] = [Math.cos(a), Math.sin(a), 0];
matrix1[1] = [-Math.sin(a), Math.cos(a), 0];
matrix1[2] = [0, 0, 1];
//plan YZ => girar em X
matrix2 = [];
matrix2[0] = [1, 0, 0];
matrix2[1] = [0, Math.cos(b), Math.sin(b)];
matrix2[2] = [0, -Math.sin(b), Math.cos(b)];
//plan ZX => girar em Y
matrix3 = [];
matrix3[0] = [Math.cos(c), 0, Math.sin(c)];
matrix3[1] = [0, 1, 0];
matrix3[2] = [-Math.sin(c), 0, Math.cos(c)];
//---
matrix = prodMatricial(matrix1, matrix2);
matrix = prodMatricial(matrix, matrix3);
//---
nx = matrix[0][0]*v.x+matrix[0][1]*v.y+matrix[0][2]*v.z+ref.x;
ny = matrix[1][0]*v.x+matrix[1][1]*v.y+matrix[1][2]*v.z+ref.y;
nz = matrix[2][0]*v.x+matrix[2][1]*v.y+matrix[2][2]*v.z+ref.z;
//---
return {x:nx, y:ny, z:nz};
}
function render(v, mc, pers) {
p = ppc;
if (pers != undefined) {
 p = pers;
}
mc._x = v.x*p/(p-v.z)+Stage.width/2;
mc._y = -v.y*p/(p-v.z)+Stage.height/2;
}
function prodMatricial(m1, m2) {
prod = [[0, 0, 0], [0, 0, 0], [0, 0, 0]];
for (i=0; i<3; i++) {
 for (j=0; j<3; j++) {
  for (k=0; k<3; k++) {
   prod[i][j] += m1[i][k]*m2[k][j];
  }
 }
}
return prod;
}
MovieClip.prototype.drawLine = function(p1, p2, props) {
if (props == undefined) {
 this.lineStyle(0);
} else {
 this.lineStyle(props.thick, props.rgb, props.alpha);
}
this.moveTo(p1.x, p1.y);
this.lineTo(p2.x, p2.y);
};
function point(mc) {
return {x:mc._x, y:mc._y};
}

regards
Leandro Amano


On 5/1/07, Tom Gooding <[EMAIL PROTECTED]> wrote:

I've seen some really good stuff done recently in Papervision3d
http://www.papervision3d.org/ , also WireEngine3D I've used before
pretty successfully http://osflash.org/we3d . As with any 3D engine,
you'll need reasonable maths to get on with either of these.

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Ron
Wheeler
Sent: 01 May 2007 15:36
To: flashcoders@chattyfig.figleaf.com
Subject: Re: [Flashcoders] rotate a cube

Why not Sandy3D ???

Waseem Shahzad wrote:
> Hello Flashcoders
>
> I am trying to rotate a cube which i made in the flash authoring
> environment. However it is not a real cube but I don't want to use API
to
> make a cube first and then rotate it. I want that a cube which have a
> specific design then it is rotate in the 3d environment using flash
> Actionscript.
>
> Please help me I don't find any solution and now i think that might be

> it is
> not possible to rotate such type of cube.
>
> Thanx in advance.
> _______________________________________________
> Flashcoders@chattyfig.figleaf.com
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com
> http://training.figleaf.com
>
>
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com




--
--
Leandro Amano
Digital Bug
Chief Creative Officer
Adobe Certified Expert
Adobe Certified Instructor
Adobe User Group Leader
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to