Three.js - How to rotate an object to lookAt one point and orient towards another

前端 未结 1 1716
小蘑菇
小蘑菇 2021-02-04 12:11

I\'m new to three.js and 3d programming in general, so this may seem like a very simple question. Ideally, I hope the answer can help me understand the underlying principles.

相关标签:
1条回答
  • 2021-02-04 12:50

    What you are really saying is you want the y-axis of the object (the object's up-vector) to be orthogonal to the plane.

    All you have to do is set the object's up-vector before you call lookAt( origin ).

    You compute the desired up vector by taking a cross-product of two vectors you know lie in the plane.

    Here is a working fiddle: http://jsfiddle.net/rQasN/43/

    Note that there are two solutions to your problem, as both the computed vector and it's negation will be orthogonal to the plane.

    EDIT: fiddle updated to three.js r.71

    0 讨论(0)
提交回复
热议问题