Animation and Input CSCI 440 - Day Six. Animation Basic Steps to Draw Something: var vertices = [ … ]; var BufferId = gl.CreateBuffer(); gl.bindBuffer.

Slides:



Advertisements
Similar presentations
Computer and Communication Fundamental Basic web programming Lecture 8 Rina Zviel-Girshin.
Advertisements

1 Computer Graphics Chapter 2 Input Devices. RM[2]-2 Input Devices Logical Input Devices  Categorized based on functional characteristics.  Each device.
Computer Science 103 Chapter 4 Advanced JavaScript.
Based on slides created by Edward Angel
Informationsteknologi Tuesday, November 6, 2007Computer Graphics - Class 41 Today’s class Input and interaction.
Scratch the Cat. Object Oriented Programing Writing computer programs Based on Objects Instead of Actions Based on Data Instead of Logic.
Michael Robertson Yuta Takayama. WebGL is OpenGL on a web browser. OpenGL is a low-level 3D graphics API Basically, WebGL is a 3D graphics API that generates.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
19/4/ :32 Graphics II Syllabus Selection and Picking Session 1.
1 Forms A form is the usual way that information is gotten from a browser to a server –HTML has tags to create a collection of objects that implement this.
© Cheltenham Computer Training 2001 Macromedia Dreamweaver 4 - Slide No 1 Macromedia Dreamweaver 4 Advanced Level Course.
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.
Fundamentals of Computer Graphics Part 3 prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared with Angel,E.: Interactive.
Interaction with Graphics System
Mr. Computer & Mrs. Function
School of Computer Science University of Seoul. 1. Interaction 2. Input Devices 3. Clients and Servers 4. Display Lists 5. Programming Event-Driven Input.
WebGL: in-browser 3D graphics Nick Whitelegg Maritme and Technology Faculty Southampton Solent University.
1Computer Graphics Input and Interaction Lecture 8 John Shearer Culture Lab – space 2
CAP 4703 Computer Graphic Methods Prof. Roy Levow Lecture 3.
Input and Interaction Lecture No. 4.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Input and Interaction. 2 Input Devices Physical input devices Keyboard devices and pointing devices Logical input devices.
Computer Graphics I, Fall 2010 Input and Interaction.
CS 450: COMPUTER GRAPHICS PORTRAIT OF AN OPENGL PROGRAM SPRING 2015 DR. MICHAEL J. REALE.
Ch 2 Graphics Programming page 1 CSC 367 Coordinate Systems (2.1.2) Device coordinates, or screen coordinates (pixels) put limitations on programmers and.
CS 480/680 Computer Graphics Programming with Open GL Part 7: Input and Interaction Dr. Frederick C Harris, Jr. Fall 2011.
1 Graphics CSCI 343, Fall 2015 Lecture 4 More on WebGL.
1 Graphics CSCI 343, Fall 2015 Lecture 2 Introduction to HTML, JavaScript and WebGL.
CSCE 121: Introduction to Program Design and Concepts, Honors Dr. J. Michael Moore Spring 2015 Set 15: GUIs 1.
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.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
Program 2 due 02/01  Be sure to document your program  program level doc  your name  what the program does  each function  describe the arguments.
1 Input and Interaction. 2 Objectives Introduce the basic input devices ­Physical Devices ­Logical Devices ­Input Modes Event-driven input Introduce double.
User Input and Animation. For Further Reading Angel 7 th Ed: –Chapter 3: Input and Animation. –Chapter 4: Rotation and other transformation. Beginning.
1 Graphics CSCI 343, Fall 2015 Lecture 6 Viewing, Animation, User Interface.
University of New Mexico
1 Graphics CSCI 343, Fall 2015 Lecture 3 Introduction to WebGL.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor.
CMPF114 Computer Literacy Chapter 3 The Visual Basic Environment 1.
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.
Understanding JavaScript and Coding Essentials Lesson 8.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
JavaScript Events Java 4 Understanding Events Events add interactivity between the web page and the user You can think of an event as a trigger that.
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
COMP 175 | COMPUTER GRAPHICS Remco Chang1/XX13 – GLSL Lecture 13: OpenGL Shading Language (GLSL) COMP 175: Computer Graphics April 12, 2016.
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.
CS 480/680 Computer Graphics Programming with Open GL Part 2: Complete Programs Dr. Frederick C Harris, Jr. Fall 2011.
Section 10.1 Define scripting
Graphics CSCI 343, Fall 2017 Lecture 13 More on WebGL
CSC461 Lecture 8: Input Devices
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Object-Oriented Programming
Programming with OpenGL Part 2: Complete Programs
Introduction to Computer Graphics with WebGL
Chapter VI OpenGL ES and Shader
Isaac Gang University of Mary Hardin-Baylor
Fundamentals of Computer Graphics Part 3
Input and Interaction Ed Angel
Introduction to Computer Graphics with WebGL
University of New Mexico
Input and Interaction Ed Angel
Input and Interaction Ed Angel Professor Emeritus of Computer Science,
Introduction to Computer Graphics with WebGL
Presentation transcript:

