1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.

Slides:



Advertisements
Similar presentations
17 HTML, Scripting, and Interactivity Section 17.1 Add an audio file using HTML Create a form using HTML Add text boxes using HTML Add radio buttons and.
Advertisements

Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Sampling and Aliasing Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
User Interface Design using jQuery Mobile CIS 136 Building Mobile Apps 1.
JQUERY – UI & THEMES "WRITE LESS, DO MORE" Built in interface elements.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Emeritus of Computer Science University of New Mexico.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
PHP Form Introduction Getting User Information Text Input.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Building Models Ed Angel Professor Emeritus of Computer Science University of New Mexico Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Emeritus of Computer Science University of New Mexico.
Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Emeritus of Computer Science University of New Mexico.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
LESSON : EVENTS AND FORM VALIDATION -JAVASCRIPT. EVENTS CLICK.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Presentation transcript:

1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science Laboratory University of New Mexico Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

2 Working with Callbacks Ed Angel Professor Emeritus of Computer Science University of New Mexico Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

3 Objectives Learn to build interactive programs using event listeners ­Buttons ­Menus ­Mouse ­Keyboard ­Reshape Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Adding a Button Let’s add a button to control the rotation direction for our rotating cube In the render function, we can use a var direction which is true or false to add or subtract a constant to the angle 4 var direction = true; // global initialization // in render() if(direction) theta += 0.1; else theta -= 0.1; Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

The Button In the HTML file ­Uses HTML button tag ­id gives an identifier we can use in JS file ­Text “Change Rotation Direction” displayed in button Clicking on button generates a click event Note we are using default style and could use CSS or jQuery to get a prettier button 5 Change Rotation Direction Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Button Event Listener (see rotatingSquare2.html + rotatingSquare2.js)rotatingSquare2.htmlrotatingSquare2.js We still need to define the listener ­If no listener, the event is ignored Two forms for event listener in JS file 6 var myButton = document.getElementById("DirectionButton"); myButton.addEventListener("click", function() { direction = !direction; }); document.getElementById("DirectionButton").onclick = function() { direction = !direction; }; Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

onclick Variants 7 myButton.addEventListener("click", function() { if (event.button == 0) { direction = !direction; } }); myButton.addEventListener("click", function() { if (event.shiftKey == 0) { direction = !direction; } }); …… Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Controling Rotation Speed 8 var delay = 100; function render() // this function has been explained // in the previous presentation { setTimeout(function() { requestAnimFrame(render); gl.clear(gl.COLOR_BUFFER_BIT); theta += (direction ? 0.1 : -0.1); gl.uniform1f(thetaLoc, theta); gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4); }, delay); } Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Menus Use the HTML select element Each entry in the menu is an option element with an integer value returned by click event 9 Toggle Rotation Direction Spin Faster Spin Slower Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Menu Listener 10 var m = document.getElementById(“Controls"); m.addEventListener("click", function() { switch (m.selectedIndex) { case 0: direction = !direction; break; case 1: delay /= 2.0; break; case 2: delay *= 2.0; break; } }); Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Using keydown Event 11 window.addEventListener("keydown", function() { switch (event.keyCode) { case 49: // ’1’ key direction = !direction; break; case 50: // ’2’ key delay /= 2.0; break; case 51: // ’3’ key delay *= 2.0; break; } }); Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Don’t Know Unicode? (see rotatingSquare2.js)rotatingSquare2.js 12 window.onkeydown = function(event) { var key = String.fromCharCode(event.keyCode); switch (key) { case ’1’: direction = !direction; break; case ’2’: delay /= 2.0; break; case ’3’: delay *= 2.0; break; } }; Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Slider Element (see rotatingSquare3.html + rotatingSquare3.js)rotatingSquare3.htmlrotatingSquare3.js Puts slider on page ­Give it an identifier ­Give it minimum and maximum values ­Give it a step size needed to generate an event ­Give it an initial value Use div tag to put below canvas 13 speed 0 <input id="slider" type="range" min="0" max="100" step="10" value="50" /> 100 Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

onchange Event Listener 14 document.getElementById("slider").onchange = function() { speed = event.srcElement.value; }; Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

List of frequently used event listeners 15 window.onload = … window.onkeydown = … document.getElementById("Controls" ).onclick = … document.getElementById("slider").onchange = … document.addEventListener(“functionmousemove", doMouseDrag, false); document.addEventListener(“functionmouseup", doMouseUp, false); document.removeEventListener(“functionmousemove", doMouseDrag, false); document.removeEventListener(“functionmouseup", doMouseUp, false); canvas.addEventListener(“functionmousedown", doMouseDown, false); For a more complete list : Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015