使用Kinect SDK创建完整的3D骨骼模型

7
这是我的第一个图形学科目,但实现的某些部分对我来说并不完美。我能正确地绘制关节,但是我正在尝试编写一个函数,在关节之间插入“骨头”。“骨头”在这一阶段只是被转换成长方体的立方体,稍后我将尝试使用来自blender或其他软件的适当模型。
我的问题在于旋转。经过大约5个小时,我和我的伙伴已经有了初步的解决办法,但是一旦你将手臂或腿伸出去,立方体就会变形并看起来很奇怪。感激任何帮助。以下是试图绘制“骨头”的功能。
private void DrawBone(Skeleton skeleton, JointType jointType0, JointType jointType1)
{
    Joint joint0 = skeleton.Joints[jointType0];
    Joint joint1 = skeleton.Joints[jointType1];

    // If we can't find either of these joints, exit
    if (joint0.TrackingState == JointTrackingState.NotTracked ||
        joint1.TrackingState == JointTrackingState.NotTracked)
    {
        return;
    }

    // Don't draw if both points are inferred
    if (joint0.TrackingState == JointTrackingState.Inferred &&
        joint1.TrackingState == JointTrackingState.Inferred)
    {
        return;
    }

    // We assume all drawn bones are inferred unless BOTH joints are tracked
    if (joint0.TrackingState == JointTrackingState.Tracked && joint1.TrackingState == JointTrackingState.Tracked)

        //jointvector(joint) takes a joint and returns a Vector2 with its position data, with the z invtred to work properly with directx11
        Vector3 bonevector = Vector3.Subtract(jointVector(joint0), jointVector(joint1));
        //cubevector is supposed to describe the initial vector of a cube centred at (0,0,0) with a side length of 2. A fair amount of guesswork has gone into this bit.
        Vector3 cubevector = new Vector3(0, 2, 0);
        //midpoint of two joints
        Vector3 transTest = Vector3.Divide(Vector3.Add(jointVector(joint0),jointVector(joint1)), 2);
        //divide by two because our original cube has side length 2
        float scaleFactor = Math.Abs(bonevector.Length() / cubevector.Length());

        //we haven't been taught quaternions in class or anything, but after a fair while searching for similar problems they seemed like the go-to option for rotations.
        world = Matrix.Transformation(new Vector3(0, 0, 0), new Quaternion(0), new Vector3(0.05f, scaleFactor, 0.05f), new Vector3(0, 0, 0), new Quaternion(Vector3.Cross(cubevector, bonevector), (float)Math.Acos(Vector3.Dot(bonevector, cubevector))), transTest);     

        //view and proj are defined elsewhere and are working fine, it's just the world that is being lame         
        worldViewProj = world * view * proj;
        worldViewProj.Transpose();
        sDXdata.context.UpdateSubresource(ref worldViewProj, sDXdata.constantBuffer);
        //36 vertices of the cube (two triangles per face) defined elsewhere
        sDXdata.context.Draw(36, 0);
        return;

嗨,文斯,你最终搞定了吗?很想了解你是如何在三维中显示模型的。 - Rob McCabe
2个回答

3

骨骼方向,请检查:

skeleton.BoneOrientations[joint.JointType]

它会给你一个BoneOrientation类。

http://msdn.microsoft.com/en-us/library/microsoft.kinect.boneorientation.aspx

从那里,你可以得到旋转,可以是四元数/矩阵,在世界空间或父骨骼空间(用于皮肤绑定)。

还可以使用以下方法:

new Quaternion(0)

这是一个0向量,不是用于旋转的有效四元数,请使用:

Quaternion.Identity;

这将是(0,0,0,1)


1

虽然这是一段时间以前的问题,但我认为在计算角度时也存在错误。你有:

(float)Math.Acos(Vector3.Dot(bonevector, cubevector)

我认为你需要:

(float)Math.Acos(Vector3.Dot(bonevector, cubevector) / (bonevector.Length() *
cubevector.Length()))

这里有一个不错的数学小例子。你也可以将它们变成单位向量,这样它们的长度就是1,而不必进行除法:

(float)Math.Acos(Vector3.Dot(bonevector.Normalize(), cubevector.Normalize()))

查看MSDN页面以获取更多信息。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接