A Flash Developer Resource Site

Results 1 to 1 of 1

Thread: AS3 3D cube (ported from as1 example)

  1. #1
    Member Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    1,087

    AS3 3D cube (ported from as1 example)

    I just finished porting this as1 example to as3, just put this script in the actions panel:
    PHP Code:
    var box = {

    points:     [
    x: -y: -z: -},
    x: -y: -z:  },
    x:  y: -z:  },
    x:  y: -z: -},

    x: -y:  z: -},
    x: -y:  z:  },
    x:  y:  z:  },
    x:  y:  z: -}

        ],

    faces:    [
    ],
    ],
    ],
    ],
    ],
    ]

        ]

        }

    var 
    rad Math.PI 180;
    var 
    my_shape:Shape = new Shape();
    var 
    dim 200;    // scale factor for unitlength obj vectors //
    function World3dobj ) {

    this.obj obj;

    this.loc scene;

    rad Math.PI 180;

    }
    var 
    pers;
    function 
    World3dRenderxa ya ) {

        
    // calculate rotate matrix //

        
    var cya Math.cosya rad );

        var 
    sya Math.sinya rad );

        var 
    cxa Math.cosxa rad );

        var 
    sxa Math.sinxa rad );

        for ( var 
    e in box.points ) {

    var 
    box.points[e];

    // rotate each point around axis //

    var tempz = ( p.cya ) - ( p.sya );

    var 
    tmpx = ( p.sya ) + ( p.cya );

    var 
    tmpz = ( p.sxa ) + ( tempz cxa );

    var 
    tmpy = ( p.cxa ) - ( tempz sxa );

    // projection to screen //

    pers / ( tmpz );

    p.sx tmpx pers dim;

    p.sy tmpy pers dim;

        }

        
    // draw faces //

    my_shape.graphics.clear();
    my_shape = new Shape();
    addChild(my_shape);
    my_shape.x=200
    my_shape
    .y=200
        
    for (e in box.faces ) {

    var 
    box.faces[e];

    box.points;

    var 
    p0 pl[0] ] , p1 pl[1] ] , p2 pl[2] ] , p3 pl[3] ];

    var 
    = (p1.sx p0.sx) * (p2.sy p0.sy) - (p1.sy p0.sy) * (p2.sx p0.sx);

    if ( 
    ) { // backface culling //




    my_shape.graphics.lineStyle(10x27D3DC1);
            
    my_shape.graphics.beginFill 0x444444 );
        
    my_shape.graphics.moveTo p0.sx p0.sy );
        
    my_shape.graphics.lineTo p1.sx p1.sy );
        
    my_shape.graphics.lineTo p2.sx p2.sy );
        
    my_shape.graphics.lineTo p3.sx p3.sy );
        
    my_shape.graphics.lineTo p0.sx p0.sy );

    my_shape.graphics.endFill ();

    }

        }

    }

    // create instance //

    var a=0
    var b=0
    // render scene depending on mouse position //
    addEventListener(Event.ENTER_FRAME,loop);
    function 
    loop(e:*){
    World3dRender(stage.mouseY,stage.mouseX 

    Last edited by Alloy Bacon; 06-30-2020 at 01:50 AM.
    When I answer questions I wonder... are you going to bring something that will cost the world with that program or are you creating something that will make the world more efficient and spend less.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center