How to get angles value of perspective camera in Three.js?

六眼飞鱼酱① 提交于 2019-12-07 08:27:38

问题


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 :)


回答1:


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?



来源:https://stackoverflow.com/questions/21530357/how-to-get-angles-value-of-perspective-camera-in-three-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!