-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlive.html
More file actions
121 lines (101 loc) · 3.19 KB
/
live.html
File metadata and controls
121 lines (101 loc) · 3.19 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<html lang="zh">
<head>
<meta charset="utf-8">
</head>
<body>
<input type="submit" name="submit" id="live" onclick="live();" value="ok" style="width: 85px; height: 60px;" />
<font size="300">
<br>
<input type="text" name="x" id="x1" value=0 style="width:500px; height: 100px; font-size:90; text-align: right;" />RPY:R
<br>
<input type="text" name="y" id="y1" value=0 style="width:500px; height: 100px; font-size:90; text-align: right;" />RPY:P
<br>
<input type="text" name="z" id="z1" value=0 style="width:500px; height: 100px; font-size:90; text-align: right;" />RPY:Y
<br><br><br>
<input type="text" name="x" id="x" value=0 style="width:500px; height: 100px; font-size:90; text-align: right;" />方位角
<br>
<input type="text" name="y" id="y" value=0 style="width:500px; height: 100px; font-size:90; text-align: right;" />高度角
<br>
<input type="text" name="z" id="z" value=0 style="width:500px; height: 100px; font-size:90; text-align: right;" />旋转角
<br>
</font>
<script language=javascript>
function int2(v) { return Math.floor(v); }
function abs(x) { return Math.abs(x); }
function sin(x) { return Math.sin(x); }
function cos(x) { return Math.cos(x); }
function tan(x) { return Math.tan(x); }
function cot(x) { return 1/tan(x); }
function asin(x) { return Math.asin(x); }
function acos(x) { return Math.acos(x); }
function atan(x) { return Math.atan(x); }
function atan2(y,x){ return Math.atan2(y,x); }
function sgn(x)
{
if(x>0)return 1;
if(x<0)return -1;
if(x==0)return 0;
}
function int(v) { return int2(abs(v))*sgn(v); }
var pi=3.14159265358979323;
var isdirection=0;
function Rmat1()
{
var a=direction_current[0]/180*pi;
var b=direction_current[1]/180*pi;
var c=direction_current[2]/180*pi;
x2=atan2(-cos(a)*sin(c)-sin(a)*sin(b)*cos(c),-sin(a)*sin(c)+cos(a)*sin(b)*cos(c))/pi*180;
o=atan2(cos(b)*sin(c),sin(b))/pi*180;
y2=-asin(cos(b)*cos(c))/pi*180;
if(x2<0)x2+=360;
return new pos3(x2,y2,o);
}
function pos3(x,y,z)
{
this.x=x;
this.y=y;
this.z=z;
}
direction_current=new Array(3);
function orientationHandler(event) {
console.log(event);
direction_current=[event.alpha,event.beta,event.gamma];
}
function setdirection() {
if (window.DeviceOrientationEvent) {
window.addEventListener("deviceorientationabsolute", orientationHandler, false);
}
}
isdirection=0;
dtime=1;
timedCount = function ()
{
if (isdirection==0)
return;
directioning=setTimeout("timedCount();",100);
setdirection();
var a=direction_current[0]/180*pi;
var b=direction_current[1]/180*pi;
var c=direction_current[2]/180*pi;
x2=atan2(-cos(a)*sin(c)-sin(a)*sin(b)*cos(c),-sin(a)*sin(c)+cos(a)*sin(b)*cos(c))/pi*180;
z2=atan2(cos(b)*sin(c),sin(b))/pi*180;
y2=-asin(cos(b)*cos(c))/pi*180;
if(x2<0)x2+=360;
document.getElementById('x').value=int(x2);
document.getElementById('y').value=int(y2);
document.getElementById('z').value=int(z2);
document.getElementById('x1').value=int(a*180/pi);
document.getElementById('y1').value=int(b*180/pi);
document.getElementById('z1').value=int(c*180/pi);
}
live = function ()
{
isdirection=1-isdirection;
timedCount();
if (isdirection==0)
window.removeEventListener("deviceorientation", orientationHandler, false);
}
live();
</script>
</body>
</html>