[Papervision3D] 2D coords from 3D in AS2

John Grden neoriley at gmail.com
Mon Jul 16 15:41:09 EDT 2007


Yeah I've got it working really well so far ;)

Give me an hour -

You're a genius jlm!!   So far it's looking like the API is going to be very
smooth and easy to use. Not complicated by any means.

On 7/16/07, jlm <jlm at justinfront.net> wrote:
>
> I got something working but my sorting does not seem to be quite right yet
> so I do not get the correct points
>
> I have modified the face3D directly so that it has public access eg
>
>         public var x0 :Number;
>         public var y0 :Number;
>         public var x1 :Number;
>         public var y1 :Number;
>         public var x2 :Number;
>         public var y2 :Number;
>
> ( setting the values in render) this seems justifyable.
>
> I found for me atleast it is easy enough to make container adjustments
> else
> where.
>
> Then I already have a hacked up plane to help me with various carousels
> which now looks like..
>
> import org.papervision3d.core.proto.MaterialObject3D;
> import org.papervision3d.objects.Plane;
> import org.papervision3d.core.geom.Face3D;
>
> 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;
>
>         }
>
>         public function getCorners(): Array
>         {
>                 if( !visible )
>                                 return null;
>
>                 var minX:       Number  =       1000000;
>                 var minY:       Number  =       1000000;
>                 var maxX:       Number  =       -1000000;
>                 var maxY:       Number  =       -1000000;
>                 var corners
>                 var face_:      Face3D;
>                 var x0:         Number;
>                 var y0:         Number;
>                 var x1:         Number;
>                 var y1:         Number;
>                 var x2:         Number;
>                 var y2:         Number;
>                 var points: Array = [];
>                 var all:        String;
>
>                 for(all in faces)
>                 {
>                         face_ = faces[all];
>                         if(faces[all].visible = true){
>                                 x0              =       face_.x0;
>                                 minX    =       Math.min(x0, minX);
>                                 maxX    =       Math.max(x0, maxX);
>                                 y0              =       face_.y0;
>                                 minY    =       Math.min(y0, minX);
>                                 maxY    =       Math.max(y0, maxX);
>                                 x1              =       face_.x1;
>                                 points.push({_x:x0, _y:y0});
>                                 minX    =       Math.min(x1, minX);
>                                 maxX    =       Math.max(x1, maxX);
>                                 y1              =       face_.y1;
>                                 minY    =       Math.min(y1, minX);
>                                 maxY    =       Math.max(y1, maxX);
>                                 points.push({_x:x1, _y:y1});
>                                 x2              =       face_.x2;
>                                 minX    =       Math.min(x2, minX);
>                                 maxX    =       Math.max(x2, maxX);
>                                 y2              =       face_.y2;
>                                 minY    =       Math.min(y2, minX);
>                                 maxY    =       Math.max(y2, maxX);
>                                 points.push({_x:x2, _y:y2});
>                         }
>
>                 }
>                 centre._x = (minX + maxX)/2;
>                 centre._y = (minY + maxY)/2
>                 points.sort(distanceFromCentre);
>                 corners = points.splice(0,4);
>                 //corners.sort(angleOf);
>                 return corners
>
>         }
>         private var centre: Object;
>         private function distanceFromCentre(b,a){
>                 return Math.pow(centre._x-a._x,2)+Math.pow(centre._y-a._y,2)
> <
> Math.pow(centre._x-b._x,2)+Math.pow(centre._y-b._y,2)
>         }
>         private function angleOf(a,b){
>                 return Math.atan2(a._y - centre._y, a._x-centre._x) >
> Math.atan2(b._y -
> centre._y, b._x-centre._x);
>         }
> }
>
>
> my sorts seem to be rather a lot of work and don't seem to work properly?
>
> on my current carousel I can draw something...
>
>         // method: imageRelease
>         //
>         private function imageRelease(targ: MovieClip, plane: Plane_flipY)
>         {
>                 var dim = plane.getCorners();
>                 var
> sq=_root.createEmptyMovieClip('sq',_root.getNextHighestDepth());
>                 sq.lineStyle(0,0xFF0000,100);
>                 sq.beginFill(0xFF00000,100);
>                 sq.moveTo(dim[0]._x +container._x,dim[0]._y+container._y);
>                 var i;
>                 for(i = 0; i<4; i++){
>                         sq.lineTo(dim[i]._x
> +container._x,dim[i]._y+container._y);
>                         trace(dim[i]._x+' '+dim[i]._y);
>                 }
>                 sq.moveTo(dim[0]._x +container._x,dim[0]._y+container._y);
>                 sq.endFill();
>
>                 onreleased(images[targ.index].videoName);
>
>
>         }
>
> but not quite right
>
> _______________________________________________
> Papervision3D mailing list
> Papervision3D at osflash.org
> http://osflash.org/mailman/listinfo/papervision3d_osflash.org
>



-- 
[  JPG  ]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://osflash.org/pipermail/papervision3d_osflash.org/attachments/20070716/cfc86c7c/attachment-0001.html 


More information about the Papervision3D mailing list