����͂ł͂��܂܂Ŋw�K����4�͂Ŋw�K����WiimoteLib�����p���A��b�I�ȃv���O���~���O�������i�߂�A���H�I�ȃv���W�F�N�g�������Ă����܂��B
WiiRemote���g�����}�E�X�G�~�����[�^�[�uWiiRemoteMouse�v��A��V�̃Q�[���J���‹�XNA�ɂ�郊�A���^�C��3DCG�uWiiRemoteXNA�v���J�����Ă����܂��B
���̃Z�N�V�����ł͑�4�͂Ŋw��WiimoteLib�ɂ��ԊO���Z���T�[�@�\������ɂ����߂�A.NET�ɂ��}�E�X����v���O�����uWiiRemoteMouse�v���J������v���Z�X��ʂ���A���H�I��WiiRemote���p�v���O�����̊J����̌����܂��B
�Ƃ���Ń}�E�X�Ƃ�����A���ɑ�3�͂�uGlovePIE�v���g������@�\�ȃ}�E�X���X�N���v�e�B���O�Ŏ������܂����B�����ł͂�����v���g�^�C�v�Ƃ���A.NET�‹��ɂ������x�ȃA�v���P�[�V�����J�����X�e�b�v��ǂ��ĉ�����Ă����܂��B�P��GlovePIE�łł��邱�Ƃ�.NET�Ɉ�A���Ă��ʔ����Ȃ��ł�����A����A�����ł͑�4�͂ł͈���Ȃ�����.NET�̊J����@��Ǝ��N���X����A�O��DLL�̎���݂�������܂��B
����J������}�E�X����v���O�����uWiiRemoteMouse�v��A��{�Z�p�̑�����A���܂܂ł̕��K�̑g����킹�ł��B�������A��r�I�傫�ȃv���O�����ɂȂ�����A�F�����V�����@�\��lj��������Ȃ邱�Ƃł��傤�B��4�͂ł�A�����ȋ@�\�̊m�F�̂��߂ɓ�����������R�[�h�������Ă��܂������A���̃R�[�f�B���O�X�^�C���̂܂ܑ傫�ȃv���O�����ɂȂ��Ă�����A�“���������A�f�o�b�O�̂��Â炢�v���O�����ɂȂ��Ă������Ƃ��\�z����܂��B���̂悤�ȃv���O�����͑���u�X�p�Q�e�B�E�R�[�h�v�ƌĂ΂�A��l�ł̊J���͂Ƃ������A�`�[���ł̊J���ɂ����Ă�A�“����f�o�b�O�̂��Â炳����A�v���W�F�N�g��i�s������ɂ��錴���ɂ��Ȃ�܂��B
������g�ޗ�̂悤��u��C������グ�邱�Ƃ��ł��Ȃ����K��`��K�͂̃v���O�����v���J������Ƃ���A�܂��͈�U�A�v���O���~���O���痣��A��肽�����Ƃ�A�����������C���^���N�V�����A�ۑ�Ȃ�A�u�d�l�v���ȒP������o����A���������������P�ʂ��Ԃ�\�Ȃǂɂ���A���ꂩ�����̒P�ʂŊ����N���X�ɂ܂Ƃ߂Ă����Ɣ�r�I���܂������܂��B�s���l�܂��Ă���d�l����l���Ă��ǂ��̂ł����A����͊��ɊJ��������3��4��uGlovePIE�ł‚���w���@�\�}�E�X�x�v���4��9��u�ԊO���Z���T�[���g���v�ŊJ�������R�[�h���x�[�X��A�����uWiiRemoteMouse�v�Ɏ�������ł��낤�@�\�Ɨ���A�v���C�I���e�B(�D����)���܂��͂܂Ƃ߂Ă݂܂��傤�B
| �v���C�I���e�B | WiiRemote������ | �@�\ |
|---|---|---|
| 1 | �ԊO���ƃ{�^������ | �t�H�[���ɕ`�� |
| 2 | �ԊO���|�C���^�̈ړ� | �}�E�X�|�C���^�̈ړ� |
| 3 | [A]�{�^�� | �}�E�X���{�^�� |
| 4 | [A]�{�^�������� | �}�E�X�E�{�^�� |
| 5 | �o�b�e���[�c�� | LED�ɓd�r�c�ʃ��x���\�� |
�����Ƃ�����A�����݂����@�\������Ƃ������܂��B�Ⴆ�΃����`���[��A�L�[���͂̑���Ȃ�A����4�͂Ŏ��������@�\�𑼂̃{�^���Ɋ��蓖�ĂĂ݂Ă��ǂ��ł��傤�B���̒i�K����ʓI�ɂ�u�T�v�݌v�v�Ƃ����܂��B�ǂ��������Ƃ��������A�Ƃ����u�T�v�v�����̂�����݌v���Ă����܂��B
���ۂɎ�������@�\�Ƃ�����Ԃ����܂�܂����̂�A��������̒P�ʂ��ƂɊJ���̗�����l���܂��B�������ʓI�ɂ�u�v��v�ƌ����܂��B�������n�߂đ̌�����l�ɂƂ���A��̂��Ƃ͌��ʂ����‚��܂��񂩂�u���ܑz�肵�Ă��闬��v�ł��܂��܂���B�����o���Ă݂܂��B
�u�T�v�݌v�v��u�v��v���ق������ӎ�����K�����‚��邾����A�v���W�F�N�g��i�s�͑傫���ς��܂��B�����ł�u�T�v�݌v�v�ƊȒP�Ȍv��������܂����B���ۂ̃v���W�F�N�g�ł�A������u�����v�A�u���ʂ��̂‚��Ă��Ȃ��Z�p�v�Ȃǂ����ł�����A���v���W�F�N�g�炵���Ȃ��Ă����܂��B�u�T�v�݌v�v������ׂȉ�ʃC���[�W��@�\�A���������ł̃p�����[�^�[�A���Ƃ���u�������v�����b�������ƂȂ̂��A�Ȃǂ����ł�����u���݌v�v�ɂȂ�܂��B
�������{����WiiRemote�ɂ�����v���O���~���O����Ƃ��̓�K���ړI�Ȃ̂ł����܂ł̃��x���ɂƂǂ߂Ă����܂��B�����̂���l��u�v���W�F�N�g�}�l�W�����g�v�ɂ‚�����X�̎��p���R�[�i�[��T���Ă݂�Ɨǂ��ł��傤�B�v���O���~���O����Ɩ��̃v���W�F�N�g�܂ł��܂��܂Ȏ��p��������͂��ł�(���莎��������܂�)�B����IT�p��̃v���W�F�N�g�}�l�W�����g��A�r�W�l�X�p��̃v���W�F�N�g�}�l�W�����g�͈Ӗ�����Ƃ���ƈ������e�������Ԃ�ƈقȂ�܂����A������ɂ���u�����ǂ݂��Ă݂Ė��ɗ��Ž��p���v�Ȃ�A�����ēǂ�ł݂Ă����͂Ȃ��ł��傤�B
�܂��͕��K�����˂�A�V�����v���W�F�N�g�������܂��B�ԊO���Z���T�[�̓��͂���M���ăt�H�[���ɕ`�悷��v���O���������܂��傤�B��4��9��3��Љ���ԊO��4�_���o�ɂ��u���W�̕`��v�v���O�������x�[�X�ɂ���A���ς��Ă��ǂ��̂ł����A���K�����˂ă|�C���g�𗬂�ʼn�����܂��̂Ŏ��ۂɎ�𓮂����Ă݂Ă��������B
�܂�C#.NET2008��V�K�v���W�F�N�g�������܂��B�uVisual C#�v���uWindows�t�H�[���A�v���P�[�V�����v�Ńv���W�F�N�g�����uWiiRemoteMouse�v�Ƃ��܂��B�\�����[�V�����G�N�X�v���[���[�ɂ���u�Q��ݒ�v���E�N���b�N���A�Q�Ƃ̒lj���u�ŋߎg�p�����t�@�C���v����uWiimoteLib.dll�v(�o�[�W����1.7.0.0)��I�����܂��B�u�\���v���u�c�[���{�b�N�X�v��I��A�uForm1�v�ɑ΂���2�‚̃{�^����z�u��Text�v���p�e�B���u�ڑ��v�A�u�ؒf�v�Ƃ��܂��B�z�u�����{�^��2�‚����ꂼ��_�u���N���b�N����A�{�^�����������Ƃ��̃C�x���g�������������܂��B�܂��uForm1�v��PictureBox��z�u���T�C�Y���u256, 128�v��ݒ肵�܂��B�f�o�b�O�p�̕������\��������Ƃ���uLabel1�v��z�u���܂��B
�܂��̓X�^�[�g�n�_�ƂȂ�u�������v�ɂȂ�܂ŃR�[�h������܂��傤�B�R�[�h���ʼnE�N���b�N���uusing������v���u���g�p��using�v����Ƃ��邱�Ƃ�Ausing�錾�ɂ���K�v�Ȃ��N���X������邱�Ƃ��ł��܂��B�K�v�ȃN���X�uWiimoteLib�v�����������܂��B���������̈���Ƃ��܂��B
using System;
using System.Drawing;
using System.Windows.Forms;
using WiimoteLib;
namespace WiiRemoteMouse {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e) {
}
private void button2_Click(object sender, EventArgs e) {
}
}
}
�����܂ł̃X�e�b�v�ŊԈႢ�͋N���Ȃ��͂��ł����A�m�F�̂��߈�x[F6]�L�[�Ŏ��s���Ă����Ȃ��‚��Ă����Ɨǂ��ł��傤�B�������t�H�[�����\�����ꂽ��I�����A�v���W�F�N�g�S�̂�ۑ����܂��B�u�t�@�C���v���u�S�Ă̕ۑ��v�Ƃ���uC:\WiiRemote�v�Ƀ\�����[�V�������uWiiRemoteMouse�v�ŕۑ����܂��傤�B
�@�Q�[���J���Ȃǂɂ���\�����u�C���^���N�e�B�u�Z�p�v�̊J���Í�A��ʓI�ɂ̓X�N���b�`(���[��)����J�����邱�Ƃ������u�v���W�F�N�g�Ǘ��v�Ȃ�Č��t�Ɠ���݂������悤�Ɋ����邩������܂���B�����̃C���^���N�V�����v���O�����̓X�p�Q�e�B�E�R�[�h�ɂȂ肪���ł��B�������{�l�ɕ����Æ�A��ȗ��R�Í�u(����Ɋւ���)���È���Ƃ��Ȃ����c�v�Ƃ����ñ“š‚Ȃ̂ł����A���슴��̌��̈�ۂɒ�������ê�Šï¿½Å‚�����A�ł���Β��J�É�����ė~�����A�Ǝv���{���ł͌܌�墂����炢�ɂ����Ɋւ��Ē��J�É�������Ă��܂�(�����v���O���}�ɂƂ��Ă͉�è‚�ǂ������邱�Ƃł��傤�I)�B�@�������A���ۂɂ̓C���^���N�e�B�u�Z�p�ƂÍ�u�l�Ô�v���Ԃɓ���Z�p�ł��B���̂��ß�A�u���ꂾ�v�ƌ��ߑł��Ŏd�l�����A���̒ʂ�É������A���ۂɂł��オ�������̂�l�Ԃ��G���Ä�A�������������x�A���z�I�ȃC���^���N�V�����ɂȂ�悤�A���r���[�Æ�ÝŒv�A�t�B�[�h�o�b�N���J��Ԃ��K�v������܂��B�@���̂��ß�A�������u���b�N����N���X���͕�������΂����Ƃ������̂ł�����܂���B�{��������R�[�f�B���O�X�^�C���������I�Ƃ������̂ł͂���܂��ñ‚ª�A���Ȃ��Ƃ��v���W�F�N�g�̌��ʂ���ǂ����邽�߂É�u�X�p�Q�e�B��䥂ő�����v�����A�����������@�\������ۂ̂܂ܔz�u���Ä�A���ɉ������Ă������@�����ɗ����܂��B���傤�ǃR�[�X�����Ì�u�M�Ì�\���v���É�l���Ä�A��������w�ǂ��������Ԃŗ�������ׂ����H�x���l����悤�Ȃ��̂ł��傤�B���������Ӗ��łÍ�w���Ü���ׂ������Í�A�X�p�Q�e�B���R�[�X�������H�f�U�[�g�͂���̂��H�x�Ȃǂ��A�܂����肪�������Ă���K�v������܂��B
����ł�A��4��9��u�ԊO���Z���T�[���g���v�ŊJ�������R�[�h���Q�l�ɂ���A�ȉ��̂悤�Ȋ�{�R�[�h�������܂��傤�B
using System;
using System.Drawing;
using System.Windows.Forms;
using WiimoteLib; //WimoteLib�̎g�p��錾
namespace WiiRemoteMouse {
public partial class Form1 : Form {
Wiimote wm = new Wiimote(); //Wiimote�N���X����
Boolean isConnected = false; //WiiRemote���ڑ����ꂽ��
public Form1() {
InitializeComponent();
//���X���b�h����̃R���g���[���Ă�o������
Control.CheckForIllegalCrossThreadCalls = false;
}
//WiiRemote���Ԃ��ω������Ƃ��ɌĂ΂����
void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs args) {
WiimoteState ws = args.WiimoteState; //WiimoteState�̒l���擾
DrawForms(ws); //�t�H�[���`�ʊ����
}
//�t�H�[���`�ʊ��
public void DrawForms(WiimoteState ws) {
//�O���t�B�b�N�X���擾
Graphics g = this.pictureBox1.CreateGraphics();
g.Clear(Color.Black);//��ʂ����F�ɃN���A
g.Dispose();//�O���t�B�b�N�X�̉��
}
//�ڑ��{�^���������ꂽ��
private void button1_Click(object sender, EventArgs e) {
wm.Connect(); //WiiReote��ڑ�
wm.WiimoteChanged += wm_WiimoteChanged; //�C�x���g����̓o�^
//���|�[�g�^�C�v��ݒ�
wm.SetReportType(InputReport.IRAccel, true);
}
//�ؒf�{�^���������ꂽ��
private void button2_Click(object sender, EventArgs e) {
wm.WiimoteChanged -= wm_WiimoteChanged; //�C�x���g����̓o�^����
wm.Disconnect(); //WiiRemote�ؒf
wm.Dispose(); //�I�u�W�F�N�g�̔j��
}
}
}
�R���p�C�����ē���m�F�����܂��BForm1�̖`����WiiRemote��ڑ���Ԃ��Ǘ��������uBoolean isConnected�v��錾���Ă��܂��B���񃌃|�[�g�^�C�v��uIRAccel�v�A�‚܂�w�ԊO���{�����x�Z���T�[�x�Ƃ��܂��B�uIRExtensionAccel�v�ł��ǂ��̂�������܂���A�����ł͊g���[�q���g���\��͂���܂���̂�A�œK�ȃ��[�h��I�����Ă����܂��傤�B
������A�����K�͂ɂȂ��Ă����ł��낤���̃v���O�����̑S�̂�\��������Ă��������Ƃ������܂��B���̒i�K�ł̃R�[�f�B���O��������ȂNJ�{�I�ȂƂ��낾���ɂƂǂ�A��X�̋@�\�̎����ɓ���O��A�������܂��傤�B�܂��̓f�B�[�v�ȃR�[�f�B���O���n�߂�O��A�ȒP�ȃR�����g�������Ă��������Ƃ��厖�ł��B����Ɏ��O��u���������@�\�������������A����\��v�Ƃ����u���b�N�����ɂ܂Ƃ߂Ă������Ƃ�A�S�̂̌��ʂ���ǂ����܂��B
�܂������̃u���b�N�����w�т܂��傤�BVisual Studio�ł�A�v���O�����R�[�h����u#region�`#endregion�v��������Ƃ�A�R�[�h���u���b�N(=�ЂƂ‚̃J�^�}��)���Ƃɂ킯�邱�Ƃ��ł��܂��B���̃u���b�N���Ƃ�Visual Studio�R�[�h�G�f�B�^�̃A�E�g���C���@�\���g�p����A�W�J��܂肽���݂��ł���悤�ɂȂ�܂��B
�g�������ȒP��A�u���b�N��}���������v���O������s�ʼnE�N���b�N����u�u���b�N�̑}���v��u#region�v��I�����邾���ł��B�����ł��L�̊�{�R�[�h�ɂ�����A�t�H�[����ڑ��{�^����ؒf�{�^���̃u���b�N�ɑ΂���u�t�H�[���̃{�^������(�ڑ��E�ؒf)�v�Ƃ������O���‚��܂��傤�u#region�v��I���A���O���‚��܂��B
�u�u���b�N�̑}���v��I��A�����ݒ肵�Ȃ��Ɖ��̂悤�ȃR�[�h���}������܂��B
#region MyRegion #endregion
���O���‚��ԈႦ�Ă��A�����ԈႦ�Ă����ł͂���܂���B�u#region�v�͂����܂�C#�̃v���O����������ꂽ�u�⑫�I����v�ł���A�r���h���A��I�I�ɂ͖�������܂�����A�C�y�Ɏg���ėǂ��̂ł��B�ł�u�t�H�[���̃{�^������(�ڑ��E�ؒf)�v���܂Ƃ߂邽�߂��������������Ă݂܂��傤�B
#region �t�H�[���̃{�^������(�ڑ��E�ؒf)
//�ڑ��{�^���������ꂽ��
private void button1_Click(object sender, EventArgs e) {
wm.Connect(); //WiiRemote��ڑ�
wm.WiimoteChanged += wm_WiimoteChanged; //�C�x���g����̓o�^
//���|�[�g�^�C�v��ݒ�
wm.SetReportType(InputReport.IRAccel, true);
}
//�ؒf�{�^���������ꂽ��
private void button2_Click(object sender, EventArgs e) {
wm.WiimoteChanged -= wm_WiimoteChanged; //�C�x���g����̓o�^����
wm.Disconnect(); //WiiRemote�ؒf
wm.Dispose(); //�I�u�W�F�N�g�̔j��
}
#endregion
}
}
�\����܂肽���ނɂ�A�R�[�h�����(�s��)�ɂ�������u�|�v���N���b�N�����A�R�[�h�u���b�N���B�����Ƃ��ł��܂��B
�Ȃ��u#endregion�v��}��������ɒ��ӂ��Ă��������B����ɂ���u}�v(�����I���)�̈ʒu���ԈႦ�Ă��v���O�����͓����܂����A�R�[�h�u���b�N��܂肽���ނƂ����S���G���[�͋N���܂���A���������ƂŃR�[�h��ǂނƂ��ɑ�ςȂ̂�A�K���Ƃ��ċC�������܂��傤�B
�u���b�N���̊�{���w�񂾂�A����WiiRemote���Ԃ��X�V���ꂽ�Ƃ��ɌĂ΂��R�[���o�b�N����uwm_WiimoteChanged()�v�����ꂩ������������̒P�ʂŃu���b�N�ɕ������Ă����܂��B���ꂼ��̋@�\�P�ʂŊ�������A�u���b�N�Ƌ�(�J��)�̊����p�ӂ��Ă����܂��B�ȉ��̒ʂ�ɃR�[�h���u���b�N�����Ă݂Ă��������B
���O����
#region WiiRemote���Ԃ��ω������Ƃ��ɌĂ΂����
void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs args) {
if (isConnected == true) {
WiimoteState ws = args.WiimoteState; //WiimoteState�̒l���擾
DrawForms(ws); // �t�H�[���`������
IR_Cursor(ws); // �ԊO���Ń}�E�X�J�[�\���ړ�
Events(ws); //�{�^���C�x���g����(�_�~�[���)
EffectsOut(ws); // LED�E����
} else {
//�ؒf
this.wm.SetLEDs(0); // LED����
this.wm.SetRumble(false); // �o�C�u���[�^�[��~
this.wm.Disconnect(); // WiiRemote��ؒf
this.wm.Dispose(); // �I�u�W�F�N�g�̔p��
}
}
#endregion
#region �{�^���C�x���g�J���p
public void Events(WiimoteState ws) {
}
#endregion
#region �t�H�[���`����
public void DrawForms(WiimoteState ws) {
//�O���t�B�b�N�X���擾
Graphics g = this.pictureBox1.CreateGraphics();
g.Clear(Color.Black);//��ʂ����F�ɃN���A
g.Dispose();//�O���t�B�b�N�X�̉��
}
#endregion
#region �ԊO���Ń}�E�X�J�[�\���ړ�
public void IR_Cursor(WiimoteState ws)
{
}
#endregion
#region LED�E����
public void EffectsOut(WiimoteState ws) {
}
#endregion
#region �t�H�[���̃{�^������(�ڑ��E�ؒf)
���ȉ�����
����ۂ̊���������͕̂s�������邩������܂���A����ł����Ȃ��r���h�͒ʂ�܂��B�m�F���Ă����܂��傤�B
�r���uEvents(ws);�v�ɂ‚���u�_�~�[����v�ƃR�����g���Ă����܂����B�����WiiRemote�����‚��ꂼ��̃{�^���C�x���g��������������z�肵�Ă��܂��B��X��K�͂ɂȂ邱�Ƃ��\�z�����̂�A�N���X�Ƃ��Ă��Ƃ�ė��p�ł������Ȃ̂�AForm1.cs�ł͂Ȃ��A�ʂ�V�����N���X�I�u�W�F�N�g�������Ď�������\��ł��B���̒i�K�ł�w�ʃN���X�ɂ����炢�����A���ʂ��‚��Ȃ���I�x�Ƃ�����ԂȂ̂�uEvents()�v�Ƃ������̊���Ŏ������A���Ƃŕʂ̃N���X�Ɉ�A���Ă����܂��B
�u#region�v���g�����Ƃ�A�R�����g�Ɠ����ł���A���₷���Ȃ�܂����BVisual Studio�ł͊���P�ʂ��A�E�g���C����u�|�v�ʼnB�������ł��܂����A�{���̈ȉ��̉���ł̓u���b�N�P�ʂʼn�����܂��̂�A#region�`#endregion�̈ʒu�͂�������ݒ肵�Ă����Ă��������B
�u���b�N�����邱�ƂŃR�[�h�����₷���Ȃ�܂����B�����������ԂŃv���O���������s����Ɨl�X�ȕs�����c���Ă��܂��B�ЂƂ‚•Еt���Ă����܂��傤�B
�܂��̓v���O�������N���������Ƃ̃t�H�[���̃C�x���g����������Ȃ���������Ă����܂��傤�B���݂��Ԃł�ڑ���ؒf������}�����܂��̂�A�uisConnected�v�Ƃ���bool�^�̕����p�ӂ���A�ڑ���Ԃ��Ǘ����Ă����܂�(WiimoteLib�ɂ�����ɂ�����v���p�e�B�������Ă��悳�����Ȃ��̂Ȃ̂ł����A�����WiimoteLib��݌v�ł͌�X�̃A�v���P�[�V�������Ŏ�����������悳�����ł�)�B
#region �t�H�[���̃{�^������(�ڑ��E�ؒf)
//�ڑ��{�^���������ꂽ��
private void button1_Click(object sender, EventArgs e) {
if (this.isConnected == false) {
this.wm = new Wiimote(); //WiiRemote�������
this.wm.Connect(); //WiiRemote�ڑ�
this.wm.SetReportType(InputReport.IRAccel, true); //���|�[�g�^�C�v��ݒ�
this.wm.SetLEDs(0); //LED ������
this.wm.SetRumble(false); //�o�C�u���[�^�X�g�b�v
this.button1.Enabled = false; //�ڑ��{�^���𖳌�
this.button2.Enabled = true; //�ؒf�{�^����L��
this.wm.WiimoteChanged += wm_WiimoteChanged; //�R�[���o�b�N��o�^
this.isConnected = true; //�ڑ���Ԃ�true
}
}
//�ؒf�{�^���������ꂽ��
private void button2_Click(object sender, EventArgs e) {
if (this.isConnected == true) {
this.wm.WiimoteChanged -= wm_WiimoteChanged; //�R�[���o�b�N����
this.button1.Enabled = true; //�ڑ��{�^����L��
this.button2.Enabled = false; //�ؒf�{�^���𖳌�
this.isConnected = false; //�ڑ���Ԃ�false
}
}
#endregion
�t�H�[���̃{�^���������ꂽ�Ƃ��A�uisConnected�v���m�F���A�����܂��ڑ�����Ă��Ȃ��Ȃ�A�ڑ������A���|�[�g�^�C�v��ݒ�A�����ăR�[���o�b�N�����o�^����A����uisConnected�v��true�ɂ��܂��B
���l��u�ؒf�v�{�^���������ꂽ�Ƃ��͊���ڑ�����Ă���WiiRemote�I�u�W�F�N�g(wm)�ɓo�^���ꂽ�R�[���o�b�N����������Ă��܂��B
�t�H�[�����u�ڑ��v��u�ؒf�v�{�^����uEnabled=false�v�Ƃ��邱�ƂŖ������A�‚܂�u�����Ȃ����v�ɂ��邱�Ƃ��ł��܂��B���̂悤�ɂǂ��炩��������A�ǂ��炩�̒l���r���I�ɕς��A������Ɩ��̂悤�ȃ{�^�����u�g�O��(toggle)�v�Ƃ����܂����A������\�t�g�E�F�A�Ŏ������Ă��邱�ƂɂȂ�܂��B
�@�{���ł͌����⓮���S�ɉ�����Ă��܂��̂�A���[�U�[�̕s�ӂ�I����G���[�����Ȃǂ�(�ɗ͗v���v����������Ă͂��܂���)���S�ɂ͈����؂�Ă��܂���B�F���񂪃t���[�E�F�A�Ȃ�A�����̃v���O�������w���L���A�N���x�Ɏg���Ă��炤�ɂ͓��ɋC�������������ǂ��ł��傤�B
�@�K���Ƃ��Ä�u������-�I���v�A�u�I�u�W�F�N�g�̒lj�-�í�œï¿½v�̓����Z�b�g�ŃR�[�f�B���O���Ă����Ǝv��ʃ~�X�̌y���ɖ𗧂��܂��B����C#�Ì�ê�‡ï¿½Í�A���[�U�[�t�����h���[�É�ÝŒv���ꂽ����‹��Ȃ̂Å�A�í�œï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ÅŽï¿½ï¿½{�������d�g�݂�����܂��B�ӎ����Ďg�����Ƃ��ł���΃G���K���g�Ȃ̂ł����A�t�É�u�����ςȂ��A�í�œï¿½Í�c���������v�Ƃ����v���O���~���O�X�^�C�����‚ɂ‚��Æ�A�I�u�W�F�N�g�̃X�R�[�v(��������)�������Âç‚�Ȃ�A�v���O�����̓��쎩�̂͊������Ă���̂É�A�c������I�u�W�F�N�g�̂������ŕs���̃G���[�����s���ɋN��������A�����ԋN�����Ă����ƃ��������[�N(�������R��)���N�����A�������ˑR�x���Ȃ�����A�N���b�V�������肷��w���Ƃ��Ǝ�̂�����v���O�����x�ð�¶‚Ý�o���܂��B
�@���ɃI�u�W�F�N�g��I����j���͖Y�ꂪ���ł��BWiimoteLib�̂悤�ɒN������������C�u��������͒P��u�I���v�Ƃ���API�������Ă��A�����ʼn�������Ă��邩�킩��Ȃ���������܂��B�R�[�f�B���O�̗����u���܂�����I�����ėǂ����킩��Ȃ��v�Ƃ������Ƃ�������ł��傤�B����ȂƂ���u//�����Ŕj���H�v�Ȃ�w�����̎������x�ɃR�����g�����Ă������Ƃ�A��X�̃R�[�h�����̎��Ɍ����ɖ��ɗ������肵�܂��B
����ԊO���Z���T�[�𗘗p����A�}�E�X�|�C���^�𓮂��������̎��������܂��B�����Ȃ�}�E�X�𓮂����������������Ă������̂ł����A�ԊO����󋵂������Ȃ��ƊJ������q���܂��̂�A�܂��̓t�H�[���`�����uDrawForms()�v�Ɏ��������ԊO����WiiRemote�̎��E�ɓ�������A�O���t�B�b�N�X�ƕ����ő���l��\������悤�ɂ��܂��B
#region �t�H�[���`����
public void DrawForms(WiimoteState ws)
{
//�O���t�B�b�N�X���擾
Graphics g = this.pictureBox1.CreateGraphics();
g.Clear(Color.Black);//��ʂ����F�ɃN���A
//�����ԊO�����P�‚ł�����������
if (ws.IRState.IRSensors[0].Found)
{
//��F�Ń}�[�J0��`��
g.FillEllipse(Brushes.Red,
ws.IRState.IRSensors[0].Position.X * 256 ,
ws.IRState.IRSensors[0].Position.Y * 128 , 5, 5);
//��F�Ń}�[�J1��`��
g.FillEllipse(Brushes.Blue,
ws.IRState.IRSensors[1].Position.X * 256,
ws.IRState.IRSensors[1].Position.Y * 128, 5, 5);
}
g.Dispose();//�O���t�B�b�N�X�̉��
label1.Text = "IR[0] " + ws.IRState.IRSensors[0].RawPosition.ToString()
+ "\nIR[1] " + ws.IRState.IRSensors[1].RawPosition.ToString();
}
#endregion
�Ԃ��A2�‚̃|�C���^�������߂ɕ\�����Ă��܂��B�t�H�[����label1�ɕ\�������e�L�X�g��A���W�̕����Ȃ�u�������v�ɂ‚���A���D�݂ʼn��ǂ��Ă��������Ă��܂��܂���A�Ō��u�����v�Ƃ��đ��g������\��ł��B���̃X�e�b�v�ł͂��܂�C�ɂ����A���i�݂܂��傤�B
���̓}�E�X�|�C���^�[��ԊO���œ�������悤�ɂ��܂��B�܂��A�������R�[�h�̒���A����uScreenSize�v��lj����܂��傤�B
Wiimote wm = new Wiimote(); //Wiimote�N���X���� System.Drawing.Point ScreenSize; //|��ʃT�C�Y���i�[ Boolean isConnected = false; //WiiRemote���ڑ����ꂽ��
����A����uIR_Cursor�v���������܂��B�����ԊO���̈ʒu�ɂ��킹��A�}�E�X�|�C���^���ړ�������R�[�h�ł��B
#region �ԊO���Ń}�E�X�J�[�\���ړ�
public void IR_Cursor(WiimoteState ws)
{
ScreenSize.X = Screen.PrimaryScreen.Bounds.Width; //��ʃT�C�Y����
ScreenSize.Y = Screen.PrimaryScreen.Bounds.Height; //��ʃT�C�Y�c��
//�����ԊO����1�”���������
if (ws.IRState.IRSensors[0].Found) {
//�ԊO�����W(0.0�`1.0)����ʃT�C�Y�Ɗ|�����킹��
int px = (int)(ws.IRState.IRSensors[0].Position.X * ScreenSize.X);
int py = (int)(ws.IRState.IRSensors[0].Position.Y * ScreenSize.Y);
//X���W�𔽓]������
px = ScreenSize.X - px;
//�}�E�X�J�[�\�����w��ʒu�ֈړ�
System.Windows.Forms.Cursor.Position = new System.Drawing.Point(px, py);
}
}
#endregion
�擾�����ԊO���}�[�J�[��1�–ڂ�X,Y���W���}�E�X�J�[�\���̈ʒu��ݒ肵�Ă��܂��BSystem.Drawing�ɗp�ӂ���Ă���2�����̓_�������^Point(px,py)���‚�����A�}�E�X�J�[�\���ʒu���X���邽��System.Windows.Cursor.Poition�ɑ�����Ă��܂��B
�����������Ă݂܂��傤�BWiiRemote��Bluetooth�ڑ����A�Z���T�[�o�[�Ȃǂ�ԊO���������������Ă���[F5]�L�[�������ăf�o�b�O�J�n���܂��B�\�����ꂽ�t�H�[����u�ڑ��v�{�^���������A���Ȃ��ڑ����ꂽ��AWiiRemote��ԊO�������Ɍ����Ă��������B
���Ȃ��Ƃ�1�_�ł��ԊO�������o�����ƃt�H�[������Ԃ��}�[�J�[���\������AWindows�̃}�E�X�J�[�\������̓����ɂ����Ĉړ����܂��B�ԊO�������o���Ă���Ԃ�APC��ڑ�����Ă���}�E�X��G���Ă��v���ʂ�ɓ��������Ƃ͂ł��܂���B
�Ȃ��A���s���Ƀ}�E�X�J�[�\�����o�^�o�^�������A�ԊO���Z���T�[�̋��x�Ɍ�������s����Ȍ��o�ɂ����̂ł��BWiiRemote�ƃZ���T�[�o�[�Ƃ̋�����2m���x�܂ŗ����Ă݂Ă��������B
�I���������A�ԊO�������o���Ȃ��悤�ɂ���(�Z���T�[���������ɂ��ė��Ă�Ƃ������ł�)��A�}�E�X����䂪�߂�܂��̂�B�u�ؒf�v�{�^���������Ă���I�������Ă��������B�}�E�X�J�[�\���ɗ��炸�A[TAB]�L�[��񉟂��A[Enter]�L�[��u�ؒf�v����͂��鎖�ł��A�ȒP��I�����邱�Ƃ��ł��܂��B
���̓{�^���C�x���g�ł��B��قǂ͋���ۂɂ��Ă����{�^���C�x���g����������_�~�[����uEvents()�v���������Ă����܂��傤�B
�{�^���C�x���g�ƊȒP�Ɍ����Ă��AWiiRemote�̃{�^���͂������ñ‚ ‚�܂��B�܂���ʓI�ȃf�W�^���M���ɂ��{�^���ɂ͈ȉ��Ì�u3�‚Ì��Ô�v������Ƃ����܂��B
�yDOWN�z�c�}�E�X�̃{�^�������������B
�yHOLD�z�c�}�E�X�̃{�^�����������ςȂ��ɂ��Ă�����B
�yUP�z�c�}�E�X�̃{�^���𗣂������B
����������ł������������Ȃ���A�_�u���N���b�N�Ȃǂ����o����͓̂���Ȃ�܂��B
�܂��͗��K�Ƃ���AA�{�^���ɑ΂���A�ȉ��̓�������蓖�ĂĂ݂܂��傤�B
�EA�{�^������������(DOWN)�A�}�E�X�Ì���N���b�N�ð”�s���܂��B
�EA�{�^����������������(HOLD)�A�}�E�X�̉E�N���b�N�ð”�s���܂��B
�EA�{�^������������(UP)�A�}�E�X�{�^���������Ă��Ȃ���Ԃɂ��܂��B
�u������(HOLD)�v��1�b�ԉ������ςȂ��ɂ��邱��A�Ƃ��Ă����܂��傤�B
�܂��͊m���ɒ������C�x���g���E����悤��A���b�Z�[�W�{�b�N�X���g���Ċm�F���܂��B
�������������ɒlj���
//�{�^���C�x���g�J���p
bool isDown;
int StartTime, PressTime = 1000;
string State = "";
��������
#region �{�^���C�x���g�J���p
public void Events(WiimoteState ws) {
if(ws.ButtonState.A) {
if (isDown == false) {
//���������߂ă{�^���������ꂽ�Ƃ�
StartTime = System.Environment.TickCount; //�����ꂽ���Ԃ��L�^
State = "DOWN"; isDown = true;
} else {
//������Ă��鎞�Ԃ�PressTime��蒷�����HOLD
if ((System.Environment.TickCount - StartTime) >= PressTime) {
State = "HOLD"; //�����ꑱ���Ă���
//���b�Z�[�W�{�b�N�X��\��
MessageBox.Show(State);
}
}
} else {
if (isDown == true) { //�{�^���������ꂽ
State = "UP"; isDown = false;
}
}
}
#endregion
���̒i�K�Ńe�X�g�����Ă݂܂��傤�B�v���O�������N������ڑ����A[A]�{�^�����������ςȂ��ɂ���1�b�܂‚�A�uHOLD�v�����ꂽ���b�Z�[�W�{�b�N�X���\������܂��B
MessageBox.Show()�ŗ��p�ł��éƒ��b�Z�[�W�{�b�N�X�͂��̎�̃f�o�b�O��J���ɔ��ɖ��ɗ����܂��B�����ł͂����m�F���I���܂����̂Å�A���Ì�s�̓R�����g�A�E�g�������Í�í�œï¿½ï¿½ï¿½Ä‚ï¿½ï¿½Ü‚ï¿½ï¿½Ä–ï¿½è‚ ï¿½ï¿½Ü‚ï¿½ï¿½ï¿½B
�@�v���O�����̓�����m���߂邽�߂�A�f�o�b�O���K�v�ɂȂ邱�Ƃ�����܂��BVisual Studio�̕W���@�\�ł�[F9]���������ƂŃu���[�N�|�C���g��}�����邱�Ƃ��ł��܂��B�������v���O�������~�߂�܂ł��Ȃ��A������Ƃ����l���������Ƃ��Ȃǂ�����܂��B
�@System.Windows.Forms.MessageBox.Show()�ȊO�̃e�L�X�g�\���̕��@�Ƃ���AC#�ł�uConsole.WriteLine�v���g���ă��b�Z�[�W���o�͂��邱�Ƃ��ł��܂��B����o�͌��ʂ�Visual Studio��̕W���o��u�\��(V)���o��(O)�v�Ō��邱�Ƃ��ł��܂��B(�Ȃ����l�̊����C++�ɂ�����܂����A�Ȃ���Visual C++���o�̓E�B���h�E�����Ă��o�͂���Ȃ��悤�ł��c)�B
�@���̂悤�Ȃ�����Ƃ����e�N�j�b�N�͒m���Ă���ƕ֗��ł��B���������s���̓p�t�H�[�}���X�ቺ���Y���������̂�A��I�I�ȃo�[�W�����ł͖Y�ꂸ�ɃR�����g�A�E�g���Ă������A�u#if DEBUG�`#endif�v�f�B���N�e�B�u���g�����ƂŃf�o�b�O�ł����R�[�h�����������Ƃ��ł��܂��B
�@���̂悤�ȃf�o�b�O�e�N�j�b�N��A�C���^���N�V���������コ����ׂ̂��܂߂ȃ`���[�j���O�ɔ��ɖ��ɗ����܂��B
�����Ä�AWiiRemote�̃{�^���_�E���ɂ��킹�Ä�A�}�E�X�{�^���̃C�x���g�ð”�s���܂��B�v���O�����������Ȃ��Ă��܂��܂��̂Å�A���ꂩ��{�^���C�x���g�̌��o��ʂ�.cs�t�@�C���̕ʃN���X�ɈÚ�A���܂��B
�܂�Visual Studio��u�v���W�F�N�g�v����u�V�������ڂ̒lj��v(Ctrl+Shift+A)���s���܂��B
�u�e���v���[�g�v��u�N���X�v��I�уt�@�C�������uButtonEvents.cs�v�Ƃ���u�lj��v�������܂��B�v���W�F�N�g�G�N�X�v���[���[��uButtonEvents.cs�v���lj�����A�ȉ��̂悤������R�[�h���\�������͂��ł��B
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WiiRemoteMouse
{
class ButtonEvents
{
}
}
���̂܂܂ł͉��������܂���̂�A���܂܂ŃR�[�f�B���O�̒��S�ɂȂ��Ă����uForm1.cs�v����Events()����̃R�[�h�ƕ������A���܂��B�u#region�v���Y�ꂸ�ɋL�q���Ă����܂��傤�B
using WiimoteLib;
namespace WiiRemoteMouse
{
class ButtonEvents {
bool isDown;
int StartTime, PressTime = 1000;
string State = "";
#region �{�^���C�x���g����
public void Events(WiimoteState ws) {
if (ws.ButtonState.A) {
if (isDown == false) {
//���������߂ă{�^���������ꂽ�Ƃ�
StartTime = System.Environment.TickCount; //�����ꂽ���Ԃ��L�^
State = "DOWN"; isDown = true;
} else {
//������Ă��鎞�Ԃ�PressTime��蒷�����HOLD
if ((System.Environment.TickCount - StartTime) >= PressTime) {
State = "HOLD"; //�����ꑱ���Ă���
//���b�Z�[�W�{�b�N�X��\��(�m�F�p)
System.Windows.Forms.MessageBox.Show(State);
}
}
} else {
if (isDown == true) { //�{�^���������ꂽ
State = "UP"; isDown = false;
}
}
}
#endregion
}
}
��A�����R�[�h��Form1.cs������A�������̓R�����g�A�E�g���܂��B
���O����
namespace WiiRemoteMouse {
public partial class Form1 : Form {
Wiimote wm = new Wiimote(); //Wiimote�N���X����
ButtonEvents wbe = new ButtonEvents(); //�{�^���C�x���g�N���X����
���ȉ��������������Ă��܂��܂���
/*
//�{�^���C�x���g�J���p
bool isDown;
int StartTime, PressTime = 1000;
string State = "";
*/
�������Ŋ�����̑O�ɃN���X���uwbe.�v��lj����܂���
wbe.Events(ws); //�{�^���C�x���g����
���ȉ�����
���̒i�K�ł��Ȃ炸���쎎�����s���Ă��������B�{�^���𒷉��������A���b�Z�[�W�{�b�N�X���\�������͂��ł��B���Ȃ������̃N���X���܂�����v���O�����ɂȂ��Ă��������ł��B
�uButtonEvents wbe = new ButtonEvents();�v�ɂ����wbe�Ƃ����N���X��V�K�����A�uwbe.Events(ws);�v���{�^���C�x���g������Ƃ��ČĂ�ł��܂��B
�����A�{�^���C�x���g������ʂ̃N���X���L�q���ꂽ�\�[�X�R�[�h�uButtonEvents.cs�v�ɕ����邱�Ƃ�������܂����B���܂܂ł͑S��Form1.cs��Form1�N���X�ɋL�q���Ă����̂ł����A�v���O����������ɂȂ����Ƃ���A�����̃v���O���}�ɂ��`�[���ŊJ������Ƃ��ɂ�A�K�؂ȃ^�C�~���O�ŃN���X��t�@�C�����킯�邱�Ƃ��d�v�ł��B
����WiIRemote�̃{�^���������ꂽ�Ƃ��É�A�}�E�X�{�^���̃N���b�N�C�x���g�����s�����ׂ��p�[�g�̃R�[�h�������Ă����܂��B���Ì�u�}�E�X�{�^���C�x���g�̔��s�v�͒P�Ƀ}�E�X�J�[�\���𓮂����Ƃ��ƈقȂè��X���G�ɂȂ�܂��B�܂�.NET Framework3.5�ł̓}�E�X�J�[�\���̈ʒu�͕Ï�X�ł��Ă��A�N���b�N����C�x���g�ð”�s�ł���API���p�ӂ���Ă��Ȃ��悤�ł��B�����ŋ������瑶�݂���Win32�v���b�g�t�H�[��SDK��Windows���[�U�[�C���^�[�t�F�[�X�T�[�r�X�uuser32.dll�v�Ƃ���DLL�Ɋ܂܂��uSendInput()�v�Ƃ���API��SendInput()�̂��߂Ì�\���̂���è�žï¿½Þ‚��ƂÅ�A���̋@�\���������܂��B
DLL�C���|�[�g��\���̂�A������x�`���ɉ������L�q���K�v�ł��B�����ł�uSendInput()�v�Ƃ���API�������A���̊���̈����ƂȂ�\����uINPUT�v��INPUT�����p����}�E�X�C�x���g���ׂ��L�q����\����uMOUSEINPUT�v������݂܂��B
using WiimoteLib;
//DllImport�ɕK�v��using��lj�
using System;
using System.Runtime.InteropServices;
namespace WiiRemoteMouse
{
class ButtonEvents {
bool isDown;
int StartTime, PressTime = 1000;
string State = "";
#region DLL�C���|�[�g
[DllImport("user32.dll")] //DLL�ǂ����
extern static uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize);
[StructLayout(LayoutKind.Sequential)]
struct INPUT {
public int type;
public MOUSEINPUT mi;
}
[StructLayout(LayoutKind.Sequential)]
struct MOUSEINPUT {
public int dx;
public int dy;
public int mouseData;
public int dwFlags;
public int time;
public IntPtr dwExtraInfo;
}
#endregion
���ȉ�����
���Ì�\���̂�Win32(C++)�̃w�b�_�t�@�C���ł���uWinUser.h�v�ɋL�q����Ă�����̂ł��B�����ʓ|�ł����A���Ì�\���̂̒�`�����낻���ɂ���Æ�ASendInput�������������Ă���܂���BC#�Ń}�E�X�Ɋ�]�̃C�x���g�ð”�s����Ƃ��Í�A�ȉ��̂悤�ɂ��ăC�x���g�ð‘—�M���܂��B
input[0].mi.dwFlags = 0x0002; //���}�E�X�_�E�� SendInput(1, input, Marshal.SizeOf(input[0])); //�}�E�X�C�x���g��M
�uMarshal�v�̓A���}�l�[�W�R�[�h�̃��������蓖�Ă̂��߂Ȃǂɗp�ӂ��ꂽ�N���X�ł��BDLL��\���̂̃C���|�[�g�͋L�q�����ԈႦ�Ȃ���Γ��ɋC�����K�v�͂���܂���A���̂܂܉��ɑ����A�{�^���C�x���g�̎������s���܂��傤�B
���R�����g�̓���u|�v���‚��Ă��������V�K�lj������ł���
#region �{�^���C�x���g����
public void Events(WiimoteState ws) {
INPUT[] input = new INPUT[1]; //|�}�E�X�C�x���g���i�[
if (ws.ButtonState.A) {
if (isDown == false) {
//���������߂ă{�^���������ꂽ�Ƃ�
StartTime = System.Environment.TickCount; //�����ꂽ���Ԃ��L�^
State = "DOWN"; isDown = true;
input[0].mi.dwFlags = 0x0002; //|���}�E�X�_�E��
SendInput(1, input, Marshal.SizeOf(input[0])); //|�}�E�X�C�x���g��M
} else {
//������Ă��鎞�Ԃ�PressTime��蒷�����HOLD���E�N���b�N
if ((System.Environment.TickCount - StartTime) >= PressTime) {
State = "HOLD"; //�����ꑱ���Ă���
input[0].mi.dwFlags = 0x0008; //|�E�}�E�X�_�E��
SendInput(1, input, Marshal.SizeOf(input[0])); //|�}�E�X�C�x���g��M
}
}
} else {
if (isDown == true) { //�{�^���������ꂽ
State = "UP"; isDown = false;
input[0].mi.dwFlags = 0x0004; //|���}�E�X�A�b�v
SendInput(1, input, Marshal.SizeOf(input[0])); //|�}�E�X�C�x���g��M
input[0].mi.dwFlags = 0x0010; //|�E�}�E�X�A�b�v
SendInput(1, input, Marshal.SizeOf(input[0])); //|�}�E�X�C�x���g��M
}
}
}
#endregion
}
}
�e�C�x���g�ɑ΂��Ä�uinput[0].mi.dwFlags = 0x0004�v�Ƃ��邱�ƂŃ{�^���̉�����Ă����Ԃð”�s���邱�Ƃ��ł��܂��B���Ì�u0x0002�v��u0x0004�v�Ƃ���16�i���\���̃t���O(dwFlags)�̓v���b�g�t�H�[��SDK�Œ�߂��Ă���è�”�Å�A�uWinUser.h�v�Ŋm�F���邱�Ƃ��ł��܂��B���ɂ��E�N���b�N��z�C�[���Ȃǂ̃f�[�^�����邱�Ƃ��ł��܂��B
| ���� | �Ӗ� | �l |
|---|---|---|
| MOUSEEVENTF_MOVE | �}�E�X���ړ� | 0x0001 |
| MOUSEEVENTF_LEFTDOWN | ���{�^���������ꂽ | 0x0002 |
| MOUSEEVENTF_LEFTUP | ���{�^���������ꂽ | 0x0004 |
| MOUSEEVENTF_RIGHTDOWN | �E�{�^���������ꂽ | 0x0008 |
| MOUSEEVENTF_RIGHTUP | �E�{�^���������ꂽ | 0x0010 |
| MOUSEEVENTF_MIDDLEDOWN | �����{�^���������ꂽ | 0x0020 |
| MOUSEEVENTF_MIDDLEUP | �����{�^���������ꂽ | 0x0040 |
| MOUSEEVENTF_WHEEL | �z�C�[������] | 0x0800 |
������API��\���̂̃t�H�[�}�b�g��A�}�C�N���\�t�g�̃h�L�������g��SDK�Ɋ܂܂��w�b�_�t�@�C���ŗ^�����Ă��܂��B�܂��ߋ����X�Ɨ��j������AC++�ɂ��Win32�v���b�g�t�H�[������������l�̃z�[���y�[�W�Ɍf�ڂ��ꂽ�T���v���Ȃǂ����Ȃ���ɗ����܂��BC#�̃R�[�f�B���O�����Ă��邩��Ƃ�����u���������C++�̃T���v�����A���ɂ͊֌W�Ȃ��c�v�Ǝv���K�v�͂Ȃ��̂ł��I
.NET�����C#�v���O���}�ɂƂ��ăA���}�l�[�W�R�[�h�̎���݂͖��m�̋��|�����邩������܂���A����Ă��܂��Ε֗��Ȃ��̂ł��B����̂悤��SendInput�̓A���}�l�[�W�h�Ȏ����𗊂�Ȃ��Ă��A�����I��.NET Framework�Ɏ���܂�A�C�y�Ɏg����悤�ɂȂ邱�Ƃ�]�݂܂����c�B
��SendInput���
�@http://msdn.microsoft.com/ja-jp/library/cc411004.aspx
��mouse_event���
�@http://msdn.microsoft.com/ja-jp/library/cc410921.aspx
����Ŋ�{�@�\�͂قڊ����ł��B�����������s���Ă݂܂��傤�B�v���O�������N������WiiRemote��Bluetooth�ڑ����u�ڑ��v�Ƃ����A���E�ɓ������ԊO���ɂ���ă}�E�X�J�[�\���𓮂�����悤�ɂȂ�܂��B
[A]�{�^���������ƃ}�E�X����N���b�N�A1�b�Ԓ���������ƉE�N���b�N�ɂȂ�܂��B�{�^�������𗣂���A���E�����̃}�E�X�{�^���𗣂������(Up)�ɂȂ�܂��B
����A�����z�肵�Ă����S�Ă̋@�\�̎������I���܂����B
�����AGlovePIE�Ŏ��������悤��A�S�Ẵ{�^���ɑ�R�̃A�N�V���������蓖�ĂĂ��������Ƃ���ł����A���������͂ǂ�ǂ�WiiRemote�Ƃ͒��ڊ֌W�Ȃ��b�ɂȂ��Ă��܂��܂��̂œK�x�ɉ���������Ǝv���܂��B
�{�^���A�N�V�����̊J���ɂ‚��Ă�A�Ⴆ��A�}�E�X�E�{�^���͒����������łȂ��A[B]�ɂ����蓖�Ă��肵�����Ƃ���ł��B������A
if (ws.ButtonState.B) {
input[0].mi.dwFlags = 0x0008; //|�E�}�E�X�_�E��
SendInput(1, input, Marshal.SizeOf(input[0])); //|�}�E�X�C�x���g��M
} else {
input[0].mi.dwFlags = 0x0010; //|�E�}�E�X�A�b�v
SendInput(1, input, Marshal.SizeOf(input[0])); //|�}�E�X�C�x���g��M
}
���������������Ηǂ��킯�ł��B���������̂悤�Ɍ�X�̃{�^���C�x���g�ɂ‚���if���Ŏ������Ă����Ă��ǂ��̂ł����A[A+B]�Ȃǂ̃{�^���R���r�l�[�V�����A�N�V�����Ȃǂ�������A����ɕ��G�ɂȂ��Ă����܂�(�o�O�������܂�)�B�����������̕������N���X�������̂�A���܂��ė��p�ł�����@���l�������Ƃ���ł��B
�{���̒��҂̂ЂƂ�ł��������A��قǎ�������State�̂悤�ȕ�������g������u������Ă���L�[�𕶎���Ƃ��Ĉ����v�Ƃ����A�C�f�B�A��A�ȉ��̂悤�ȕ��@��V�����N���X��݌v���Ă݂܂����B���ꂪ�������ǂ�������ɂ�肯��ł����A�Q�l�ɂ͂Ȃ�ł��傤(�����i����⌤������HP����_�E�����[�h�ł��܂���)�B
�܂����݂̃C�x���g�N���X��uButtonEvent�v�Ƃ����N���X��lj����܂��B
public ButtonEvent(String buttonName) {
this.isDown = false; //�����l��false
this.State = ""; //�����l��""
this.onButtonTime = 1000; //����������
this.Flg = false; //�����l��false
this.ButtonName = buttonName; //�{�^���̖��O���擾
}
�܂��A��X�̃{�^����A���̂悤�ɃL�[�ƂȂ镶�����ݒ肳��Ă���Ƃ��܂��B
A�{�^�� �@�� A Home�{�^���� Home
B�{�^�� �@�� B ���{�^���@�� Up
1�{�^�� �@�� One ���{�^���@�� Down
2�{�^�� �@�� Two ���{�^���@�� Left
-�{�^�� �@�� Minus ���{�^���@�� Right
+�{�^�� �@�� Plus
�Ⴆ��[A]�{�^������A�uA�v�Ƃ�����������g����ButtonEvent�N���X��new����AButtonA�Ƃ����N���X�I�u�W�F�N�g�������邱�Ƃ��ł��܂��B���̕��@��A�e�X�̃{�^���ɂ‚��ăC�x���g���Ǘ�����N���X�Q���ł�������܂��B
public ButtonEvent ButtonA = new ButtonEvent("A");
public ButtonEvent ButtonB = new ButtonEvent("B");
public ButtonEvent ButtonUP = new ButtonEvent("Up");
public ButtonEvent ButtonDOWN = new ButtonEvent("Down")
��...�ȉ����ׂẴ{�^���ɂ‚���new���܂���
�����ButtonEvent�N���X��uGetOnButton(WiimoteState ws)�v�Ƃ���String��Ԃ����\�b�h��p�ӂ��A�����ꂽ�{�^���̃e�L�X�g��Ԃ��܂��B�ȉ��̂悤�ɃR�[�f�B���O���邱�Ƃ��ł��܂��B
public String GetOnButton(WiimoteState ws) {
//A�������ꂽ ���@" A"
//B�������ꂽ ���@" B"
//A,B�������ꂽ ���@" A B"
//A,B,1,2�������ꂽ ���@" A B One Two"
String onButtons = "";
if (ws.ButtonState.A) { onButtons += " A"; }
if (ws.ButtonState.B) { onButtons += " B"; }
if (ws.ButtonState.One) { onButtons += " One"; }
���ȉ��S�Ẵ{�^����
return onButtons; //�����ꂽ�{�^��onButtons��Ԃ�
}
���̊����
if (this.ButtonName.Equals(this.GetOnButton(ws).Trim()))
�Ǝg�����Ƃ�A������Ă���{�^�������ڂ������{�^���ł���ButtonName�Ɠ������ǂ������ׂ鎖���ł��܂��B�Ȃ��O��̃X�y�[�X���������Ă�����\�b�hTrim()��Equals()��AString�^���p�����Ă���̂�A�lj������Ȃ��ŗ��p�ł��܂��B
������AEvents����̒���
switch (ButtonA.onButton(ws))
�Ƃ��Aswitch����p����A�{�^����������ꂼ���"Down"�A"Up"�A"Hold"����ɑΉ����閽�߂������Ă��܂��B
�}�E�X�����������A���x�̓L�[�{�[�h�������������Ȃ�Ǝv���܂��B.NET�ɂ͕֗���API�uSendKeys.SendWait()�v�Ƃ������������A����͔��s�������L�[�{�[�h���͂𕶎���ŕ\�����邱�ƂŎ����ł��܂��B�Ⴆ��uAlt+F4�v�̂悤�ȕ����̃L�[�����������L�[�o�C���h�����s�ł��܂��B
SendKeys.SendWait("%{F4}");
�J�[�\���L�[��Ctrl�L�[�ȂǂقƂ�ǂ̃{�^���R���r�l�[�V�����͂��̕��@����o�����Ƃ��ł��܂��B��ׂ�SendKeys�𒲂ׂĂ݂Ă��������B
�܂��u���̃c�[���̕\�����B�������v�Ƃ����v��������Ǝv���܂��B����ȂƂ���A�ȉ��̃R�[���ł��̃v���O�������v���O�������g�����������邱�Ƃ��ł��܂��B
this.WindowState = FormWindowState.Minimized;
���̂悤��.NET�̋@�\���t�����p���AWiiRemote�̃C�x���g�ɑ΂��ă}�E�X�ƃL�[�{�[�h�̓��͂����蓖�Ă���A����u�����`���[�v�Ŋw�񂾃A�v���P�[�V�����̎��s�Ȃǂ�g����킹����A���ɂ͊O����API�����p���Ȃ��玩����D���ȋ@�\������A�u�����̂��߂�WiiRemoteMouse�v������Ă݂Ă��������B
�Ō��LED�o�͂�18:57 2009/06/12��
LED�̕\���������������܂��B�C���[�W�Ƃ��Ă�LED�ɂ̓o�b�e���[�̎c�ʂ��o25%�ȉ��A50%�A75%�A75%���p�Ƃ�����4�i�K�ŕ\���������̂�SetLEDs()����𗘗p����A
wm.SetLEDs(1); //��������
wm.SetLEDs(3); //��������
wm.SetLEDs(7); //��������
wm.SetLEDs(15); //��������
���̂悤�ɕ\�����Ă������Ƃ��ł���ł��傤�B
�������uswitch�`case�v�����g���Ă����\����������A������1�s�ɂ܂Ƃ߂���@������܂��̂�A�����1�s����������Ŏ������Ă݂܂��B
#region LED�E����
public void EffectsOut(WiimoteState ws) {
//25%����LED��\��������
wm.SetLEDs((int)Math.Pow(2.0f, (int)(ws.Battery / 25) +1 ) - 1);
}
#endregion
������1�s�̎��ł����A�ȉ��̂悤�ȈӖ��������Ă��܂��B
�o�b�e���[�̒l��[0��Battery��100]��float�^�Ŏ�ɓ���܂��̂�A�����25�Ŋ�����A������(�����_�ȉ���؂藎�Ƃ�)���܂��B����ƃo�b�e���[�̎c�ʂɉ�����u0,1,2,3�v�Ƃ��������ɂȂ�܂��Bn�����R��(1,2,3,...)�Ƃ���Ƃ��A2�ׂ̂���[2^n]��u2,4,8,16,...�v�Ƃ����l���Ƃ�܂��̂�A������-1���Ă����邱�Ƃ�A�K�v��u1,3,7,15�v�Ƃ���4�‚�LED�o�͗p������𓾂邱�Ƃ��ł��܂��B
���̂悤�ɖ@������������͉̂”\�Ȍ������A�‚܂����ŕ\���ł���悤�ɂ���N�Z���‚����A�R�[�f�B���O�������قǒZ���Ȃ�܂��̂�A�f�o�b�O����Ƃ��������Ƃ�������܂��B�����w�Z�Ŋw����w�����ɖ��ɗ����܂��B�u���w�v�Ƃ��������u�Z���p�Y���v�̂悤�Ȃ��̂Ȃ̂�A�������Ċ��������̂ł͂Ȃ��w�y����ʼn����Ă݂悤�I�x�Ƃ����Ƃ���ł��傤���B
using System;
using System.Drawing;
using System.Windows.Forms;
using WiimoteLib;
namespace WiiRemoteMouse {
public partial class Form1 : Form {
Wiimote wm = new Wiimote(); //Wiimote��錾�������
WiiButtonEvents wbe = new WiiButtonEvents(); //WiiRemote�̃{�^���C�x���g��錾�������
System.Drawing.Point ScreenSize; �@ //��ʃT�C�Y���i�[
int size = 20;
Boolean isConnect = false; //Wii���ڑ����ꂽ��
public Form1() {
InitializeComponent();
Control.CheckForIllegalCrossThreadCalls = false; //���X���b�h����̃R���g���[���Ă�o������
this.ScreenSize.X = Screen.PrimaryScreen.Bounds.Width; //��ʃU�C�Y�̉������擾
this.ScreenSize.Y = Screen.PrimaryScreen.Bounds.Height; //��ʃU�C�Y�̗������擾
this.button2.Enabled = false; //�ؒf�{�^���𖳌���
}
#region �ڑ�/�ؒf
//�ڑ��{�^�����N���b�N���ꂽ
private void button1_Click(object sender, EventArgs e) {
if (this.isConnect == false) {
this.wm = new Wiimote(); //Wiimote�������
this.wm.Connect(); //Wiimote��ڑ�
this.wm.SetReportType(InputReport.IRExtensionAccel, true); //���|�[�g�^�C�v��ݒ�
this.wm.SetLEDs(0); //LED������
this.wm.SetRumble(false); //�o�C�u���[�^�X�g�b�v
this.isConnect = true; //�ڑ���Ԃ�true
this.button1.Enabled = false; //�ڑ��{�^���𖳌�
this.button2.Enabled = true;�@ //�ؒf�{�^����L��
this.wm.WiimoteChanged += wm_WiimoteChanged; //�C�x���g����̓o�^
}
}
//�ؒf�{�^�����N���b�N���ꂽ
private void button2_Click(object sender, EventArgs e) {
if (this.isConnect == true) {
this.button1.Enabled = true; //�ڑ�1��L��
this.button2.Enabled = false; //�ؒf2�𖳌�
this.isConnect = false; //�ڑ���Ԃ�false
}
}
#endregion
//WiiRemote���Ԃ��ω������Ƃ��ɌĂ΂����
public void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs args) \
{
if (isConnect == true) {
WiimoteState ws = args.WiimoteState;//WiimoteState �̒l���擾
IR_Cursor(ws); //�ԊO���Ń}�E�X�J�[�\���ړ�
wbe.Events(ws); //WiiButtonEvents(ws)�ʼn����ꂽ�{�^���ɑ΂��������s��
DrawForms(ws); //�t�H�[���X�V
EffectsOut(ws); //LED,�o�C�u���[�^�[�o��
} else {
this.wm.SetLEDs(0); //LED������
this.wm.SetRumble(false); //�o�C�u���[�^�X�g�b�v
this.wm.Disconnect(); //Wii�ؒf
this.wm.Dispose();
}
}
#region IR_Cursor
//�ԊO���Ń}�E�X�J�[�\���ړ�
public void IR_Cursor(WiimoteState ws) {
//�����ԊO�����P�”���������
if (ws.IRState.IRSensors[0].Found) {
//�ԊO�����W(0.0?1.0)����ʃT�C�Y�Ɗ|�����킹��
int px = (int)(ws.IRState.IRSensors[0].Position.X * this.ScreenSize.X);
int py = (int)(ws.IRState.IRSensors[0].Position.Y * this.ScreenSize.Y);
//X���W�𔽓]������
px = this.ScreenSize.X - px;
//�}�E�X�J�[�\�����w��ʒu�ֈړ�
System.Windows.Forms.Cursor.Position = new System.Drawing.Point(px, py);
//�ԊO������ʂ̒[�ɂ����Ƃ�
if ((px <= size) || px >= (this.ScreenSize.X - size) || (py <= size) || py \
>= (this.ScreenSize.Y - size)) {
if (this.checkBox1.Checked) {
wm.SetRumble(true);//�o�C�u���[�V����ON
} else {
wm.SetRumble(false);//�o�C�u���[�V����OFF
}
} else {
wm.SetRumble(false);//�o�C�u���[�V����OFF
}
} else {
if (this.checkBox1.Checked) {
wm.SetRumble(true);//�o�C�u���[�V����ON
} else {
wm.SetRumble(false);//�o�C�u���[�V����OFF
}
}
}
#endregion
#region EffectsOut
//LED,�o�C�u���[�^�[�o��
public void EffectsOut(WiimoteState ws) {
//A�{�^����������Ă���Ԃ����\������B
//25%����LED��\��������
switch ((int)(this.wbe.Battery / 25)) {
case 0: //0-25
this.wm.SetLEDs(0);
break;
case 1: //25-50
this.wm.SetLEDs(1);
break;
case 2: //50-75
this.wm.SetLEDs(3);
break;
case 3: //75-100
this.wm.SetLEDs(7);
break;
case 4: //100
this.wm.SetLEDs(15);
break;
}
}
#endregion
#region DrawForms
//�t�H�[���`��X�V
public void DrawForms(WiimoteState ws) {
//�O���t�B�b�N�X���擾
Graphics g = this.pictureBox1.CreateGraphics();
g.Clear(Color.Black);//��ʂ����F�ɃN���A
//�����ԊO�����P�”���������
if (ws.IRState.IRSensors[0].Found) {
//��F�Ń}�[�J��`��
g.FillEllipse(Brushes.Red,
ws.IRState.IRSensors[0].Position.X * 256,
ws.IRState.IRSensors[0].Position.Y * 256, 10, 10);
}
g.Dispose();//�O���t�B�b�N�X�̉��
}
#endregion
private void Form1_FormClosed(object sender, FormClosedEventArgs e) {
//Windows��X�{�^����������Form���‚����Ƃ�
//Wii�����R����ؒf����
if (this.isConnect == true) {
this.isConnect = false; //�ڑ���Ԃ�false
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WiimoteLib;
using System.Runtime.InteropServices; //DllImport���g�����߂�錾
using Shell32; //�f�X�N�g�b�v�̕\���E�B����p����̂ɕK�v
namespace WiiRemoteMouse {
class ButtonEvent {
public Boolean isDown; //�{�^���������ꂽ
public String State; //�{�^������,��ނ��i�[�@
//DOWN �{�^���������ꂽ
//UP �{�^���������ꂽ
//DOWNING �{�^����������Ă���@onButtonTime���Ԃ𒴂����
public int onButtonTime; //����������
private int StartTime; //�{�^���������ꂽ�����Ԃ��i�[
public Boolean Flg; //�f�B�X�N�g�b�v�̃f�X�N�g�b�v�̕\���E�B����Ԃ��L�^����t���t
public String ButtonName; //�{�^���̖��O
public ButtonEvent(String buttonName) {
this.isDown = false; //�����l��false
this.State = ""; //�����l��""
this.onButtonTime = 1000; //����������
this.Flg = false; //�����l��false
this.ButtonName = buttonName; //�{�^���̖��O���擾
}
#region GetOnButton
public String GetOnButton(WiimoteState ws) {
//�����ꂽ�{�^���̃e�L�X�g��Ԃ��B
//A�������ꂽ ���@" A"
//B�������ꂽ ���@" B"
//A,B�������ꂽ ���@" A B"
//A,B,1,2�������ꂽ ���@" A B One Two"
String onButtons = "";
if (ws.ButtonState.A) { onButtons += " A"; }
if (ws.ButtonState.B) { onButtons += " B"; }
if (ws.ButtonState.One) { onButtons += " One"; }
if (ws.ButtonState.Two) { onButtons += " Two"; }
if (ws.ButtonState.Minus) { onButtons += " Minus"; }
if (ws.ButtonState.Plus) { onButtons += " Plus"; }
if (ws.ButtonState.Home) { onButtons += " Home"; }
if (ws.ButtonState.Down) { onButtons += " Down"; }
if (ws.ButtonState.Up) { onButtons += " Up"; }
if (ws.ButtonState.Left) { onButtons += " Left"; }
if (ws.ButtonState.Right) { onButtons += " Right"; }
return onButtons; //�����ꂽ�{�^����Ԃ�
}
#endregion
#region �{�^������
public String onButton(WiimoteState ws) {
//ws WiimoteState
if (this.ButtonName.Equals(this.GetOnButton(ws).Trim())) {
//������Ă���{�^����,ButtonName�𓯂����ǂ������ׂ�
//����̃X�y�[�X������Ă��璲�ׂ�
if (this.isDown == false) {
//���������߂ă{�^���������ꂽ�Ƃ�
this.StartTime = System.Environment.TickCount; //�����ꂽ���Ԃ��L�^
this.State = "DOWN"; //�_�E��
this.isDown = true; //Down���ꂽ
} else {
if ((System.Environment.TickCount - StartTime) >= onButtonTime) {
//������Ă��鎞�Ԃ�onButtonTime��뒷�����
this.State = "DOWNING"; //�����ꑱ���Ă���
}
}
} else {
if (this.isDown == true) {
//�{�^�����A�b�v���ꂽ
this.State = "UP"; //�A�b�v
this.isDown = false; //Up���ꂽ
}
}
return this.State;
}
#endregion
#region Clerar
//�������ς�
public void Clear() {
//�������I��������� State��""�ɖ߂�
this.State = "";
}
#endregion
}
class WiiButtonEvents {
#region DLL�֌W
//DLL�ǂ���ݗp
[DllImport("user32.dll")]
extern static uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize);
//DLL�ǂ���ݗp
[StructLayout(LayoutKind.Sequential)]
struct INPUT {
public int type;
public MOUSEINPUT mi;
}
//DLL�ǂ���ݗp
[StructLayout(LayoutKind.Sequential)]
struct MOUSEINPUT {
public int dx;
public int dy;
public int mouseData;
public int dwFlags;
public int time;
public IntPtr dwExtraInfo;
}
#endregion
public float Battery; //�o�b�e���[�l
public ButtonEvent ButtonAB = new ButtonEvent("A B");
public ButtonEvent ButtonA = new ButtonEvent("A");
public ButtonEvent ButtonB = new ButtonEvent("B");
public ButtonEvent ButtonUP = new ButtonEvent("Up");
public ButtonEvent ButtonDOWN = new ButtonEvent("Down");
public ButtonEvent ButtonLEFT = new ButtonEvent("Left");
public ButtonEvent ButtonRIGHT = new ButtonEvent("Right");
public ButtonEvent ButtonMINUS = new ButtonEvent("Minus");
public ButtonEvent ButtonHOME = new ButtonEvent("Home");
public ButtonEvent ButtonONE = new ButtonEvent("One");
public ButtonEvent ButtonTWO = new ButtonEvent("Two");
/*
������WiiRemote �����̓A�v���������
ok 1 �ԊO���ƃ{�^����ԃt�H�[���ɕ`��
ok 2 �ԊO��(X,Y) �}�E�X�|�C���^�̈ړ�
ok 3 A �{�^���}�E�X���{�^��
ok 3 B �{�^���}�E�X�E�{�^��
ok 4 �\���L�[�J�[�\���L�[
ok 4 ?�{�^���A�v���P�[�V�����I��[Alt+F4]
ok 4 Home �{�^���ؒf���ăv���O�����I��
NG 4 1 �{�^��GlovePIE ������^�ő剻
ok 4 2 �{�^���E�V���O���N���b�NEsc �L�[(�v���[���e�[�V�����I��)
ok 5 A+B �{�^�����������f�X�N�g�b�v��\��
NG 5 �{�{�^���A�v���P�[�V�����؂�ւ�[Alt+Tab]
OK 5 2 �{�^��������PowerPoint ���N��
NG 5 2 �{�^���E�_�u���N���b�N�v���[���e�[�V�����J�n[F5]
NG 5 A �{�^���E�_�u���N���b�NEnter �L�[
NG 5 B �{�^���E�_�u���N���b�NDelete �L�[
OK 6 �}�E�X�J�[�\������ʒ[�o�C�u���[�^�[
OK 6 (��L�{�^���u�������v) LED �Ɏc�莞�ԕ\��
74
*/
//�����ŃC�x���g��䂳����B
public void Events(WiimoteState ws) {
this.Battery = 0; //�o�b�e���[�l��0��
INPUT[] input = new INPUT[1]; //�}�E�X�C�x���g���i�[
/*�@�{�^�������̎g����
* �e�{�^���̓���ɂ���ē��������蓖�Ă邱�Ƃ��ł��܂��B
* ���Ƃ���u�}�E�X�̃N���b�N����v�Ƃ�������Ɋւ���A��ׂɌ��Ă݂��A
* �@���}�E�X�{�^����������
* �@���}�E�X�{�^������������
* �@���}�E�X�{�^���𗣂���
* �Ƃ����R�‚̓���ƂƂ炦�邱�Ƃ��ł��܂��B
*
* ����͂��̂R�‚̓���A
* �@���}�E�X�������� �� DOWN
* �@���}�E�X���������� �@ ��DOWNING
* �@���}�E�X�𗣂��� �� UP
*
* �ɑ΂���A����Ăق�����������蓖�Ă܂��B
*
* A�{�^���ɑ΂���A����͈ȉ��̓�������蓖�Ă܂��B
* ��A�{�^���}�E�X���{�^��
* ��A�{�^�������� LED �Ɏc�莞�ԕ\��
*
* �‚܂�A�ȉ��̓�������܂��B
*�@ A�{�^�����������Æ�A�}�E�X�Ì���N���b�N(Down)�ð”�s���܂��B
* �@A�{�^�����������Æ�A�}�E�X�Ì���N���b�N(UP)�ð”�s���܂��B
* �@A�{�^����������������A�o�b�e���[�̒l��LED�ɕ\�����܂��B
*
* �܂��A
* public ButtonEvent ButtonA = new ButtonEvent("A");
* �Å�AButtonA�Ƃ����{�^���C�x���g�N���X�����A�C�x���g�ð”������L�[������ݒ�܂��B
*
* �����A���}�̂悤�ɃL�[������ݒ肵�Ă��܂��B
* A�{�^�� �@�� A
* B�{�^�� �@�� B
* 1�{�^�� �@�� One
* 2�{�^�� �@�� Two
* -�{�^���@ �� Minus
* +�{�^���@ �� Plus
* Home�{�^���� Home
* ���{�^���@�� Up
* ���{�^���@�� Down
* ���{�^���@�� Left
* ���{�^���@�� Right
*
* ������AEvents����̒���
* switch (this.ButtonA.onButton(ws)) { //A�{�^��������@��Q������A���ׂ����{�^����String�^�œ����
*�@�Ƃ��Aswitch����p����"Down" "Up" "DOWING" ����ɑΉ����閽�߂������Ă��܂��B
*�@
*/
#region A�{�^������
switch (this.ButtonA.onButton(ws)) { //A�{�^��������@��Q������A���ׂ����{�^����String�^�œ����
case "DOWN": //A�{�^����Down�����Ƃ������
input[0].mi.dwFlags = 0x0002; //���}�E�X�_�E��
SendInput(1, input, Marshal.SizeOf(input[0])); //�}�E�X�C�x���g��M
this.ButtonA.Clear(); //�������ς�
break;
case "UP": //A�{�^����UP�����Ƃ������
input[0].mi.dwFlags = 0x0004; //���}�E�X�_�E��
SendInput(1, input, Marshal.SizeOf(input[0])); //�}�E�X�C�x���g��M
this.ButtonA.Clear(); //�������ς�
break;
case "DOWNING": //A�{�^�������������ꂽ�Ƃ������
this.Battery = ws.Battery; //�o�b�e���[�̒l���擾 ����������Ă���Ԃ���
break;
}
#endregion
#region B�{�^������
switch (this.ButtonB.onButton(ws)) {
case "DOWN": //B�{�^����Down�����Ƃ������
input[0].mi.dwFlags = 0x0008; //�E�}�E�X�_�E��
SendInput(1, input, Marshal.SizeOf(input[0])); //�}�E�X�C�x���g��M
this.ButtonB.Clear(); //�������ς�
break;
case "UP": //B�{�^����UP�����Ƃ������
input[0].mi.dwFlags = 0x00010; //�E�}�E�X�_�E��
SendInput(1, input, Marshal.SizeOf(input[0])); //�}�E�X�C�x���g��M
this.ButtonB.Clear(); //�������ς�
break;
}
#endregion
#region A,B�{�^������
switch (this.ButtonAB.onButton(ws)) {
case "DOWN": //AB�{�^����Down�����Ƃ������
Shell32.ShellClass shell = new Shell32.ShellClass();
if (this.ButtonAB.Flg) { //Flag��true�̎�
shell.UndoMinimizeALL(); //�f�X�N�g�b�v�̕\����߂�
this.ButtonAB.Flg = false;
} else {
//Flag��false�̎�
shell.MinimizeAll(); //�f�X�N�g�b�v�̕\��
this.ButtonAB.Flg = true;
}
this.ButtonAB.Clear(); //�������ς�
break;
}
#endregion
#region �J�[�\�� Up����
switch (this.ButtonUP.onButton(ws)) { \
//�J�[�\���{�^��������@��Q������A���ׂ����{�^����String�^�œ����
case "DOWN": //�{�^����Down�����Ƃ������
SendKeys.SendWait("{UP}"); //UP�L�[�ð”�s
this.ButtonUP.Clear(); //�������ς�
break;
}
#endregion
#region �J�[�\�� Down����
switch (this.ButtonDOWN.onButton(ws)) { \
//�J�[�\���{�^��������@��Q������A���ׂ����{�^����String�^�œ����
case "DOWN": //�{�^����Down�����Ƃ������
SendKeys.SendWait("{Down}"); //Down�L�[�ð”�s
this.ButtonDOWN.Clear(); //�������ς�
break;
}
#endregion
#region �J�[�\�� Left����
switch (this.ButtonLEFT.onButton(ws)) { \
//�J�[�\���{�^��������@��Q������A���ׂ����{�^����String�^�œ����
case "DOWN": //�{�^����DOWN�����Ƃ������
SendKeys.SendWait("{Left}"); //Left�L�[�ð”�s
this.ButtonLEFT.Clear(); //�������ς�
break;
}
#endregion
#region �J�[�\�� Right����
switch (this.ButtonRIGHT.onButton(ws)) { \
//�J�[�\���{�^��������@��Q������A���ׂ����{�^����String�^�œ����
case "DOWN": //�{�^����DOWN�����Ƃ������
SendKeys.SendWait("{Right}"); //��L�[�ð”�s
this.ButtonRIGHT.Clear(); //�������ς�
break;
}
#endregion
#region �{�^�� Minus����
switch (this.ButtonMINUS.onButton(ws)){ //�{�^��������@��Q������A���ׂ����{�^����String�^�œ����
case "DOWN": //�{�^����DOWN�����Ƃ������
SendKeys.SendWait("%{F4}"); //ALT + F4�L�[�ð”�s
this.ButtonMINUS.Clear(); //�������ς�
break;
}
#endregion
#region �{�^�� HOME����
switch (this.ButtonHOME.onButton(ws)) { //�{�^��������@��Q������A���ׂ����{�^����String�^�œ����
case "DOWN": //�{�^����DOWN�����Ƃ������
Environment.Exit(0); //�A�v���P�[�V������I��
this.ButtonHOME.Clear(); //�������ς�
break;
}
#endregion
#region �{�^�� TWO����
switch (this.ButtonTWO.onButton(ws)) { //�{�^����DOWN�����Ƃ������
case "DOWN": //�{�^����DOWN�����Ƃ������
SendKeys.SendWait("{ESC}"); //ESC�L�[�ð”�s
this.ButtonTWO.Clear(); //�������ς�
break;
case "DOWNING": //�{�^�������������ꂽ
//PowerPoint���N������
//�C���X�g�[������Ă���‹��ɂ����A���̃p�X�͈قȂ��Ă���
System.Diagnostics.Process.Start("C:\\ProgramData\\Microsoft\\Windows\\Start \
Menu\\Programs\\Microsoft Office\\Microsoft Office PowerPoint \
2007");�@//�p���[�|�C���g�̋N��
break;
}
#endregion
}
}
}
�@�C���^���N�e�B�u�Z�p���v���O����������Ƃ��A�Ⴆ�΃Q�[���J���⌤���J���ɂ����Ä�uï¿½Æ‚è‚ ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½Ô�v����A���̃`���[�j���O�����Ă�����ŊÖ�����A����������Î�u�o���I�ȃ��W�b�N�ð�”Šw���K���v���‚��邱�Ƃ͔��É�d�v�ł��B
�@�{���Ɍf�ڂ��Ă���v���O�����͎��ʂł��̂�A�ł��邾���f�ڂ���R�[�h��s���ɖ��ʂ������A���‚��悢�����̂��߂ɗ����ǂ��₷���f�ڂ���悤�ɂ��Ă��܂��B����͕M�҂����`���w��������s���Ă����u�}�C�R��BASIC�}�K�W���v(�d�g�V����)��l�������̗p���Ă��܂��B�����A�ǎ��ȃv���O�����̎�ȗ��ʕ��@��Web��d�q���[���ł͂Ȃ��u����v�ł����̂�w�����ɒZ���Ĕ������R�[�h���������x�Ƃ����A������l����Ƌ��낵���X�g�C�b�N�ȃR�[�f�B���O�X�^�C�������s���Ă����킯�ł��B������ABASIC�}�K�W���͌������ł����̂�A�K�x�Ȓ��؂�A��W���̖��ȃm�����A�i��������u�݂�Ȃ����Ă��������v�����o���Ă��܂����B
�@���̂悤��u�W���m�v�╶���c����������Ȍ������������u�W���m�ɂ��n���I�R�[�f�B���O�v�A�ŋ߂̗��s�ŕ\�������u�w�j�R�j�R����E�Z�p���x�����Ă݂��v�����Ȃ�߂����o�ł��傤���B�w�j�R���x�ł̃C���^���N�e�B�u�Z�p�Ɋւ����ڂ͔���������̂�����܂�(����Ȏ����m��Ȃ��̂��c�Ƌ������Ƃ������̂ł����I)�B
�@�����Ė{���̓ǎ҂��w�j�R�������x��v���ł��邱�Ƃ��傫���Ƃ������܂��B�F���������A�������i�⊈�����f��������A�O�ڂɂ��炵�Ă݂�Ƃ悢�ł��傤�B�u����www�I�v��܎^���ꂽ���Ƃ�A�����]���Č��J�����v���O�������u�����̃X�p�Q�e�B�E�R�[�h!!�v�ƃK�b�J������Ȃ��悤��A�ė��p���₷���A���l�̕׋��ɂȂ�R�[�f�B���O�X�^�C�����ɂ߂Ă݂Ă݂�̂��J�b�R�C�C�Ƃ������܂��B
����ԊO���Z���T�[���Ԃ��t�H�[����PictureBox�ɕ`��ł���悤�ɂ��܂��B���W��F�̂‚����ȉ~�ŕ\�����邾���Ȃ�A4�͂ł����ɒ��킵�܂����̂�A���̃p�[�g�ł�����i�߂�u�X����\���v�ł���悤�ɂ��܂��B����Wii�{�̂�u�w�|�C���^�v�ŕ\������Ă���悤��A��]��������悤�ɂȂ�킯�ł��B
#region �t�H�[���`����
public void DrawForms(WiimoteState ws)
{
//�O���t�B�b�N�X���擾
Graphics g = this.pictureBox1.CreateGraphics();
System.Drawing.Point pos = new System.Drawing.Point(0,0);
System.Drawing.Rectangle rect = new Rectangle(0,0,10,10);
Font drawFont = new Font("Arial", 9);
SolidBrush drawBrush = new SolidBrush(Color.White);
double radians, angle = 0.0f;
String drawString = "Text";
/*
String url="http://akihiko.shirai.as/projects/WiiRemote/web1016x546.jpg";
Image img;
using (System.Net.WebClient wc = new System.Net.WebClient())
using (System.IO.Stream st = wc.OpenRead(url))
{
img = Image.FromStream(st);
}
// img.Dispose();
*/
Bitmap targetBMP;
targetBMP = new Bitmap("c:\\WiiRemote\\yubi.png");
targetBMP.MakeTransparent(targetBMP.GetPixel(0, 0));
System.Drawing.PointF drawPoint = new System.Drawing.PointF(150.0F, \
150.0F);
g.Clear(Color.Black);//��ʂ����F�ɃN���A
//�����ԊO�����P�‚ł�����������
if (ws.IRState.IRSensors[0].Found)
{
//��F�Ń}�[�J0��`��
g.FillEllipse(Brushes.Red,
ws.IRState.IRSensors[0].Position.X * 256 ,
ws.IRState.IRSensors[0].Position.Y * 128 ,
ws.IRState.IRSensors[0].Size + 5,
ws.IRState.IRSensors[0].Size + 5);
//��F�Ń}�[�J1��`��
g.FillEllipse(Brushes.Blue,
ws.IRState.IRSensors[1].Position.X * 256,
ws.IRState.IRSensors[1].Position.Y * 128,
ws.IRState.IRSensors[1].Size + 5,
ws.IRState.IRSensors[1].Size + 5);
//�ԊO����2�Œ������炻�̒��Ԃ��Ƃ�
if (ws.IRState.IRSensors[1].Found ) {
pos.X = (int)(ws.IRState.IRSensors[0].Position.X * 256
+ ws.IRState.IRSensors[1].Position.X * 256 ) / 2;
pos.Y = (int)(ws.IRState.IRSensors[0].Position.Y * 128
+ ws.IRState.IRSensors[1].Position.Y * 128 ) / 2;
radians = Math.Atan2(ws.IRState.IRSensors[0].Position.Y - \
ws.IRState.IRSensors[1].Position.Y,
ws.IRState.IRSensors[0].Position.X - ws.IRState.IRSensors[1].Position.X );
angle = radians * (180 / Math.PI);
} else {
//�ԊO����1�‚Ȃ�A1�‚߂̒l���̗p����
pos.X = (int)(ws.IRState.IRSensors[0].Position.X * 256);
pos.Y = (int)(ws.IRState.IRSensors[0].Position.Y * 128);
}
rect.Location = pos;
rect.Height = 10; rect.Width = 10;
drawString = "{" + rect.X + ", "+ rect.Y +"}";
g.DrawString(drawString, drawFont, drawBrush, pos);
g.DrawPie(Pens.Azure,rect, (float)-angle, (float)angle);
//���W�A���P�ʂɕϊ�
double d = angle / (180 / Math.PI);
//�V�������W�ʒu���v�Z����
float x = pos.X;
float y = pos.Y;
float x1 = x + targetBMP.Width * (float)Math.Cos(d);
float y1 = y + targetBMP.Width * (float)Math.Sin(d);
float x2 = x - targetBMP.Height * (float)Math.Sin(d);
float y2 = y + targetBMP.Height * (float)Math.Cos(d);
//PointF�z�����
System.Drawing.PointF[] destinationPoints = {new System.Drawing.PointF(x, \
y),
new System.Drawing.PointF(x1, y1),
new System.Drawing.PointF(x2, y2)};
//�摜��\��
g.DrawImage(targetBMP, destinationPoints);
}
g.Dispose();//�O���t�B�b�N�X�̉��
label1.Text = "IR[0] " + ws.IRState.IRSensors[0].RawPosition.ToString()
+ "\nIR[1] " + ws.IRState.IRSensors[1].RawPosition.ToString()
+ "\n size0 "+ ws.IRState.IRSensors[0].Size.ToString()
+ "\n angle = " + angle;
}
#endregion
C#.NET�ɑ΂���C++.NET�‹��͂��̂悤�Ȕ�.NET���݊‹��ɋ����A�`����uwindows.h�v��#include�錾���邾����A�֘A����\���̂�AC#�̃R�[�h�ɂ�����u0x0002�v�ɂ�����uMOUSEEVENTF_LEFTUP�v�Ȃǂ͂����ׂĎ����Ŏ����ł���܂��B���̂܂܃r���h�����A����̎��̂����‚���Ȃ��Ƃ����G���[���o��̂ł����A�u�v���W�F�N�g�̃v���p�e�B�v���u�\���v���p�e�B�v���u�����J�v���u����v���u�lj��̈ˑ��t�@�C���v��\������u�e�܂��̓v���W�F�N�g�K��l����̌p���v�Ƀ`�F�b�N�����邱�Ƃ�A�r���h���Ɏ��ۂ̊���������N���Ă����悤�ɂȂ�܂��B
���̃Z�N�V�����ł�XNA Game Studio 3.0��WiimoteLib���g����AC#.NET�ɂ��Q�[���J���‹����x�[�X�ɂ������A���^�C��3DCG�ɂ��C���^���N�V������������܂��B
XNA�Ƃ�A�}�C�N���\�t�g�����i���Ă���ADirectX�̗���������V��.NET�ɂ��Q�[���J�������‹��ł��B
XNA�ɂ��R�[�f�B���O�X�^�C���A�‚܂�XNA Framework�ɂ�����C#�����A�����̃��A���^�C��3DCG�J���‹��̖{���ł�����DirectX��Managed DirectX�ɉ����A����ɃQ�[���J���ɕ֗��Ȋ���������܂܂�Ă���A�ȒP�ɃQ�[���v���O���������ł���悤�ɂȂ��Ă��܂��B����V�̃R���V���[�}�[(�ƒ�p)�Q�[���@�ł�Xbox 360�A������WindowsPC�p�̃Q�[���J���̗����ɂ�����A���Ɍ����I�����i�I�ȊJ�����ł��邽��A����傫�ȗ�������o���”\��������ł��傤�B
���ꂩ��AWiiRemote�̉����x�Z���T�[�̌X���ɂ����A3D�ŕ`�悳�ꂽWiiRemote�����A���^�C���ŕω�����v���O�����uWiiRemoteXNA�v�������܂��B
�Ȃ��Ȃ��h��Ȋ��������邩������܂���AXNA Game Studio 3.0���g����A���ɒZ���R�[�h������邱�Ƃ��ł��܂��B
�܂���A�J���‹��̃Z�b�g�A�b�v���s���܂��傤�BMicrosoft XNA Game Studio���_�E�����[�h���ăC���X�g�[�����܂��B
Microsoft XNA Game Studio 3.0
http://www.microsoft.com/downloads/details.aspx?familyid=7D70D6ED-1EDD-4852-9883-9A33C0AD8FEE
XNA�͖����ŊJ���‹�����ɓ���邱�Ƃ��ł��܂��BPC�ŗ��p�����ł̓��C�Z���X��]�������ŗ��p���邱�Ƃ��ł��܂����AXBox�v���b�g�t�H�[���ŊJ�����邽�߂ɂ͔N�ԃ��C�Z���X��(1���~���x��)�𕥂��K�v������܂��B�{���ł�XBox�v���b�g�t�H�[���ɂ‚��Ă͈����܂���A����‹��Ƃ��Ĉ��肵�Ĉ����œ���ł���R���V���[�}�Q�[���@������ق�����ł͂Ȃ����C�Z���X���ŊJ���ł���̂͑傫�Ȗ��͂ł��B
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
namespace WiiRemoteXNA
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
/// <summary>
/// Allows the game to perform any initialization it needs to before \
starting to run.
/// This is where it can query for any required services and load any \
non-graphic
/// related content. Calling base.Initialize will enumerate through any \
components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here
base.Initialize();
}
/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
// TODO: use this.Content to load your game content here
}
/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// all content.
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// TODO: Add your update logic here
base.Update(gameTime);
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code here
base.Draw(gameTime);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using WiimoteLib; //WiimoteLib�̓ǂ����
using System.Collections; //Collection�̓ǂ����
namespace XNAWii {
public class Game1 : Microsoft.Xna.Framework.Game {
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
private Model xfile; //X�t�@�C��
Wiimote wm = new Wiimote(); //Wiimote��錾
ArrayList[] Accel = new ArrayList[2]; //�X���Z���T�̒l�i�[
#region Game
public Game1() {
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
#endregion
#region Initialize ������
protected override void Initialize() {
base.Initialize();
//���̃f�[�^��������A�Z���T�l�̃u���������̂Ŏw�肵����̕��ς���邽�߂̃��X�g
this.Accel[0] = new ArrayList(); //���X�g��`
this.Accel[1] = new ArrayList(); //���X�g��`
this.wm.Connect(); //�ڑ�
this.wm.SetReportType(InputReport.IRExtensionAccel, true); //���|�[�g�^�C�v��ݒ�
this.wm.WiimoteChanged += wm_WiimoteChanged; //�C�x���g����̓o�^
this.wm.SetLEDs(0); //LED��_�������Ȃ�
}
#endregion
#region LoadContent �O���t�B�b�N�֌W�̓ǂ����
protected override void LoadContent() {
spriteBatch = new SpriteBatch(GraphicsDevice);
this.xfile = this.Content.Load<Model>("wii"); //X�t�@�C���̓ǂ����
foreach (ModelMesh mesh in this.xfile.Meshes)//���b�V������
{
foreach (BasicEffect effect in mesh.Effects) {
//�r���[�s��
effect.View = Matrix.CreateLookAt(new Vector3(0.0f, 0.0f, 10.0f), \
Vector3.Zero, Vector3.Up);
//�v���W�F�N�V�����s��
effect.Projection = Matrix.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(45.0f),
(float)this.GraphicsDevice.Viewport.Width / \
(float)this.GraphicsDevice.Viewport.Height,
1.0f,
50.0f
);
}
}
}
#endregion
#region UnloadContent �O���t�B�b�N�֌W�̔j��
protected override void UnloadContent() {
}
#endregion
#region Update �O���t�B�b�N�ȊO�̒���X�V
protected override void Update(GameTime gameTime) {
//���̂܂܎��s����ƈȉ��̂悤�ȃG���[���������܂��B
//�u�G���[ 1 'ButtonState' ��A'Microsoft.Xna.Framework.Input.ButtonState' �� \
'WiimoteLib.ButtonState'' �Ԃ̂����܂��ȎQ�Ƃł��B C:\Users\kosaka\Documents\Visual \
Studio 2008\Projects\XNAWii\XNAWii\Game1.cs 101 58 XNAWii�v
//'Microsoft.Xna.Framework.Input.ButtonState' �� \
'WiimoteLib.ButtonState'��ButtonState�A�ǂ������g���̂��æ‚�킩��Ȃ��Ɠ{���܂��B
//�����ł�'Microsoft.Xna.Framework.Input.ButtonState'���g���܂��̂�A�ȉ��̂悤�ɒlj����܂��B
// �C���O: if (GamePad.GetState(PlayerIndex.One).Buttons.Back == \
ButtonState.Pressed)
// �C����: if (GamePad.GetState(PlayerIndex.One).Buttons.Back == \
Microsoft.Xna.Framework.Input.ButtonState.Pressed)
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == \
Microsoft.Xna.Framework.Input.ButtonState.Pressed)
this.Exit();
base.Update(gameTime);
}
#endregion
#region �O���t�B�b�N�֌W�̒���X�V
protected override void Draw(GameTime gameTime) {
GraphicsDevice.Clear(Color.CornflowerBlue);
float x, y; //��]�p�x���i�[
float tmp; //�v�Z�p���
//X�̕��ς����߂�
tmp = 0; //tmp�̒l��0�ɂ���
//���v�����߂�
for (int i = 0; i < this.Accel[0].Count; i++) {
tmp = tmp + (float)this.Accel[0][i];
}
//���ς����߂�@���v������Ŋ���
x = tmp / this.Accel[0].Count;
//Y�̕��ς����߂�
tmp = 0; //tmp�̒l��0�ɂ���
//���v�����߂�
for (int i = 0; i < this.Accel[1].Count; i++) {
tmp = tmp + (float)this.Accel[1][i];
}
//���ς����߂�@���v������Ŋ���
y = tmp / this.Accel[1].Count;
//90�Ɋg��
//�Z���T�̒l���p�x�ɕϊ�
x = (-x * 90.0f);
y = (-y * 90.0f);
//�p�x�����W�A���ɕϊ�
x = x / 180 * 3.14f;
y = y / 180 * 3.14f;
//��ʂɕ`�悷��
foreach (ModelMesh mesh in this.xfile.Meshes) {
foreach (BasicEffect effect in mesh.Effects) {
//��]�p�x��ݒ�@Yaw�@Pitch�@Roll���w�肷��B Yaw�͎g��Ȃ��̂�Pitch�ɂ���Roll��x��ݒ�
effect.World = Matrix.CreateFromYawPitchRoll(0, y, x);
}
mesh.Draw();//mesh��`��
}
base.Draw(gameTime);
}
#endregion
#region wm_WiimoteChanged Wii�����R���l����X������
void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs args) {
WiimoteState ws = args.WiimoteState; //WiimoteState�̒l���擾
//���X�g�ɓ˂�����
this.Accel[0].Add(ws.AccelState.Values.X);
this.Accel[1].Add(ws.AccelState.Values.Y);
int avg_count = 50; //�����
//avg_count�“�����Â��l���P�������
//����V���Ԃ�avg_count�‚̃f�[�^���i�[�����B
if (this.Accel[0].Count >= avg_count) { this.Accel[0].RemoveAt(0); }
if (this.Accel[1].Count >= avg_count) { this.Accel[1].RemoveAt(0); }
}
#endregion
}
}
�܂Ƃ