首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >绕世界轴旋转物体

绕世界轴旋转物体
EN

Stack Overflow用户
提问于 2015-05-12 13:11:42
回答 2查看 551关注 0票数 0

我发现了几种不同的工作方式来围绕世界轴旋转一个物体,但它们都是围绕着它自己的轴旋转,而不是绕着世界的轴旋转。那么,怎样才能让一个物体绕着世界的轴旋转呢?

如果我对这个问题不清楚,这里有一幅代表我的问题的图画

编辑:对不起,我也应该在问题中详细说明我使用的是Three.js

Edit2:

代码语言:javascript
复制
//camera is the object I want to rotate 
//I also found a method that uses Euler but the result was far from the expected

/**Method 1**/

//Found this somewhere here in so
var rotateAroundWorldAxis = function(object, axis, radians) {
  var rotWorldMatrix;
  rotWorldMatrix = new THREE.Matrix4();
  rotWorldMatrix.makeRotationAxis(axis.normalize(), radians);
  rotWorldMatrix.multiply(object.matrix);
  object.matrix = rotWorldMatrix;
  object.rotation.setFromRotationMatrix(object.matrix);
}

//this is how I call the method
rotateAroundWorldAxis(camera, new THREE.Vector3(0,1,0), movementX*-0.001);
rotateAroundWorldAxis(camera, new THREE.Vector3(1,0,0), movementY*-0.001);
/**Method 1**/


/**Method 2**/
//I've also tried this method
var q = new THREE.Quaternion();

q.setFromAxisAngle( new THREE.Vector3(0,1,0), movementX*-0.001 ); // axis must be normalized, angle in radians
camera.quaternion.multiplyQuaternions( q, camera.quaternion );
/**Method 2**/


//movementX and movementY are values provided by the mouse movement using the pointerlock. 
//These values works as I've tried them using rotateOnAxis
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-05-15 13:20:34

最后我使用了FirstPersonControls类。不过,我不得不对这门课做了些改动。

票数 0
EN

Stack Overflow用户

发布于 2015-05-12 16:32:00

用四元数。

代码语言:javascript
复制
var rotateAroundWorldAxis = function(object, axis, radians) {
  var rotation = new THREE.Quaternion();
  rotation.setFromAxisAngle ( axis, radians );
  object.quaternion.multiply(rotation);
}

rotateAroundWorldAxis(myObject, THREE.Vector3(0,1,0), movementX*-0.001);

我相信你之前使用四元数方法的问题是把四元数乘以错的,所以你绕着Y轴旋转,然后执行局部旋转,最终在局部Y轴上旋转。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30191963

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档