[[Tutorial]] テスト中 **動作確認バージョン [#w7344684] -OpenNI Stable Build for Windows x86 (32-bit) v1.5.2.23 Development Edition → ダウンロードは[[こちら>http://75.98.78.94/Downloads/OpenNIModules.aspx]]。 -PrimeSene NITE Stable Build for Windows x86 (32-bit) v1.5.2.21 Development → 上と同じページのOpenNI Compliant Middleware Binariesを選択してダウンロード。 -ドライバ PrimeSense Sensor Module for OpenNI Version 5.1.0.25 → [[こちら>https://github.com/avin2/SensorKinect]]からダウンロード。 **クライアント側 [#g906fc36] ***ソースコード [#v654549b] #ref(SIGNiUserTracker.zip) ***バイナリ [#sb954688] #ref(SIGNiUserTracker_bin.zip) **コントローラソースコード [#y2f178b2] #highlight(cpp){{ #include <string> //stringをインクルード #include "Controller.h" #include "Logger.h" #include "ControllerEvent.h" #define PI 3.141592 #define DEG2RAD(DEG) ( (PI) * (DEG) / 180.0 ) using namespace std; //利用名前空間の定義 class AgentController : public Controller { public: double onAction(ActionEvent &evt); //音声データを受け取った時に呼出される関数onRecvSoundの利用を宣言します。 void onRecvSound(RecvSoundEvent &evt); // メッセージを受信したときの関数onRecvMessageの利用を宣言します。 void onRecvMessage(RecvMessageEvent &evt); void onInit(InitEvent &evt); private: double m_posx; double m_posy; double m_posz; double m_range; int m_maxsize; }; void AgentController::onInit(InitEvent &evt) { SimObj *my = getObj(myname()); m_posx = my->x(); m_posy = my->y(); m_posz = my->z(); m_range = 0.1; m_maxsize = 15; } double AgentController::onAction(ActionEvent &evt) { return 10.0; } void AgentController::onRecvSound(RecvSoundEvent &evt) { } void AgentController::onRecvMessage(RecvMessageEvent &evt) { //自分自身の取得 SimObj *my = getObj(myname()); char *all_msg = (char*)evt.getString(0); char *msg = strtok(all_msg," "); if(strcmp(msg,"KINECT_DATA") == 0) { int i = 0; while(true) { i++; if(i == m_maxsize+1) break; char *type = strtok(NULL,":"); if(strcmp(type,"POSITION") == 0) { double x = atof(strtok(NULL,",")); double y = atof(strtok(NULL,",")); double z = atof(strtok(NULL," ")); my->setPosition(m_posx+x,m_posy+y,m_posz+z); continue; } else if(strcmp(type,"WAIST") == 0) { double w = atof(strtok(NULL,",")); double x = atof(strtok(NULL,",")); double y = atof(strtok(NULL,",")); double z = atof(strtok(NULL," ")); my->setAxisAndAngle(x,y,z,acos(w)*2); continue; } else if(strcmp(type,"END") == 0) break; else { double w = atof(strtok(NULL,",")); double x = atof(strtok(NULL,",")); double y = atof(strtok(NULL,",")); double z = atof(strtok(NULL," ")); double angle = acos(w)*2; double tmp = sin(angle/2); double vx = x/tmp; double vy = y/tmp; double vz = z/tmp; double len = sqrt(vx*vx+vy*vy+vz*vz); if(len < (1 - m_range) || (1 + m_range) < len) continue; my->setJointQuaternion(type,w,x,y,z); continue; } } } } extern "C" Controller * createController () { return new AgentController; } }} #highlight(end)