Changeset 21173


Ignore:
Timestamp:
08/31/16 00:56:52 (9 years ago)
Author:
dlcheng
Message:

CHG (JS): Transform matrices rework improvements and switch to using meters as base units. Separating translaton center and rotation/scale pivot. Adding seperate rendering options for sky, space, and ground under "render" option, replacing "atmosphere". Updating plotdoc. Adding in modifyZoom function for UI interfacing with canvas.zoom. Adding printNodes function for debugging node attributes.

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

Legend:

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

    r21138 r21173  
    332332        } //}}}
    333333        //Atmosphere {{{
    334         if (options.exist('atmosphere')) {
    335                 if (options.getfieldvalue('atmosphere')=='on') {
    336                         var meshresults = processmesh(md,data,options);
    337                         var x = meshresults[0];
    338                         var y = meshresults[1];
    339                         var z = meshresults[2];
    340                         var elements = meshresults[3];
    341                         var is2d = meshresults[4];
    342                         var isplanet = meshresults[5];
    343                        
    344                         var modelxlim = [ArrayMin(x),ArrayMax(x)];
    345                         var modelylim = [ArrayMin(y),ArrayMax(y)];
    346                         var modelzlim = [ArrayMin(z),ArrayMax(z)];
    347                         var xlim = options.getfieldvalue('xlim',modelxlim);
    348                         var ylim = options.getfieldvalue('ylim',modelylim);
    349                         var zlim = options.getfieldvalue('zlim',modelzlim);
    350                         xmin = xlim[0];
    351                         xmax = xlim[1];
    352                         ymin = ylim[0];
    353                         ymax = ylim[1];
    354                         zmin = zlim[0];
    355                         zmax = zlim[1];
    356 
    357                         var scale = 1;
    358                         var atmosphereScale = 1.25;
    359                        
    360                         //Atmosphere
     334        if (options.exist('render')) {
     335                var meshresults = processmesh(md,data,options);
     336                var x = meshresults[0];
     337                var y = meshresults[1];
     338                var z = meshresults[2];
     339                var elements = meshresults[3];
     340                var is2d = meshresults[4];
     341                var isplanet = meshresults[5];
     342               
     343                var modelxlim = [ArrayMin(x),ArrayMax(x)];
     344                var modelylim = [ArrayMin(y),ArrayMax(y)];
     345                var modelzlim = [ArrayMin(z),ArrayMax(z)];
     346                var xlim = options.getfieldvalue('xlim',modelxlim);
     347                var ylim = options.getfieldvalue('ylim',modelylim);
     348                var zlim = options.getfieldvalue('zlim',modelzlim);
     349                xmin = xlim[0];
     350                xmax = xlim[1];
     351                ymin = ylim[0];
     352                ymax = ylim[1];
     353                zmin = zlim[0];
     354                zmax = zlim[1];
     355               
     356                var global = vec3.length([(xmin + xmax) / 2, (ymin + ymax) / 2, (zmin + zmax) / 2]) < 6371000/10; //tolerance for global models = center is 637100 meters away from center of earth
     357                var atmosphereScale = 1.25;
     358                var translation = global ? [(xmin + xmax) / 2, (ymin + ymax) / 2, (zmin + zmax) / 2] : [(xmin + xmax) / 2, (ymin + ymax) - 6371000, (zmin + zmax) / 2];
     359               
     360                if (options.getfieldvalue('render',[]).indexOf('sky')!=-1) {   
     361                        //atmosphere
    361362                        var node = Node(gl,options);
    362363                        canvas.nodes[canvas.nodes.length] = node;
     364                        node["name"] = "atmosphere";
    363365                        node["shaderName"] = "SkyFromSpace";
    364366                        node["shader"] = gl["shaders"][node["shaderName"]];
     
    367369                        node["mesh"] = GL.Mesh.icosahedron({size:6371000*atmosphereScale,subdivisions:6});
    368370                        node["useIndexBuffer"] = false;
    369                         node["rotation"] = [0,0,0];
    370                         node["translation"] = [(xmin + xmax) / (-2 / scale), (ymin + ymax) / (-2 / scale), (zmin + zmax) / (2 / scale)];
    371                         node["scale"] = [scale, scale, scale];
     371                        node["rotation"] = [0, 0, 0]
     372                        node["translation"] = translation;
     373                        node["center"] = [0, 0, 0];
    372374                        node["modelMatrix"] = recalculateModelMatrix(node);
    373                        
    374                         //Skysphere
    375                         var node = Node(gl,options);
     375                }
     376                if (options.getfieldvalue('render',[]).indexOf('space')!=-1) { 
     377                        //skysphere
     378                        node = Node(gl,options);
    376379                        canvas.nodes[canvas.nodes.length] = node;
     380                        node["name"] = "skysphere";
    377381                        node["shaderName"] = "Textured";
    378382                        node["shader"] = gl["shaders"][node["shaderName"]];
     
    382386                        node["texture"] = initTexture(gl,'../../../js/textures/TychoSkymapII_t4_2k.jpg');
    383387                        node["useIndexBuffer"] = false;
    384                         node["rotation"] = [0,0,0];
    385                         node["translation"] = [(xmin + xmax) / (-2 / scale), (ymin + ymax) / (-2 / scale), (zmin + zmax) / (2 / scale)];
    386                         node["scale"] = [scale, scale, scale];
     388                        node["rotation"] = [0, 0, 0]
     389                        node["translation"] = translation;
     390                        node["center"] = [0, 0, 0];
    387391                        node["modelMatrix"] = recalculateModelMatrix(node);
    388392                }
  • issm/trunk-jpl/src/m/plot/plot_mesh.js

    r21138 r21173  
    6161        var node = Node(gl,options);
    6262        canvas.nodes[canvas.nodes.length] = node;
    63         scale = 1;
     63        node["name"] = "mesh";
    6464        node["shaderName"] = "Colored";
    6565        node["shader"] = gl["shaders"][node["shaderName"]];
    6666        node["lineWidth"] = options.getfieldvalue('linewidth',1);
    67         node["scale"] = [scale, scale, scale * matrixscale];
    68         node["translation"] = [(xmin + xmax) / (-2 / scale), (ymin + ymax) / (-2 / scale), (zmin + zmax) / (2 / scale)];
     67        node["scale"] = [1, 1, matrixscale];
     68        node["rotation"] = [-90, 0, 0];
     69        node["translation"] = [(xmin + xmax) / 2, (ymin + ymax) / 2, (zmin + zmax) / 2];
     70        node["center"] = [(xmin + xmax) / 2, (ymin + ymax) / 2, (zmin + zmax) / 2];
    6971        node["modelMatrix"] = recalculateModelMatrix(node);
    7072        node["drawMode"] = gl.LINES;
  • issm/trunk-jpl/src/m/plot/plot_overlay.js

    r21164 r21173  
    1515        var ymin,ymax;
    1616        var zmin,zmax;
    17         var scale,matrixscale,vertexscale;
     17        var matrixscale,vertexscale;
    1818
    1919        //Process data and model
     
    6161        var node = Node(gl,options);
    6262        canvas.nodes[canvas.nodes.length] = node;
    63         scale = 1;
    64         node["shaderName"] = (options.getfieldvalue('atmosphere','off') == 'on') ? "GroundFromSpace" : "Textured";
     63        node["name"] = "overlay";
     64        node["shaderName"] = (options.getfieldvalue('render',[]).indexOf('ground')!=-1) ? "GroundFromSpace" : "Textured";
    6565        node["shader"] = gl["shaders"][node["shaderName"]];
    66         node["scale"] = [scale, scale, scale * matrixscale];
    67         node["translation"] = [(xmin + xmax) / (-2 / scale), (ymin + ymax) / (-2 / scale), (zmin + zmax) / (2 / scale)];
     66        node["scale"] = [1, 1, matrixscale];
     67        node["rotation"] = [-90, 0, 0];
     68        node["translation"] = [(xmin + xmax) / 2, (ymin + ymax) / 2, (zmin + zmax) / 2];
     69        node["center"] = [(xmin + xmax) / 2, (ymin + ymax) / 2, (zmin + zmax) / 2];
    6870        node["modelMatrix"] = recalculateModelMatrix(node);
    6971        node["texture"] = initTexture(gl,options.getfieldvalue('overlay_image'));
     
    9698                zmax = zlim[1];
    9799               
    98                 node["translation"] = [node["translation"][0], node["translation"][1], (zmax) / (-1 / scale)];
     100                node["center"] = [node["center"][0], node["center"][1], -zmax];
    99101        }
    100102       
  • issm/trunk-jpl/src/m/plot/plot_quiver.js

    r21138 r21173  
    6363        var node = Node(gl,options);
    6464        canvas.nodes[canvas.nodes.length] = node;
    65         scale = 1;
     65        node["name"] = "quiver";
    6666        node["shaderName"] = "Colored";
    6767        node["shader"] = gl["shaders"][node["shaderName"]];
    6868        node["lineWidth"] = options.getfieldvalue('linewidth',1);
    69         node["scale"] = [scale, scale, scale * matrixscale];
    70         node["translation"] = [(xmin + xmax) / (-2 / scale), (ymin + ymax) / (-2 / scale), (zmin + zmax) / (2 / scale)];
     69        node["scale"] = [1, 1, matrixscale];
     70        node["rotation"] = [-90, 0, 0];
     71        node["translation"] = [(xmin + xmax) / 2, (ymin + ymax) / 2, (zmin + zmax) / 2];
     72        node["center"] = [(xmin + xmax) / 2, (ymin + ymax) / 2, (zmin + zmax) / 2];
    7173        node["modelMatrix"] = recalculateModelMatrix(node);
    7274        node["drawMode"] = gl.LINES;
  • issm/trunk-jpl/src/m/plot/plot_unit.js

    r21138 r21173  
    2525        var zmin,zmax;
    2626        var datamin,datamax,datadelta;
    27         var scale,matrixscale,vertexscale;
     27        var matrixscale,vertexscale;
    2828
    2929        //Compue scaling through matrices for 2d meshes and vertices for 3d meshes
     
    6363        var node = Node(gl,options);
    6464        canvas.nodes[canvas.nodes.length] = node;
    65         scale = 1;
     65        node["name"] = "unit";
    6666        node["shaderName"] = "Textured";
    6767        node["shader"] = gl["shaders"][node["shaderName"]];
    68         node["scale"] = [scale, scale, scale * matrixscale];
    69         node["translation"] = [(xmin + xmax) / (-2 / scale), (ymin + ymax) / (-2 / scale), (zmin + zmax) / (2 / scale)];
     68        node["scale"] = [1, 1, matrixscale];
     69        node["rotation"] = [-90, 0, 0];
     70        node["translation"] = [(xmin + xmax) / 2, (ymin + ymax) / 2, (zmin + zmax) / 2];
     71        node["center"] = [(xmin + xmax) / 2, (ymin + ymax) / 2, (zmin + zmax) / 2];
    7072        node["modelMatrix"] = recalculateModelMatrix(node);
    7173        node["alpha"] = options.getfieldvalue('alpha',1.0);
     
    7577        node["maskColor"] = options.getfieldvalue('innermaskcolor',[0.0,0.0,1.0,1.0]);
    7678        node["enabled"] = options.getfieldvalue('nodata','off') == 'off';
     79        vec3.add(canvas.translation, canvas.translation, node["center"]);
    7780       
    7881        switch(datatype){
     
    236239                                                var buffer = node["mesh"].getBuffer("coords");
    237240                                                buffer.data = texcoords[node["movieFrame"]];
    238                                                 buffer.upload(gl.DYNAMIC_DRAW);
     241                                                buffer.upload(canvas.gl.DYNAMIC_DRAW);
    239242                                        }, node["movieInterval"]);
    240243                                if (canvas["progressBar"]) {
  • issm/trunk-jpl/src/m/plot/plotdoc.js

    r21164 r21173  
    1616        console.log('                  - "mesh": draw mesh using trisurf');
    1717        console.log('                  - "quiver": quiver plot');
     18        console.log('       "2d": renders orthographic camera with view set to [0, 90] (default "off", ex: "on", "off")');
     19        console.log('       "backgroundcolor": plot background color. (default "lightcyan", ex: "green","blue")');
    1820        console.log('       "caxis": modify  colorbar range. (array of type [a, b] where b>=a)');
    19         console.log('       "backgroundcolor": plot background color. (default "lightcyan", ex: "green","blue")');
    2021        console.log('       "colorbar": add colorbar (default "off", ex: "on", "off")');
    2122        console.log('       "colorbarid": colorbar canvas id (string)');
     
    2930        console.log('       "colorbarheight": multiplier (default 1) to the default height colorbar');
    3031        console.log('       "colormap": same as standard matlab option (default "jet", ex: "hsv","cool","spring","gray","Ala","Rignot",...)');
     32        console.log('       "controlsensitivity": sensitivty of view/zoom changes as a percentage of default (default 1, ex: 0.5, 2.75)');
     33        console.log('       "displayview": print view value to console (default "off", ex: "on", "off")');
     34        console.log('       "displayzoom": print zoom value to console (default "off", ex: "on", "off")');
    3135        console.log('       "edgecolor": same as standard matlab option EdgeColor (default "black", ex: color name: "blue" or RGB array: [0.5, 0.2, 0.8])');
     36        console.log('       "heightscale": scaling factor to accentuate height. (default 1, ex: 0.5, 100)');
     37        console.log('       "linewidth*": line width for mesh, quiver, and contour plots, currently limited by WebGL to 1. (default 1, ex: 2, 5)');
     38        console.log('       "log": value of log (default 10, ex: 2, Math.E)');
     39        console.log('       "mask": list of flags of size numberofnodes or numberofelements. Only "true" values are plotted ');
     40        console.log('       "moviefps": frames per second when displaying transient runs (default 5, ex: 1, 10)');
     41        console.log('       "innermask*": Special mask that colors all parts of a data mesh below a height a certain color. provide innermaskheight and innermaskcolor options also (default "off", ex: "on", "off")');
     42        console.log('       "outermask*": Special mask that colors all parts of a overlay mesh below a height a certain color. provide outermaskheight and outermaskcolor options also (default "off", ex: "on", "off")');
     43        console.log('       "overlay": overlay a radar amplitude image behind (default "off", ex: "on", "off")');
     44        console.log('       "overlay_image": path to overlay image (default "off", ex: "on", "off")');
     45        console.log('       "scaling": scaling factor used by quiver plots. Default is 0.4');
     46        console.log('       "alpha": transparency coefficient 0.0 to 1.0, the lower, the more transparent. (default 1.0, ex: 0.5, 0.25)');
     47        console.log('       "azlim": azimuth view limits (ex: [0, 180])');
     48        console.log('       "ellim": elevation view limits (ex: [-90, 90])');
     49        console.log('       "origin": initial camera offset from model center (default [0,0,0.0], ex: [-2, 1.5, 0.01])');
     50        console.log('       "render": toggle sky, ground, and space rendering. (default [], ex: ["sky", "space"], ["ground"])');
    3251        console.log('       "viewPanning": enable view origin panning with two-finger touch or shift+mouse drag. (default "off", ex: "on", "off")');
    3352        console.log('       "view": initial azimuth and elevation angles for camera (default [0,90], ex: [90, 180]');
    34         console.log('       "zoom": initial camera zoom as a percentage of default (default 1, ex: 1.5, 0.01)');
    35         console.log('       "centeroffset": initial camera offset from model center (default [0,0,0.0], ex: [-2, 1.5, 0.01])');
    3653        console.log('       "xlim": x coordinates to fit inside camera (ex: [0, 500])');
    3754        console.log('       "ylim": y coordinates to fit inside camera (ex: [0, 500])');
    3855        console.log('       "zlim": z coordinates to fit inside camera (ex: [0, 500])');
    39         console.log('       "azlim": azimuth view limits (ex: [0, 180])');
    40         console.log('       "ellim": elevation view limits (ex: [-90, 90])');
    4156        console.log('       "zoomlim": zoom view limits (ex: [0.05, 10])');
    42         console.log('       "displayview": print view value to console');
    43         console.log('       "displayzoom": print zoom value to console');
    44         console.log('       "controlsensitivity": sensitivty of view/zoom changes as a percentage of default (default 1, ex: 0.5, 2.75)');
    45         console.log('       "2d": renders orthographic camera with view set to [0, 90] (default "off", ex: "on", "off")');
    46         console.log('       "moviefps": frames per second when displaying transient runs (default 5, ex: 1, 10)');
    47         console.log('       "overlay": overlay a radar amplitude image behind (default "off", ex: "on", "off")');
    48         console.log('       "overlay_image": path to overlay image (default "off", ex: "on", "off")');
    49         console.log('       "atmosphere": toggle atmospheric/skysphere shading. (default "off", ex: "on", "off")');
    50         console.log('       "alpha": transparency coefficient 0.0 to 1.0, the lower, the more transparent. (default 1.0, ex: 0.5, 0.25)');
    51         console.log('       "heightscale": scaling factor to accentuate height. (default 1, ex: 0.5, 100)');
    52         console.log('       "scaling*": scaling factor used by quiver plots. Default is 0.4');
    53         console.log('       "linewidth*": line width for mesh, quiver, and contour plots, currently limited by WebGL to 1. (default 1, ex: 2, 5)');
     57        console.log('       "zoom": initial camera zoom as a percentage of default (default 1, ex: 1.5, 0.01)');
    5458        console.log('       "cloud*": plot a cloud of points, given a flat array of 3d coordinates (ex: [0.0, 0.0, 0.0, 1.0, 1.0, 1.0])');
    5559        console.log('       "expdisp*": plot exp file on top of a data plot. provide exp file as an argument (use a cell of strings if more than one)');
    5660        console.log('       "textlabels*": plot text labels rendered in 3d space, using an array of text/coordinate pairs (ex: [{"pos":[0.0,0.0,0.0],"text":"origin"}])');
    57         console.log('       "outermask*": Special mask that colors all parts of a overlay mesh below a height a certain color. provide outermaskheight and outermaskcolor options also (default "off", ex: "on", "off")');
    58         console.log('       "innermask*": Special mask that colors all parts of a data mesh below a height a certain color. provide innermaskheight and innermaskcolor options also (default "off", ex: "on", "off")');
    59         console.log('       "mask": list of flags of size numberofnodes or numberofelements. Only "true" values are plotted ');
    60         console.log('       "log": value of log');
     61       
    6162        console.log('  ');
    6263        console.log('   Examples:');
  • issm/trunk-jpl/src/m/plot/webgl.js

    r21138 r21173  
    8383} //}}}
    8484function Node(gl,options) { //{{{
    85         //Returns a Node object that contains default display states for webgl object
    86         return {buffers:[],
     85        //Returns a Node object that contains default display states for webgl object. center represents pivot point of rotation.
     86        return {
     87                buffers:[],
     88                name:"node",
    8789                shader:gl.shaders["Colored"],
    8890                draw:null,
     
    9799                drawMode:gl.TRIANGLES,
    98100                texture:null,
     101                scale:vec3.fromValues(1, 1, 1),
     102                rotation:vec3.create(),
    99103                translation:vec3.create(),
    100                 rotation:vec3.fromValues(-90, 0, 0),
    101                 scale:vec3.fromValues(1, 1, 1),
     104                center:vec3.create(),
    102105                modelMatrix:mat4.create(),
    103106                shaderName:"Colored",
     
    106109                maskHeight:150.0,
    107110                maskColor:vec4.fromValues(0.0, 0.0, 1.0, 1.0),
    108                 enabled:true,
     111                enabled:true
    109112        };
    110113} //}}}
     114function displayNodes() {
     115        var nodes = $('.sim-canvas')[0].nodes;
     116        console.log("Nodes:");
     117        for (var node in nodes) {
     118                console.log("name", nodes[node]["name"], "translation", nodes[node]["translation"], "center", nodes[node]["center"], "rotation", nodes[node]["rotation"]);
     119        }
     120}
    111121function recalculateModelMatrix(node) { //{{{
    112122        //TODO: move to 0,0,0, rotate,move back to normal space, then apply transform
    113123        var modelMatrix = mat4.create();
    114124
     125        var translationMatrix = mat4.create();
     126        mat4.translate(translationMatrix, translationMatrix, [-node["center"][0],-node["center"][1],-node["center"][2]]); //scale/rotation centering
     127        mat4.multiply(modelMatrix, translationMatrix, modelMatrix);
     128       
    115129        var scaleMatrix = mat4.create();
    116130        mat4.scale(scaleMatrix, scaleMatrix, node["scale"]);
    117131        mat4.multiply(modelMatrix, scaleMatrix, modelMatrix);
    118 
    119         var translationMatrix = mat4.create();
    120         mat4.translate(translationMatrix, translationMatrix, node["translation"]); //relative translation
    121         mat4.multiply(modelMatrix, translationMatrix, modelMatrix);
    122132       
    123133        var zRotationMatrix = mat4.create();   
     
    130140        mat4.rotate(xRotationMatrix, xRotationMatrix, radians(node["rotation"][0]), [1.0, 0.0, 0.0]);
    131141        mat4.multiply(modelMatrix, xRotationMatrix, modelMatrix);
    132 
     142       
     143        mat4.identity(translationMatrix);
     144        mat4.translate(translationMatrix, translationMatrix, node["center"]); //relative translation
     145        mat4.multiply(modelMatrix, translationMatrix, modelMatrix);
     146       
     147        // mat4.identity(translationMatrix);
     148        // mat4.translate(translationMatrix, translationMatrix, [-node["translation"][0],-node["translation"][1],-node["translation"][2]]); //absolute translation
     149        // mat4.multiply(modelMatrix, translationMatrix, modelMatrix);
     150       
     151        mat4.identity(translationMatrix);
     152        mat4.translate(translationMatrix, translationMatrix, node["translation"]); //absolute translation
     153        mat4.multiply(modelMatrix, translationMatrix, modelMatrix);
    133154        return modelMatrix;
    134155} //}}}
     
    153174function loadShaders(gl) { //{{{
    154175        shaders = {};
    155         shaders["Colored"] = new Shader.fromURL("/js/shaders/Colored.vsh", "/js/shaders/Colored.fsh");
    156         shaders["Textured"] = new Shader.fromURL("/js/shaders/Textured.vsh", "/js/shaders/Textured.fsh");
    157         shaders["SkyFromSpace"] = new Shader.fromURL("/js/shaders/SkyFromSpace.vert", "/js/shaders/SkyFromSpace.frag");
    158         shaders["GroundFromSpace"] = new Shader.fromURL("/js/shaders/GroundFromSpace.vert", "/js/shaders/GroundFromSpace.frag");
     176        shaders["Colored"] = new Shader.fromURL("../../../js/shaders/Colored.vsh", "../../../js/shaders/Colored.fsh");
     177        shaders["Textured"] = new Shader.fromURL("../../../js/shaders/Textured.vsh", "../../../js/shaders/Textured.fsh");
     178        shaders["SkyFromSpace"] = new Shader.fromURL("../../../js/shaders/SkyFromSpace.vert", "../../../js/shaders/SkyFromSpace.frag");
     179        shaders["GroundFromSpace"] = new Shader.fromURL("../../../js/shaders/GroundFromSpace.vert", "../../../js/shaders/GroundFromSpace.frag");
    159180        return shaders;
    160181} //}}}
     
    168189        if (ev.srcEvent.shiftKey || ev.pointers.length == 2) {
    169190                if (!canvas.viewPanning) return;
    170                 var deltaX = (canvas.lastDeltaX - ev.deltaX) / canvas.clientWidth / canvas.zoom * -2 * canvas.controlSensitivity;
    171                 var deltaY = (canvas.lastDeltaY - ev.deltaY) / canvas.clientHeight / canvas.zoom * -2 * canvas.controlSensitivity;
     191                var deltaX = (canvas.lastDeltaX - ev.deltaX) / canvas.clientWidth / canvas.zoom * -2 * canvas.controlSensitivity * 6371000.0;
     192                var deltaY = (canvas.lastDeltaY - ev.deltaY) / canvas.clientHeight / canvas.zoom * -2 * canvas.controlSensitivity * 6371000.0;
    172193               
    173194                if (canvas.twod) {
    174195                        canvas.translation[0] += Math.cos(radians(canvas.rotation[0])) * deltaX - Math.sin(radians(0)) * deltaY;
    175                         canvas.translation[1] += Math.sin(radians(canvas.rotation[0])) * deltaX + Math.cos(radians(0)) * deltaY;
     196                        canvas.translation[2] += Math.sin(radians(canvas.rotation[0])) * deltaX + Math.cos(radians(0)) * deltaY;
    176197                }
    177198                else {
    178199                        canvas.translation[0] += Math.cos(radians(canvas.rotation[0])) * deltaX - Math.sin(radians(canvas.rotation[0])) * deltaY;
    179                         canvas.translation[1] += Math.sin(radians(canvas.rotation[0])) * deltaX + Math.cos(radians(canvas.rotation[0])) * deltaY;
     200                        canvas.translation[2] += Math.sin(radians(canvas.rotation[0])) * deltaX + Math.cos(radians(canvas.rotation[0])) * deltaY;
    180201                }
    181202        }
     
    203224        }
    204225        else {
    205                 canvas.zoom = clamp(ev.scale * canvas.zoomLast, canvas.zoomBounds[0], canvas.zoomBounds[1]);
    206                 if (displaylog) console.log(canvas.zoom);
     226                modifyZoom(ev.scale * canvas.zoomLast, canvas, displaylog);
    207227        }
    208228} //}}}
    209229function onZoom(ev,canvas,displaylog) { //{{{
    210230        ev.preventDefault();
    211         var delta = clamp(ev.scale || ev.wheelDelta || -ev.detail, -1, 1) * canvas.controlSensitivity * canvas.zoom / 20;
    212         canvas.zoom = clamp(canvas.zoom + delta, canvas.zoomBounds[0], canvas.zoomBounds[1]);
    213        
     231        var delta = clamp(ev.scale || ev.wheelDelta || -ev.detail, -1, 1) * canvas.controlSensitivity * canvas.zoom / 10;
     232        modifyZoom(canvas.zoom + delta, canvas, displaylog);
     233} //}}}
     234function modifyZoom(value,canvas,displaylog) { //{{{
     235        canvas.zoom = clamp(value, canvas.zoomBounds[0], canvas.zoomBounds[1]);
    214236        if (displaylog) console.log(canvas.zoom);
    215237} //}}}
     
    230252        }
    231253        else {
    232                 mat4.perspective(pMatrix, 60 * Math.PI / 180, aspectRatio, 1000, 10000000000.0);
     254                mat4.perspective(pMatrix, 60 * Math.PI / 180, aspectRatio, 100, 1000000000.0);
    233255        }
    234256       
    235257        //Apply worldspace translation
    236         mat4.translate(translateMatrix, translateMatrix, [6371000.0 * canvas.translation[0], 6371000.0 * canvas.translation[2], 6371000.0 * canvas.translation[1]]);
     258        mat4.translate(translateMatrix, translateMatrix, [-canvas["translation"][0],-canvas["translation"][1],-canvas["translation"][2]]);
    237259        mat4.multiply(vMatrix, translateMatrix, vMatrix);
    238260       
Note: See TracChangeset for help on using the changeset viewer.