如何在 Three.js 中获取透视相机的角度值? [英] How to get angles value of perspective camera in Three.js?

查看:51
本文介绍了如何在 Three.js 中获取透视相机的角度值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 3D 场景中透视相机的每个角度获取值.我正在使用 Three.js 库.

为了更准确,我将用下一个符号标记我想知道的内容:

我需要知道哪些坐标:

我需要它,因为我正在创建一个实模式地图引擎,通过鼠标光标在 3D 场景中移动.

我想要实现的目标在这里可用:>

How can I get the value from each angle of my perspective camera in 3D scene. I'm using Three.js library.

To be more accurate, I shall mark what I want to get known with the next sign:

What coordinates I need to know:

It's needed for me, because I'm creating a real mode map engine with moving in 3D scene via mouse cursor.

What I'm trying to achieve is available here: http://www.zephyrosanemos.com/windstorm/current/live-demo.html

As you could see, in this sample, new terrain is loading with intersecting the new location (which previously were not available with the garbage collection, when the camera is leaving the old viewport):

Now, I want to show a piece of screen from my three.js application:

As you are able to see, I'm loading my scene statically, where is available only one plane with buildings (buildings data are loading from my server, and the data I have token from some osm services).

And it may be controlled only with pushing the keyboard button (for e.g. the 3D scene is locating to the new location by pushing on keyboard arrows, aslo you could see the empty space in map :) this is only because of preparing the cut data in DB for testing purposes, when the application is ready - it won't me empty, it's miles easy to work with light count of records in DB ). All meshes are being deleted, and with each new movement the new data is loaded and the new building are rendered.

But I want to made them loaded dynamically with camera movement. So I want to make it be able dynamically loaded as in the example of dynamic terrain generation. I suggest, that I shall prepare a big plane matrix, which loads data only for the 8 planes (as in terrain generation sample) and to make a logic with the camera intersacting/leavaing old view for such a dynamic work.

So... I want you to help me with this piece of hard task :)

解决方案

To get the field of view angle simply get the value of this field:

Three.PerspectiveCamera.fov

With that angle you should can have an imaginary cubic cone and test it for collision. For the collision part refer to this question:

How to detect collision in three.js?

这篇关于如何在 Three.js 中获取透视相机的角度值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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