1 Graphics CSCI 343, Fall 2015 Lecture 6 Viewing, Animation, User Interface.

Slides:



Advertisements
Similar presentations
Computer Graphic Creator: Mohsen Asghari Session 2 Fall 2014.
Advertisements

Animation and Input CSCI Day Six. Animation Basic Steps to Draw Something: var vertices = [ … ]; var BufferId = gl.CreateBuffer(); gl.bindBuffer.
CSC 461: Lecture 51 CSC461 Lecture 5: Simple OpenGL Program Objectives: Discuss a simple program Discuss a simple program Introduce the OpenGL program.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
InteractionHofstra University1 Graphics Programming Input and Interaction.
Based on slides created by Edward Angel
CSC461 Lecture 9: GLUT Callbacks Objectives Introduce double buffering for smooth animations Programming event input with GLUT.
19/4/ :32 Graphics II Syllabus Selection and Picking Session 1.
CSE 381 – Advanced Game Programming Basic 3D Graphics
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.
The Viewing Pipeline (Chapter 4) 5/26/ Overview OpenGL viewing pipeline: OpenGL viewing pipeline: – Modelview matrix – Projection matrix Parallel.
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.
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
Computer Graphics I, Fall 2010 Input and Interaction.
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 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Graphics CSCI 343, Fall 2015 Lecture 2 Introduction to HTML, JavaScript and WebGL.
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 User Interaction Includes material by Ed Angel Jeff Parker © 2013.
X-WindowsP.K.K.Thambi The X Window System Module 5.
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.
OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.
1 Input and Interaction. 2 Objectives Introduce the basic input devices ­Physical Devices ­Logical Devices ­Input Modes Event-driven input Introduce double.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
1 Graphics CSCI 343, Fall 2015 Lecture 21 Lighting and Shading III.
University of New Mexico
1 Graphics CSCI 343, Fall 2015 Lecture 5 Color in WebGL.
1 Graphics CSCI 343, Fall 2015 Lecture 3 Introduction to WebGL.
CS COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor.
1 Graphics CSCI 343, Fall 2015 Lecture 25 Texture Mapping.
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 Perception and VR MONT 104S, Fall 2008 Lecture 20 Computer Graphics and VR.
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
Coordinate Systems Lecture 1 Fri, Sep 2, The Coordinate Systems The points we create are transformed through a series of coordinate systems before.
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 15 Creating 3D Models.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
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.
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
CSC461 Lecture 8: Input Devices
Programming with OpenGL Part 2: Complete Programs
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Programming with OpenGL Part 2: Complete Programs
Introduction to Computer Graphics with WebGL
Programming with OpenGL Part 2: Complete Programs
Introduction to Computer Graphics with WebGL
Isaac Gang University of Mary Hardin-Baylor
Input and Interaction Ed Angel
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
University of New Mexico
Input and Interaction Ed Angel
Programming with OpenGL Part 2: Complete Programs
Computer Graphics 3Practical Lesson
Programming with OpenGL Part 2: Complete Programs
Input and Interaction Ed Angel Professor Emeritus of Computer Science,
Presentation transcript:

1 Graphics CSCI 343, Fall 2015 Lecture 6 Viewing, Animation, User Interface

2 The Clipping Volume The region of the scene that's imaged is the clipping volume. (Or the clipping rectangle for 2D images). near far left right top bottom Regions outside the clipping volume are not rendered.

3 WebGL default The default clipping volume for WebGL is a 2-unit cube. Each dimension (x, y and z) ranges from -1 to 1. far plane at z = -1 (1, 1, 1)(-1, 1, 1) (1, -1, 1) (-1, -1, 1) The camera image plane is located at z = 0. The camera points along the negative z axis. For orthographic projection, items behind the camera are also imaged. WebGL uses orthographic projection as the default.

4 Orthographic projection Orthographic projection sets all Z values to zero. Point P = (X, Y, Z), will project to image point p = (x, y) where x = X and y = Y Y Z P = (Xp, Yp, Zp) Yp

5 View Ports  Clipping window is defined in world coordinates.  WebGL renders the image in screen coordinates.  WebGL must translate the image from world coordinates to the screen pixel coordinates.  The drawing region on the screen is called the viewport.

6 Defining a viewport gl.viewport(x, y, width, height); (x, y) w h Lower lefthand corner

7 Mapping from world to screen Want entire image from the clipping region to be mapped onto the entire viewport. Therefore, you need to make the height/width (aspect ratio) the same for both (or you will get a distorted image). ClippingViewPort hchc wcwc wvwv hvhv Demo with triangle1.js

