unit ddsd3d1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  DDSD, StdCtrls, d3dtypes, DSound, ComCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    OpenDialog1: TOpenDialog;
    Button2: TButton;
    DDSD1: TDDSD;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    LblX: TLabel;
    LblY: TLabel;
    LblZ: TLabel;
    TrackBar1: TTrackBar;
    TrackBar2: TTrackBar;
    TrackBar3: TTrackBar;
    GroupBox2: TGroupBox;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    lblVX: TLabel;
    lblVY: TLabel;
    lblVZ: TLabel;
    TrackBar4: TTrackBar;
    TrackBar5: TTrackBar;
    TrackBar6: TTrackBar;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure TrackBar1Change(Sender: TObject);
  private
    { Private 宣言 }
  public
    { Public 宣言 }
    sourcePos:D3DVector;  //音源の位置
    sourceVel:D3DVector;  //音源の速度
    w3d:TDDSDWave3D;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

//WAVの読み込み
procedure TForm1.Button1Click(Sender: TObject);
begin
  with OpenDialog1 do begin
    if Execute then begin
      //TDDSDWave3D型として読み込む
      w3d:=TDDSDWave3D.Create(DDSD1,FileName);
      with w3d.Params3D.Velocity do begin
        x:=0; y:=0; z:=0;
      end;
      DDSD1[0].WaveData:=w3d;
    end;
  end;
  Button2.Enabled:=True;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  DDSD1[0].Params3D.Position:=SourcePos;
  DDSD1[0].Params3D.Velocity:=SourceVel;
  DDSD1[0].Play;
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
  with SourcePos do begin
    x:=0; y:=0; z:=0;
  end;
  with SourceVel do begin
    x:=0; y:=0; z:=0;
  end;
end;


//トラックバーの位置に応じて、キャプション、音源の位置を変更
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
  if Sender = TrackBar1 then
    LblX.Caption:=IntToStr(TTrackBar(Sender).Position - 50)
  else if Sender = TrackBar2 then
    LblY.Caption:=IntToStr(TTrackBar(Sender).Position - 50)
  else if Sender = TrackBar3 then
    LblZ.Caption:=IntToStr(TTrackBar(Sender).Position - 50)

  else if Sender = TrackBar4 then
    LblVX.Caption:=IntToStr(TTrackBar(Sender).Position - 50)
  else if Sender = TrackBar5 then
    LblVY.Caption:=IntToStr(TTrackBar(Sender).Position - 50)
  else if Sender = TrackBar6 then
    LblVZ.Caption:=IntToStr(TTrackBar(Sender).Position - 50);

  with SourcePos do begin
    x:=TrackBar1.Position-50;
    y:=TrackBar2.Position-50;
    z:=TrackBar3.Position-50;
  end;

  with SourceVel do begin
    x:=TrackBar4.Position-50;
    y:=TrackBar5.Position-50;
    z:=TrackBar6.Position-50;
  end;

  DDSD1[0].Params3D.Position:=SourcePos;
  DDSD1[0].Params3D.Velocity:=SourceVel;
end;

end.
