English 中文(简体)
使用音轨球控制器时重置相机位置/旋转
原标题:Reset camera position/rotation when using TrackballControls

我有一个带有 3 js 的 Webgl 应用程序。 它使用音轨球控制控制器控制相机。 我有一个按钮, 我想用它重置现场, 所以, 相机应该到初始状态 。 目前我有一个( jquery) :

$( #reset ).click(function() {
    camera.position.set(0, 0 , 400);
    camera.rotation.set(0, 0, 0);
});

但奇怪的是,当我记录位置和旋转时,它们并不像应该的那样,摄影机也不在正确的位置。 我做错什么了,有没有更好的办法做到这一点?

最佳回答

直到虫子被固定(见Yuval Adam 回答的评论), 一个有效的(虽然肮脏的)解决方案就是从现场移除相机, 然后创建一个新的相机, 添加控件, 并将新的相机添加到现场 。

Update: TrackballControls now has a reset() method. Call this after the tween completes and all is well! (https://github.com/mrdoob/three.js/commit/4f800f61809560c434bbbf12e76c3931e8e8c0fb)

问题回答

camera. position 应始终更新, 以确保您重新查看右边的 camera , 并且它没有超出范围。 理想的情况是, 它应该是窗口上的一个全局 var 。

关于 camera. rotation ,您应该检查您的相机是否有:

camera.useQuaternion == true

某些控件将此设定为相机上的一个先决条件。 如果是这样, 相机角度由 < code> camera. quarternion 而不是 < code> camera. roptation 设定。 允许, < code> Trackball control 没有这种行为( 至少是r49)。


Edit: 似乎有 camera 的错误,它扰乱了 trackball controlts

而不是更改相机。 旋转为 0, 0, 将相机修改为 0, 1, 0 。 您可以使用 Tween 来动画 。

这个问题曾经被问过,但我遇到了这个问题,找到了最新的 TrackBall controles 版本的变通办法。除了 camera.position camera.rotation , camera.up 之外,还必须设置为所需的坐标。

设置重置坐标时, 设置全部 3 : 位置、 旋转和上方 。 切换重置坐标时, 再次设置全部 3 。 据我理解, 对于此用例, < code> camera. up 很重要, 比 < code> camera. rotation 还要重要 。 希望这对我有用 。

更多信息:





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.