gpt4 book ai didi

c# - 使用 Kinect SDK 创建完整的 3d 骨架

转载 作者:太空狗 更新时间:2023-10-29 20:31:16 27 4
gpt4 key购买 nike

这是我在 uni 的第一个图形主题,实现的某些部分对我不起作用。我可以让关节正确绘制,但我正在尝试编写一个在关节之间放置“骨骼”的函数。此时骨骼只是转换为直角棱柱的立方体,稍后我将尝试从 blender 或其他东西中引入适当的模型。

我的麻烦在于轮换。大约 5 小时后,我和我的搭档开始工作了,但是一旦你将 ARM 或腿移出,立方体就会变形并且看起来很奇怪。任何帮助,将不胜感激。下面是尝试绘制骨骼的函数。

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;

最佳答案

对于骨骼方向,检查:

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)

关于c# - 使用 Kinect SDK 创建完整的 3d 骨架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12613991/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com