センサーの値をイベントにより取得するサンプルコード
TDx.TDxInput.Sensor sensor = null;
初期化処理
protected override void OnLoad( EventArgs e )
{
base.OnLoad( e );
TDx.TDxInput.Device device = new TDx.TDxInput.Device();
this.sensor = device.Sensor;
this.sensor.SensorInput += new TDx.TDxInput._ISensorEvents_SensorInputEventHandler( sensor_SensorInput );
device.Connect();
}
終了処理
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( this.sensor != null )
{
TDx.TDxInput.Device device = ( TDx.TDxInput.Device )this.sensor.Device;
if( device != null )
{
device.Disconnect();
}
}
}
base.Dispose( disposing );
}
イベントハンドラ
private void sensor_SensorInput()
{
TDx.TDxInput.AngleAxis rotation = this.sensor.Rotation;
Console.Write( string.Format(
"Rotation x:{0} y:{1} z:{2} angle:{0}",
rotation.X,
rotation.Y,
rotation.Z,
rotation.Angle ) );
TDx.TDxInput.Vector3D translation = this.sensor.Translation;
Console.Write( string.Format(
"Translation x:{0} y:{1} z:{2} length:{0}",
translation.X,
translation.Y,
translation.Z,
translation.Length ) );
}