搞清楚多少立方体的侧面是可见 [英] Figuring out how much of the side of a cube is visible

查看:149
本文介绍了搞清楚多少立方体的侧面是可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单Three.js场景用相机的轨道围绕一个立方体,总是直接看着它。我需要弄清楚的一方,是目前相机最显着的百分比它环绕周围的立方体。

I have a simple Three.js scene with a camera that orbits around a cube, always looking directly at it. I need to figure out the percentage of the side that is currently most visible by the camera as it orbits around the cube.

所以,如果我在寻找直行,然后侧1(前),可看到100%,所有其他的5个面都为0%。如果我旋转摄像头略向右再向右部侧2(以下简称右边),现在可以看到 - 也许是20%,而一边一个,现在可以看到在80%。如果我再起来,那么也许侧3轻微旋转(顶部)为10%,可见,等。

So if I'm looking straight on then side 1 (the "front") can be seeing 100% and all other 5 sides are at 0%. If I rotate the camera slightly to the right right then part of side 2 (the "right side") can now be seen -- perhaps 20%, while side one can now be seen at %80. If I then rotate slightly up then perhaps side 3 (the top) is 10% visible, etc.

我怎么能去搞清楚了这一点?请记住,立方体本身不旋转 - 只有照相机。 Three.js或JavaScript将是巨大的,但我可以用pretty的多任何编程语言处理。我最感兴趣的想法如何实现这一点。

How can I go about figuring this out? Remember, the cube itself does not rotate -- only the camera. Three.js or JavaScript would be great, but I can deal with pretty much any programming language. I'm mostly interested in ideas for how to achieve this.

推荐答案

作为另一种选择,你可以计算相机的视图向量的点积和立方体面法线,也许?然后计算从点积度的角度,你知道每一个角度面对正常的相对摄像机视图载体。我不能肯定,如果这个工程,只是一个想法。所以,一切都超过90度是不可见的一切,0度是完全面向相机。 好了,关于百分比不太清楚,但我不知道你的用例。就是想节省提出Gero3莫名其妙的屏幕空间操作....只用角与面法线。例如,如果你在看立方体的边缘,有2个面从摄像机视图方向45度,你知道,你是50%,每个两副面孔?

As another option, you could calculate the dot product of the camera's view vector and the cubes face normals, maybe? Then calculate the angle in degrees from the dot product and you know the angle of each face normal relative to the cameras view vector. I am not quite sure if this works, was just an idea. So everything above 90 degrees is not visible at all and 0 degrees is completely facing the camera. Well, not quite sure about the percentages but i don't know your use case. Just thought about saving the screenspace operations proposed by Gero3 somehow.... by only using the angles from the face normals. FOr example if you would be looking at the edge of the cube and have 2 faces in 45 degrees from the camera view direction, you know that you are 50% for each of the two faces?

这篇关于搞清楚多少立方体的侧面是可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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