Changeset 19917


Ignore:
Timestamp:
12/29/15 13:19:43 (9 years ago)
Author:
dlcheng
Message:

CHG (javascript): Adding in pinch zoom handling, azimuth/elevation camera rotation view, and azimuthbounds/elevationbounds clamping options with console output for debugging.

Location:
issm/trunk-jpl/src/m/plot
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/plot/plot_overlay.js

    r19915 r19917  
    4949        node["shader"] = gl["shaders"][node["shaderName"]]["program"];
    5050        node["scale"] = [scale, scale, scale*options.getfieldvalue('heightscale',1)];
    51         node["rotation"] = options.getfieldvalue('view',[0,0,0]);
    5251        node["translation"] = [(xmin + xmax) / (-2 / scale), (ymin + ymax) / (-2 / scale), (zmax) / (-1 / scale)];
    5352        node["modelMatrix"] = recalculateModelMatrix(node);
  • issm/trunk-jpl/src/m/plot/plot_unit.js

    r19915 r19917  
    5656        node["shader"] = gl["shaders"][node["shaderName"]]["program"];
    5757        node["scale"] = [scale, scale, scale*options.getfieldvalue('heightscale',1)];
    58         node["rotation"] = options.getfieldvalue('view',[0,0,0]);
    5958        node["translation"] = [(xmin + xmax) / (-2 / scale), (ymin + ymax) / (-2 / scale), (zmax) / (-1 / scale)];
    6059        node["modelMatrix"] = recalculateModelMatrix(node);
  • issm/trunk-jpl/src/m/plot/webgl.js

    r19916 r19917  
    3333
    3434        // Add context state variables
     35        //TODO:Group variables in objects for organization and naming
    3536        canvas.zoomBounds = options.getfieldvalue('zoombounds',[0,-.52]);
    36         canvas.zoomFactor = Math.max(canvas.zoomBounds[1], Math.min(options.getfieldvalue('zoomfactor',canvas.zoomBounds[1]), canvas.zoomBounds[0]));
     37        canvas.zoomFactor = clamp(options.getfieldvalue('zoomfactor',canvas.zoomBounds[1]), canvas.zoomBounds[1], canvas.zoomBounds[0]);
     38        canvas.zoomLast = canvas.zoomFactor;
    3739        canvas.cameraMatrix = mat4.create();
    3840        canvas.translation = [0,0];
    39         canvas.rotation = [0,0,0];
     41        canvas.rotationAzimuthBounds = options.getfieldvalue('azimuthbounds',[0,360]);
     42        canvas.rotationElevationBounds = options.getfieldvalue('elevationbounds',[-180,180]);
     43        canvas.rotationDefault = options.getfieldvalue('view',[0,90]); //0 azimuth - up is north, 90 elevation - looking straight down
     44        canvas.rotation = canvas.rotationDefault;
    4045        canvas.controlsensitivity = 1;
    4146
     
    113118                texture:null,
    114119                translation:vec3.create(),
    115                 rotation:vec3.create(),
     120                rotation:vec3.fromValues(-90, 0, 0),
    116121                scale:vec3.fromValues(1, 1, 1),
    117122                modelMatrix:mat4.create(),
     
    134139       
    135140        var zRotationMatrix = mat4.create();   
    136         mat4.rotate(zRotationMatrix, zRotationMatrix, node["rotation"][2] * Math.PI/180.0, [0.0, 0.0, 1.0]);
     141        mat4.rotate(zRotationMatrix, zRotationMatrix, radians(node["rotation"][2]), [0.0, 0.0, 1.0]);
    137142        mat4.multiply(modelMatrix, zRotationMatrix, modelMatrix);
    138143        var yRotationMatrix = mat4.create();   
    139         mat4.rotate(yRotationMatrix, yRotationMatrix, node["rotation"][1] * Math.PI/180.0, [0.0, 1.0, 0.0]);
     144        mat4.rotate(yRotationMatrix, yRotationMatrix, radians(node["rotation"][1]), [0.0, 1.0, 0.0]);
    140145        mat4.multiply(modelMatrix, yRotationMatrix, modelMatrix);
    141146        var xRotationMatrix = mat4.create();   
    142         mat4.rotate(xRotationMatrix, xRotationMatrix, node["rotation"][0] * Math.PI/180.0, [1.0, 0.0, 0.0]);
     147        mat4.rotate(xRotationMatrix, xRotationMatrix, radians(node["rotation"][0]), [1.0, 0.0, 0.0]);
    143148        mat4.multiply(modelMatrix, xRotationMatrix, modelMatrix);
    144149
    145150        return modelMatrix;
     151} //}}}
     152function radians (degrees) { //{{{
     153  return degrees * Math.PI / 180;
     154} //}}}
     155function degrees (radians) { //{{{
     156  return radians * 180 / Math.PI;
     157} //}}}
     158function clamp(value, min, max) { //{{{
     159        return Math.max(min, Math.min(value, max));
    146160} //}}}
    147161//}}}
     
    271285//{{{ Interface Functions
    272286function onPan(ev,canvas) {
     287        ev.preventDefault();
    273288        if (ev.type == 'panstart') {
    274289                canvas.lastDeltaX = 0;
     
    279294        //canvas.translation[1] -= (canvas.lastDeltaY - ev.deltaY) / canvas.clientHeight * canvas.zoomFactor * 2;
    280295        // else if double finger/pan with modifier key, move camera center
    281         canvas.rotation[0] += (canvas.lastDeltaX - ev.deltaX) / canvas.clientWidth * canvas.zoomFactor * 2;
    282         canvas.rotation[1] += (canvas.lastDeltaY - ev.deltaY) / canvas.clientHeight * canvas.zoomFactor * 2;
     296        canvas.rotation[0] += degrees((canvas.lastDeltaX - ev.deltaX) / canvas.clientWidth * canvas.zoomFactor * 2);
     297        canvas.rotation[1] += degrees((canvas.lastDeltaY - ev.deltaY) / canvas.clientHeight * canvas.zoomFactor * 2);
     298       
     299        if (canvas.rotation[0] > 360) {canvas.rotation[0] -= 360};
     300        if (canvas.rotation[0] < 0) {canvas.rotation[0] += 360};
     301        if (canvas.rotation[1] > 180) {canvas.rotation[1] -= 360};
     302        if (canvas.rotation[1] < -180) {canvas.rotation[1] += 360};
     303       
     304        canvas.rotation[0] = clamp(canvas.rotation[0], canvas.rotationAzimuthBounds[0], canvas.rotationAzimuthBounds[1]);
     305        canvas.rotation[1] = clamp(canvas.rotation[1], canvas.rotationElevationBounds[0], canvas.rotationElevationBounds[1])
     306       
    283307        canvas.lastDeltaX = ev.deltaX;
    284308        canvas.lastDeltaY = ev.deltaY;
     309       
     310        console.log(canvas.rotation);
    285311}
    286312function onPinch(ev,canvas) {
     313        ev.preventDefault();
    287314        if (ev.type == 'pinchstart') {
    288                 canvas.lastScale = 1;
    289         }
    290         canvas.zoomFactor = Math.max(canvas.zoomBounds[1], Math.min(-ev.scale * canvas.lastScale, canvas.zoomBounds[0]));
    291         canvas.lastScale = ev.scale;
     315                canvas.zoomLast = canvas.zoomFactor;
     316        }
     317        else {
     318                canvas.zoomFactor = clamp(ev.scale * canvas.zoomLast, canvas.zoomBounds[1], canvas.zoomBounds[0]);
     319                console.log(canvas.zoomFactor);
     320        }
    292321}
    293322function onZoom(ev,canvas) {
    294         // prevent scrolling when over canvas
    295323        ev.preventDefault();
    296         var delta = 1/10 * Math.max(-1, Math.min(ev.scale || ev.wheelDelta || -ev.detail, 1));
    297         canvas.zoomFactor = Math.max(canvas.zoomBounds[1], Math.min(canvas.zoomFactor - delta * canvas.zoomFactor, canvas.zoomBounds[0]));
     324        var delta = 1/10 * clamp(ev.scale || ev.wheelDelta || -ev.detail, -1, 1);
     325        canvas.zoomFactor = clamp(canvas.zoomFactor - delta * canvas.zoomFactor, canvas.zoomBounds[1], canvas.zoomBounds[0]);
     326        console.log(canvas.zoomFactor);
    298327}
    299328//}}}
     
    304333        var pMatrix = mat4.create();
    305334        var rotationMatrix = mat4.create();
    306         var traversalRotationMatrix = mat4.create();
     335        var azimuthRotationMatrix = mat4.create();
    307336        var elevationRotationMatrix = mat4.create();
    308337
     
    310339       
    311340        //Calculate rotation around camera focal point about worldspace origin
    312         mat4.rotate(traversalRotationMatrix, traversalRotationMatrix, canvas.rotation[0], [0, 1, 0]);
    313         mat4.rotate(elevationRotationMatrix, elevationRotationMatrix, canvas.rotation[1], [1, 0, 0]);
    314         mat4.multiply(rotationMatrix, elevationRotationMatrix, traversalRotationMatrix);
     341        mat4.rotate(azimuthRotationMatrix, azimuthRotationMatrix, radians(canvas.rotation[0]), [0, 1, 0]);
     342        mat4.rotate(elevationRotationMatrix, elevationRotationMatrix, radians(canvas.rotation[1]), [1, 0, 0]);
     343        mat4.multiply(rotationMatrix, elevationRotationMatrix, azimuthRotationMatrix);
    315344       
    316345        //Apply rotation and scaling transform
Note: See TracChangeset for help on using the changeset viewer.