如何在 flex papervision3d 上获取鼠标 z 坐标?

发布于 2024-10-22 07:43:18 字数 764 浏览 1 评论 0原文

我正在研究全景场景。我想用光标移动飞机。当我移动鼠标时,平面必须是鼠标坐标。我想获取平面 3D 坐标 (x,y,z),特别是 z 坐标。我尝试下面的代码。但它不能正常工作。鼠标和平面在屏幕上的坐标不同。我该怎么办?

public class RayTracer
{
    public static function getIntersection(viewport:Viewport3D, camera:CameraObject3D, normal:Array):Number3D
    {
        var plane3D:Plane3D=new Plane3D(); 
        plane3D.setNormalAndPoint(new Number3D(0, 1, 0), new Number3D(0, 0, 0));
        var cameraPosition:Number3D=new Number3D(camera.x, camera.y, camera.z);
        var ray:Number3D=camera.unproject(viewport.containerSprite.mouseX, viewport.containerSprite.mouseY);
        ray=Number3D.add(ray, cameraPosition);
        var intersect:Number3D=plane3D.getIntersectionLineNumbers(cameraPosition, ray);
        return intersect;
    }
}

I am working on panoramic scene . And I want to move a plane with cursor. When I move mouse, plane must be mouse coordinates. And I want to take plane 3D coordinates (x,y,z) expecially z-coordinate. I try below code. But it doesnt work correctly. Mouse and plane are not be same coordinates on screen. How I can do?

public class RayTracer
{
    public static function getIntersection(viewport:Viewport3D, camera:CameraObject3D, normal:Array):Number3D
    {
        var plane3D:Plane3D=new Plane3D(); 
        plane3D.setNormalAndPoint(new Number3D(0, 1, 0), new Number3D(0, 0, 0));
        var cameraPosition:Number3D=new Number3D(camera.x, camera.y, camera.z);
        var ray:Number3D=camera.unproject(viewport.containerSprite.mouseX, viewport.containerSprite.mouseY);
        ray=Number3D.add(ray, cameraPosition);
        var intersect:Number3D=plane3D.getIntersectionLineNumbers(cameraPosition, ray);
        return intersect;
    }
}

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

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

发布评论

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

评论(2

娇女薄笑 2024-10-29 07:43:18

据我所知,即使在 PV3d 中也没有鼠标的 Z 坐标。

As far as I know there is no Z coordinate of the Mouse even in PV3d.

分分钟 2024-10-29 07:43:18

不,我会尝试。我正在尝试使用 Mouse3d 对象并运行以下代码:

private function onEnterFrame(param1:Event=null):void{
renderer.renderScene(scene, camera, viewport);
var mouse3D:Mouse3D;
viewport.interactive=true;
Mouse3D.enabled=true;
mouse3D=viewport.interactiveSceneManager.mouse3D;
trace(mouse3D.x, mouse3D.y, mouse3D.z)

}

但 mouse3D 坐标始终为 (0,0,0)。我不知道为什么。

No i will try. I am trying to Mouse3d object and run below code:

private function onEnterFrame(param1:Event=null):void{
renderer.renderScene(scene, camera, viewport);
var mouse3D:Mouse3D;
viewport.interactive=true;
Mouse3D.enabled=true;
mouse3D=viewport.interactiveSceneManager.mouse3D;
trace(mouse3D.x, mouse3D.y, mouse3D.z)

}

But mouse3D coordinates always (0,0,0). I dont know why.

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