使用AxisAngleRotation3D进行相机旋转

时间:2015-09-21 17:13:50

标签: c# rotation transform kinect-sdk


我正在使用kinect v2 sdk 2.0进行相机旋转(非几何旋转)任何人都可以指导我哪种方法更好地找到需要旋转的向量或使用四元数?
我正在使用这段代码在我的应用程序中进行一些奇怪的旋转:

double sum = Math.Sqrt(Math.Pow(rotX, 2) + Math.Pow(rotY, 2) + Math.Pow(rotZ, 2));
static double rotX = 0;
static double rotY = 0;
static double rotZ = 0;
static RotateTransform3D trRot = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(rotX, rotY, rotZ), 0));
if (gesture == GestureRecognition.rotation.ClockwiseYaw)
{
    myCamera.Transform = trRot;
    trRot.Rotation = new AxisAngleRotation3D(new Vector3D(rotX / sum, rotY / sum, -rotZ / sum), rotZ -= 5);
    if (rotZ == 360)
    {
        rotZ = 0;
    }
}
else if (gesture == GestureRecognition.rotation.CounterClockwiseYaw)
{
    myCamera.Transform = trRot;
    trRot.Rotation = new AxisAngleRotation3D(new Vector3D(rotX / sum, rotY / sum, -rotZ / sum), rotZ += 5);
    if (rotZ == 360)
    {
        rotZ = 0;
    }
}
else if (gesture == GestureRecognition.rotation.ClockwisePitch)
{
    myCamera.Transform = trRot;
    trRot.Rotation = new AxisAngleRotation3D(new Vector3D(rotX / sum, -rotY / sum, rotZ / sum), rotY -= 5);
    if (rotY == 360)
    {
        rotY = 0;
    }
}
else if (gesture == GestureRecognition.rotation.CounterClockwisePitch)
{
    myCamera.Transform = trRot;
    trRot.Rotation = new AxisAngleRotation3D(new Vector3D(rotX / sum, -rotY / sum, rotZ / sum), rotY += 5);
    if (rotY == 360)
    {
        rotY = 0;
    }
}
else if (gesture == GestureRecognition.rotation.TiltUp)
{
    myCamera.Transform = trRot;
    trRot.Rotation = new AxisAngleRotation3D(new Vector3D(-rotX / sum, rotY / sum, rotZ / sum), rotX += 5);
    if (rotX == 360)
    {
        rotX = 0;
    }
}
else if (gesture == GestureRecognition.rotation.TiltDown)
{
    myCamera.Transform = trRot;
    trRot.Rotation = new AxisAngleRotation3D(new Vector3D(-rotX / sum, rotY / sum, rotZ / sum), rotX -= 5);
    if (rotX == 360)
    {
        rotX = 0;
    }
}
else if (gesture == GestureRecognition.rotation.NothingRecognized)
{
    myCamera.Position = new Point3D(myCamera.Position.X, myCamera.Position.Y, myCamera.Position.Z);
}

0 个答案:

没有答案