2011-09-20 16:02 117人閱讀 收藏 舉報(bào)
- </pre><pre class="delphi" name="code"> Tlight 的 Light Type 有三種屬性.
-
- ltDirectional
- ltPoint
- ltSpot
在ltDriectional下, 無(wú)論光源的位置如何改變, 場(chǎng)景內(nèi)的圖形都不變
ltPoint 下,光源就像個(gè)電燈泡,改變光源位置會(huì)造成陰影的改變.
ltSpot 就像個(gè)手電筒, 指到哪里,哪里才亮.
窗體代碼 :
- object Form1: TForm1
- Left = 0
- Top = 0
- BiDiMode = bdLeftToRight
- Caption = 'Form1'
- ClientHeight = 400
- ClientWidth = 600
- Transparency = False
- Visible = False
- object Light1: TLight
- Position.Point = '(-2.91962718963623,-2.18277525901794,-5.00000905990601)'
- Width = 1.000000000000000000
- Height = 1.000000000000000000
- Depth = 1.000000000000000000
- Opacity = 1.000000000000000000
- LightType = ltPoint
- Quanternion = '(0,0,0,1)'
- object FloatAnimation3: TFloatAnimation
- Duration = 5.000000000000000000
- Loop = True
- StartValue = -5.000000000000000000
- StartFromCurrent = True
- StopValue = 5.000000000000000000
- PropertyName = 'Position.X'
- end
- end
- object Cube1: TCube
- Position.Point = '(-3.13717293739319,-2.5406289100647,-3.68232804248692E-7)'
- RotationAngle.Point = '(10,5,5)'
- Width = 2.000000000000000000
- Height = 2.000000000000000000
- Depth = 2.000000000000000000
- Opacity = 1.000000000000000000
- Material.Diffuse = xFFB41B1B
- Quanternion =
- '(0.0888853296637535,0.0472101084887981,0.039613988250494,0.99413' +
- '3472442627)'
- object FloatAnimation1: TFloatAnimation
- Enabled = True
- Duration = 100.000000000000000000
- StopValue = 360.000000000000000000
- PropertyName = 'RotationAngle.X'
- end
- end
- object Cone1: TCone
- Position.Point = '(3.08346128463745,-2.22207975387573,-1.62784465373989E-6)'
- Width = 2.500000000000000000
- Height = 2.000000000000000000
- Depth = 2.000000000000000000
- Opacity = 1.000000000000000000
- Material.Diffuse = xFF426CC9
- Quanternion = '(0,0,0,1)'
- object FloatAnimation2: TFloatAnimation
- Enabled = True
- Duration = 100.000000000000000000
- Loop = True
- StopValue = 360.000000000000000000
- PropertyName = 'RotationAngle.Y'
- end
- end
- object Layer3D1: TLayer3D
- Position.Point = '(-0.700324535369873,2.73746109008789,9.99998569488525)'
- RotationAngle.Point = '(-20,0,0)'
- Width = 45.193157196044920000
- Height = 29.603034973144530000
- Depth = 0.009999999776482582
- Opacity = 1.000000000000000000
- OnMouseMove = Layer3D1MouseMove
- StyleLookup = 'backgroundstyle'
- Quanternion = '(-0.173648178577423,0,0,0.984807729721069)'
- object SpeedButton1: TSpeedButton
- Position.Point = '(280,1136)'
- Width = 80.000000000000000000
- Height = 22.000000000000000000
- Scale.Point = '(10,10)'
- OnClick = SpeedButton1Click
- TabOrder = 0
- StaysPressed = False
- IsPressed = False
- Text = #28857#20809#28304
- end
- object SpeedButton2: TSpeedButton
- Position.Point = '(1056,1136)'
- Width = 80.000000000000000000
- Height = 22.000000000000000000
- Scale.Point = '(10,10)'
- OnClick = SpeedButton2Click
- TabOrder = 1
- StaysPressed = False
- IsPressed = False
- Text = #23556#32447#20809#28304
- end
- end
- end
代碼
- unit Unit1;
-
- interface
-
- uses
- System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
- FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.Ani, FMX.Objects3D,
- FMX.Types3D, FMX.Layers3D, FMX.Layouts, FMX.Memo;
-
- type
- TForm1 = class(TForm3D)
- Light1: TLight;
- Cube1: TCube;
- Cone1: TCone;
- FloatAnimation1: TFloatAnimation;
- FloatAnimation2: TFloatAnimation;
- Layer3D1: TLayer3D;
- FloatAnimation3: TFloatAnimation;
- SpeedButton1: TSpeedButton;
- SpeedButton2: TSpeedButton;
- procedure Layer3D1MouseMove(Sender: TObject; Shift: TShiftState; X,
- Y: Single; RayPos, RayDir: TVector3D);
- procedure SpeedButton1Click(Sender: TObject);
- procedure SpeedButton2Click(Sender: TObject);
- private
-
- public
-
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.fmx}
-
- procedure TForm1.Layer3D1MouseMove(Sender: TObject; Shift: TShiftState; X,
- Y: Single; RayPos, RayDir: TVector3D);
- begin
- light1.Position.X := raydir.X * 15;
- light1.Position.y := raydir.y * 15;
- end;
-
- procedure TForm1.SpeedButton1Click(Sender: TObject);
- begin
- light1.LightType := FMX.Types3D.TLightType.ltPoint;
- end;
-
- procedure TForm1.SpeedButton2Click(Sender: TObject);
- begin
- light1.LightType := FMX.Types3D.TLightType.ltSpot;
- end;
-
- end.
|