-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguiClass.js
More file actions
209 lines (184 loc) · 7.86 KB
/
guiClass.js
File metadata and controls
209 lines (184 loc) · 7.86 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/* Description: Custom GUI class for Rotation Visualization
*
* This class is used to create a custom GUI for the rotation visualization.
* The GUI manages all display text and stores user inputs.
*/
class CustomGUI {
constructor() {
this._controlsLabel = createDiv('<b>Object Control</b>');
// Buttons
this._animateButton = createButton('Animate');
this._wireframeButton = createButton('Toggle Wireframe');
this._EulButton = createButton('Euler');
this._RPYButton = createButton('RPY');
this._resetButton = createButton('Reset');
// Inputs
this._rollInput = createInput("0","number");
this._pitchInput = createInput("0","number")
this._yawInput = createInput("0","number")
this._rollSlider = createSlider(-180, 180, 0, 1);
this._pitchSlider = createSlider(-180, 180, 0, 1);
this._yawSlider = createSlider(-180, 180, 0, 1);
// For Syncing Sliders and Inputs
this.prevRoll = 0;
this.prevPitch = 0;
this.prevYaw = 0;
// Labels
this._rollLabel = createDiv("Roll")
this._pitchLabel = createDiv("Pitch")
this._yawLabel = createDiv("Yaw")
// Currently Selected Rotation Type
this.rotationType = "RPY";
this.rotationAxis = "";
this._rotationTypeLabel = createDiv("Current Rotation Type: " + this.rotationType)
// Toggle wireframe view
this.wireframe = false;
// Animation Requesed?
this.animationRequested = false;
}
/*
* Initialize the GUI
*/
init() {
this._controlsLabel.position(601, 255);
this._controlsLabel.style('font-size','20px');
this._controlsLabel.style('text-align','center');
this._controlsLabel.style('width','239px');
this._controlsLabel.style('background-color','rgb(200,200,200)');
this._animateButton.position(610, 10);
this._animateButton.size(105,50);
this._resetButton.position(725, 10);
this._resetButton.size(105,50);
this._EulButton.position(725, 70);
this._EulButton.size(105,50);
this._RPYButton.position(610, 70);
this._RPYButton.size(105,50);
this._wireframeButton.position(610, 130);
this._wireframeButton.size(220,30);
this._rollLabel.position(665,169)
this._rollInput.position(610,165)
this._rollSlider.position(700,168)
this._rollInput.size(40,20)
this._pitchLabel.position(665,199)
this._pitchInput.position(610,195)
this._pitchSlider.position(700,198)
this._pitchInput.size(40,20)
this._yawLabel.position(665,229)
this._yawInput.position(610,225)
this._yawSlider.position(700,228)
this._yawInput.size(40,20)
this._rotationTypeLabel.position(10, 10)
// Interactive Callbacks
// Using inline functions used to avoid scope issues (cant use 'this' in callback functions)
this._EulButton.mousePressed(() => this.rotationType = "Euler");
this._RPYButton.mousePressed(() => this.rotationType = "RPY");
this._animateButton.mousePressed(() => this.animationRequested = true);
this._wireframeButton.mousePressed(() => this.wireframe = !this.wireframe);
this._resetButton.mousePressed(() => this.resetAngles(this._rollInput,this._pitchInput,this._yawInput));
// Highlight the selected rotation axis
this._rollSlider.mouseOver(() => this.rotationAxis = 1);
this._rollInput.mouseOver(() => this.rotationAxis = 1);
this._pitchSlider.mouseOver(() => this.rotationAxis = 2);
this._pitchInput.mouseOver(() => this.rotationAxis = 2);
this._yawSlider.mouseOver(() => this.rotationAxis = 3);
this._yawInput.mouseOver(() => this.rotationAxis = 3);
this._rollSlider.mouseOut(() => this.rotationAxis = 0);
this._rollInput.mouseOut(() => this.rotationAxis = 0);
this._pitchSlider.mouseOut(() => this.rotationAxis = 0);
this._pitchInput.mouseOut(() => this.rotationAxis = 0);
this._yawSlider.mouseOut(() => this.rotationAxis = 0);
this._yawInput.mouseOut(() => this.rotationAxis = 0);
}
updateElementColor(element, color) {
element.style('background-color', color);
}
/*
* Update the GUI.
* Synchronize input methods and display the current rotation type.
*/
update() {
// Sync Sliders and Inputs
if (this.prevRoll != this._rollInput.value()) {
this._rollSlider.value(this._rollInput.value());
} else if (this.prevRoll != this._rollSlider.value()) {
this._rollInput.value(this._rollSlider.value());
}
if (this.prevPitch != this._pitchInput.value()) {
this._pitchSlider.value(this._pitchInput.value());
} else if (this.prevPitch != this._pitchSlider.value()) {
this._pitchInput.value(this._pitchSlider.value());
}
if (this.prevYaw != this._yawInput.value()) {
this._yawSlider.value(this._yawInput.value());
} else if (this.prevYaw != this._yawSlider.value()) {
this._yawInput.value(this._yawSlider.value());
}
this.prevRoll = this._rollInput.value();
this.prevPitch = this._pitchInput.value();
this.prevYaw = this._yawInput.value();
// Display Rotation Type Selection
if (this.rotationType == "Euler") {
this._EulButton.style('background-color', 'rgb(0,255,0)');
this._RPYButton.style('background-color', 'rgb(255,255,255)');
this._rotationTypeLabel.html("<b>Rotation Mode: Euler Convention</b> <p><b style='color:blue;'>Roll (Local Z)</b> → <b style='color:red'> Pitch (Local X)</b> → <b style='color:green'>Yaw (Local Y)</b></p>");
} else if (this.rotationType == "RPY") {
this._RPYButton.style('background-color', 'rgb(0,255,0)');
this._EulButton.style('background-color', 'rgb(255,255,255)');
this._rotationTypeLabel.html('<b>Rotation Mode: RPY Convention</b> <p><b style="color:red;">Roll (Global X)</b> → <b style="color:green"> Pitch (Global Y)</b> → <b style="color:blue">Yaw (Global Z)</b></p>');
}
}
/*
* Reset the angles to 0
* Input: rollInput, pitchInput, yawInput (p5.js input objects)
*/
resetAngles(rollInput, pitchInput, yawInput) {
rollInput.value(0);
pitchInput.value(0);
yawInput.value(0);
}
/*
* Get the current rotation type
* Returns: "Euler" or "RPY"
*/
getRotation() {
return [this.rotationType, this.rotationAxis];
}
/*
* Get the angles from the GUI inputs
* Returns: [roll, pitch, yaw]
*/
getAngles() {
return [this._rollInput.value()*PI/180, this._pitchInput.value()*PI/180, this._yawInput.value()*PI/180];
}
/*
* Check if an animation has been requested
* If an animation has been requested, reset the flag
* Returns: true if an animation has been requested, false otherwise
*/
checkAnimationRequest() {
if (this.animationRequested) {
this.animationRequested = false;
return true;
}
return false;
}
/*
* Show the GUI buttons
*/
showButtons() {
this._EulButton.show()
this._RPYButton.show()
this._resetButton.show()
this._animateButton.show()
}
/*
* Hide the GUI buttons
* Used when an animation is in progress
*/
hideButtons() {
this._EulButton.hide()
this._RPYButton.hide()
this._resetButton.hide()
this._animateButton.hide()
}
}