ブログ@kaorun55

HoloLensやKinectなどのDepthセンサーを中心に書いています。

Kinect for Windows SDK v1.6 の 加速度センサーを使ってみる(C++)

C++で加速度センサーの値を取得してみます。

INuiSensor::NuiAccelerometerGetCurrentReading() で取得できます。加速度の値はVector4のx,y,zに格納されます。

#include <Windows.h>

#include <NuiApi.h>

#include <iostream>

#include <conio.h>

void main()

{

try {

int count = 0;

::NuiGetSensorCount( &count );

if ( count == 0 ) {

throw std::runtime_error( "利用可能なKinectがありません" );

}

INuiSensor* kinect;

::NuiCreateSensorByIndex( 0, &kinect );

while ( true ) {

Vector4 accelerometer = { 0 };

kinect->NuiAccelerometerGetCurrentReading( &accelerometer );

std::cout << '\r' << accelerometer.x << ", "

<< accelerometer.y << ", "

<< accelerometer.z;

if ( ::_kbhit() ) {

break;

}

}

}

catch ( std::exception& ex ) {

std::cout << ex.what() << std::endl;

}

}

C#のほうでも載せましたが、座標系はこのようになっているようです。

全体のコードはこちらにあります