Papervision3D:使物体在移动相机时看起来静止

发布于 2024-08-23 20:59:19 字数 266 浏览 13 评论 0原文

我想让一个物体在移动相机时看起来保持在同一个地方。

我正在使用这个脚本 http://pv3d.org /2008/11/19/dragging-mouse-for-camera-orbit/ 使用鼠标拖动来绕对象旋转。但场景中有一个物体我想保持静止。我该如何做到这一点?

谢谢, 乔什

I'd like to keep an object appear to remain in the same place while moving the camera.

I'm using this script http://pv3d.org/2008/11/19/dragging-mouse-for-camera-orbit/ to orbit an object using a mouse drag. But I have an object in the scene that I would like to keep still. How to I do this?

Thanks,
Josh

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故乡的云 2024-08-30 20:59:19

好的,我浏览了 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() 之前,并且它应该与您的相机保持静止。

Ok, I browsed through the Camera3D source in Papervision. Here is the implementation for orbit:

            /**
             * 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);
            }

You could implement this as a helper function for the object you want to keep still. I believe the only camera specific code involved in this function would be the lookAt() function.

You can then add this before the camera.orbit() in the mouseMove handler and it should stay still with your camera.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文