【问题标题】:Papervision3D: Making Object Appear Still When Moving CameraPapervision3D:移动相机时使物体看起来静止
【发布时间】:2010-03-08 16:09:22
【问题描述】:

我想让一个物体在移动相机时保持在原地。

我正在使用此脚本http://pv3d.org/2008/11/19/dragging-mouse-for-camera-orbit/ 使用鼠标拖动来环绕对象。但是我在场景中有一个我想保持静止的对象。我该怎么做?

谢谢, 乔什

【问题讨论】:

  • 静止是什么意思?您希望对象在您的视野发生变化时保持在您视野中的同一位置?
  • @CookieOfFortune - 是的,没错。

标签: flash actionscript-3 papervision3d


【解决方案1】:

好的,我浏览了 Papervision 中的 Camera3D 源代码。这是轨道的实现:

            /**
             * Orbits the camera around the specified target. If no target is specified the 
             * camera's #target property is used. If this camera's #target property equals null
             * the camera orbits the origin (0, 0, 0).
             * 
             * @param       pitch   Rotation around X=axis (looking up or down).
             * @param       yaw             Rotation around Y-axis (looking left or right).
             * @param       useDegrees      Whether to use degrees for pitch and yaw (defaults to 'true').
             * @param       target  An optional target to orbit around.
             */ 
            public override function orbit(pitch:Number, yaw:Number, useDegrees:Boolean=true, target:DisplayObject3D=null):void
            {
                    target = target || _target;
                    target = target || DisplayObject3D.ZERO;

                    if(useDegrees)
                    {
                            pitch *= (Math.PI/180);
                            yaw *= (Math.PI/180);
                    }

                    // Number3D.sub
                    var dx                  :Number = target.world.n14 - this.x;
                    var dy                  :Number = target.world.n24 - this.y;
                    var dz                  :Number = target.world.n34 - this.z;

                    // Number3D.modulo
                    var distance    :Number = Math.sqrt(dx*dx+dy*dy+dz*dz);

                    // Rotations
                    var rx :Number = Math.cos(yaw) * Math.sin(pitch);
                    var rz :Number = Math.sin(yaw) * Math.sin(pitch);
                    var ry :Number = Math.cos(pitch);

                    // Move to specified location
                    this.x = target.world.n14 + (rx * distance);
                    this.y = target.world.n24 + (ry * distance);
                    this.z = target.world.n34 + (rz * distance);

                    this.lookAt(target);
            }

您可以将其实现为要保持静止的对象的辅助函数。我相信这个函数中唯一涉及的相机特定代码是 lookAt() 函数。

然后您可以在 mouseMove 处理程序中的 camera.orbit() 之前添加它,它应该与您的相机保持静止。

【讨论】:

    猜你喜欢
    • 2018-11-08
    • 1970-01-01
    • 2011-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多