3D geometry: how to align an object with a vector

I have an object in 3d space that I want to align in vector. I already got Y-rotation by doing atan2 on the x and z component of the vector. but I would also like to have an X-rotation so that the object looks up or down.

imagine a plane that makes it a feed shaft, just without a roll.

I use openGL to set the turns, so I need the Y-angle and X-angle.

+3
source share
3 answers

You must use some form of Quaternion interpolation ( Spherical Linear Interpolation ) to animate your object from its current orientation to this new orientation.

Quaternions ( ), . Slerp, .

, .

+3

, /. , Opengl glRotate .

, , - , . (, ) , from to .

axis = from X to

from.to = cos(theta) ( )

theta = arccos(from.to)

glRotate(axis, theta) from to.

, , , . , , .

+2

... . , , , , .

+1

Source: https://habr.com/ru/post/1733665/


All Articles