Three.Js:四元数轮换错误

时间:2015-12-17 15:21:11

标签: javascript three.js rotation kinect quaternions

我的输入是来自kinect流的jsonObject骨架。目标是测量骨架在xz平面上的角度,并在y轴上旋转整个骨架,这样无论姿势如何,它总是面向"相机 我有一个函数,通过臀部坐标计算人的角度 像这样:

 function GetHipRotation(skeleton)
 {
   var   leftHip = skeleton.Joints[SkeletonJointEnum.HipLeft];
   var   rightHip = skeleton.Joints[SkeletonJointEnum.HipRight];
    var zL=leftHip.Position.Z;
        var zR=rightHip.Position.Z;
        var D=zR-zL;
        var W=rightHip.Position.X-leftHip.Position.X ; 
        return Math.atan(D/W);       
}

和一个创建四元数并在此角度上旋转骨架的函数:

function RotateSkeleton(skeleton)
{

var rot_angle=usrAngle=GetHipRotation(skeleton);
for (var i = 0; i < skeleton.Joints.length; i++) {
    //create vector R, the axis of rotation (y-axis in our case)
    var R= new THREE.Vector3 (0, 1, 0); //THIS IS THE Y AXIS//      
    ///////////////////////////////////////////////////////////////////////
    //Create my quaternion and do the rotation using R axis and the Angle 
    //////////////////////////////////////////////////////////////////////
     var skelquat = new THREE.Quaternion();
    skelquat.setFromAxisAngle( R, rot_angle ); // INANGLE HERE
    jointVector3=new THREE.Vector3(0,0,0);
    jointVector3=OriginJointVector[i];
            rotJointVector.push(jointVector3);
    rotJointVector[i].applyQuaternion(skelquat);
    rotX=rotJointVector[i].x;
    rotY=rotJointVector[i].y;

然后我试着画出来,这里一切都出错了。

    context2.beginPath();
    context2.arc(parseFloat(rotX) * 200 + 300 , parseFloat(rotY) * -200 + 200, 4, 0, Math.PI * 2, true);
    //draw joint number over the joint
    context2.strokeText(i,parseFloat(rotX) * 200 + 300 , parseFloat(rotY) * -200 + 200,200);

    context2.closePath();
    if(skeleton.Joints[i].TrackingState === 2)
        context2.fillStyle = "#cc0066";
    else
        context2.fillStyle = "#ff9900";             
    context2.fill();
}
 }

骨架似乎没有做出相应的反应。我希望最小的&#34;旋转&#34;但是,当我输入一个旋转的男人时,它仍然显示为旋转而不是&#34;自动校正&#34;这个位置,即使我处于一个恒定的旋转角度。任何想法?

0 个答案:

没有答案
相关问题