five3d local3dtoglobal [英] five3d local3dtoglobal

查看:175
本文介绍了five3d local3dtoglobal的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用Five3d包来绘制3D小精灵和动画它,然后在应用程序的根目录下创建一个形状,它覆盖了精灵的3D移动时。我想尽一切办法得到它的工作,但似乎无法得到它正确地排队。它看起来像视角出来。我有检查的3D X,Y和全局的x,y这导致我写的方法之间的关系后,它的工作local3dToGlobalXY如下图所示但这只是工作时,舞台是768分之1024,奇怪的。我被告知,Sprite2d在Five3d包中做到这一点,但不能得到这工作的。它具有相同的结果作为我的'local3dToGlobalXY'方法。

我已经把一个例子起来这里和项目为例子的此处

红星是一个精灵是在3D和两个十字线都画成不同的范围。一个被抽入一个Sprite2d这正是我recomended做,而另一个被吸入到根。

希望有人遇到这样或能指出我做错了。

感谢,J

  / **
 * ...
 * @author詹姆斯·乔丹
 * /
公共类主要扩展Sprite
{

    私人VAR S3D:Sprite3D;
    私人VAR _scene:Scene3D;
    私人VAR _s:Sprite3D;
    私人VAR star3D:一个Shape3D;
    私人变种T:定时器;
    私人VAR crossHairs2D:雪碧;
    私人VAR otherPlane:Sprite2D;
    私人VAR _plane:Sprite3D;
    私人VAR crossHairsRoot:雪碧;
    私人VAR animationPlane:Sprite3D;
    私人VAR crossHairsPlane:Sprite2D;
    私人VAR starsPlane:Sprite3D;

    公共函数main():无效
    {
        如果(阶段)的init();
        其他的addEventListener(Event.ADDED_TO_STAGE,INIT);
    }

    私有函数初始化(E:事件= NULL):无效
    {
        removeEventListener(Event.ADDED_TO_STAGE,INIT);
        // 入口点
        stage.align = StageAlign.TOP_LEFT;
        在Stage.scaleMode = StageScaleMode.NO_SCALE时;

        animationPlane =新Sprite3D();

        starsPlane =新Sprite3D();
        animationPlane.addChild(starsPlane);

        crossHairsPlane =新Sprite2D();
        animationPlane.addChild(crossHairsPlane);

        _scene =新Scene3D();
        _scene.x = stage.stageWidth / 2;
        _scene.y = stage.stageHeight / 2;

        _scene.addChild(animationPlane);

        的addChild(_scene);

        star3D = drawStar(starsPlane);
        crossHairs2D = drawGlobalShape(crossHairsPlane,0xff000,10);
        crossHairsRoot = drawGlobalShape(根,0x0000ff,5);

        T =新的Timer(1000,0);
        t.addEventListener(TimerEvent.TIMER,计时器触发);
        t.start();

    }

    私有函数的OnTimer(E:TimerEvent):无效
    {
        TweenLite.to(star3D,1,{X:(的Math.random()* stage.stageWidth) - (stage.stageWidth / 2)中,y:(的Math.random()* stage.stageHeight) - (stage.stageHeight / 2)中,z:(的Math.random()* 500),的onupdate:onTweenUpdate});
    }

    私有函数onTweenUpdate():无效
    {
        VAR号码:点= local3dToGlobalXY(starsPlane,新的三维点(star3D.x,star3D.y,star3D.z));
        crossHairs2D.x = p.x  -  stage.stageWidth / 2;
        crossHairs2D.y = p.y  -  stage.stageHeight / 2;

        crossHairsRoot.x = p.x;
        crossHairsRoot.y = p.y;
    }

    私有函数local3dToGlobalXY(_s:Sprite3D,P3D:三维点):点
    {
        VAR M:的Matrix3D = _s.concatenatedMatrix;
        VAR newP3d:三维点= m.transformPoint(P3D);
        VAR globalPoint:点= _s.local3DToGlobal(新的Vector3D(newP3d.x,newP3d.y,newP3d.z));
        返回globalPoint;
    }

    私有函数drawStar(父:Sprite3D):一个Shape3D {

        VAR starShape:一个Shape3D =新一个Shape3D();
        DrawingUtils.star(starShape.graphics3D,5,30,20,(45/180)* Math.PI,为0xFF0000);

        parent.addChild(starShape);

        返回starShape;
    }

    私有函数drawGlobalShape(号码:* C:UINT,线宽:号码):雪碧
    {
        变种D:雪碧=新的Sprite();
        d.graphics.lineStyle(线宽,C);
        d.graphics.moveTo(-20,0);
        d.graphics.lineTo(20,0);
        d.graphics.moveTo(0,-20);
        d.graphics.lineTo(0,20);
        d.graphics.endFill();

        p.addChild(四);

        返回D组;

    }

}
 

解决方案

这是你的观点和Z坐标。除去随机ž吐温在TweenLite.to声明中,你会看到他们排队完美。

