-
Notifications
You must be signed in to change notification settings - Fork 0
/
SkeletonBasics.h
138 lines (113 loc) · 4.69 KB
/
SkeletonBasics.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//------------------------------------------------------------------------------
// <copyright file="SkeletonBasics.h" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
#pragma once
#include "resource.h"
#include "NuiApi.h"
#include "Motion.h"
class CSkeletonBasics
{
static const int cScreenWidth = 320;
static const int cScreenHeight = 240;
static const int cStatusMessageMaxLen = MAX_PATH*2;
public:
/// <summary>
/// Constructor
/// </summary>
CSkeletonBasics();
/// <summary>
/// Destructor
/// </summary>
~CSkeletonBasics();
/// <summary>
/// Handles window messages, passes most to the class instance to handle
/// </summary>
/// <param name="hWnd">window message is for</param>
/// <param name="uMsg">message</param>
/// <param name="wParam">message data</param>
/// <param name="lParam">additional message data</param>
/// <returns>result of message processing</returns>
static LRESULT CALLBACK MessageRouter(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
/// <summary>
/// Handle windows messages for a class instance
/// </summary>
/// <param name="hWnd">window message is for</param>
/// <param name="uMsg">message</param>
/// <param name="wParam">message data</param>
/// <param name="lParam">additional message data</param>
/// <returns>result of message processing</returns>
LRESULT CALLBACK DlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
/// <summary>
/// Creates the main window and begins processing
/// </summary>
/// <param name="hInstance"></param>
/// <param name="nCmdShow"></param>
int Run(HINSTANCE hInstance, int nCmdShow);
private:
HWND m_hWnd;
bool m_bSeatedMode;
// Current Kinect
INuiSensor* m_pNuiSensor;
// Skeletal drawing
ID2D1HwndRenderTarget* m_pRenderTarget;
ID2D1SolidColorBrush* m_pBrushJointTracked;
ID2D1SolidColorBrush* m_pBrushJointInferred;
ID2D1SolidColorBrush* m_pBrushBoneTracked;
ID2D1SolidColorBrush* m_pBrushBoneInferred;
D2D1_POINT_2F m_Points[NUI_SKELETON_POSITION_COUNT];
// Direct2D
ID2D1Factory* m_pD2DFactory;
HANDLE m_pSkeletonStreamHandle;
HANDLE m_hNextSkeletonEvent;
/// <summary>
/// Main processing function
/// </summary>
void Update();
/// <summary>
/// Create the first connected Kinect found
/// </summary>
/// <returns>S_OK on success, otherwise failure code</returns>
HRESULT CreateFirstConnected();
/// <summary>
/// Handle new skeleton data
/// </summary>
void ProcessSkeleton();
/// <summary>
/// Ensure necessary Direct2d resources are created
/// </summary>
/// <returns>S_OK if successful, otherwise an error code</returns>
HRESULT EnsureDirect2DResources( );
/// <summary>
/// Dispose Direct2d resources
/// </summary>
void DiscardDirect2DResources( );
/// <summary>
/// Draws a bone line between two joints
/// </summary>
/// <param name="skel">skeleton to draw bones from</param>
/// <param name="joint0">joint to start drawing from</param>
/// <param name="joint1">joint to end drawing at</param>
void DrawBone(const NUI_SKELETON_DATA & skel, NUI_SKELETON_POSITION_INDEX bone0, NUI_SKELETON_POSITION_INDEX bone1);
/// <summary>
/// Draws a skeleton
/// </summary>
/// <param name="skel">skeleton to draw</param>
/// <param name="windowWidth">width (in pixels) of output buffer</param>
/// <param name="windowHeight">height (in pixels) of output buffer</param>
void DrawSkeleton(const NUI_SKELETON_DATA & skel, int windowWidth, int windowHeight);
/// <summary>
/// Converts a skeleton point to screen space
/// </summary>
/// <param name="skeletonPoint">skeleton point to tranform</param>
/// <param name="width">width (in pixels) of output buffer</param>
/// <param name="height">height (in pixels) of output buffer</param>
/// <returns>point in screen-space</returns>
D2D1_POINT_2F SkeletonToScreen(Vector4 skeletonPoint, int width, int height);
/// <summary>
/// Set the status bar message
/// </summary>
/// <param name="szMessage">message to display</param>
void SetStatusMessage(WCHAR* szMessage);
};