Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
300 views
in Technique[技术] by (71.8m points)

javascript - How to rotate camera towards point in 3d?

I've got a camera somewhere in a 3d space. I need to calculate angle between camera and a given point.

I can't use lookAt() method (nor any built-in Controller), because I'm also rotating camera on mousemove and want to animate the rotation.

In a word: how to change camera.rotation to make it look at specified point?

question from:https://stackoverflow.com/questions/65830332/how-to-rotate-camera-towards-point-in-3d

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The typical approach for rotating a 3D object towards a target is the usage of Quaternion.rotateTowards(). It's usage is demonstrated in the official example webgl_math_orientation_transform.

The important bit of this approach is:

camera.quaternion.rotateTowards( targetQuaternion, step );

targetQuaternion represents the target orientation whereas step represents the angular step in radians. This value should honor the time delta for a correct animation.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...