fermisurfer Git
修訂 | 4ab2a5e0912eb16dfa1a8944b33736e8e8686d7c (tree) |
---|---|
時間 | 2020-12-21 01:09:26 |
作者 | Mitsuaki Kawamura <kawamitsuaki@gmai...> |
Commiter | Mitsuaki Kawamura |
backup
@@ -111,11 +111,7 @@ function main() { | ||
111 | 111 | |
112 | 112 | var el = document.getElementById("glcanvas"); |
113 | 113 | el.addEventListener("touchstart", handleStart, false); |
114 | - el.addEventListener("touchend", handleEnd, false); | |
115 | - el.addEventListener("touchcancel", handleCancel, false); | |
116 | 114 | el.addEventListener("touchmove", handleMove, false); |
117 | - //el.addEventListener("mousemove", mouseMove, false); | |
118 | - | |
119 | 115 | } |
120 | 116 | // |
121 | 117 | // Draw the scene. |
@@ -268,7 +264,7 @@ function drawScene() { | ||
268 | 264 | icount = 0; |
269 | 265 | for (ibzl = 0; ibzl < nbzl; ++ibzl) { |
270 | 266 | for (i = 0; i < 2; ++i) { |
271 | - for (j = 0; j < 3; ++j) { | |
267 | + for (j = 0; j < 4; ++j) { | |
272 | 268 | colors[icount] = LineColor[j]; |
273 | 269 | icount += 1; |
274 | 270 | } |
@@ -428,67 +424,53 @@ function loadShader(gl, type, source) { | ||
428 | 424 | return shader; |
429 | 425 | } |
430 | 426 | |
431 | -var ongoingTouches = []; | |
427 | +let touch0x = 0.0; | |
428 | +let touch0y = 0.0; | |
429 | +let touch1x = 0.0; | |
430 | +let touch1y = 0.0; | |
432 | 431 | |
433 | 432 | function handleStart(evt) { |
434 | 433 | evt.preventDefault(); |
435 | 434 | var touches = evt.changedTouches; |
436 | 435 | |
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 | + } | |
439 | 445 | } |
440 | 446 | } |
441 | 447 | |
442 | 448 | function handleMove(evt) { |
443 | 449 | evt.preventDefault(); |
444 | 450 | var touches = evt.changedTouches; |
451 | + let dx = 0.0, dy = 0.0, dold = 0.0, dnew = 0.; | |
445 | 452 | |
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) | |
452 | 458 | 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; | |
467 | 461 | } |
468 | 462 | } |
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(); | |
490 | 473 | } |
491 | - return -1; // not found | |
492 | 474 | } |
493 | 475 | |
494 | 476 | let isDrawing = false; |
@@ -3143,32 +3125,31 @@ function compute_patch_segment() { | ||
3143 | 3125 | } |
3144 | 3126 | } |
3145 | 3127 | function update_delay() { |
3146 | - terminal("uptedate\n"); | |
3147 | 3128 | compute_patch_segment() |
3148 | 3129 | drawScene(); |
3149 | 3130 | } |
3150 | 3131 | 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); | |
3158 | 3139 | // |
3159 | 3140 | // Back ground color |
3160 | 3141 | // |
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); | |
3164 | 3145 | // |
3165 | 3146 | //Rotate, scale, translate |
3166 | 3147 | // |
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); | |
3172 | 3153 | rot[0][0] = Math.cos(thetay) * Math.cos(thetaz); |
3173 | 3154 | rot[0][1] = -Math.cos(thetay) * Math.sin(thetaz); |
3174 | 3155 | rot[0][2] = Math.sin(thetay); |
@@ -3178,16 +3159,15 @@ function update_now() { | ||
3178 | 3159 | rot[2][0] = -Math.cos(thetax) * Math.cos(thetaz) * Math.sin(thetay) + Math.sin(thetax) * Math.sin(thetaz); |
3179 | 3160 | rot[2][1] = Math.cos(thetaz) * Math.sin(thetax) + Math.cos(thetax) * Math.sin(thetay) * Math.sin(thetaz); |
3180 | 3161 | rot[2][2] = Math.cos(thetax) * Math.cos(thetay); |
3181 | - scl = document.getElementById("scale").value; | |
3182 | - | |
3162 | + scl = Number(document.getElementById("scale").value); | |
3183 | 3163 | drawScene(); |
3184 | 3164 | } |
3185 | 3165 | function update_interpol() { |
3186 | - interpol = document.getElementById("interpol").value; | |
3166 | + interpol = Number(document.getElementById("interpol").value); | |
3187 | 3167 | refresh_interpol = 1; |
3188 | 3168 | } |
3189 | 3169 | function update_efermi(){ |
3190 | - EF = document.getElementById("fermienergy").value; | |
3170 | + EF = Number(document.getElementById("fermienergy").value); | |
3191 | 3171 | refresh_patch = 1; |
3192 | 3172 | } |
3193 | 3173 | function update_color() { |
@@ -3195,8 +3175,8 @@ function update_color() { | ||
3195 | 3175 | refresh_color = 1; |
3196 | 3176 | } |
3197 | 3177 | 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); | |
3200 | 3180 | refresh_color = 1; |
3201 | 3181 | skip_minmax = 1; |
3202 | 3182 | } |