[Papervision3D] calculateScreenCoords issue
wactor
menorki at yahoo.com
Wed Dec 31 04:41:19 PST 2008
Hey Andy,
The fact is I am still having problems when resizing the viewport.
Below is a simple flex app that demonstrates the issue. The app contains a
canvas that acts as a container for the Viewport3D. The viewport3D is
adjusted to the canvas when this one is resized.
- The screen coords are correct when the display object location is (0,0,0)
or viewport3D is resized to its creation time size (640x480 in this case).
There is a slight offset otherwise.
- I also tried to use camera.update() function but without any success.
Thanks a lot for any help.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
creationComplete="onCreationComplete()"
horizontalAlign="center"
verticalAlign="middle"
horizontalScrollPolicy="off"
verticalScrollPolicy="off"
>
<mx:Script>
<![CDATA[
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.view.Viewport3D;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.events.RendererEvent;
import org.papervision3d.materials.WireframeMaterial;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.objects.primitives.Plane;
import org.papervision3d.view.BasicView;
import mx.events.ResizeEvent;
private var scene:Scene3D;
private var viewport3D:Viewport3D;
private var renderer:BasicRenderEngine;
private var camera:Camera3D
private var plane:Plane;
private var marker:Sprite;
private function onCreationComplete():void {
createScene3D();
marker = createScreenLocationMarker();
scene3DCanvas.rawChildren.addChild(marker);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
addEventListener(ResizeEvent.RESIZE , onAppResized );
}
private function onAppResized(e:ResizeEvent=null):void {
// recompute canvas proportional size
scene3DCanvas.width = this.width * 0.8;
scene3DCanvas.height = scene3DCanvas.width * 3/4;
// adjust viewport size
viewport3D.width = scene3DCanvas.width;
viewport3D.height = scene3DCanvas.height;
//camera.update(viewport3D.sizeRectangle);
// reposition marker
invalidateMarkerLocation();
}
private function invalidateMarkerLocation():void {
marker.x = plane.screen.x + viewport3D.width*0.5;
marker.y = plane.screen.y + viewport3D.height*0.5;
viewportSizeLabel.text = int(viewport3D.width) + "x" +
int(viewport3D.height);
}
private function createScene3D():void {
scene = new Scene3D();
viewport3D = new Viewport3D(scene3DCanvas.width, scene3DCanvas.height,
false, false);
scene3DCanvas.rawChildren.addChild(viewport3D);
renderer = new BasicRenderEngine();
camera = new Camera3D();
// basic plane
plane = new Plane(new WireframeMaterial(0XFF0000) , 500 , 800, 1 , 1);
plane.autoCalcScreenCoords = true;
plane.x = 500; // <<<< working when 0
scene.addChild(plane);
camera.z = -3000;
}
private function onEnterFrame(e:Event):void {
renderer.renderScene(scene, camera, viewport3D);
}
private function createScreenLocationMarker():Sprite {
var sprite:Sprite = new Sprite();
sprite.filters = [new DropShadowFilter(1)];
with (sprite.graphics) {
lineStyle(2,0x00FF00);
moveTo(10,0);lineTo(0,0);lineTo(0,10);moveTo(0,0);lineTo(20,20);
}
return sprite;
}
]]>
</mx:Script>
<mx:HBox horizontalAlign="center" verticalAlign="middle" width="100%"
height="100%" >
<mx:Canvas id="scene3DCanvas" backgroundColor="#F2DBDB" filters="{[new
DropShadowFilter]}" width="640" height="480">
<mx:Label id="viewportSizeLabel" x="10" y="10" text=""/>
</mx:Canvas>
</mx:HBox>
</mx:Application>
Andy Zupko wrote:
>
> I haven't had any issues with the screen coords - if the drawing still
> looks right then it should be fine (it uses the same code as the
> projection). Maybe make sure you dont have scale on and are TL aligned.
>
>
> On Dec 30, 2008, at 8:28 AM, wactor wrote:
>
>>
>> Hello,
>>
>> I have a problem with screen coords (autoCalcScreenCoords=true) of a
>> displayObject3D when the Viewport3D object has been resized
>> (viewportWidth
>> / viewportHeight). The coordinates are correct when the Viewport3D is
>> initialized but wrong after any change has been applied.
>>
>> note : I am using camera.useProjectionMatrix = false
>>
>> Is there something I am missing here ?
>>
>> thx a lot for any hint.
>> --
>> View this message in context:
>> http://www.nabble.com/calculateScreenCoords-issue-tp21217850p21217850.html
>> Sent from the Papervision3D mailing list archive at Nabble.com.
>>
>>
>> _______________________________________________
>> Papervision3D mailing list
>> Papervision3D at osflash.org
>> http://osflash.org/mailman/listinfo/papervision3d_osflash.org
>
>
> _______________________________________________
> Papervision3D mailing list
> Papervision3D at osflash.org
> http://osflash.org/mailman/listinfo/papervision3d_osflash.org
>
>
--
View this message in context: http://www.nabble.com/calculateScreenCoords-issue-tp21217850p21230966.html
Sent from the Papervision3D mailing list archive at Nabble.com.
More information about the Papervision3D
mailing list