• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

fermisurfer Git


Commit MetaInfo

修訂4ab2a5e0912eb16dfa1a8944b33736e8e8686d7c (tree)
時間2020-12-21 01:09:26
作者Mitsuaki Kawamura <kawamitsuaki@gmai...>
CommiterMitsuaki Kawamura

Log Message

backup

Change Summary

差異

--- a/javascript/fermisurfer.js
+++ b/javascript/fermisurfer.js
@@ -111,11 +111,7 @@ function main() {
111111
112112 var el = document.getElementById("glcanvas");
113113 el.addEventListener("touchstart", handleStart, false);
114- el.addEventListener("touchend", handleEnd, false);
115- el.addEventListener("touchcancel", handleCancel, false);
116114 el.addEventListener("touchmove", handleMove, false);
117- //el.addEventListener("mousemove", mouseMove, false);
118-
119115 }
120116 //
121117 // Draw the scene.
@@ -268,7 +264,7 @@ function drawScene() {
268264 icount = 0;
269265 for (ibzl = 0; ibzl < nbzl; ++ibzl) {
270266 for (i = 0; i < 2; ++i) {
271- for (j = 0; j < 3; ++j) {
267+ for (j = 0; j < 4; ++j) {
272268 colors[icount] = LineColor[j];
273269 icount += 1;
274270 }
@@ -428,67 +424,53 @@ function loadShader(gl, type, source) {
428424 return shader;
429425 }
430426
431-var ongoingTouches = [];
427+let touch0x = 0.0;
428+let touch0y = 0.0;
429+let touch1x = 0.0;
430+let touch1y = 0.0;
432431
433432 function handleStart(evt) {
434433 evt.preventDefault();
435434 var touches = evt.changedTouches;
436435
437- for (var i = 0; i < touches.length; i++) {
438- ongoingTouches.push(copyTouch(touches[i]));
436+ for (i = 0; i < touches.length; i++) {
437+ if (touches[i].identifier == 0) {
438+ touch0x = touches[i].clientX;
439+ touch0y = touches[i].clientY;
440+ }
441+ else if (touches[i].identifier == 1) {
442+ touch1x = touches[i].clientX;
443+ touch1y = touches[i].clientY;
444+ }
439445 }
440446 }
441447
442448 function handleMove(evt) {
443449 evt.preventDefault();
444450 var touches = evt.changedTouches;
451+ let dx = 0.0, dy = 0.0, dold = 0.0, dnew = 0.;
445452
446- for (var i = 0; i < touches.length; i++) {
447- var idx = ongoingTouchIndexById(touches[i].identifier);
448-
449- if (idx == 0) {
450- rotatex += -0.01 * (touches[i].clientX - ongoingTouches[idx].clientX);
451- rotatey += 0.01 * (touches[i].clientY - ongoingTouches[idx].clientY);
453+ if (touches.length == 1) {
454+ if (touches[0].identifier == 0) {
455+ dx = 0.001 * (touches[0].clientX - touch0x);
456+ dy = 0.001 * (touches[0].clientY - touch0y);
457+ mouserotation(dx, dy)
452458 drawScene();
453- ongoingTouches.splice(idx, 1, copyTouch(touches[i])); // swap in the new touch record
454- }
455- }
456-}
457-function handleEnd(evt) {
458- evt.preventDefault();
459- var touches = evt.changedTouches;
460-
461- //log("touchend");
462- for (var i = 0; i < touches.length; i++) {
463- var idx = ongoingTouchIndexById(touches[i].identifier);
464-
465- if (idx >= 0) {
466- ongoingTouches.splice(idx, 1); // remove it; we're done
459+ touch0x = touches[0].clientX;
460+ touch0y = touches[0].clientY;
467461 }
468462 }
469-}
470-function handleCancel(evt) {
471- evt.preventDefault();
472- var touches = evt.changedTouches;
473-
474- for (var i = 0; i < touches.length; i++) {
475- var idx = ongoingTouchIndexById(touches[i].identifier);
476- ongoingTouches.splice(idx, 1); // remove it; we're done
477- }
478-}
479-function copyTouch({ identifier, clientX, clientY }) {
480- return { identifier, clientX, clientY };
481-}
482-
483-function ongoingTouchIndexById(idToFind) {
484- for (var i = 0; i < ongoingTouches.length; i++) {
485- var id = ongoingTouches[i].identifier;
486-
487- if (id == idToFind) {
488- return i;
489- }
463+ else if (touches.length == 2) {
464+ dold = Math.sqrt((touch1x - touch0x) * (touch1x - touch0x) + (touch1y - touch0y) * (touch1y - touch0y));
465+ touch0x = touches[0].clientX;
466+ touch0y = touches[0].clientY;
467+ touch1x = touches[1].clientX;
468+ touch1y = touches[1].clientY;
469+ dnew = Math.sqrt((touch1x - touch0x) * (touch1x - touch0x) + (touch1y - touch0y) * (touch1y - touch0y));
470+ scl += 0.001 * (dnew - dold);
471+ document.getElementById("scale").value = String(scl);
472+ drawScene();
490473 }
491- return -1; // not found
492474 }
493475
494476 let isDrawing = false;
@@ -3143,32 +3125,31 @@ function compute_patch_segment() {
31433125 }
31443126 }
31453127 function update_delay() {
3146- terminal("uptedate\n");
31473128 compute_patch_segment()
31483129 drawScene();
31493130 }
31503131 function update_now() {
3151- linewidth = document.getElementById("linewidth").value;
3152- /*
3153- Line color
3154- */
3155- LineColor[0] = document.getElementById("linecolorr").value;
3156- LineColor[1] = document.getElementById("linecolorg").value;
3157- LineColor[2] = document.getElementById("linecolorb").value;
3132+ linewidth = Number(document.getElementById("linewidth").value);
3133+ //
3134+ // Line color
3135+ //
3136+ LineColor[0] = Number(document.getElementById("linecolorr").value);
3137+ LineColor[1] = Number(document.getElementById("linecolorg").value);
3138+ LineColor[2] = Number(document.getElementById("linecolorb").value);
31583139 //
31593140 // Back ground color
31603141 //
3161- BackGroundColor[0] = document.getElementById("backgraoundr").value;
3162- BackGroundColor[1] = document.getElementById("backgraoundg").value;
3163- BackGroundColor[2] = document.getElementById("backgraoundb").value;
3142+ BackGroundColor[0] = Number(document.getElementById("backgraoundr").value);
3143+ BackGroundColor[1] = Number(document.getElementById("backgraoundg").value);
3144+ BackGroundColor[2] = Number(document.getElementById("backgraoundb").value);
31643145 //
31653146 //Rotate, scale, translate
31663147 //
3167- thetax = document.getElementById("rotatex").value;
3168- thetay = document.getElementById("rotatey").value;
3169- thetaz = document.getElementById("rotatez").value;
3170- trans[0] = document.getElementById("positionx").value;
3171- trans[1] = document.getElementById("positiony").value;
3148+ trans[0] = Number(document.getElementById("positionx").value);
3149+ trans[1] = Number(document.getElementById("positiony").value);
3150+ thetax = Number(document.getElementById("rotatex").value);
3151+ thetay = Number(document.getElementById("rotatey").value);
3152+ thetaz = Number(document.getElementById("rotatez").value);
31723153 rot[0][0] = Math.cos(thetay) * Math.cos(thetaz);
31733154 rot[0][1] = -Math.cos(thetay) * Math.sin(thetaz);
31743155 rot[0][2] = Math.sin(thetay);
@@ -3178,16 +3159,15 @@ function update_now() {
31783159 rot[2][0] = -Math.cos(thetax) * Math.cos(thetaz) * Math.sin(thetay) + Math.sin(thetax) * Math.sin(thetaz);
31793160 rot[2][1] = Math.cos(thetaz) * Math.sin(thetax) + Math.cos(thetax) * Math.sin(thetay) * Math.sin(thetaz);
31803161 rot[2][2] = Math.cos(thetax) * Math.cos(thetay);
3181- scl = document.getElementById("scale").value;
3182-
3162+ scl = Number(document.getElementById("scale").value);
31833163 drawScene();
31843164 }
31853165 function update_interpol() {
3186- interpol = document.getElementById("interpol").value;
3166+ interpol = Number(document.getElementById("interpol").value);
31873167 refresh_interpol = 1;
31883168 }
31893169 function update_efermi(){
3190- EF = document.getElementById("fermienergy").value;
3170+ EF = Number(document.getElementById("fermienergy").value);
31913171 refresh_patch = 1;
31923172 }
31933173 function update_color() {
@@ -3195,8 +3175,8 @@ function update_color() {
31953175 refresh_color = 1;
31963176 }
31973177 function update_minmax() {
3198- patch_min = document.getElementById("scalemin").value;
3199- patch_max = document.getElementById("scalemax").value;
3178+ patch_min = Number(document.getElementById("scalemin").value);
3179+ patch_max = Number(document.getElementById("scalemax").value);
32003180 refresh_color = 1;
32013181 skip_minmax = 1;
32023182 }