1

我已经遍历了顶点并将一个平面映射到每个顶点。我在正确定位飞机时遇到问题。我可以让它与一个球体一起工作,但是当我对基元进行任何更改时 - 位置是正确的,但它们不会以正确的方式面对/倾斜。

编辑:注意 - 球体的交替是在球体创建之前完成的。我更新了 Sphere 类以创建一个细长的球体。

我用来放置飞机的代码如下:

pivotDO3D = new DisplayObject3D();
scene.addChild(pivotDO3D);
var bigSphere:Sphere = new Sphere(null, 500, 20, 20);

for each (var v:Vertex3D in bigSphere.geometry.vertices)
{
 var __seatmaterial:ColorMaterial = new ColorMaterial(0x000000);
 __seatmaterial.doubleSided = true;
 var p:Plane = new Plane(__seatmaterial, 20, 20, 2, 2);
 pivotDO3D.addChild(p);
 p.position = v.toNumber3D();
 p.lookAt(bigSphere);
}
4

1 回答 1

1

以下演示显示了如何最小化问题。我将乘法因子 0.6 更改为 2.0 以及球体大小,以夸大效果,以便您轻松查看。确保在 Sphere.as 中也将 0.6 更改为 2.0。

关键在于改变目标点的 z 位置与球体上点的 z 位置。

为了比较,按原样运行它以查看“固定”版本,并将 lookAt 目标从 pivotDO3D2 更改为 bigSphere 以查看旧版本。

package
{
    import flash.display.Sprite;
    import flash.events.Event;

    import org.papervision3d.cameras.*;
    import org.papervision3d.core.geom.renderables.*;
    import org.papervision3d.materials.*;
    import org.papervision3d.objects.*;
    import org.papervision3d.objects.primitives.*;
    import org.papervision3d.render.*;
    import org.papervision3d.scenes.*;
    import org.papervision3d.view.*;

    [SWF(width='400', height='400', backgroundColor='0x000000', frameRate='30')]

    public class PlaneOrientationDemo extends Sprite
    {
        private var scene:Scene3D;
        private var camera:Camera3D;
        private var renderer:BasicRenderEngine;
        private var viewport:Viewport3D;
        private var pivotDO3D:DisplayObject3D;

        public function PlaneOrientationDemo()
        {
            viewport = new Viewport3D(0, 0, true, true);
            addChild( viewport );

            renderer = new BasicRenderEngine();                         
            scene = new Scene3D( );

            camera = new Camera3D();
            camera.z = -700;
            camera.zoom = 50;

            pivotDO3D = new DisplayObject3D();
            scene.addChild(pivotDO3D);

            var pivotDO3D2:DisplayObject3D = new DisplayObject3D();

            var bigSphere:Sphere = new Sphere(null, 150, 20, 20);

            for each (var v:Vertex3D in bigSphere.geometry.vertices)
            {
                 var __seatmaterial:ColorMaterial = new ColorMaterial(0x00FF00);
                 __seatmaterial.doubleSided = true;
                 var p:Plane = new Plane(__seatmaterial, 20, 20, 2, 2);
                 pivotDO3D.addChild(p);
                 p.position = v.toNumber3D();

                 // This number should match the fx multiplication factor in Sphere.as.
                 var xFactor:Number = 2.0;

                 pivotDO3D2.z = v.z / (Math.PI / xFactor);
                 p.lookAt(pivotDO3D2);
            }

            stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
        }

        private function onEnterFrame(event: Event): void
        {
            pivotDO3D.rotationX += 1;
            pivotDO3D.rotationY += 1;
            renderer.renderScene(scene, camera, viewport);
        }
    }
}
于 2009-12-15T17:19:06.437 回答