检查面朝鼠标方向向上/向下 [英] Check a face is upwards/downwards towards mouse direction

查看:27
本文介绍了检查面朝鼠标方向向上/向下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在 3D 空间中有一个人脸,相机通过用户交互转动它.当鼠标光标击中脸部时,光线投射会检测到相交点.到目前为止没有什么特别的.

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.

问题:如何检测摄像头是在看脸的下侧还是上侧?

我确实有鼠标方向向量和正常的脸.Three.js 中的操作是什么(或者如果你愿意,可以在数学上进行操作).

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.

伪代码:

if (dot(camera.forward, face.normal) < 0)
    // facing the camera
else
    // facing away from the camera

这篇关于检查面朝鼠标方向向上/向下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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