| 1 |
{%MainUnit x3dnodes.pas} |
| 2 |
{ |
| 3 |
Copyright 2008-2018 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 |
{ Base type for all the environmental sensor nodes. } |
| 19 |
TAbstractEnvironmentalSensorNode = class(TAbstractSensorNode) |
| 20 |
{$I auto_generated_node_helpers/x3dnodes_x3denvironmentalsensornode.inc} |
| 21 |
end; |
| 22 |
|
| 23 |
{ Generate events when the viewer enters, exits, and/or moves within |
| 24 |
a region of 3D space. } |
| 25 |
TProximitySensorNode = class(TAbstractEnvironmentalSensorNode) |
| 26 |
public |
| 27 |
function TransformationChange: TNodeTransformationChange; override; |
| 28 |
{$I auto_generated_node_helpers/x3dnodes_proximitysensor.inc} |
| 29 |
end; |
| 30 |
|
| 31 |
{ Generates events when the target object |
| 32 |
enters, exits, and moves within a region of 3D space. |
| 33 |
@bold(Not implemented yet.) } |
| 34 |
TTransformSensorNode = class(TAbstractEnvironmentalSensorNode) |
| 35 |
{$I auto_generated_node_helpers/x3dnodes_transformsensor.inc} |
| 36 |
end; |
| 37 |
|
| 38 |
{ Detects visibility changes of a rectangular box as the user navigates the world. } |
| 39 |
TVisibilitySensorNode = class(TAbstractEnvironmentalSensorNode) |
| 40 |
strict private |
| 41 |
FIsActive: boolean; |
| 42 |
public |
| 43 |
function TransformationChange: TNodeTransformationChange; override; |
| 44 |
function Box: TBox3D; |
| 45 |
|
| 46 |
property IsActive: boolean read FIsActive; |
| 47 |
procedure SetIsActive(const Value: boolean; const Time: TX3DTime); |
| 48 |
|
| 49 |
{$I auto_generated_node_helpers/x3dnodes_visibilitysensor.inc} |
| 50 |
end; |
| 51 |
|
| 52 |
{$endif read_interface} |
| 53 |
|
| 54 |
{$ifdef read_implementation} |
| 55 |
|
| 56 |
function TProximitySensorNode.TransformationChange: TNodeTransformationChange; |
| 57 |
begin |
| 58 |
Result := ntcProximitySensor; |
| 59 |
end; |
| 60 |
|
| 61 |
function TVisibilitySensorNode.TransformationChange: TNodeTransformationChange; |
| 62 |
begin |
| 63 |
Result := ntcVisibilitySensor; |
| 64 |
end; |
| 65 |
|
| 66 |
function TVisibilitySensorNode.Box: TBox3D; |
| 67 |
begin |
| 68 |
if (FdSize.Value[0] < 0) or |
| 69 |
(FdSize.Value[1] < 0) or |
| 70 |
(FdSize.Value[2] < 0) then |
| 71 |
begin |
| 72 |
WritelnWarning('X3D', 'All VisibilitySensor.size components must be >= 0'); |
| 73 |
Exit(TBox3D.Empty); |
| 74 |
end; |
| 75 |
|
| 76 |
{ In case of VisibilitySensor, specification doesn't say that size = 0 |
| 77 |
indicates empty box (like in case of ProximitySensor). |
| 78 |
And this is sensible: flat (0 depth or such) VisibilitySensor |
| 79 |
makes sense. So for a valid X3D, this box is never TBox3D.Empty. } |
| 80 |
|
| 81 |
Result := Box3DAroundPoint(FdCenter.Value, FdSize.Value); |
| 82 |
end; |
| 83 |
|
| 84 |
procedure TVisibilitySensorNode.SetIsActive(const Value: boolean; const Time: TX3DTime); |
| 85 |
begin |
| 86 |
if FIsActive <> Value then |
| 87 |
begin |
| 88 |
FIsActive := Value; |
| 89 |
EventIsActive.Send(Value, Time); |
| 90 |
if Value then |
| 91 |
EventEnterTime.Send(Time.Seconds, Time) else |
| 92 |
EventExitTime.Send(Time.Seconds, Time); |
| 93 |
end; |
| 94 |
end; |
| 95 |
|
| 96 |
procedure RegisterEnvironmentalSensorNodes; |
| 97 |
begin |
| 98 |
NodesManager.RegisterNodeClasses([ |
| 99 |
TProximitySensorNode, |
| 100 |
TTransformSensorNode, |
| 101 |
TVisibilitySensorNode |
| 102 |
]); |
| 103 |
end; |
| 104 |
|
| 105 |
{$endif read_implementation} |