DelphiXE2 FireMonkey3D 光源的3种类型

 Tlight 的 Light Type 有三种属性. 

ltDirectional   
ltPoint
ltSpot



在ltDriectional下, 无论光源的位置如何改变,  场景内的图形都不变

 

 

ltPoint 下,光源就像个电灯泡,改变光源位置会造成阴影的改变.

 

 

ltSpot 就像个手电筒, 指到哪里,哪里才亮. 

 

 窗体代码 :

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
    { Private declarations }
  public
    { Public declarations }
  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.


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值