Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commitd31ecfbf0e16069163e82ee33f815174de2391f6 (patch)
Author
 Syndamia <kamen@syndamia.com>
2023-08-27 16:24:25 +0300
Committer
 Syndamia <kamen@syndamia.com>
2023-08-27 16:24:25 +0300
Filesfff6bea135b5688c2338fdf3745c19c7c324a923
uni-projects-d31ecfbf0e16069163e82ee33f815174de2391f6.tar
uni-projects-d31ecfbf0e16069163e82ee33f815174de2391f6.tar.gz
uni-projects-d31ecfbf0e16069163e82ee33f815174de2391f6.zip
Parent034d9301fdd5cc70648e2cd9a6ae202b89eebe39 (diff)
[WGL/P] Added coordinates in the top left corner
diff --git a/Year 2/Computer Graphics with WebGL/Project/Project.html b/Year 2/Computer Graphics with WebGL/Project/Project.html
index c4d090c..b4463df 100644
--- a/Year 2/Computer Graphics with WebGL/Project/Project.html
+++ b/Year 2/Computer Graphics with WebGL/Project/Project.html
@@ -59,6 +59,12 @@ h2 {
max-width: 24em;
max-height: calc(100vh - 0.5em);
}
+#coordinates {
+ left: 0;
+ top: 0;
+ color: white;
+ position: absolute;
+}
</style>
<script src="spaceship.js"></script>
@@ -165,10 +171,12 @@ h2 {
<h2>Settings</h2>
<p>
Debug mode: <input type="checkbox" id="debug-mode"><br>
+ Toggle coordinates: <input type="checkbox" id="coordinates-cb"><br>
Only horizontal mouse movement: <input type="checkbox" id="only-horizontal"><br>
Only vertical mouse movement: <input type="checkbox" id="only-vertical">
</p>
</div>
</div>
+ <div id="coordinates"></div>
<script src="menu.js"></script>
</body>
diff --git a/Year 2/Computer Graphics with WebGL/Project/menu.js b/Year 2/Computer Graphics with WebGL/Project/menu.js
index 9b61ef7..0b56d2b 100644
--- a/Year 2/Computer Graphics with WebGL/Project/menu.js
+++ b/Year 2/Computer Graphics with WebGL/Project/menu.js
@@ -30,6 +30,17 @@ function verChange() {
verChange.call(onlyVerticalCB);
onlyVerticalCB.addEventListener('change', verChange);
+coordsElem = document.getElementById('coordinates');
+const coordsCB = document.getElementById('coordinates-cb');
+function coordscbChange() {
+ if (this.checked)
+ coordsElem.classList.remove('hide');
+ else
+ coordsElem.classList.add('hide');
+}
+coordscbChange.call(coordsCB);
+coordsCB.addEventListener('change', coordscbChange);
+
/* Levels */
const levelSelect = document.getElementById('level-select');
diff --git a/Year 2/Computer Graphics with WebGL/Project/spaceship.js b/Year 2/Computer Graphics with WebGL/Project/spaceship.js
index 5b98229..a50f2fc 100644
--- a/Year 2/Computer Graphics with WebGL/Project/spaceship.js
+++ b/Year 2/Computer Graphics with WebGL/Project/spaceship.js
@@ -150,8 +150,13 @@ function mouseInit() {
/*
* On every draw
*/
+coordsElem = undefined;
+
function updateCamera() {
for (var i = 0; i < pressedKeys.length; i++)
if (pressedKeys[i]) keyAction[i]();
lookAt(pos, vecSum(pos, forward.toCartesian()), up.toCartesian());
+ if (coordsElem) {
+ coordsElem.innerText = 'X: '+pos[0]+' Y: '+pos[1]+' Z: '+pos[2];
+ }
}