//------------------------------------------------------------------------------
// <copyright file="SkeletonBasics.cpp" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
#include "stdafx.h"
#include <strsafe.h>
#include "SkeletonBasics.h"
#include "resource.h"
static const float g_JointThickness = 3.0f;
static const float g_TrackedBoneThickness = 6.0f;
static const float g_InferredBoneThickness = 1.0f;
/// <summary>
/// Entry point for the application
/// </summary>
/// <param name="hInstance">handle to the application instance</param>
/// <param name="hPrevInstance">always 0</param>
/// <param name="lpCmdLine">command line arguments</param>
/// <param name="nCmdShow">whether to display minimized, maximized, or normally</param>
/// <returns>status</returns>
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
{
CSkeletonBasics application;
application.Run(hInstance, nCmdShow);
}
/// <summary>
/// Constructor
/// </summary>
CSkeletonBasics::CSkeletonBasics() :
m_pD2DFactory(NULL),
m_hNextSkeletonEvent(INVALID_HANDLE_VALUE),
m_pSkeletonStreamHandle(INVALID_HANDLE_VALUE),
m_bSeatedMode(false),
m_pRenderTarget(NULL),
m_pBrushJointTracked(NULL),
m_pBrushJointInferred(NULL),
m_pBrushBoneTracked(NULL),
m_pBrushBoneInferred(NULL),
m_pNuiSensor(NULL)
{
ZeroMemory(m_Points,sizeof(m_Points));
}
/// <summary>
/// Destructor
/// </summary>
CSkeletonBasics::~CSkeletonBasics()
{
if (m_pNuiSensor)
{
m_pNuiSensor->NuiShutdown();
}
if (m_hNextSkeletonEvent && (m_hNextSkeletonEvent != INVALID_HANDLE_VALUE))
{
CloseHandle(m_hNextSkeletonEvent);
}
// clean up Direct2D objects
DiscardDirect2DResources();
// clean up Direct2D
SafeRelease(m_pD2DFactory);
SafeRelease(m_pNuiSensor);
}
/// <summary>
/// Creates the main window and begins processing
/// </summary>
/// <param name="hInstance">handle to the application instance</param>
/// <param name="nCmdShow">whether to display minimized, maximized, or normally</param>
int CSkeletonBasics::Run(HINSTANCE hInstance, int nCmdShow)
{
MSG msg = {0};
WNDCLASS wc = {0};
// Dialog custom window class
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.cbWndExtra = DLGWINDOWEXTRA;
wc.hInstance = hInstance;
wc.hCursor = LoadCursorW(NULL, IDC_ARROW);
wc.hIcon = LoadIconW(hInstance, MAKEINTRESOURCE(IDI_APP));
wc.lpfnWndProc = DefDlgProcW;
wc.lpszClassName = L"SkeletonBasicsAppDlgWndClass";
if (!RegisterClassW(&wc))
{
return 0;
}
// Create main application window
HWND hWndApp = CreateDialogParamW(
hInstance,
MAKEINTRESOURCE(IDD_APP),
NULL,
(DLGPROC)CSkeletonBasics::MessageRouter,
reinterpret_cast<LPARAM>(this));
// Show window
ShowWindow(hWndApp, nCmdShow);
const int eventCount = 1;
HANDLE hEvents[eventCount];
// Main message loop
while (WM_QUIT != msg.message)
{
hEvents[0] = m_hNextSkeletonEvent;
// Check to see if we have either a message (by passing in QS_ALLEVENTS)
// Or a Kinect event (hEvents)
// Update() will check for Kinect events individually, in case more than one are signalled
DWORD dwEvent = MsgWaitForMultipleObjects(eventCount, hEvents, FALSE, INFINITE, QS_ALLINPUT);
// Check if this is an event we're waiting on and not a timeout or message
if (WAIT_OBJECT_0 == dwEvent)
{
Update();
}
if (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE))
{
// If a dialog message will be taken care of by the dialog proc
if ((hWndApp != NULL) && IsDialogMessageW(hWndApp, &msg))
{
continue;
}
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
}
return static_cast<int>(msg.wParam);
}
/// <summary>
/// Main processing function
/// </summary>
void CSkeletonBasics::Update()
{
if (NULL == m_pNuiSensor)
{
return;
}
// Wait for 0ms, just quickly test if it is time to process a skeleton
if ( WAIT_OBJECT_0 == WaitForSingleObject(m_hNextSkeletonEvent, 0) )
{
ProcessSkeleton();
}
}
/// <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>
LRESULT CALLBACK CSkeletonBasics::MessageRouter(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
CSkeletonBasics* pThis = NULL;
if (WM_INITDIALOG == uMsg)
{
pThis = reinterpret_cast<CSkeletonBasics*>(lParam);
SetWindowLongPtr(hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(pThis));
}
else
{
pThis = reinterpret_cast<CSkeletonBasics*>(::GetWindowLongPtr(hWnd, GWLP_USERDATA));
}
if (pThis)
{
return pThis->DlgProc(hWnd, uMsg, wParam, lParam);
}
return 0;
}
/// <summary>
/// Handle windows messages for the 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 CSkeletonBasics::DlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
{
// Bind application window handle
m_hWnd = hWnd;
// Init Direct2D
D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &m_pD2DFactory);
// Look for a connected Kinect, and create it if found
CreateFirstConnected();
}
break;
// If the titlebar X is clicked, destroy app
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
// Quit the main message pump
PostQuitMessage(0);
break;
// Handle button press
case WM_COMMAND:
// If it was for the near mode control and a clicked event, change near mode
if (IDC_CHECK_SEATED == LOWORD(wParam) && BN_CLICKED == HIWORD(wParam))
{
// Toggle out internal state for near mode
m_bSeatedMode = !m_bSeatedMode;
if (NULL != m_pNuiSensor)
{
// Set near mode for sensor based on our internal state
m_pNuiSensor->NuiSkeletonTrackingEnable(m_hNextSkeletonEvent, m_bSeatedMode ? NUI_SKELETON_TRACKING_FLAG_ENABLE_SEATED_SUPPORT : 0);
}
}
break;
}
return FALSE;
}
/// <summary>
/// Create the first connected Kinect found
/// </summary>
/// <returns>indicates success or failure</returns>
HRESULT CSkeletonBasics::CreateFirstConnected()
{
INuiSensor * pNuiSensor;
int iSensorCount = 0;
HRESULT hr = NuiGetSensorCount(&iSensorCount);
if (FAILED(hr))
{
return hr;
}
// Look at each Kinect sensor
for (int i = 0; i < iSensorCount; ++i)
{
// Create the sensor so we can check status, if we can't create it, move on to the next
hr = NuiCreateSensorByIndex(i, &pNuiSensor);
if (FAILED(hr))
{
continue;
}
// Get the status of the sensor, and if connected, then we can initialize it
hr = pNuiSensor->NuiStatus();
if (S_OK == hr)
{
m_pNuiSensor = pNuiSensor;
break;
}
// This sensor wasn't OK, so release it since we're not using it
pNuiSensor->Release();
}
if (NULL != m_pNuiSensor)
{
// Initialize the Kinect and specify that we'll be using skeleton
hr = m_pNuiSensor->NuiInitialize(NUI_INITIALIZE_FLAG_USES_SKELETON);
if (SUCCEEDED(hr))
{
// Create an event that will be signaled when skeleton data is available
m_hNextSkeletonEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
// Open a skeleton stream to receive skeleton data
hr = m_pNuiSensor->NuiSkeletonTrackingEnable(m_hNextSkeletonEvent, 0);
}
}
if (NULL == m_p
没有合适的资源?快使用搜索试试~ 我知道了~
SkeletonBasics-D2D.zip_SkeletonBasics-D2D_SkeletonBasics-WPF_kin
共58个文件
tlog:25个
log:4个
pdb:3个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 112 浏览量
2022-09-22
23:27:31
上传
评论
收藏 23.83MB ZIP 举报
温馨提示
自己编写的通过Kinect用手势控制鼠标程序,右手移动鼠标跟随移动
资源推荐
资源详情
资源评论
收起资源包目录
SkeletonBasics-D2D.zip (58个子文件)
SkeletonBasics-D2D
SkeletonBasics-D2D.vcxproj 9KB
app.ico 31KB
Release
CL.write.1.tlog 372B
CL.read.1.tlog 15KB
rc.write.1.tlog 254B
rc.read.1.tlog 2KB
SkeletonBasics-D2D.write.1.tlog 0B
cl.command.1.tlog 702B
SkeletonBasics-D2D.unsuccessfulbuild 0B
SkeletonBasics-D2D.Build.CppClean.log 857B
link.write.1.tlog 2B
link.command.1.tlog 2B
rc.command.1.tlog 568B
link.read.1.tlog 2B
SkeletonBasics-D2D.log 2KB
SkeletonBasics-D2D.lastbuildstate 68B
SkeletonBasics.res 32KB
vc100.pdb 236KB
SkeletonBasics.obj 365KB
stdafx.h 2KB
SkeletonBasics.cpp 18KB
SkeletonBasics.rc 6KB
SkeletonBasics.h 5KB
resource.h 1KB
SkeletonBasics-D2D.sln 1KB
SkeletonBasics-D2D.suo 18KB
ipch
skeletonbasics-d2d-213f6c4b
skeletonbasics-d2d-7cfd142d.ipch 36.31MB
SkeletonBasics-D2D.vcxproj.user 143B
Debug
vc100.idb 515KB
SkeletonBasics-D2D.exe.manifest 682B
CL.write.1.tlog 364B
CL.read.1.tlog 15KB
mt.read.1.tlog 342B
rc.write.1.tlog 250B
SkeletonBasics-D2D.exe 472KB
rc.read.1.tlog 2KB
SkeletonBasics-D2D.write.1.tlog 0B
SkeletonBasics-D2D.pdb 2.83MB
mt.command.1.tlog 516B
cl.command.1.tlog 682B
link-cvtres.read.1.tlog 2B
SkeletonBasics-D2D.Build.CppClean.log 2KB
link.write.1.tlog 858B
link-cvtres.write.1.tlog 2B
link.command.1.tlog 2KB
SkeletonBasics-D2D.ilk 1.13MB
SkeletonBasics-D2D.vcxprojResolveAssemblyReference.cache 707B
rc.command.1.tlog 560B
link.read.1.tlog 3KB
SkeletonBasics-D2D.log 2KB
mt.write.1.tlog 342B
SkeletonBasics-D2D.lastbuildstate 66B
SkeletonBasics-D2D.exe.intermediate.manifest 640B
SkeletonBasics.res 32KB
vc100.pdb 772KB
SkeletonBasics.obj 144KB
SkeletonBasics-D2D.sdf 48.96MB
SkeletonBasics-D2D.v11.suo 10KB
共 58 条
- 1
资源评论
weixin_42653672
- 粉丝: 93
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功