Animation and Input CSCI Day Six

Animation Basic Steps to Draw Something: var vertices = [ … ]; var BufferId = gl.CreateBuffer(); gl.bindBuffer ( …, BufferId ); gl.bufferData ( …, flatten (vertices),…) function render() { gl.clear (…); gl.drawArrays (gl.TRIANGLES, 0, vertexCount); }

Animation To create movement: 1.data points must change –option one: send new data points –option two: make the vertex shader compute new points 2.render() must be called again –option one: call itself recursively –option two: put it on a timer

Animation - options to create movement Example stolen from section 3.1 Option 1 - inside render(): have CPU update vertices[], then call bufferData. Option 2A - send just the new angle Option 2B - send a 4x4 matrix

Option 2A - send new angle JavaScript: var theta = 0.0; var vertices = [ a square ]; bufferData vertices to GPU's vPosition var thetaLocation = gl.getUniformLocation ( program, "theta" ); function render() { gl.clear … theta += 0.1; gl.uniform1f (thetaLocation, theta); gl.drawArrays … } Vertex Shader: attribute vec4 vPosition; uniform float theta; void main() { gl_Position.x = -sin(theta) * vPosition.x + … gl_Position.y = sin(theta) * vPosition.y + … gl_Position.z = 0.0; gl_Position.w = 1.0; }

Option 2B - send a new matrix JavaScript: var vertices = [ a square ]; bufferData vertices to GPU's vPosition modelMatrixLocation = gl.getUniformLocation ( program, "modelMatrix" ); function render() { gl.clear … amount += 0.01; myMatrix = rotate (amount, [0,0,1]); gl.uniformMatrix4fv (modelMatrixLocation, false, flatten(myMatrix) ); gl.drawArrays ( … ); } Vertex Shader: attribute vec4 vPosition; uniform mat4 modelMatrix; void main() { gl_Position = modelMatrix * vPosition; } How this works is next week

Animation Animation - repeating render()  Manually set a timer: setInterval ( render, 33 ); // 30 frames/sec  Make render() recursive: render() {... render (); }  Update as fast as possible when visible: render() { … requestAnimFrame ( render ); }

Input Input - vocabulary Physical Input Device - characterized by its mechanics –e.g. a mouse Logical Input Device - characterized by what the device does –e.g. an (X,Y) location or a menu choice In 99.99% of applications, you probably want to avoid programming at the physical device level –tedious code –non-portable code see textbook section 3.4

Input Modes Request Mode –the device returns a value when device is triggered –e.g. cin >> value; Sample Mode –input is immediate –e.g. periodically poll the location of the mouse Event Mode –user creates events that trigger callback functions –e.g. nearly every server –e.g. nearly every GUI see textbook section 3.4

Traditional Logical Input Devices String –e.g. keyboard input Locator –e.g. an X,Y location from a mouse Pick –e.g. an item on the screen that was selected Choice –e.g. one of a discrete number of options, menu Valuator –e.g. a slide bar Stroke –e.g. an array of locations Gesture –e.g. two finger pinch see textbook section 3.4

Input with WebGL WebGL has No direct support for input –OpenGL discontinued support for input –makes WebGL code more portable JavaScript –event driven –we can tie callback functions to HTML buttons, slide bars, menus, text boxes, etc.

JavaScript's Logical Input Devices String –HTML text box Locator –X,Y location connected to a click event Pick –see next slide Choice –HTML menu Valuator –HTML slidebar Stroke –store X,Y locations of a series of click events

Picking with JavaScript 1.Make a "hit list" of which objects remained after clipping 2.transform the event's X,Y screen coordinates into world coordinates 3.check each un-clipped object to determine which one was near the selected location this is difficult because we usually only know the modelling coordinates of objects, not where the objects where transformed

Suppose the variable "amount" is set by some buttons or a slide bar. How does our render() code need to change? function render() { gl.clear … myMatrix = rotate (amount, [0,0,1]); gl.uniformMatrix4fv(…,flatten(myMatrix)); gl.drawArrays ( … ); requestAnimFrame ( render ); }

Next class Lots of JavaScript code –buttons –menus –slide bars