//AS3/////////////////////////////////////////////////////////////////////////// // // Copyright 2009 ImpTech. // // http://pv3d.org/2009/06/13/how-to-click-on-stuff-in-papervision3d-viewport-viewportlayers-interactivescene3devent-mouse3d-and-moviematerial-buttons/ // aka http://tinyurl.com/ylyz23a // //////////////////////////////////////////////////////////////////////////////// package { public class Papervision3D_Notes { public function Papervision3D_Notes() { super(); } public function almostOrthogonicView():void { // Update all transformations // displayObject3D.updateTransform(); // Set camera trasform to match object transform // camera.copyTransform( displayObject3D.transform ); // Backup camera away from object // camera.moveBackward( ( ( camera.zoom - 1 ) * camera.focus ) - Math.abs( camera.z ) ); } public function getObj2DCords ( o:DisplayObject3D, camera:CameraObject3D, offsetX:Number = 0, offsetY:Number = 0 ):Point { var view:Matrix3D = o.view; var persp:Number = (camera.focus * camera.zoom) / (camera.focus + view.n34); return new Point ( (view.n14 * persp) + offsetX, (view.n24 * persp) + offsetY ); } public function getDimentions():void { dO3D.calculateScreenCoords( camera ); var screenCoords:String = int( dO3D.screen.x ) + 'x' + int( dO3D.screen.y ) + 'x' + int( dO3D.screen.z ); var perspective:Number = camera.focus * camera.zoom / dO3D.screen.z; var obj:Object = new Object(); obj.size = 100; // Can this be pulled from the DirectObject3D or must it be saved in extra? obj.scene = new Object(); obj.scene.width = dO3D.scaleX * obj.size; obj.scene.height = dO3D.scaleY * obj.size; obj.screen = new Object(); obj.screen.width = dO3D.scaleX * obj.size * perspective; obj.screen.height = dO3D.scaleY * obj.size * perspective; } // Calculating Perspective // public function getPerspective():void { var perspective:Number = camera3D.focus * camera3D.zoom / screen.z; var x:Number = object.x * perspective; var y:Number = object.y * perspective; perspective = camera3D.focus * camera3D.zoom / camera3D.focus; // Old? } // Converting 3D X and Y coordinates to Screen X & Y coordinates // public function getScreenXY():void { displayObject3D.calculateScreenCoords( camera3D ); // Must be called each time you wish to update the DisplayObject3D.screen property. sprite.x = displayObject3D.screen.x + ( viewport3D.width / 2 ); sprite.y = displayObject3D.screen.y + ( viewport3D.height / 2 ); // might be minus half of viewport3D.height. } // Positioning: Equations -- http://blog.computerelibol.com/?p=3 // public function positioningEquations():void { //compute the distance var distance:Number = cam.focus*cam.zoom-cam.focus; //Compute the perspective var persp:Number = cam.focus*cam.zoom/distance; //Compute half of the width of the item at the computed distance, //we need this value because the registration point of 3D display objects are at their center, //and we don't want objects falling outside of xArea var perspItemWidth:Number = item.width/2*persp; //The following operation gives us a value which will produce the inverse ratio of persp var negatePersp:Number = 1/persp; //First subtract item.width, //which we've computed perspective for at item.screen.z from xArea, //then apply the inverse operation of perspective on xArea, //we should think of xArea as if it were the screen.x of an object at item.sceen.z var negatedXArea:Number = (xArea-perspItemWidth)*negatedPersp; } // Scaling: Equations -- http://blog.computerelibol.com/?p=3 // public function scalingEquations():void { //Solve for perfect distance var distance:Number = cam.focus*cam.zoom-cam.focus; //or just get it distance = Math.abs(item.z-cam.z); //Solve for cam.zoom cam.zoom = (cam.focus + distance) / cam.focus; //Solve for cam.focus cam.focus = distance / (cam.zoom * (1-1/cam.zoom)); //negate perspective from screenX/screenY //this equation has been changed since 10/09/2008 to exclude the addition of cam.focus to distance before the division var negatePersp:Number = 1/(cam.focus*cam.zoom/distance); } } }