Changeset 20771
- Timestamp:
- 06/18/16 16:38:40 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/plot/webgl.js
r20770 r20771 47 47 canvas.gl = gl; 48 48 canvas.zoomBounds = options.getfieldvalue('zoomlim',[0.001,100.0]); 49 canvas.zoom Factor= clamp(options.getfieldvalue('zoom',1.0), canvas.zoomBounds[0], canvas.zoomBounds[1]);50 canvas.zoomLast = canvas.zoom Factor;49 canvas.zoom = clamp(options.getfieldvalue('zoom',1.0), canvas.zoomBounds[0], canvas.zoomBounds[1]); 50 canvas.zoomLast = canvas.zoom; 51 51 canvas.cameraMatrix = mat4.create(); 52 52 canvas.translation = options.getfieldvalue('origin',[0,0,0.0]); 53 53 canvas.rotationAzimuthBounds = options.getfieldvalue('azlim',[0,360]); 54 54 canvas.rotationElevationBounds = options.getfieldvalue('ellim',[-180,180]); 55 canvas. rotationDefault= options.getfieldvalue('view',[0,90]); //0 azimuth - up is north, 90 elevation - looking straight down56 canvas.rotation = canvas. rotationDefault;55 canvas.view = options.getfieldvalue('view',[0,90]); //0 azimuth - up is north, 90 elevation - looking straight down 56 canvas.rotation = canvas.view; 57 57 canvas.controlsensitivity = options.getfieldvalue('controlsensitivity',1); 58 58 canvas.twod = options.getfieldvalue('2d','off') == 'on'; … … 180 180 return Math.max(min, Math.min(value, max)); 181 181 } //}}} 182 function recover view(canvasid,defaultview) { //{{{182 function recover(canvasid,name,defaultvalue) { //{{{ 183 183 var canvas = document.getElementById(canvasid); 184 if (canvas && canvas.hasOwnProperty("rotation")) { 185 return canvas.rotation; 186 } 187 return defaultview; 188 } //}}} 189 function recovercenteroffset(canvasid,defaultcenter) { //{{{ 190 var canvas = document.getElementById(canvasid); 191 if (canvas && canvas.hasOwnProperty("translation")) { 192 return canvas.translation; 193 } 194 return defaultcenter; 184 if (canvas && canvas.hasOwnProperty(name)) { 185 return canvas[name]; 186 } 187 return defaultvalue; 195 188 } //}}} 196 189 //}}} … … 339 332 } 340 333 if (ev.srcEvent.shiftKey || ev.pointers.length == 2) { 341 var deltaX = (canvas.lastDeltaX - ev.deltaX) / canvas.clientWidth / canvas.zoom Factor* -2 * canvas.controlsensitivity;342 var deltaY = (canvas.lastDeltaY - ev.deltaY) / canvas.clientHeight / canvas.zoom Factor* -2 * canvas.controlsensitivity;334 var deltaX = (canvas.lastDeltaX - ev.deltaX) / canvas.clientWidth / canvas.zoom * -2 * canvas.controlsensitivity; 335 var deltaY = (canvas.lastDeltaY - ev.deltaY) / canvas.clientHeight / canvas.zoom * -2 * canvas.controlsensitivity; 343 336 344 337 canvas.translation[0] += Math.cos(radians(canvas.rotation[0])) * deltaX - Math.sin(radians(canvas.rotation[0])) * deltaY; … … 346 339 } 347 340 else { 348 canvas.rotation[0] += degrees((canvas.lastDeltaX - ev.deltaX) / canvas.clientWidth / canvas.zoom Factor* -2 * canvas.controlsensitivity);349 canvas.rotation[1] += degrees((canvas.lastDeltaY - ev.deltaY) / canvas.clientHeight / canvas.zoom Factor* -2 * canvas.controlsensitivity);341 canvas.rotation[0] += degrees((canvas.lastDeltaX - ev.deltaX) / canvas.clientWidth / canvas.zoom * -2 * canvas.controlsensitivity); 342 canvas.rotation[1] += degrees((canvas.lastDeltaY - ev.deltaY) / canvas.clientHeight / canvas.zoom * -2 * canvas.controlsensitivity); 350 343 351 344 if (canvas.rotation[0] > 360) {canvas.rotation[0] -= 360}; … … 365 358 ev.preventDefault(); 366 359 if (ev.type == 'pinchstart') { 367 canvas.zoomLast = canvas.zoom Factor;360 canvas.zoomLast = canvas.zoom; 368 361 } 369 362 else { 370 canvas.zoom Factor= clamp(ev.scale * canvas.zoomLast, canvas.zoomBounds[0], canvas.zoomBounds[1]);371 if (displaylog) console.log(canvas.zoom Factor);363 canvas.zoom = clamp(ev.scale * canvas.zoomLast, canvas.zoomBounds[0], canvas.zoomBounds[1]); 364 if (displaylog) console.log(canvas.zoom); 372 365 } 373 366 } //}}} 374 367 function onZoom(ev,canvas,displaylog) { //{{{ 375 368 ev.preventDefault(); 376 var delta = clamp(clamp(ev.scale || ev.wheelDelta || -ev.detail, -1, 1) * canvas.controlsensitivity * canvas.zoom Factor/ 20, -1.0, 1.0);377 canvas.zoom Factor = clamp(canvas.zoomFactor+ delta, canvas.zoomBounds[0], canvas.zoomBounds[1]);378 379 if (displaylog) console.log(canvas.zoom Factor);369 var delta = clamp(clamp(ev.scale || ev.wheelDelta || -ev.detail, -1, 1) * canvas.controlsensitivity * canvas.zoom / 20, -1.0, 1.0); 370 canvas.zoom = clamp(canvas.zoom + delta, canvas.zoomBounds[0], canvas.zoomBounds[1]); 371 372 if (displaylog) console.log(canvas.zoom); 380 373 } //}}} 381 374 //}}} … … 392 385 393 386 if (canvas.twod) { 394 mat4.ortho(pMatrix, - 1*aspectRatio/canvas.zoomFactor, 1*aspectRatio/canvas.zoomFactor, -1*aspectRatio/canvas.zoomFactor, 1*aspectRatio/canvas.zoomFactor, -1.0, 10000.0);387 mat4.ortho(pMatrix, -aspectRatio/canvas.zoom, aspectRatio/canvas.zoom, -1/canvas.zoom, 1/canvas.zoom, -1.0, 10000.0); 395 388 } 396 389 else { … … 404 397 //Calculate rotation around camera focal point about worldspace origin 405 398 if (canvas.twod) { 399 mat4.rotate(azimuthRotationMatrix, azimuthRotationMatrix, radians(0), [0, 1, 0]); 400 mat4.rotate(elevationRotationMatrix, elevationRotationMatrix, radians(90), [1, 0, 0]); 401 mat4.multiply(rotationMatrix, elevationRotationMatrix, azimuthRotationMatrix); 402 } 403 else { 406 404 mat4.rotate(azimuthRotationMatrix, azimuthRotationMatrix, radians(canvas.rotation[0]), [0, 1, 0]); 407 405 mat4.rotate(elevationRotationMatrix, elevationRotationMatrix, radians(canvas.rotation[1]), [1, 0, 0]); 408 406 mat4.multiply(rotationMatrix, elevationRotationMatrix, azimuthRotationMatrix); 409 407 } 410 else {411 mat4.rotate(azimuthRotationMatrix, azimuthRotationMatrix, radians(0), [0, 1, 0]);412 mat4.rotate(elevationRotationMatrix, elevationRotationMatrix, radians(90), [1, 0, 0]);413 mat4.multiply(rotationMatrix, elevationRotationMatrix, azimuthRotationMatrix);414 }415 408 416 409 //Apply rotation and scaling transform … … 419 412 //Apply screenspace translation 420 413 mat4.identity(translateMatrix); 421 mat4.translate(translateMatrix, translateMatrix, [0.0, 0.0, -1/canvas.zoom Factor]);414 mat4.translate(translateMatrix, translateMatrix, [0.0, 0.0, -1/canvas.zoom]); 422 415 mat4.multiply(vMatrix, translateMatrix, vMatrix); 423 416
Note:
See TracChangeset
for help on using the changeset viewer.