Debian Codegraph @

src/scene/castlescene_fog.inc

raw
1 {%MainUnit castlescene.pas}
2 {
3 Copyright 2022-2022 Michalis Kamburelis.
4
5 This file is part of "Castle Game Engine".
6
7 "Castle Game Engine" is free software; see the file COPYING.txt,
8 included in this distribution, for details about the copyright.
9
10 "Castle Game Engine" is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
14 ----------------------------------------------------------------------------
15 }
16
17 {$ifdef read_interface}
18
19 type
20 { Control fog in 3D world. }
21 TCastleFog = class(TCastleComponent)
22 strict private
23 FFogNode: TFogNode;
24 FColor: TCastleColorRGB;
25 FFogType: TFogType;
26 FVisibilityRange: Single;
27 procedure SetColor(const Value: TCastleColorRGB);
28 procedure SetFogType(const Value: TFogType);
29 procedure SetVisibilityRange(const Value: Single);
30 procedure UpdateFogNode;
31 public
32 const
33 DefaultColor: TCastleColorRGB = (X: 0.5; Y: 0.5; Z: 0.5);
34 DefaultFogType = ftExponential;
35 DefaultVisibilityRange = 100;
36
37 constructor Create(AOwner: TComponent); override;
38 destructor Destroy; override;
39 function PropertySections(const PropertyName: String): TPropertySections; override;
40
41 { In the distance, the rendered color changes into this fog color.
42 By default this is gray (RGB 0.5,0.5,0.5). }
43 property Color: TCastleColorRGB read FColor write SetColor;
44
45 { @exclude }
46 property InternalFogNode: TFogNode read FFogNode;
47 published
48 { Type of fog determines how quickly is the @link(Color) applied.
49 The default is a more realistic ftExponential. }
50 property FogType: TFogType read FFogType write SetFogType default DefaultFogType;
51
52 { The fog reaches maximum intensity, that is all colors are equal to @link(Color),
53 at this distance from the observer. }
54 property VisibilityRange: Single read FVisibilityRange write SetVisibilityRange
55 {$ifdef FPC}default DefaultVisibilityRange{$endif};
56
57 {$define read_interface_class}
58 {$I auto_generated_persistent_vectors/tcastlefog_persistent_vectors.inc}
59 {$undef read_interface_class}
60 end;
61
62 {$endif read_interface}
63
64 {$ifdef read_implementation}
65
66 { TCastleFog ----------------------------------------------------------------- }
67
68 constructor TCastleFog.Create(AOwner: TComponent);
69 begin
70 inherited;
71
72 { set default values }
73 FColor := DefaultColor;
74 FFogType := DefaultFogType;
75 FVisibilityRange := DefaultVisibilityRange;
76
77 FFogNode := TFogNode.Create;
78 UpdateFogNode;
79
80 {$define read_implementation_constructor}
81 {$I auto_generated_persistent_vectors/tcastlefog_persistent_vectors.inc}
82 {$undef read_implementation_constructor}
83 end;
84
85 destructor TCastleFog.Destroy;
86 begin
87 {$define read_implementation_destructor}
88 {$I auto_generated_persistent_vectors/tcastlefog_persistent_vectors.inc}
89 {$undef read_implementation_destructor}
90
91 FreeAndNil(FFogNode);
92 inherited;
93 end;
94
95 procedure TCastleFog.UpdateFogNode;
96 begin
97 FFogNode.Color := Color;
98 FFogNode.FogType := FogType;
99 FFogNode.VisibilityRange := VisibilityRange;
100 end;
101
102 procedure TCastleFog.SetColor(const Value: TCastleColorRGB);
103 begin
104 if not TCastleColorRGB.PerfectlyEquals(FColor, Value) then
105 begin
106 FColor := Value;
107 UpdateFogNode;
108 end;
109 end;
110
111 procedure TCastleFog.SetFogType(const Value: TFogType);
112 begin
113 if FFogType <> Value then
114 begin
115 FFogType := Value;
116 UpdateFogNode;
117 end;
118 end;
119
120 procedure TCastleFog.SetVisibilityRange(const Value: Single);
121 begin
122 if FVisibilityRange <> Value then
123 begin
124 FVisibilityRange := Value;
125 UpdateFogNode;
126 end;
127 end;
128
129 function TCastleFog.PropertySections(const PropertyName: String): TPropertySections;
130 begin
131 if (PropertyName = 'ColorPersistent') or
132 (PropertyName = 'FogType') or
133 (PropertyName = 'VisibilityRange') then
134 Result := [psBasic]
135 else
136 Result := inherited PropertySections(PropertyName);
137 end;
138
139 {$define read_implementation_methods}
140 {$I auto_generated_persistent_vectors/tcastlefog_persistent_vectors.inc}
141 {$undef read_implementation_methods}
142
143 {$endif read_implementation}