|  
  
  
   
   
   
   
   
   
  | 
| 
| DelphiXE3 [3D-FMX] 3Dアプリケーションテスト(1) 2014/04/20 |  前回で 3D FireMonkey アプリケーションのコンポーネントの紹介は終了しました。今回は少しだけテストプログラムを作ってみます。
 
 2Dアプリケーションでの図形の作図は、コンポーネントでの作図以外でも、PaintBox の Canvas でのメソッド実行により各種図形作図を行う事が出来ますが、3Dアプリケーションでは、今のところ、同様にプログラム上での任意図形作図を行う方法が分かりません。
 
 静的に3Dコンポーネントを貼り付ける方法はこれまで行なってきたように可能ですが、プログラム上で任意に3D作図をさせるには、この方法では不便です。そのため、動的に3Dオブジェクトを生成して、表示させてみます。
 
 下記は、立方体 Cube を 100個作図して表示するテストプログラムです。
 
 
しかしこれでは、色は全て赤色になってしまいますので、少し寂しいですから、ライトを配置し、ライト材質ソースも複数生成して、それぞれ乱数で色を指定してみます。
| type TForm1 = class(TForm3D)
 ・・・
 end;
 
 var
 Form1: TForm1;
 boxn: integer ;
 box : array of TCube ;
 
 implementation
 
 {$R *.fmx}
 
 procedure TForm1.Form3DShow(Sender: TObject);
 var
 i : integer ;
 begin
 boxn := 0 ;
 for i := 0 to 99 do begin
 Inc(boxn);
 if ((boxn mod 20) = 1) then
 SetLength(box, boxn+19);
 box[boxn-1] := nil ;
 try
 box[boxn-1] := TCube.Create(Self);
 box[boxn-1].Visible := False ;
 box[boxn-1].Name := 'Cube' + IntToStr(boxn) ;
 box[boxn-1].Tag := boxn ;
 box[boxn-1].Parent := Form1 ;
 box[boxn-1].Position.X := (i mod 10)*1.5 - 6.75 ;
 box[boxn-1].Position.Y := 0 ;
 box[boxn-1].Position.Z := (i div 10)*1.5 - 6.75 ;
 box[boxn-1].Width := 1 ;
 box[boxn-1].Height:= 1 ;
 box[boxn-1].Depth := 1 ;
 box[boxn-1].Visible := True ;
 except
 ;
 end;
 end;
 end;
 end;
 |  
 
 
| type TForm1 = class(TForm3D)
 ・・・
 end;
 
 var
 Form1: TForm1;
 mtrn: integer ;
 mtr : array of TLightMaterialSource;
 boxn: integer ;
 box : array of TCube ;
 
 implementation
 
 {$R *.fmx}
 
 procedure TForm1.Form3DShow(Sender: TObject);
 var
 i : integer ;
 begin
 mtrn := 0 ;
 boxn := 0 ;
 for i := 0 to 99 do begin
 Inc(mtrn);
 if ((mtrn mod 20) = 1) then
 SetLength(mtr, mtrn+19);
 mtr[mtrn-1] := nil ;
 try
 mtr[mtrn-1] := TLightMaterialSource.Create(Self);
 mtr[mtrn-1].Name := 'Mtr' + IntToStr(mtrn) ;
 mtr[mtrn-1].Parent := Form1 ;
 mtr[mtrn-1].Diffuse := $FF000000 + Cardinal(Random(256)
 + Random(256)*256 + Random(256)*65536);
 except
 ;
 end;
 
 Inc(boxn);
 if ((boxn mod 20) = 1) then
 SetLength(box, boxn+19);
 box[boxn-1] := nil ;
 try
 box[boxn-1] := TCube.Create(Self);
 box[boxn-1].Visible := False ;
 box[boxn-1].Name := 'Cube' + IntToStr(boxn) ;
 box[boxn-1].Tag := boxn ;
 box[boxn-1].MaterialSource := mtr[mtrn-1] ;
 box[boxn-1].Parent := Form1 ;
 box[boxn-1].Position.X := (i mod 10)*1.5 - 6.75 ;
 box[boxn-1].Position.Y := 0 ;
 box[boxn-1].Position.Z := (i div 10)*1.5 - 6.75 ;
 box[boxn-1].Width := 1 ;
 box[boxn-1].Height:= 1 ;
 box[boxn-1].Depth := 1 ;
 box[boxn-1].Visible := True ;
 except
 ;
 end;
 end;
 end;
 |  更に、カメラとタイマーを配置し、カメラを移動させる事により簡易のアニメーションをさせるようにしてみます。 カメラの高さは、トラックバー TrackBar1 によって変えられるようにしておきます。トラックバーは3Dレイヤの上に配置しておきます。
 
 ソース・実行プログラムのダウンロード(ZIP圧縮;3,248KB)
 
 
 |  | バッチファイル BASIC
 C言語のお勉強
 拡張子な話
 DOSプログラム
 Delphi
 >Dehi入門編
 >Delphi2010
 >DelphiXE3
 ▲2014/04/10
 2014/04/20
 ▼2014/04/30
 
 シェアウェア
 Script!World
 データベース
 
 |