Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

three.js - OrbitControl or TrackballControl

I've read a lot about these 2 controls and currently I'm using TrackballControls.

I need to rotate an object along all three axis (Both controls already do that), but I also need to set sometimes a new camera position/rotation by hand. And this doesn't really work.

My workaround is to disable the trackballcontrols, get the quaternions-object of the new position, apply these to camera.up and then enable the camera

But as mentioned, this doesn't really work stable.

I read that OrbitControls could be a better solution for such a task. But OrbitControls has a "limit" on vertical rotation of objects and I need to rotate my objects without limits.

So my questions are:

1. Which Controls System is more suitable for my task

2. If it's Trackball - how would you set manually a new camera position and rotation? And if it's Orbit - is there a way to disable this vertical rotation limit?

Thanks a lot!!

Regards - Misa

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

First of all, TrackballControls and OrbitControls rotate the camera, not the objects.

Second, OrbitControls enforces the camera up direction, and TrackballControls allows the camera to rotate upside-down.

TrackballControls has a reset() method, which restores the target (center of rotation), camera position, and camera up vector to their original settings.

controls.reset();

The above code will restore the original position, target, and up vector. You can change those too, if you want, before you call controls.reset().

controls.position0.set( 0, 0, 10 ); // set a new desired position
controls.target0.set( 0, 0, 0 ); // set a new target
controls.up0.set( 0, 1, 0 ); // set a new up vector
controls.reset();

Read the reset() function source code so you understand what it is doing.

EDIT: OrbitControls now has a reset() method, too. Check the source code.

three.js r.82


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...