TwelvestoneFlash

Papervision - get the 2D coords on a plane of a 2D point on the screen


Sign in

  • Waiting for Godot ( 730 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 5.1 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.9 k posts )
    general front end design an...
  • Back End ( 9.7 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
DontBogartMe
 
2008-09-17

I mean - if I point the mouse at a plane, I want to know the 2D X/Y coords of where the mouse is relative to the plane.

http://www.danwashere.com/dev/papervision/interactive_cows.2.html

That test uses InteractiveUtils.getMapCoordAtPointDO3D to get those coords and as you can see they're wrong - what I need is that when you hover over the top left corner you get 0/0 and over the bottom right you get 1000/750 (the size of the plane).

JLM
 
2008-09-18

Don't know off hand the simple way.. but taking it back to basics '2d coordinates are available on render' ie in as2 onRelease I got 2D corners of 3D image to tween a video to be 2D using sandy distort class. Here is my plane extension.

import org.papervision3d.core.proto.MaterialObject3D; import org.papervision3d.objects.Plane; import org.papervision3d.core.geom.Face3D; // other classes import com.dynamicflash.utils.Delegate; class net.justinfront.papervision3d.objects.Plane_flipY extends Plane {

private static  var PIE:    Number  = ( Math.PI );
private static  var PI2:    Number  = ( 2*Math.PI );

private var yAbs:       Number;
private var ySign:      Number;
private var __face:     Boolean;
private var __left:     Boolean;

public function Plane_flipY( material:MaterialObject3D,  

width:Number, height:Number, segmentsW:Number, segmentsH:Number,
initObject:Object ) { super(material, width, height, segmentsW, segmentsH, initObject ); }

// property: rotationY
//  keep _rotationY below PI
public function set rotationY( rot:Number )
{

    // keep it below 360;
    if(DEGREES){
        rot = rot%360;
    } else {
        //TODO: check if works!!!
        // not needed for app!
        rot = rot%PI2;
    }

    var abs:Number = Math.abs( rot );
    yAbs = abs;

    // since we use the sign for direction checking do here.
    var sign:Number = Math.round( abs/rot);
    ySign = sign;

    if( DEGREES ){

        this.__left =  Boolean( abs > 90 );
        if( abs > 180 ) this._rotationY= deg2rad( rot   - (sign*360) );
        else this._rotationY    = deg2rad( rot );

    }
    else
    {
        this.__left = Boolean( abs > PIE );
        if( abs > PIE ) this._rotationY =  rot%360   - sign*PI2;
        else this._rotationY    = rot;

    }

    this._rotation = true;
}
public function get rotationY( ):Number
{

    if( DEGREES ) return rad2deg( this._rotationY );
    else return this._rotationY;

}
// method: isLeft
//  used to find out if a material is at an left angle
public function get isLeft():Boolean
{
    if( this.__left == undefined )
        rotationY = this._rotationY;

    return this.__left;

}

// additional code for getting corner info

// variable: vertexNo
//
private var vertexNo: Object;

// method: findCorners
//
private function findCorners( arr: Array ):Array
{
        var i:              Number;
        var len:            Number;
        var all:            String;
        var vertex_obj:     Object;
        var vertex_arr:     Array;
        var curr:           String;
        var no:             Number;
        var arri:           Object;
        vertexNo            =   {};
        vertex_obj          =   {};
        vertex_arr          =   [];
        i                   =   -1;
        len                 =   arr.length-1;

        // sort for all vertex that appear only once or twice in the list,  

as they are corner vertex. while( i++ < len ) {

            arri =  arr[i];
            curr =  arri._x + '_' + arri._y;

            // fancy way to avoid if undefined
            vertexNo[ curr ] = vertexNo[ curr ]|0;
            no = vertexNo[ curr ]++;


            // internal or side vertex
            if( no > 1)
            {

                // remove internal vertex
                delete vertex_obj[ curr ];

            }
            else if(no == 0)
            {

                // store vertex
                vertex_obj[ curr ] = { _x: arri._x, _y:arri._y, no: no, face:  

arri.face, index:arri.index };

            } else {

                //increment vertex no
                vertex_obj[ curr ].no = no;

            }

        }

        // push the four corners left in the vertex_obj into an array
        for( all in vertex_obj )
        {

            vertex_arr.push( vertex_obj[ all ] )

        }

        // sort by vertex number
        vertex_arr.sort( sortVertexNo );

        // return alternate opposite sides so that lineto will be either  

clockwise or anti clockwise.
return [ vertex_arr[0], vertex_arr[3], vertex_arr[1], vertex_arr [2] ];

}

// method sortVertexNo
// sorts by number vertex repeated (opposite corners will have the  

same vertex repeat number (0 or 1) ) private function sortVertexNo( a , b ) { var ano = a.no; var bno = b.no; var abigger = Boolean( ano > bno ); if( ano == bno ) {

        return 0;

    }
    else if( abigger )
    {

        return -1;

    }
    else
    {

        return 1;

    }

}

private var corners: Array;

// method: calculateCornerValues
//  
private function calculateCornersValues(): Array
{   

    var i:      Number;
    var c:      Object;
    var out:    Array = [];

    for( i = 0; i < 4; i++ )
    {

        c = corners[ i ];
        out.push( { _x: c.face['x'+c.index], _y: c.face['y'+c.index] } )

    }

    return out

}

// method: getCorners
public function getCorners():Array
{
    // if we already know which vertex are corners then get them
    if( corners != undefined )
    {

        // after first time of running getCorners
        // already know the corners just need to return thier current values

    } else {

        // first time getCorners need to find the applicable corner vertex's

        var all:            String;
        var out:            Array;
        var points:         Array;
        var face_:          Array;

        points          =   [];

        for( all in faces )
        {   

            face_ = faces[all]
            points.push({_x:face_.x0, _y:face_.y0, face: face_, index: '0'});
            points.push({_x:face_.x1, _y:face_.y1, face: face_, index: '1'});
            points.push({_x:face_.x2, _y:face_.y2, face: face_, index: '2'});

        }

        corners = findCorners( points );

    }

    return calculateCornersValues();

}

}

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneFlash

Papervision - get the 2D coords on a plane of a 2D point on the screen