-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLuminaire.m
More file actions
88 lines (75 loc) · 2.41 KB
/
Copy pathLuminaire.m
File metadata and controls
88 lines (75 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
classdef Luminaire < SimulationObject & Equipment
%LUMINAIRE Luminaire class
% Detailed explanation goes here
properties
Sensors Sensor
View = 'narrow'
Orientation = 'landscape'
Graphic
State
end
properties (Dependent, SetAccess = protected)
ActiveSensor
Shape
end
methods
function sensor = get.ActiveSensor(obj)
sensor = findobj(obj.Sensors, 'View', obj.View);
end
function shape = get.Shape(obj)
switch obj.Orientation
case 'landscape'
h = 2;
w = 4;
case 'portrait'
h = 4;
w = 2;
end
x = w*[0, 0, 1, 1]';
y = h*[0, 1, 1, 0]';
shape = [x,y];
end
function render(obj, sim, varargin)
if nargin == 3
arrayfun(@(o)prender(o, sim, varargin{1}),obj);
else
arrayfun(@(o)prender(o, sim),obj);
end
end
end
methods (Access = private)
function prender(obj, sim, varargin)
if nargin == 3
render(obj.ActiveSensor, sim, varargin{1});
else
render(obj.ActiveSensor, sim);
end
X = obj.Shape(:,1) + obj.Position(1);
Y = obj.Shape(:,2) + obj.Position(2);
Z = 2*ones(size(X));
if nargin == 3
ax = varargin{1};
else
ax = gca;
end
if isgraphics(obj.Graphic)
obj.Graphic.XData = X;
obj.Graphic.YData = Y;
obj.Graphic.ZData = Z;
else
obj.Graphic = patch(ax,'XData',X,'YData',Y,'ZData',Z,'FaceColor','yellow','EdgeColor','black');
end
state = obj.State(obj.SimRelTime == sim.Clock);
if state == 1
obj.Graphic.FaceColor = [255 255 0]/255;
obj.Graphic.FaceAlpha = 1;
elseif state == 0
obj.Graphic.FaceColor = 'black';
obj.Graphic.FaceAlpha = 0;
else
obj.Graphic.FaceColor = state*[255 255 0]/255;
obj.Graphic.FaceAlpha = 0.75;
end
end
end
end