究竟是什么你想在这里做?除了抵消明星,在Z参数似乎没有(基于观测距离比例)补充?

I am trying to use the Five3d package to draw a sprite in 3d and animate it then create a shape on the root of the app and overlay it over the sprite in 3d as it moves. I have tried everything to get it to work but can't seem to get it to line up properly. It looks like the perspective is out. I had it working after inspecting the relationship between the 3d x,y and global x,y which lead me to write the method 'local3dToGlobalXY' shown below but this only worked when the stage was 1024 / 768, strange. I was told that the Sprite2d in the Five3d package does this but can't get that to work either. It has the same results as my 'local3dToGlobalXY' method.

I have put an example up here and the project for the example is here.

The red star is a sprite that is in 3d and the two crosshairs are draw into different scopes. One is drawn into a Sprite2d which is what I was recomended to do and the other is drawn into the root.

Hopefully someone has encountered this or can point out what I have done wrong.

Thanks, J

/**
 * ...
 * @author James Jordan
 */
public class Main extends Sprite 
{

    private var s3D:Sprite3D;
    private var _scene:Scene3D;
    private var _s:Sprite3D;
    private var star3D:Shape3D;
    private var t:Timer;
    private var crossHairs2D:Sprite;
    private var otherPlane:Sprite2D;
    private var _plane:Sprite3D;
    private var crossHairsRoot:Sprite;
    private var animationPlane:Sprite3D;
    private var crossHairsPlane:Sprite2D;
    private var starsPlane:Sprite3D;

    public function Main():void 
    {
        if (stage) init();
        else addEventListener(Event.ADDED_TO_STAGE, init);
    }

    private function init(e:Event = null):void 
    {
        removeEventListener(Event.ADDED_TO_STAGE, init);
        // entry point
        stage.align = StageAlign.TOP_LEFT;
        stage.scaleMode = StageScaleMode.NO_SCALE;

        animationPlane = new Sprite3D();

        starsPlane = new Sprite3D();
        animationPlane.addChild(starsPlane);

        crossHairsPlane = new Sprite2D();
        animationPlane.addChild(crossHairsPlane);

        _scene = new Scene3D();
        _scene.x = stage.stageWidth / 2;
        _scene.y = stage.stageHeight / 2;

        _scene.addChild(animationPlane);

        addChild(_scene);

        star3D = drawStar(starsPlane);
        crossHairs2D = drawGlobalShape(crossHairsPlane, 0xff000, 10);
        crossHairsRoot = drawGlobalShape(root, 0x0000ff, 5);

        t = new Timer(1000, 0);
        t.addEventListener(TimerEvent.TIMER, onTimer);
        t.start();

    }

    private function onTimer(e:TimerEvent):void 
    {
        TweenLite.to(star3D, 1, { x:(Math.random() * stage.stageWidth) - (stage.stageWidth/2), y:(Math.random() * stage.stageHeight) - (stage.stageHeight / 2), z:(Math.random() * 500), onUpdate:onTweenUpdate } );
    }

    private function onTweenUpdate():void 
    {
        var p:Point = local3dToGlobalXY(starsPlane, new Point3D(star3D.x, star3D.y, star3D.z));
        crossHairs2D.x = p.x - stage.stageWidth / 2;
        crossHairs2D.y = p.y -  stage.stageHeight / 2;

        crossHairsRoot.x = p.x;
        crossHairsRoot.y = p.y;
    }

    private function local3dToGlobalXY(_s:Sprite3D, p3d:Point3D):Point 
    {
        var m:Matrix3D = _s.concatenatedMatrix;
        var newP3d:Point3D = m.transformPoint(p3d);
        var globalPoint:Point = _s.local3DToGlobal(new Vector3D(newP3d.x, newP3d.y, newP3d.z));
        return globalPoint;
    }

    private function drawStar(parent:Sprite3D):Shape3D {

        var starShape:Shape3D = new Shape3D();
        DrawingUtils.star(starShape.graphics3D, 5, 30, 20, (45 / 180) * Math.PI, 0xff0000);

        parent.addChild(starShape);

        return starShape;
    }

    private function drawGlobalShape(p:*, c:uint, lineWeight:Number):Sprite 
    {
        var d:Sprite = new Sprite();
        d.graphics.lineStyle(lineWeight, c);
        d.graphics.moveTo( -20, 0);
        d.graphics.lineTo(20, 0);
        d.graphics.moveTo( 0, -20);
        d.graphics.lineTo(0, 20);
        d.graphics.endFill();

        p.addChild(d);

        return d;

    }

}

解决方案

It's your perspective and Z coordinate. Remove the random Z tween in the TweenLite.to statement and you'll see that they line up perfectly.

What exactly are you trying to do here? Other than offset the star, the Z param doesn't seem to add anything (scaling based on distance from observer)?

这篇关于five3d local3dtoglobal的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