检查一个脸向上/向下朝鼠标方向 [英] Check a face is upwards/downwards towards mouse direction
问题描述
假设我有一个在三维空间中,该摄像头转身通过用户交互单个面。当鼠标光标击中脸,一个光线投射检测的交叉点。没什么特别的这么远。</ P>
问:如何检测,如果相机看脸的下跌或上涨
我有鼠标的方向向量和正常的脸,以及。什么是在three.js的操作(或数学,如果你想)。
您需要做你的脸,正常和你的相机前向向量之间的点积。
如果该产品是正它背离相机,如果它是负的它的面对摄像机
伪code:
如果(点(camera.forward,face.normal)℃下)
//所面临的相机
其他
//背离相机
Assume I a have a single face in 3D space, which the camera turns around by user interaction. When the mouse cursor hits the face, a raycast detects the intersection. Nothing special so far.
Question: How to detect if the camera looks at the downside or upside of the face?
I do have the mouse direction vector and the faces normal as well. What would be the operation in three.js (or mathematically if you want).
You need to do a dot product between your face normal and your camera forward vector.
If the product is positive it's facing away from the camera, if it's negative it's facing the camera.
pseudocode:
if (dot(camera.forward, face.normal) < 0)
// facing the camera
else
// facing away from the camera
这篇关于检查一个脸向上/向下朝鼠标方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!