Check a face is upwards/downwards towards mouse di

2020-08-01 07:40发布

问题:

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

回答1:

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


标签: 3d three.js