Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 赤手空拳或使用Kinect SDK for Windows从空中投掷物体(物体)_C#_Wpf_Kinect_Nui - Fatal编程技术网

C# 赤手空拳或使用Kinect SDK for Windows从空中投掷物体(物体)

C# 赤手空拳或使用Kinect SDK for Windows从空中投掷物体(物体),c#,wpf,kinect,nui,C#,Wpf,Kinect,Nui,我正在学习Rob Miles的《学习Kinect API》一书中的教程。 基本上,这是一个增强现实游戏,蜘蛛从屏幕顶部坠落,你用木槌击打它们。在遵循教程并查看代码之后,我了解了蜘蛛是如何坠落的,以及它们的位置是如何随机化的等等 虽然我对木槌的理解有问题,但我希望用篮子的图像来代替木槌 这就是木槌的代码 Brush malletHandleBrush = new SolidColorBrush(Colors.Black); Brush malletHeadBrush = new SolidColo

我正在学习Rob Miles的《学习Kinect API》一书中的教程。 基本上,这是一个增强现实游戏,蜘蛛从屏幕顶部坠落,你用木槌击打它们。在遵循教程并查看代码之后,我了解了蜘蛛是如何坠落的,以及它们的位置是如何随机化的等等

虽然我对木槌的理解有问题,但我希望用篮子的图像来代替木槌

这就是木槌的代码

Brush malletHandleBrush = new SolidColorBrush(Colors.Black);
Brush malletHeadBrush = new SolidColorBrush(Colors.Red);
float malletHandleLength = 100;
float malletHeadLength = 50;
System.Windows.Vector malletPosition;
float malletHitRadius = 40;
bool malletValid = false;

void updateMallet(Joint j1, Joint j2)
{
    // If Joint 1 (Right Wrist) or Joint 2 (Right Hand) is not tracked, we stop here
    if (j1.TrackingState != JointTrackingState.Tracked || j2.TrackingState != JointTrackingState.Tracked)
        return;

    // Get the start and end positions of the mallet vector
    ColorImagePoint j1P = myKinect.CoordinateMapper.MapSkeletonPointToColorPoint(j1.Position, ColorImageFormat.RgbResolution640x480Fps30);
    ColorImagePoint j2P = myKinect.CoordinateMapper.MapSkeletonPointToColorPoint(j2.Position, ColorImageFormat.RgbResolution640x480Fps30);

    int dX = j2P.X - j1P.X;
    int dY = j2P.Y - j1P.Y;

    System.Windows.Vector malletDirection = new System.Windows.Vector(dX, dY);

    if (malletDirection.Length < 1) return;

    // Convert into a vector of length 1 unit
    malletDirection.Normalize();

    // now set the length of the mallet 
    System.Windows.Vector handleVector = malletDirection * malletHandleLength;

    Line handleLine = new Line();

    handleLine.Stroke = malletHandleBrush;
    handleLine.StrokeThickness = 10;

    handleLine.X1 = j1P.X;
    handleLine.Y1 = j1P.Y;

    handleLine.X2 = j1P.X + handleVector.X;
    handleLine.Y2 = j1P.Y + handleVector.Y;

    //malletCanvas.Children.Add(handleLine);

    Line headLine = new Line();

    headLine.Stroke = malletHeadBrush;
    headLine.StrokeThickness = 50;

    System.Windows.Vector headVector = malletDirection * malletHeadLength;

    headLine.X1 = handleLine.X2;
    headLine.Y1 = handleLine.Y2;

    headLine.X2 = handleLine.X2 + headVector.X;
    headLine.Y2 = handleLine.Y2 + headVector.Y;
    //malletCanvas.Children.Add(headLine);

    malletPosition = new System.Windows.Vector(j1P.X, j1P.Y);

    malletPosition = malletPosition + (malletDirection * (malletHandleLength + (malletHeadLength / 2)));

    malletValid = true;
}
// Declare Hit Vector for each Dollar Note
System.Windows.Vector _spiderHitVector = new System.Windows.Vector(malletPosition.X - _spiderCenterX, malletPosition.Y - _spiderCenterY);

是否有人有任何资源或给我一些关于如何处理此问题的提示?

SDK附带了一个演示应用程序,Shape Game(如果我没记错的话),它描述了如何处理骨架以及如何与屏幕上的对象交互。你有机会看一下那个代码吗?@EvilClosetMonkey谢谢!我看了一下代码,这确实是一个非常简单的游戏,代码非常复杂。我很难理解所有的类文件。如果我能完全理解它们,我就可以轻松开发出一款比我提出这个问题时想象的更复杂的游戏。你知道有哪些资源记录了这个示例游戏吗?