| 1 |
{%MainUnit castlescene.pas} |
| 2 |
{ |
| 3 |
Copyright 2021-2024 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 |
{ Cylinder with configurable size, position and material. } |
| 21 |
TCastleCylinder = class(TCastleAbstractPrimitive) |
| 22 |
strict private |
| 23 |
CylinderNode: TCylinderNode; |
| 24 |
FRadius, FHeight: Single; |
| 25 |
FDoubleSided: Boolean; |
| 26 |
FBottom, FSide, FTop: Boolean; |
| 27 |
FSlices: Cardinal; |
| 28 |
procedure SetRadius(const Value: Single); |
| 29 |
procedure SetHeight(const Value: Single); |
| 30 |
procedure SetDoubleSided(const Value: Boolean); |
| 31 |
procedure SetBottom(const Value: Boolean); |
| 32 |
procedure SetSide(const Value: Boolean); |
| 33 |
procedure SetTop(const Value: Boolean); |
| 34 |
procedure SetSlices(const Value: Cardinal); |
| 35 |
public |
| 36 |
constructor Create(AOwner: TComponent); override; |
| 37 |
function PropertySections(const PropertyName: String): TPropertySections; override; |
| 38 |
published |
| 39 |
{ Cylinder radius. } |
| 40 |
property Radius: Single read FRadius write SetRadius {$ifdef FPC}default 1{$endif}; |
| 41 |
|
| 42 |
{ Cylinder height. } |
| 43 |
property Height: Single read FHeight write SetHeight {$ifdef FPC}default 2{$endif}; |
| 44 |
|
| 45 |
{ When this is @true, the object is visible (and lit) from both sides. } |
| 46 |
property DoubleSided: Boolean read FDoubleSided write SetDoubleSided default false; |
| 47 |
|
| 48 |
{ Display bottom of the cylinder. |
| 49 |
When @false, you can see the cylinder interior if looking from the outside |
| 50 |
(note: turn on DoubleSided to make interior visible). } |
| 51 |
property Bottom: Boolean read FBottom write SetBottom default true; |
| 52 |
|
| 53 |
{ Display side of the cylinder. |
| 54 |
When @false, you can see the cylinder interior if looking from the outside |
| 55 |
(note: turn on DoubleSided to make interior visible). } |
| 56 |
property Side: Boolean read FSide write SetSide default true; |
| 57 |
|
| 58 |
{ Display top of the cylinder. |
| 59 |
When @false, you can see the cylinder interior if looking from the outside |
| 60 |
(note: turn on DoubleSided to make interior visible). } |
| 61 |
property Top: Boolean read FTop write SetTop default true; |
| 62 |
|
| 63 |
{ How many "slices" to use to approximate the cylinder. |
| 64 |
The cylinder is rendered using polygons (triangles and quads) |
| 65 |
that approximate the cylinder shape. |
| 66 |
The more slices, the more the cylinder will look like a cylinder. |
| 67 |
|
| 68 |
Slices divide the objects like slices of a pizza. |
| 69 |
|
| 70 |
The default value of 0 means to follow global variable |
| 71 |
@link(DefaultTriangulationSlices).} |
| 72 |
property Slices: Cardinal read FSlices write SetSlices default 0; |
| 73 |
end; |
| 74 |
|
| 75 |
{$endif read_interface} |
| 76 |
|
| 77 |
{$ifdef read_implementation} |
| 78 |
|
| 79 |
{ TCastleCylinder ---------------------------------------------------------------- } |
| 80 |
|
| 81 |
constructor TCastleCylinder.Create(AOwner: TComponent); |
| 82 |
begin |
| 83 |
inherited; |
| 84 |
|
| 85 |
{ default properties values } |
| 86 |
FRadius := 1; |
| 87 |
FHeight := 2; |
| 88 |
FBottom := true; |
| 89 |
FSide := true; |
| 90 |
FTop := true; |
| 91 |
|
| 92 |
CylinderNode := TCylinderNode.Create; |
| 93 |
CylinderNode.Radius := FRadius; |
| 94 |
CylinderNode.Height := FHeight; |
| 95 |
CylinderNode.Solid := not FDoubleSided; |
| 96 |
CylinderNode.Slices := FSlices; |
| 97 |
ShapeNode.Geometry := CylinderNode; |
| 98 |
end; |
| 99 |
|
| 100 |
function TCastleCylinder.PropertySections(const PropertyName: String): TPropertySections; |
| 101 |
begin |
| 102 |
if ArrayContainsString(PropertyName, ['Radius', 'Height', 'DoubleSided', |
| 103 |
'Bottom', 'Side', 'Top', 'Slices']) then |
| 104 |
Result := [psBasic] |
| 105 |
else |
| 106 |
Result := inherited PropertySections(PropertyName); |
| 107 |
end; |
| 108 |
|
| 109 |
procedure TCastleCylinder.SetRadius(const Value: Single); |
| 110 |
begin |
| 111 |
if FRadius <> Value then |
| 112 |
begin |
| 113 |
FRadius := Value; |
| 114 |
CylinderNode.Radius := FRadius; |
| 115 |
UpdateCollider; |
| 116 |
end; |
| 117 |
end; |
| 118 |
|
| 119 |
procedure TCastleCylinder.SetHeight(const Value: Single); |
| 120 |
begin |
| 121 |
if FHeight <> Value then |
| 122 |
begin |
| 123 |
FHeight := Value; |
| 124 |
CylinderNode.Height := FHeight; |
| 125 |
UpdateCollider; |
| 126 |
end; |
| 127 |
end; |
| 128 |
|
| 129 |
procedure TCastleCylinder.SetDoubleSided(const Value: Boolean); |
| 130 |
begin |
| 131 |
if FDoubleSided <> Value then |
| 132 |
begin |
| 133 |
FDoubleSided := Value; |
| 134 |
CylinderNode.Solid := not Value; |
| 135 |
end; |
| 136 |
end; |
| 137 |
|
| 138 |
procedure TCastleCylinder.SetBottom(const Value: Boolean); |
| 139 |
begin |
| 140 |
if FBottom <> Value then |
| 141 |
begin |
| 142 |
FBottom := Value; |
| 143 |
CylinderNode.Bottom := Value; |
| 144 |
end; |
| 145 |
end; |
| 146 |
|
| 147 |
procedure TCastleCylinder.SetSide(const Value: Boolean); |
| 148 |
begin |
| 149 |
if FSide <> Value then |
| 150 |
begin |
| 151 |
FSide := Value; |
| 152 |
CylinderNode.Side := Value; |
| 153 |
end; |
| 154 |
end; |
| 155 |
|
| 156 |
procedure TCastleCylinder.SetTop(const Value: Boolean); |
| 157 |
begin |
| 158 |
if FTop <> Value then |
| 159 |
begin |
| 160 |
FTop := Value; |
| 161 |
CylinderNode.Top := Value; |
| 162 |
end; |
| 163 |
end; |
| 164 |
|
| 165 |
procedure TCastleCylinder.SetSlices(const Value: Cardinal); |
| 166 |
begin |
| 167 |
if FSlices <> Value then |
| 168 |
begin |
| 169 |
FSlices := Value; |
| 170 |
CylinderNode.Slices := FSlices; |
| 171 |
end; |
| 172 |
end; |
| 173 |
|
| 174 |
{$endif read_implementation} |