Changeset 19917 for issm/trunk-jpl/src/m/plot/webgl.js
- Timestamp:
- 12/29/15 13:19:43 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/plot/webgl.js
r19916 r19917 33 33 34 34 // Add context state variables 35 //TODO:Group variables in objects for organization and naming 35 36 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; 37 39 canvas.cameraMatrix = mat4.create(); 38 40 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; 40 45 canvas.controlsensitivity = 1; 41 46 … … 113 118 texture:null, 114 119 translation:vec3.create(), 115 rotation:vec3. create(),120 rotation:vec3.fromValues(-90, 0, 0), 116 121 scale:vec3.fromValues(1, 1, 1), 117 122 modelMatrix:mat4.create(), … … 134 139 135 140 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]); 137 142 mat4.multiply(modelMatrix, zRotationMatrix, modelMatrix); 138 143 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]); 140 145 mat4.multiply(modelMatrix, yRotationMatrix, modelMatrix); 141 146 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]); 143 148 mat4.multiply(modelMatrix, xRotationMatrix, modelMatrix); 144 149 145 150 return modelMatrix; 151 } //}}} 152 function radians (degrees) { //{{{ 153 return degrees * Math.PI / 180; 154 } //}}} 155 function degrees (radians) { //{{{ 156 return radians * 180 / Math.PI; 157 } //}}} 158 function clamp(value, min, max) { //{{{ 159 return Math.max(min, Math.min(value, max)); 146 160 } //}}} 147 161 //}}} … … 271 285 //{{{ Interface Functions 272 286 function onPan(ev,canvas) { 287 ev.preventDefault(); 273 288 if (ev.type == 'panstart') { 274 289 canvas.lastDeltaX = 0; … … 279 294 //canvas.translation[1] -= (canvas.lastDeltaY - ev.deltaY) / canvas.clientHeight * canvas.zoomFactor * 2; 280 295 // 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 283 307 canvas.lastDeltaX = ev.deltaX; 284 308 canvas.lastDeltaY = ev.deltaY; 309 310 console.log(canvas.rotation); 285 311 } 286 312 function onPinch(ev,canvas) { 313 ev.preventDefault(); 287 314 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 } 292 321 } 293 322 function onZoom(ev,canvas) { 294 // prevent scrolling when over canvas295 323 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); 298 327 } 299 328 //}}} … … 304 333 var pMatrix = mat4.create(); 305 334 var rotationMatrix = mat4.create(); 306 var traversalRotationMatrix = mat4.create();335 var azimuthRotationMatrix = mat4.create(); 307 336 var elevationRotationMatrix = mat4.create(); 308 337 … … 310 339 311 340 //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); 315 344 316 345 //Apply rotation and scaling transform
Note:
See TracChangeset
for help on using the changeset viewer.