我正在从传感器获取四元数坐标[x,y,z,w]
。我想更改该坐标,以便可以将React VR应用程序场景旋转为旋转该场景。我需要将四元数坐标更改为旋转坐标。但是此处的旋转并不平滑,因为必须将平滑旋转的“四元数坐标”转换为旋转。
import {VRInstance} from 'react-vr-web';
import scene from 'three.js';
//let us assume x,y,z,w are my coordinate in quaternion formate which I //am taking through web socket
function init(bundle, parent, options)
{
//scene=new scene()//three.js
const vr = new VRInstance(bundle, 'musical_exp_react_vr_pusher',
parent, {
// Add custom options here
...options,
});
vr.render = function() {
//but its not working as I took the quaternion coordiate
//smoothness is not there
vr.scene.rotationx=x;
vr.scene.rotationx=y;
vr.scene.rotationx=z;
//it is also not working
vr.scene.quaternion.x=x;
vr.scene.quaternion.y=y;
vr.scene.quaternion.z=z;
// Any custom behavior you want to perform on each frame goes here
};
// Begin the animation loop
vr.start();
return vr;
}
window.ReactVR = {init};
主要问题是我需要从四元数坐标中找到旋转轴坐标。
答案 0 :(得分:0)
Quaternions和Euler angles是两个独立的概念,不能通过简单的分配进行转换。根据您的框架使用的欧拉角的类型,conversion algorithm can be a bit complex。
Three.js通过Euler.setFromQuaternion()方法实现此转换。
但是,查看three.js的文档,似乎像您想要的quaternion assignment should work一样-您只需要分配四元数的所有4个元素(您的代码缺少W元素)。