8 Calculating the mapping  Points on the left border of the clipping window, map to points on the left border of the viewPort.  Points on the right border of the clipping window, map to points on the right border of the viewPort.  Points 1/3 of the width from the left in the clipping window, map to points 1/3 of the width from the left in the viewPort. 1/3w c 1/3w v

9 Animation To animate an object in WebGL, the program changes something about the object (e.g. its position) and then redraws it. Computing a new set of positions for every vertex in our scene, and then resending all the position information to the GPU, is inefficient. Instead, we send the vertex positions once, and have a small number of variables that indicate how the position is changing that we send to the GPU. The new positions are calculated by the vertex shaders.

10 Example: Rotating Square (cos(  ), sin(  ))(-cos(  ), -sin(  )) (-sin(  ), cos(  )) (sin(  ), -cos(  )) The vertices of a square inscribed in the unit circle can be given in terms of the sin and cos of the angle of rotation of the square. To rotate the square, we start with initial values for each vertex and theta = 0, which are sent to the vertex shader. We then increment theta and send it to the vertex shader, which re-computes the vertex positions.

11 Drawing the initial square var vertices = [ vec2(0, 1), vec2(1, 0), vec2(-1, 0), vec2(0, -1)];... //Bind the initial vertex positions var bufferId = gl.createBuffer(); gl.bindBuffer( gl.ARRAY_BUFFER, bufferId ); gl.bufferData( gl.ARRAY_BUFFER, flatten(vertices), gl.STATIC_DRAW );... //Get the location of the uniform variable, theta, from the // vertex shader program //A uniform variable remains the same for all vertices in an object. thetaLoc = gl.getUniformLocation( program, "theta" ); render();

12 Calculate the vertex positions in the vertex shader attribute vec4 vPosition; uniform float theta; void main() { float s = sin( theta ); float c = cos( theta ); gl_Position.x = -s * vPosition.x + c * vPosition.y; gl_Position.y = s * vPosition.y + c * vPosition.x; gl_Position.z = 0.0; gl_Position.w = 1.0; }

13 Double Buffering Problem: When we re-draw the object in a new position, the new drawing might not be synchronized with the frame rate of the monitor. Solution: Use double buffering. Draw into one buffer while displaying the other, then swap the two. This way we can guarantee that a scene is displayed only after the drawing is finished.

14 Double Buffering WebGL automatically uses double-buffering. The front buffer is the one displayed. The back buffer is the one into which we draw. To request the browser to display the new version of the square use: requestAnimFrame(render); This will refresh the display with the new rendering. It then calls render (recursively).

15 A new render function function render() { gl.clear( gl.COLOR_BUFFER_BIT ); theta += 0.1; gl.uniform1f( thetaLoc, theta ); gl.drawArrays( gl.TRIANGLE_STRIP, 0, 4 ); window.requestAnimFrame(render); } Note: gl.uniform1f(thetaLoc, theta); sends the new theta to the vertex shader. The 1f in the function name means we are sending 1 floating point value. Both thetaLoc and theta were declared as global variables.

16 Input and output devices Input: Keyboard, mouse, light pen, track ball, joystick Information sent to the computer depends on the device: Keyboard: ASCII characters Mouse: Move, position, button click (up or down) Output: Printer, monitor

17 Program requests for input 1)Request Mode Program requests information from the device and waits for a reply. Device collects information into a buffer until a trigger is hit. Then it sends the information to the computer Example: scanf( ) in C is used to read input from the keyboard. The program waits for the user to enter information and hit ( ). 2)Sample Mode Program calls a function that measures and returns a device value (e.g. the mouse position). No trigger is needed. This mode is immediate. Problem: program controlled, not user controlled.

18 Event driven programming Event mode: Every time a device is triggered, it generates an event. Device identifier and measure are stored in the event queue. Example: Mouse click-- Event: Button down Device: left-button Measure: Mouse current position The program examines the events in the queue and responds to them (or not). (The program only responds if it has instructions for handling that particular event).

19 Callback functions The program handles specific events using callback functions. (Also known as Event handlers, or Event Listeners) Program specifies which function should be called for a given event. When a particular event occurs, the specified function is called to handle the event. We will create callback functions for menus, mouse clicks, etc.

20 The client-server model The workstation is the server. It provides input through the keyboard and mouse. It provides output through the monitor (raster display). The program is the client. It requests information from the input devices and sends information to the output devices. Our client and server are the same machine, but they could work over a network. CRT keyboard server Client program Network