Papervision3D的;在摄像机视图中旋转子对象

时间:2009-09-04 16:29:37

标签: actionscript-3 flex3 papervision3d

这是我第一次使用Papervision3D,我创建了一个在y轴上倾斜的图像幻灯片。左侧最小的照片,右侧的尺寸增大。所以他们从左到右,从最小到最大。

当您将鼠标悬停在照片上时,我会弹出一个工具提示,但工具提示也会与相机视图(倾斜)成比例偏斜。我希望工具提示的角度独立于整个摄像机视图。

是否知道如何旋转对象而不依赖于父摄像机角度?

谢谢!

2 个答案:

答案 0 :(得分:0)

my_obj = new DisplayObject3D(); my_plane = my_obj.addChild(new Plane(bla bla)); my_obj.lookAt(照相机);

'lookAt'位是你需要的。

答案 1 :(得分:0)

为什么不在2d中绘制工具提示?你可以获得图像的屏幕位置,然后像这样绘制一个普通的Sprite:

package 
{
import flash.display.Sprite;
import flash.text.TextField;

import org.papervision3d.events.InteractiveScene3DEvent;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.primitives.Plane;
import org.papervision3d.typography.Text3D;
import org.papervision3d.view.BasicView;

public class PVTest extends Sprite
{
    private var world:BasicView;
    private var text:Text3D;
    private var text2d:TextField;

    public function PVTest()
    {
        world = new BasicView(stage.width, stage.height, true, true);

        var colorMat:ColorMaterial = new ColorMaterial();
        colorMat.interactive = true;

        var planeContainer:DisplayObject3D = new DisplayObject3D();
        var plane:Plane;
        for(var i:int = 0; i < 11; i++)
        {
            plane= new Plane(
                colorMat,
                100, 100,
                10);
            plane.x = (i * 105) - 500;
            plane.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, handleMouseOver);
            plane.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, handleMouseOut);
            planeContainer.addChild(plane);
        }

        planeContainer.rotationY = 10;
        world.scene.addChild(planeContainer);

        world.camera.z = -500;

        addChild(world);
        world.startRendering();
    }

    private function handleMouseOver(event:InteractiveScene3DEvent):void
    {
        var plane:Plane = Plane(event.displayObject3D);
        plane.calculateScreenCoords(world.camera);

        const OFFSET_X:int = -20;
        const OFFSET_Y:int = 30;
        text2d = new TextField();
        text2d.text = "toolTip";
        text2d.x = plane.screen.x + (stage.width/2) + OFFSET_X;
        text2d.y = plane.screen.y + (stage.height/2) + OFFSET_Y;
        addChild(text2d);
    }

    private function handleMouseOut(event:InteractiveScene3DEvent):void
    {
        removeChild(text2d);
    }
}

}

即使对于此示例,您也必须根据对象比例偏移工具提示的y位置,但它可能比计算旋转更容易,并且是获得一致外观结果的最佳方法。