Reactjs 我想将四元数坐标更改为旋转坐标

Reactjs 我想将四元数坐标更改为旋转坐标,reactjs,react-native,quaternions,react-360,Reactjs,React Native,Quaternions,React 360,我正在从传感器获取四元数坐标[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

我正在从传感器获取四元数坐标
[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};
主要问题是我需要从四元数坐标中找到旋转轴坐标。

和是两个独立的概念,不能通过简单的赋值进行转换。根据您的框架使用的Euler角度的类型

Three.js在方法中实现此转换


然而,看看three.js的文档,它似乎是您想要的-您只需要分配四元数的所有4个元素(您的代码缺少W元素)。

转换算法可能有点复杂,但其工作原理我尝试过,但当我将四元数坐标转换为旋转轴时,它只给我3自由度(自由度)但我需要6个自由度,所以我必须使用three.js实现,所以在尝试之后,我会让您知道结果。但是我没有使用预定义函数three.js,如setFromQuaternion和所有函数,希望它可以工作。非常感谢:)。