Changeset 20792


Ignore:
Timestamp:
06/22/16 14:14:46 (9 years ago)
Author:
dlcheng
Message:

CHG (javascript): Fully scaling arrow quiver plot.

File:
1 edited

Legend:

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

    r20769 r20792  
    2525        var is2d = meshresults[4];
    2626        var isplanet = meshresults[5];
    27         var vx = md.initialization.vx;
    28         var vy = md.initialization.vy;
     27        var v = md.initialization.vel;
     28        var vx = md.initialization.vx;
     29        var vy = md.initialization.vy;
    2930               
    3031        //Compue scaling through matrices for 2d meshes and vertices for 3d meshes
     
    9394                vertices.itemSize = 3;
    9495                var xyz = vec3.create();
     96                var xyz = vec3.create();
    9597                var direction = vec3.create();
    9698                var vertex = vec3.create();
     99                var vertexBase = vec3.create();
     100                var verticesArrow = [vec3.fromValues(0.0, 0.0, 0.0), vec3.fromValues(1.0, 0.0, 0.0), vec3.fromValues(0.667, -0.167, 0.0), vec3.fromValues(1.0, 0.0, 0.0), vec3.fromValues(0.667, 0.166, 0.0), vec3.fromValues(1.0, 0.0, 0.0)];
    97101                var magnitude;
    98102                var color = edgecolor;
    99103                var scaling = options.getfieldvalue('scaling',1);
     104                var scale;
    100105                for(var i = 0; i < x.length; i++){
    101106                        //Check for NaN values and remove from indices array as necessary, but preserve vertex array spacing
    102107                        if (isNaN(x[i]) || isNaN(y[i]) || isNaN(z[i])) continue;
    103108                        //Scale vertices
    104                         xyz1 = vec3.fromValues(x[i], y[i], z[i]);
    105                         magnitude = vec3.length(xyz1) + md.geometry.surface[i] * vertexscale;
    106                         vec3.normalize(direction, xyz1);
     109                        xyz = vec3.fromValues(x[i], y[i], z[i]);
     110                        magnitude = vec3.length(xyz) + md.geometry.surface[i] * vertexscale;
     111                        vec3.normalize(direction, xyz);
    107112                        vec3.scale(vertex, direction, magnitude);
    108                         vertices[vertices.length] = vertex[0];
    109                         vertices[vertices.length] = vertex[1];
    110                         vertices[vertices.length] = vertex[2];
     113                        vec3.copy(vertexBase, vertex);
    111114                       
    112                         xyz2 = vec3.fromValues(vx[i], vy[i], 0.0);
    113                         magnitude = 1000.0*scaling; //mesh resolution
    114                         vec3.normalize(direction, xyz2);
    115                         vec3.scale(direction, direction, magnitude);
    116                         vec3.add(vertex, direction, vertex);
    117                         vertices[vertices.length] = vertex[0];
    118                         vertices[vertices.length] = vertex[1];
    119                         vertices[vertices.length] = vertex[2];
    120                        
    121                         colors[colors.length] = color[0];
    122                         colors[colors.length] = color[1];
    123                         colors[colors.length] = color[2];
    124                         colors[colors.length] = color[3];
    125                         colors[colors.length] = color[0];
    126                         colors[colors.length] = color[1];
    127                         colors[colors.length] = color[2];
    128                         colors[colors.length] = color[3];
     115                        scale = scaling*v[i];
     116                        var modelMatrix = mat4.create();
     117                        var scaleMatrix = mat4.create();
     118                        var rotationMatrix = mat4.create();
     119                        mat4.scale(scaleMatrix, scaleMatrix, vec3.fromValues(scale, scale, scale));
     120                        mat4.rotate(rotationMatrix, rotationMatrix, Math.atan2(vy[i], vx[i]), [0.0, 0.0, 1.0]);
     121                        mat4.multiply(modelMatrix, rotationMatrix, scaleMatrix);
     122
     123                        var temp = vec3.fromValues(0.0, 0.0, 0.0);
     124                        for (var j = 0; j < 6; j++){
     125                                vec3.transformMat4(vertex, verticesArrow[j], modelMatrix);
     126                                vec3.add(vertex, vertex, vertexBase);
     127                                vertices[vertices.length] = vertex[0];
     128                                vertices[vertices.length] = vertex[1];
     129                                vertices[vertices.length] = vertex[2];
     130                               
     131                                colors[colors.length] = color[0];
     132                                colors[colors.length] = color[1];
     133                                colors[colors.length] = color[2];
     134                                colors[colors.length] = color[3];
     135                        }
    129136                }
    130137        }
Note: See TracChangeset for help on using the changeset viewer.