-
Notifications
You must be signed in to change notification settings - Fork 0
/
BodyBasics.h
executable file
·153 lines (129 loc) · 5.76 KB
/
BodyBasics.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//------------------------------------------------------------------------------
// <copyright file="BodyBasics.h" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
#pragma once
#include "resource.h"
class CBodyBasics
{
static const int cDepthWidth = 512;
static const int cDepthHeight = 424;
public:
/// <summary>
/// Constructor
/// </summary>
CBodyBasics();
/// <summary>
/// Destructor
/// </summary>
~CBodyBasics();
/// <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 uMsg, 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 uMsg, 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;
INT64 m_nStartTime;
INT64 m_nLastCounter;
double m_fFreq;
INT64 m_nNextStatusTime;
DWORD m_nFramesSinceUpdate;
// Current Kinect
IKinectSensor* m_pKinectSensor;
ICoordinateMapper* m_pCoordinateMapper;
// Body reader
IBodyFrameReader* m_pBodyFrameReader;
// Direct2D
ID2D1Factory* m_pD2DFactory;
// Body/hand drawing
ID2D1HwndRenderTarget* m_pRenderTarget;
ID2D1SolidColorBrush* m_pBrushJointTracked;
ID2D1SolidColorBrush* m_pBrushJointInferred;
ID2D1SolidColorBrush* m_pBrushBoneTracked;
ID2D1SolidColorBrush* m_pBrushBoneInferred;
ID2D1SolidColorBrush* m_pBrushHandClosed;
ID2D1SolidColorBrush* m_pBrushHandOpen;
ID2D1SolidColorBrush* m_pBrushHandLasso;
/// <summary>
/// Main processing function
/// </summary>
void Update();
/// <summary>
/// Initializes the default Kinect sensor
/// </summary>
/// <returns>S_OK on success, otherwise failure code</returns>
HRESULT InitializeDefaultSensor();
/// <summary>
/// Handle new body data
/// <param name="nTime">timestamp of frame</param>
/// <param name="nBodyCount">body data count</param>
/// <param name="ppBodies">body data in frame</param>
/// </summary>
void ProcessBody(INT64 nTime, int nBodyCount, IBody** ppBodies);
/// <summary>
/// Set the status bar message
/// </summary>
/// <param name="szMessage">message to display</param>
/// <param name="nShowTimeMsec">time in milliseconds for which to ignore future status messages</param>
/// <param name="bForce">force status update</param>
bool SetStatusMessage(_In_z_ WCHAR* szMessage, DWORD nShowTimeMsec, bool bForce);
/// <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>
/// Converts a body point to screen space
/// </summary>
/// <param name="bodyPoint">body 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 BodyToScreen(const CameraSpacePoint& bodyPoint, int width, int height);
/// <summary>
/// Draws a body
/// </summary>
/// <param name="pJoints">joint data</param>
/// <param name="pJointPoints">joint positions converted to screen space</param>
void DrawBody(const Joint* pJoints, const D2D1_POINT_2F* pJointPoints);
/// <summary>
/// Draws a hand symbol if the hand is tracked: red circle = closed, green circle = opened; blue circle = lasso
/// </summary>
/// <param name="handState">state of the hand</param>
/// <param name="handPosition">position of the hand</param>
void DrawHand(HandState handState, const D2D1_POINT_2F& handPosition);
/// <summary>
/// Draws one bone of a body (joint to joint)
/// </summary>
/// <param name="pJoints">joint data</param>
/// <param name="pJointPoints">joint positions converted to screen space</param>
/// <param name="pJointPoints">joint positions converted to screen space</param>
/// <param name="joint0">one joint of the bone to draw</param>
/// <param name="joint1">other joint of the bone to draw</param>
void DrawBone(const Joint* pJoints, const D2D1_POINT_2F* pJointPoints, JointType joint0, JointType joint1);
};