ok, I extended the test, the same link: http://prologis.win.pl/OverlayTest.swf

the red sprite is a real sprite added as an overlay sprite, a leading
object3D is a Plane

the red sprite uses matrix3D of the camera and the plane

here is what I am after:
--------------------------
as long as the size of the view is 700x600 the red sprite covers the
plane, but when the size of the view changes something happens to the
red sprite
it has something to do with the x and y of the view (I eliminated
other things)
-------------------------

I had to change the Overlay class a bit, here is the new code:

package away3d.overlays
{
        import away3d.cameras.*;
        import away3d.core.base.*;
        import away3d.containers.View3D;
        import away3d.cameras.Camera3D;
        import away3d.primitives.*;


        import flash.geom.*;
        import flash.display.*;
        import flash.events.*;


        public class Overlay extends Sprite implements IOverlay
        {


                private var view:View3D = null;
                private var camera:Camera3D = null;


                public var object3D:Plane;
                private var scale:Number;
                private var sourceProjection:Vector3D;

                public var overlayMatrix:Matrix3D = new Matrix3D();
                private var flipY:Matrix3D = new Matrix3D();
                private var viewMatrix:Matrix3D = new Matrix3D();

                private var overlayContainer:Sprite;
                private var testSprite:Sprite;
                private var viewContainer:Sprite;



                public function Overlay(vc:Sprite, v:View3D, c:Camera3D, 
init:Object
= null) {
                        viewContainer = vc;
                        view = v;
                        camera = c;
                        flipY.appendScale(1, -1, 1);
                        overlayContainer = new Sprite();
                        this.visible = false;
                        createTestSprite();

                }

                private function createTestSprite():void {
                        testSprite = new Sprite();
                        testSprite.graphics.clear();
                        testSprite.graphics.beginFill(0xFF0000, 1);
                        testSprite.graphics.lineStyle(3, 0x000000);
                        testSprite.graphics.drawRect(-150, -150, 300, 300);
                        testSprite.graphics.endFill();
                        setNewSettings();
                }


                private function setNewSettings():void {
                        object3D = new Plane({width:testSprite.width,
height:testSprite.height,yUp:false});
                        object3D.x = 0;
                        object3D.y = 0;
                        object3D.z = 400;

                        view.scene.addChild(object3D);
                        this.addChild(testSprite);
                        view.addOverlay(this);
                }


                public function update():void {



                        sourceProjection = camera.screen(object3D, new
Vertex(object3D.x,object3D.y,object3D.z));

                        if(!sourceProjection || sourceProjection.z < 0){
                                if(this.visible) this.visible = false;
                                return;
                        }
                        if(!this.visible) this.visible = true;

                        scale = camera.lens.getPerspective(sourceProjection.z);

                        viewMatrix.identity();
                        viewMatrix.rawData = camera.viewMatrix.rawData;
                        viewMatrix.prepend(flipY);

                        overlayMatrix.identity();
                        overlayMatrix.prepend(viewMatrix);
                        overlayMatrix.append(object3D.sceneTransform);


                        scale = camera.lens.getPerspective(sourceProjection.z);
                        overlayMatrix.appendScale(scale,scale,1);

                        overlayMatrix.position = new 
Vector3D(sourceProjection.x,
sourceProjection.y, 0);

                        this.transform.matrix3D = overlayMatrix;

                        //trace(this.parent.x);

                }


        }
}

Reply via email to