Changeset 19922


Ignore:
Timestamp:
01/02/16 23:24:06 (9 years ago)
Author:
dlcheng
Message:

CHG (javascript): Fixing low canvas resolution and adding in explicit canvas persistence handling for camera.

File:
1 edited

Legend:

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

    r19921 r19922  
    1515                gl = null;
    1616        }
    17 
     17               
    1818        // Enable depth testing
    1919        gl.enable(gl.DEPTH_TEST);
     
    3131        // Load shaders and store them in gl object
    3232        gl.shaders = loadShaders(gl);
     33       
     34
    3335
    3436        // Add context state variables
     
    3840        canvas.zoomLast = canvas.zoomFactor;
    3941        canvas.cameraMatrix = mat4.create();
    40         canvas.translation = [0,0,options.getfieldvalue('centeroffset',0.25)];
     42        canvas.translation = options.getfieldvalue('centeroffset',[0,0,0.25]);
    4143        canvas.rotationAzimuthBounds = options.getfieldvalue('azimuthbounds',[0,360]);
    4244        canvas.rotationElevationBounds = options.getfieldvalue('elevationbounds',[-180,180]);
    4345        canvas.rotationDefault = options.getfieldvalue('view',[0,90]); //0 azimuth - up is north, 90 elevation - looking straight down
    44         canvas.rotation = queryView(canvas);
     46        canvas.rotation = canvas.rotationDefault;
    4547        canvas.controlsensitivity = 1;
    4648
     
    163165        return Math.max(min, Math.min(value, max));
    164166} //}}}
    165 function queryView(canvas) { //{{{
    166         if (canvas.rotation) {
     167function recoverview(canvasid,defaultview) { //{{{
     168        var canvas  = document.getElementById(canvasid);
     169        if (canvas && canvas.hasOwnProperty("rotation")) {
    167170                return canvas.rotation;
    168171        }
    169         return canvas.rotationDefault;
     172        return defaultview;
     173} //}}}
     174function recovercenteroffset(canvasid,defaultcenter) { //{{{
     175        var canvas  = document.getElementById(canvasid);
     176        if (canvas && canvas.hasOwnProperty("translation")) {
     177                return canvas.translation;
     178        }
     179        return defaultcenter;
    170180} //}}}
    171181//}}}
     
    441451} //}}}
    442452function draw(gl,options,canvas,nodes) { //{{{
     453        // Ensure canvas and gl viewport sizes are the same
     454        var displayWidth  = canvas.clientWidth;
     455        var displayHeight = canvas.clientHeight;
     456        if (canvas.width  != displayWidth || canvas.height != displayHeight) {
     457                canvas.width  = displayWidth;
     458                canvas.height = displayHeight;
     459                gl.viewport(0, 0, canvas.width, canvas.height);
     460        }
     461       
    443462        // Set clear color to black, fully opaque
    444463        var backgroundcolor=new RGBColor(options.getfieldvalue('backgroundcolor','lightcyan'));
     
    457476        // Else, clear the color as well as the depth buffer for new frame
    458477        gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
     478
    459479        window.requestAnimationFrame(function(time) {draw(gl,options,canvas,nodes)});
    460480       
Note: See TracChangeset for help on using the changeset viewer.