-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnect.js
More file actions
143 lines (119 loc) · 3.75 KB
/
Copy pathconnect.js
File metadata and controls
143 lines (119 loc) · 3.75 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
const LOCAL_DEV = false; // Set to false when running against the actual server
var host = "cpsc484-01.stdusr.yale.internal:8888";
array = []
function setup() {
frames.start();
console.log(frames)
sp2tx.start();
}
var frames = {
socket: null,
start: function() {
var url = "ws://" + host + "/frames";
this.socket = new WebSocket(url);
this.socket.onmessage = function(event) {
frames.processFrame(JSON.parse(event.data));
};
},
processFrame: function(data) {
if (data.people) {
for (const person of data.people) {
// Process each person's data
this.processPerson(person);
}
}
},
processPerson: function(person) {
console.log(person)
const bodyId = person.body_id;
const joints = person.joints;
const handLeft = joints[8]; //;make this 7
const handRight = joints[14];
const head = joints[26]
this.checkPosture(head, handLeft, handRight, bodyId);
},
checkPosture: function(
head,
handLeft,
handRight,
bodyId
) {
const raiseThreshold = -100;
const timeRequired = 3000; // milliseconds the hand must be held up
if (handLeft.position.y < head.position.y
+ raiseThreshold && handRight.position.y < head.position.y + raiseThreshold) { // Both hands up
// both hands up
this.selectOption(1, bodyId)
}
else if (
handLeft.position.y < head.position.y + raiseThreshold
) {
// left hand up
this.selectOption(2, bodyId);
} else if (
handRight.position.y < head.position.y + raiseThreshold) {
// right hand up
this.selectOption(3, bodyId);
} else if (handLeft.position.x > head.position.x + 500 &&
handRight.position.x < head.position.x - 500) {
// both hands out
this.selectOption(4, bodyId);
}
else if (
handLeft.position.x > head.position.x + 500) {
// left hand out
this.selectOption(5, bodyId);
} else if (handRight.position.x < head.position.x - 500) {
// right hand out
this.selectOption(6, bodyId);
}
},
selectOption: function(optionNumber, bodyId) {
console.log(`Body ID ${bodyId} selected option ${optionNumber}`);
option = 0
if (array.length == 0) {
array.push(optionNumber)
} else {
if (array.length > 15) { // adjust this to increase/decreaes time before registering position
console.log("array length", array.length)
option = optionNumber
}
if (optionNumber != array[array.length - 1]) {
array = []
} else {
array.push(optionNumber)
}
}
function getParameterByName(name) {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get(name);
}
city = getParameterByName('cityName')
budget = getParameterByName('budgetAmount')
if (option != 0) {
array = []
}
if (option === 1) {
// Exit, go back to home
console.log("Option 1 selected - Both hands raised");
window.location.href = "index.html";
} else if (option === 2) {
console.log("Option 2 selected - Left hand raised");
} else if (option === 3) {
console.log("Option 3 selected - Right hand raised");
} else if (option === 4) {
console.log("Option 4 selected - Both hands out");
// go back, go to previous page
window.location.href = "itinerary.html?cityName=" + city + "&budgetAmount=" + budget;
} else if (option == 5) {
console.log("Option 5 selected - Left hand out");
} else if (option == 6) {
console.log("Option 6 selected - Right hand out");
}
},
};
// Event listener
document.addEventListener('DOMContentLoaded', function() {
setup();
// document.getElementById('navigateButton').addEventListener('click', navigateToPage);
});