I need a real sprite to be projected over a view but I would like this sprite to be transformed this way an Object3D would be
here is the link: http://prologis.win.pl/OverlayTest.swf the top red square is an overlay sprite object the bottom one is a Plane that is used as a leading object3D for the overlay sprite I use these matrixes for the red sprite: viewMatrix.identity(); viewMatrix.rawData = camera.viewMatrix.rawData; overlayMatrix.identity(); overlayMatrix.rawData = object3D.sceneTransform.rawData; overlayMatrix.append(viewMatrix); (object3D - is a leading Plane) possition ON means I add to matrixes: if (away3D.db.selected) overlayMatrix.position = new Vector3D(sourceProjection.x, sourceProjection.y, 0); sourceProjection - is the screen coordinates I get from the leading plane normally the possition should be ON, but when it is off we can see that the red top sprite is sort of above the Plane - this is probably where the differences come from I use standard away3D scene and add the overlay with this code: overlay = new Overlay(this,viewContainer, view, camera); the overlay class looks like this: 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 away3D:Object = null; 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(a:Object, vc:Sprite, v:View3D, c:Camera3D, init:Object = null) { away3D = a; 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; object3D.yaw(30); //object3D.pitch(180); object3D.rotationX = -60; //object3D.rotationY = -70; //object3D.rotationZ = 0; //testSprite.rotationX = 90; view.scene.addChild(object3D); this.addChild(testSprite); view.addOverlay(this); } public function update():void { sourceProjection = camera.screen(object3D); 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; overlayMatrix.identity(); overlayMatrix.rawData = object3D.sceneTransform.rawData; overlayMatrix.append(viewMatrix); scale = camera.lens.getPerspective(sourceProjection.z); overlayMatrix.appendScale(scale,scale,1); var posZ = overlayMatrix.rawData[14] if (away3D.db.selected) overlayMatrix.position = new Vector3D(sourceProjection.x, sourceProjection.y, 0); this.transform.matrix3D = overlayMatrix; //trace(this.parent.x); } } }
