I am trying to get the following value: for any vector in 3D space (the blue one), I need to project it on the green plane so I can compute the angle alpha on this green plane between the projected vector (purple) and the z axis of the camera.
So far, my best attempt was by first trying to get the green plane, whichever the camera position is in 3D space, assuming that the green plane normal is pointing to +y :
var greenPlane= new THREE.Vector3( 0, 1, 0 );
greenPlane.applyQuaternion( camera.quaternion );
But the values get by tracing the purple vector are incorrect. My final purpose is to detect if the purple vector is pointing towards left or right of the screen, so I can correctly place a label at its extremity.
I am not familiar with applyMatrix4 function (very few tutos about how to use it).
Does this apply a transformation to the blue vector so we get its coordinates in the camera/view coordinates? And I am confused, you mention purple, but for me I can’t get the purple unless I am figuring out what is the green plane.
But if I can project the blue vector directly to the camera plane, then I can use cos to see if it’s positive or negative yes. I am only concerned about left or right with respect to the view (screen).
The green one has only be declared var greenPlane= new THREE.Vector3( 0, 1, 0 ). If I move the camera it doesn’t go along. If I want it to actually be the green plane I have to apply a transformation in respect to the camera position, and this was (supposedly) achieved by greenPlane.applyQuaternion( camera.quaternion );
But following your previous idea, projecting the blue directly to the view should work.
blueVector.applyMatrix4( camera.matrixWorldInverse );
const zAxis = new THREE.Vector( 0, 0, - 1 );
blueVectorProject= blueVector.projectOnPlane(zAxis );
// then I compute the cos value between blueVectorProject and view x axis