diff --git a/ECTrainer2/ECTrainerGUI.cpp b/ECTrainer2/ECTrainerGUI.cpp index 0414528..19aacc4 100644 --- a/ECTrainer2/ECTrainerGUI.cpp +++ b/ECTrainer2/ECTrainerGUI.cpp @@ -1,6 +1,9 @@ #include "ECTrainer.h" #include "ECTrainerGUI.h" +#include +#pragma comment(lib,"winmm.lib") +#include #define CVUI_IMPLEMENTATION #include "cvui.h" @@ -55,7 +58,10 @@ bool fShowEyesPos = true; bool fStimulus = false; - float targetSize = 1.0; + bool fContact = false; + bool fKeepContact = false; + float targetSize = 2.0; + clock_t startContact = 0; while (_pEct->IsRunning() && cv::getWindowProperty(WIN_MAIN, 0) >= 0) { @@ -78,33 +84,83 @@ } // �h���摜 - float dist; if (_pEct->GetGazeI().x >= 0) { cv::circle(_DispImage, cv::Point((int)(_DispImage.cols * _pEct->GetGazeI().x), (int)(_DispImage.rows * _pEct->GetGazeI().y)), - (int)(_DispImage.rows * 0.03), CV_RGB(0, 0, 255), 1); + (int)(_DispImage.rows * 0.03), CV_RGB(0, 0, 255), 2); } - if (fStimulus && fShowEyesPos) { - cv::circle(_DispImage, - cv::Point((int)(_DispImage.cols * _pEct->GetEyeR().x), (int)(_DispImage.rows * _pEct->GetEyeR().y)), - (int)(_DispImage.rows * 0.03), CV_RGB(0, 128, 0), 1); - cv::circle(_DispImage, - cv::Point((int)(_DispImage.cols * _pEct->GetEyeL().x), (int)(_DispImage.rows * _pEct->GetEyeL().y)), - (int)(_DispImage.rows * 0.03), CV_RGB(0, 128, 0), 1); + fContact = false; + if (fStimulus) { + float dx = _pEct->GetEyeR().x - _pEct->GetEyeL().x; + float dy = _pEct->GetEyeR().y - _pEct->GetEyeL().y; + float eyesDistance = sqrtf(dx * dx + dy * dy); + float areaSize = eyesDistance * targetSize / 2.0F; + if (fShowEyesPos) { + cv::circle(_DispImage, + cv::Point((int)(_DispImage.cols * _pEct->GetEyeR().x), (int)(_DispImage.rows * _pEct->GetEyeR().y)), + (int)(_DispImage.rows * 0.03), CV_RGB(0, 128, 0), 2); + cv::circle(_DispImage, + cv::Point((int)(_DispImage.cols * _pEct->GetEyeL().x), (int)(_DispImage.rows * _pEct->GetEyeL().y)), + (int)(_DispImage.rows * 0.03), CV_RGB(0, 128, 0), 2); + cv::circle(_DispImage, + cv::Point((int)(_DispImage.cols * _pEct->GetEyeR().x), (int)(_DispImage.rows * _pEct->GetEyeR().y)), + (int)(_DispImage.cols * areaSize), CV_RGB(200, 200, 0), 2); + cv::circle(_DispImage, + cv::Point((int)(_DispImage.cols * _pEct->GetEyeL().x), (int)(_DispImage.rows * _pEct->GetEyeL().y)), + (int)(_DispImage.cols * areaSize), CV_RGB(200, 200, 0), 2); + } + if (_pEct->GetGazeI().x >= 0) { + float dxR = _pEct->GetEyeR().x - _pEct->GetGazeI().x; + float dyR = _pEct->GetEyeR().y - _pEct->GetGazeI().y; + float edR = sqrtf(dxR * dxR + dyR * dyR); + float dxL = _pEct->GetEyeL().x - _pEct->GetGazeI().x; + float dyL = _pEct->GetEyeL().y - _pEct->GetGazeI().y; + float edL = sqrtf(dxL * dxL + dyL * dyL); + if (edR <= areaSize || edL <= areaSize) { + fContact = true; + } + } + } + + // �R���^�N�g���� + if (fContact) { + if (!fKeepContact) { + fKeepContact = true; + startContact = clock(); + PlaySound(_T("../voices/voice2.wav"), NULL, SND_FILENAME | SND_ASYNC); + } else { + if ((clock() - startContact) / CLOCKS_PER_SEC >= 3) { + PlaySound(_T("../voices/voice1.wav"), NULL, SND_FILENAME | SND_SYNC); + fKeepContact = false; + targetSize -= 0.2; + _pEct->Next(); + } + } + } else { + fKeepContact = false; } // UI�`�� cvui::image(_MainFrame, 0, 0, _Logo); cvui::beginColumn(_MainFrame, 10, 100, 140, -1, 10); if (fStimulus) { - if (cvui::button(140, 30, "STOP")) fStimulus = false; - if (cvui::button(140, 30, "NEXT")) _pEct->Next(); + if (cvui::button(140, 30, "STOP")) { + fKeepContact = false; + fStimulus = false; + } + if (cvui::button(140, 30, "NEXT")) { + fKeepContact = false; + _pEct->Next(); + } cvui::trackbar(140, &targetSize, (float)0, (float)3.0); cvui::checkbox("Show Eyes", &fShowEyesPos); + cvui::text(fContact ? "Eyes Contact!" : "No contact"); } else { if (cvui::button(140, 30, "CALIBRATION")) _pEct->Calib(); if (cvui::button(140, 30, "START")) { - _pEct->Start(); fStimulus = true; + fStimulus = true; + fKeepContact = false; + _pEct->Start(); } } cvui::printf("Mouse W %d, %d", mp.x, mp.y);