-
Notifications
You must be signed in to change notification settings - Fork 3
/
RotateBox.m
67 lines (55 loc) · 1.19 KB
/
RotateBox.m
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
% RotateBox
% Rotates 3D box based on phone orientation
% Enable Connector
connector on
if exist('m', 'var')
clear m
end
% Connect to device
m = mobiledev;
% Create a 3D box with multi-colored sides
X = [ 0 1 1 0 0 0;
1 1 0 0 1 1;
1 1 0 0 1 1;
0 1 1 0 0 0];
Y = [ 0 0 1 1 0 0;
0 1 1 0 0 0;
0 1 1 0 1 1;
0 0 1 1 1 1];
Z = [ 0 0 0 0 0 1;
0 0 0 0 0 1;
1 1 1 1 0 1;
1 1 1 1 0 1];
h = patch(4*X-2,8*Y-4,Z, 1:6);
% Set plot display
xlim([-5 5]);
ylim([-5 5]);
zlim([-5 5]);
% Enable Sensor and Start Logging Data
m.OrientationSensorEnabled=1;
m.Logging=1;
% Collect Data while phone is rotated
% pause(5);
pause(1)
% Read Data from Log
[o, t] = orientlog(m);
% Measure differences in rotations
% Rotate 3D Box in same fashion as phone
for k = 1:200
set(h, 'XData', 4*X-2, 'YData', 8*Y-4, 'ZData', Z);
% Read Data from Log
[o, t] = orientlog(m);
if ~isempty(o)
discardlogs(m)
rotate(h, [1 0 0], -o(1,2)); % pitch
rotate(h, [0 1 0], o(1,3)); % roll
rotate(h, [0 0 1], -o(1,1)+65); % azimuth
end
pause(1)
end
% Stop Logging
m.Logging=0;
% clean up
close all
clear m
connector off