0
\$\begingroup\$

here is my question, which I hope will be in general interest:

If you have got 2 Points in 3D space and want a plane to connect those, you can quite easily use a function similar to "lookAt" to orient the layer pointing with its x-axis from one point to the other. But how can you at the same time make sure the layer is rotated in the way so that the layer is facing the camera (the maximum amount possible, of course it cant be orthogonal to the camera)? The x Axis from the resulting plane should face from the one point to the other.

\$\endgroup\$
  • \$\begingroup\$ I'm not sure I understand the question. Do you mean planes instead of layers? When you say you want a layer between two points and also facing the camera, are you referring to billboarding? \$\endgroup\$ – TomTsagk May 21 '18 at 12:17
  • \$\begingroup\$ yes I mean planes, I was´t aware that layers is used differently, sorry.. So what i need is the orientation of a plane between two points and also facing the camera as much as possible. \$\endgroup\$ – ayma May 21 '18 at 13:12
2
\$\begingroup\$

Take the vector pointing from the first point to the second and also the vector from the first point to the camera position, take their cross product. This creates a vector perpendicular to the other ones. Take this vector and the one pointing from the first point to the second and take their cross products too and normalize it. This gives you the normal of the plane that contains both point and is looking at the camera as much as possible.

Let's say the 2 points are A and B and the camera is C:

n1 = cross(B - A, C - A)
normal = normalize(cross(B - A, n1)) 
\$\endgroup\$
  • \$\begingroup\$ wow, that sounds promising. But the result of your calculation is a vector. But to get the correct 3D orientation of the layer I think a vector isn´t enough. There are infinitive possibilities to rotate that vector, aren´t there? What i need in the end is three values defining the rotation in degrees around every axis. \$\endgroup\$ – ayma May 21 '18 at 12:51
  • \$\begingroup\$ @ayma That's the plane's normal vector. It already has a direction, you can't rotate it, you could probably convert it to euler angles. \$\endgroup\$ – Bálint May 21 '18 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.