吵吵   2011-10-19  阅读:3,024

DelphiXE2 FireMonkey3D 光源的3种类型

view plain
Tlight 的 Light Type 有三种属性.

ltDirectional
ltPoint
ltSpot

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


asd

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

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

窗体代码 :

view plain
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  

代码

view plain
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.  

吵吵微信朋友圈,请付款实名加入:

吵吵 吵吵

7条回应:“DelphiXE2 FireMonkey3D 光源的3种类型”

  1. 图片是不是挂了啊

  2. 九阳豆浆机说道:

    我也看不到图片!!!!!

  3. 地球博客说道:

    技术性的东西,老朽不懂。

  4. 一阵风说道:

    看不懂的说,这是啥东东的?

  5. 说道:

    feed出错了。。
    提示 未知标题
    [unable to retrieve full-text content]

  6. 顶上的图片不在 ,但是代码写的好完美 顶一个

发表评论

电子邮件地址不会被公开。 必填项已用*标注