Align the cube's nearest face to the camera

114 Views Asked by At

I have a cube and 4x4 transformation matrix Cube is rotated randomly I need to find the nearest face of cube regarding to camera and rotate the cube by aligning that face to the camera.

How can I do that. Thanks in advance.

1

There are 1 best solutions below

0
On

Find the vertex closest to the camera.

There are three faces containing that vertex. Compute the dot product of the normal to each face with the vector from the vertex to the camera. The one with the largest dot product is the face that is closest (because $A\cdot B =||A||\ ||B|| \cos \theta $).

You then want to rotate that face so its normal points directly at the camera.