diff --git a/three_d_viewer/templates/three_d_viewer/base.html b/three_d_viewer/templates/three_d_viewer/base.html index c4bb597..d5e6c00 100644 --- a/three_d_viewer/templates/three_d_viewer/base.html +++ b/three_d_viewer/templates/three_d_viewer/base.html @@ -31,7 +31,7 @@ {% endblock %} -
Put some intro text sort of stuff here
{% endblock %} diff --git a/three_d_viewer/templates/three_d_viewer/detail.html b/three_d_viewer/templates/three_d_viewer/detail.html index 21f90c4..9225853 100644 --- a/three_d_viewer/templates/three_d_viewer/detail.html +++ b/three_d_viewer/templates/three_d_viewer/detail.html @@ -70,6 +70,9 @@ function formatNumber(numero, decimales){ } function load(){ + window.addEventListener('resize', resizeCanvas, false); + resizeCanvas(); + var sampleFilename = '{{ sample.model_filename|escapejs }}'; request = new XMLHttpRequest(); request.open("GET", '{{ MEDIA_URL }}' + sampleFilename, true); @@ -107,8 +110,10 @@ function loaded(){ } function webGLStart(){ - var canvas = document.getElementById("canvas") ; + var canvas = document.getElementById("canvas"); + canvas.oncontextmenu = function() { return false; } // supress the context menu in the canvas + initGL(canvas); initBoundingBox(); initOffsets(); @@ -339,23 +344,57 @@ function handleMouseUp(event){ function handleMouseMove(event){ if (mouseDown){ var newX = event.clientX; - var newY = event.clientY; + var newY = event.clientY; + var deltaX = newX - lastMouseX; + var deltaY = newY - lastMouseY; + + switch (event.which) { + case 1: // left mouse + - var newRotationMatrix = mat4.create(); - mat4.identity(newRotationMatrix); + var newRotationMatrix = mat4.create(); + mat4.identity(newRotationMatrix); + mat4.rotate(newRotationMatrix, degToRad(deltaX / 5), [0, 1, 0]); + + mat4.rotate(newRotationMatrix, degToRad(deltaY / 5), [1, 0, 0]); + mat4.multiply(newRotationMatrix, rotationMatrix, rotationMatrix); - var deltaX = newX - lastMouseX; - mat4.rotate(newRotationMatrix, degToRad(deltaX / 5), [0, 1, 0]); + break; + case 3: // right mouse + //translationMatrix[0] += deltaX; + //translationMatrix[1] += deltaY; + var newTranslateMatrix = mat4.create(); + mat4.identity(newTranslateMatrix); + mat4.translate(newTranslateMatrix, [deltaX, deltaY, 0], [deltaX, deltaY, 0]) + console.log('moving ' + deltaX + ', ' + deltaY) - var deltaY = newY - lastMouseY; - mat4.rotate(newRotationMatrix, degToRad(deltaY / 5), [1, 0, 0]); - - mat4.multiply(newRotationMatrix, rotationMatrix, rotationMatrix); - - lastMouseX = newX - lastMouseY = newY; + break; + } + + lastMouseX = newX + lastMouseY = newY; } } + +function resizeCanvas() { + var canvas = document.getElementById("canvas") ; + var parent = document.getElementById("contentdiv"); + + var canvasWidth1 = canvas.width; + var canvasHeight1 = canvas.height; + + canvas.width = parent.offsetWidth; + canvas.height = parent.offsetHeight; + + if (gl){ + /*hmove = canvas.width / 2 - canvasWidth1 / 2 + vmove = canvas.height / 2 - canvasHeight1 / 2 + mat4.translate(mvMatrix, [hmove, vmove, 0.0]) + console.log('Resizing from ' + canvasWidth1 + ' x ' + canvasHeight1 + ' to ' + canvas.width + ' x ' + canvas.height); + console.log('moving centre ' + hmove + ' x ' + vmove)*/ + } +} + {% endblock %} @@ -376,6 +415,6 @@ function handleMouseMove(event){ {% endblock %} {% block content %} - +