summaryrefslogtreecommitdiffhomepage
path: root/FaceTrackNoIR/ClientFiles/FlightGear/Nasal/headtracker.xml
blob: 0d6e800582819dd6a588714711bdc1e7277534cd (plain)
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
<?xml version="1.0"?>

<PropertyList>
	<input>
		<keyboard>
			<key n="61">
				<name>= (equal sign)</name>
				<desc>Reset Head Tracker</desc>
				<binding>
					<command>nasal</command>
					<script>headtracker.reset()</script>
				</binding>
			</key>
		</keyboard>
	</input>

	<nasal>
		<headtracker>
			<script>
				var Value = {
					new: func(prop) {
						var m = { parents: [Value] };
						m.prop = props.globals.getNode(prop, 1);
						m.lowpass = aircraft.lowpass.new(0.7);
						m.value = 0;
						return m;
					},
					apply: func(value) {
						value = me.lowpass.filter(value);
						me.prop.setDoubleValue(me.prop.getValue() - me.value + value);
						me.value = value;
					},
				};


				var x = Value.new("/sim/current-view/x-offset-m");
				var y = Value.new("/sim/current-view/y-offset-m");
				var z = Value.new("/sim/current-view/z-offset-m");
				var h = Value.new("/sim/current-view/heading-offset-deg");
				var p = Value.new("/sim/current-view/pitch-offset-deg");
				var r = Value.new("/sim/current-view/roll-offset-deg");


				var resetting = 0;
				var status = nil;

				var reset = func {
					if (status != 1) {
						setprop("/sim/headtracker/control", 1);
						resetting = 1;
						view.resetViewPos();
						view.resetViewDir();
						x.value = y.value = z.value = h.value = p.value = r.value = 0;
					}
				}

				setlistener("/sim/headtracker/status", func(n) {
					var s = n.getValue();
					if (!status and s) {
						setprop("/sim/headtracker/control", 0);
						resetting = 0;
					}
					status = s;
				}, 1, 0);


				var loop = func {
					if (!view.index and !resetting) {
						x.apply(getprop("/sim/headtracker/x-m"));
						y.apply(getprop("/sim/headtracker/y-m"));
						z.apply(getprop("/sim/headtracker/z-m"));

						h.apply(getprop("/sim/headtracker/heading-deg"));
						p.apply(getprop("/sim/headtracker/pitch-deg"));
						r.apply(-1 * getprop("/sim/headtracker/roll-deg"));
					}
					settimer(loop, 0);
				}

				loop();

				gui.popupTip("press '=' (equal sign) to reset head tracker", 20);
			</script>
		</headtracker>
	</nasal>

	<sim>
		<headtracker>
			<x-m type="double">0</x-m>
			<y-m type="double">0</y-m>
			<z-m type="double">0</z-m>
			<heading-deg type="double">0</heading-deg>
			<pitch-deg type="double">0</pitch-deg>
			<roll-deg type="double">0</roll-deg>
			<status type="int">0</status>
			<control type="int">0</control>
		</headtracker>
	</sim>
</PropertyList>