Translation and Rotation in 2D and 3D David Meredith Aalborg University.

Slides:



Advertisements
Similar presentations
Computer Graphics 2D & 3D Transformation.
Advertisements

This terms course Last term we both worked on learning 2 things –Processing –The concepts of graphics etc. This term will focus more on the basic concepts.
A Quick Introduction to Processing
Text David Meredith Aalborg University.
Three Dimensional Modeling Transformations
Informationsteknologi Wednesday, November 7, 2007Computer Graphics - Class 51 Today’s class Geometric objects and transformations.
1 Computer Graphics Week6 –Basic Transformations- Translation & Scaling.
FUNDAMENTALS OF PROGRAMMING SM1204 Semester A 2011.
CMPE 466 COMPUTER GRAPHICS
, Fall 2006IAT 800 Lab 2: Polygons, Transformations, and Arrays.
2.1 si SI31 Advanced Computer Graphics AGR Lecture 2 Basic Modelling.
Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 8 Chapter 8: Transformation Operators.
CHAPTER 7 Viewing and Transformations © 2008 Cengage Learning EMEA.
Transformations Dilations Translations Reflections Rotations.
2D Transformations. World Coordinates Translate Rotate Scale Viewport Transforms Hierarchical Model Transforms Putting it all together.
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
CS 450: Computer Graphics REVIEW: OVERVIEW OF POLYGONS
Graphs in Science You Can Do It!!!.
Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations.
The Viewing Pipeline (Chapter 4) 5/26/ Overview OpenGL viewing pipeline: OpenGL viewing pipeline: – Modelview matrix – Projection matrix Parallel.
Computer Graphics World, View and Projection Matrices CO2409 Computer Graphics Week 8.
Lecture 3 Transformations.
Image Synthesis Rabie A. Ramadan, PhD 2. 2 Java OpenGL Using JOGL: Using JOGL: Wiki: You can download JOGL from.
Part7: Geometric Transformations
CO1301: Games Concepts Dr Nick Mitchell (Room CM 226) Material originally prepared by Gareth Bellaby.
Enlargement OCR Stage 6.
Element. The element Used to dynamically draw graphics using javascript. Capable of drawing paths, circles, rectangles, text, and images.
Geometric Objects and Transformation
1 Computer Graphics Week9 -3D Geometric Transformation.
16/5/ :47 UML Computer Graphics Conceptual Model Application Model Application Program Graphics System Output Devices Input Devices API Function.
Introduction to Computer Graphics Chapter 6 – 2D Viewing Pt 1 1.
Review Inheritance Overloading and overriding. example1.pde.
Transformations Objective: to develop an understanding of the four transformations. Starter – if 24 x 72 = 2016, find the value of: 1)2.8 x 72 = 2)2.8.
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.
Transformations.
Transformations To move a figure in the coordinate system to another location or image, by a rule.
Geometric Transformations Hearn & Baker Chapter 5 Some slides are taken from Robert Thomsons notes.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Computation as an Expressive Medium Lab 2: Polygons, Transformations, and Arrays Evan.
Lecture 3 Transformations. 2D Object Transformations The functions used for modifying the size, location, and orientation of objects or of the camera.
David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke
January 19, y X Z Translations Objects are usually defined relative to their own coordinate system. We can translate points in space to new positions.
Computer Science I 3D Classwork / Homework: plan and implement your own 3D example.
Lecture 5: Introduction to 3D
Computer Graphics Matrices
FUNDAMENTALS OF PROGRAMMING SM1204 SEMESTER A 2012.
Honors Geometry.  We learned how to set up a polygon / vertex matrix  We learned how to add matrices  We learned how to multiply matrices.
Computation as an Expressive Medium Lab 2: Polygons, Transformations, and Arrays (Oh My) Micah.
1 By Dr. HANY ELSALAMONY.  We have seen how to create models in the 3D world. We discussed transforms in lecture 3, and we have used some transformations.
Coordinates and Design. What You Will Learn: To use ordered pairs to plot points on a Cartesian plane To draw designs on a Cartesian plane To identify.
Viewing and Projection. The topics Interior parameters Projection type Field of view Clipping Frustum… Exterior parameters Camera position Camera orientation.
Chapter 5 Notes. 5.6 Reflections ▪ Reflection (flip) – a transformation in which a figure is reflected over a line of reflection (the x and y axes are.
CS 551 / 645: Introductory Computer Graphics Viewing Transforms.
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
Transformations of Shapes Translation by a vector Stretches Rotations around a point Reflections in the x- and y- axis Reflections in the line y = x and.
Section 1-5 Graphical Transformations. Section 1-5 vertical and horizontal translations vertical and horizontal translations reflections across the axes.
CSCE 441 Computer Graphics: 2D Transformations
Transformations. Transformations Introduce standard transformations ◦ Rotation ◦ Translation ◦ Scaling ◦ Shear Derive homogeneous coordinate transformation.
David Meredith Aalborg University
Chapter 14, Translate & Rotate
Polygons, Transformations, and Arrays
The Unit Square Saturday, 22 September 2018.
Transformations Example Draw the line Draw 1 at , ,
FP1 Matrices Transformations
IAT 265 Lecture 2: Java Loops, Arrays Processing setup, draw, mouse Shapes Transformations, Push/Pop.
2D/3D Transformations User Interfaces.
Geometric Objects and Transformations (II)
Translate, Rotate, Matrix
Computation as an Expressive Medium
Transformations with Matrices
Presentation transcript:

Translation and Rotation in 2D and 3D David Meredith Aalborg University

Source This lecture is based on Chapter 14 of Shiffman, D. (2008). Learning Processing. Morgan Kaufmann. ISBN:

Overview 2D and 3D translation Using P3D and OpenGL Vertex shapes 2D and 3D rotation Saving the transformation state in the stack – pushMatrix() and popMatrix()

“Voxels” – pixels in 3D You can draw things in 3D in Processing You specify 3D positions with 3D co-ordinates, (x,y,z) The x and y axes are the same as for 2D – x increases to the right – y increases downwards The positive z-axis points out of the screen towards you A voxel is the 3D equivalent of a pixel – it is an atomic cubic region in the 3D space – The properties of the space within a voxel must be the same throughout the voxel

translate() in 2D The translate(x,y) function moves the origin, (0,0), to position (x,y) For example, translate(50,50) moves the origin, (0,0), to (50,50) so a point that was at (100,100) becomes (50,50) A call to translate() only has effect until the end of the current frame – at the beginning of the next frame, the origin moves back to (0,0)

Using translate(x,y)

Translations in 3D Use P3D renderer in size() function Add 3 rd co- ordinate to translate() function

Simple animation in 3D translate() only has effect until the end of the current frame (i.e., the end of the current call to draw()) So must reposition origin relative to (0,0,0) on every frame translate() only has effect until the end of the current frame (i.e., the end of the current call to draw()) So must reposition origin relative to (0,0,0) on every frame

Java2D, P3D or OpenGL To render objects in 2D, Processing uses the Java2D renderer and libraries – this is what we’ve been doing all along! To render objects in 3D, you have to tell Processing which renderer to use There are two renderers: – P3D – developed especially for Processing cannot use smooth() with P3D – OPENGL Can use if you have an OpenGL graphics card Uses hardware acceleration for rendering graphics faster All graphics are smoothed (ignores smooth() and noSmooth()) To use P3D, put following line in setup(): size(x,y,P3D); To use OpenGL – Put following line in setup(): size(x,y,OPENGL); – Import the Processing opengl library by putting following line at beginning of sketch import processing.opengl.*;

Vertex shapes - Open Use beginShape() to start the vertex shape Then use vertex(x,y) to specify a vertex at (x,y) Use endShape() to end the vertex shape Note that if endShape has no argument, then the shape is “open”

Vertex shapes - Closed Use the CLOSE argument to close the vertex shape Note that this shape is closed

Vertex Shapes - POINTS Use the POINTS argument to beginShape to get Processing to render each vertex in the vertex shape as a separate, unconnected point If POINTS is given to beginShape, then it doesn’t matter if CLOSE is given to endShape or not

Vertex shapes - LINES Use the LINES argument in beginShape to get processing to interpret each pair of consecutive vertices as the endpoints of a line This vertex is the start of the first line This vertex is the end of the first line This vertex is the start of the second line

Vertex shapes - TRIANGLES Use TRIANGLES as the argument to beginShape to make Processing interpret each set of 3 consecutive vertices as forming a triangle These three points form the first triangle These three points form the second triangle

Vertex shapes – Other beginShape arguments beginShape can also take other arguments: – TRIANGLE_FAN – TRIANGLE_STRIP – QUADS – QUAD_STRIP See the Processing reference for details

Vertex shapes in 3D Position of apex depends on size of display Can use TRIANGLES argument to beginShape to draw the triangular faces of a pyramid Can change the fill colour of each face in between calling beginShape and endShape

Rotation in 2D rotate(theta) rotates theta radians clockwise around the origin (i.e., (0,0) )

Rotation in 2D Translate the origin to the desired centre of rotation Change rectMode so that specify centre of rectangle Rotate the co-ordinate system by 45 degrees clockwise around the new origin

Rotate in response to mouse Translate centre of rotation to centre of display Find the angle of rotation based on horizontal mouse position Rotate the co- ordinate system clockwise by theta radians

Changing the axis of rotation rotateX(theta) rotates around the x-axis rotateY(theta) rotates around the y-axis rotate() and rotateZ() rotate around the z- axis

Combining rotateX and rotateY Angle of rotation around X axis controlled by horizontal mouse position Angle of rotation around Y axis controlled by vertical mouse position

Rotating a 3D object

The scale() function The scale(f) function shrinks or enlarges objects by the scale factor f, which is a float For example, scale(0.5) shrinks all objects drawn between this line and the end of the current frame to ½ of their specified size scale(3.0) enlarges all objects drawn between this line and the end of the current frame to 3 times their specified size The centre of enlargement is always (0,0), so if you want to change this, you have to use a call to translate (x,y) before calling scale

A shrinking and growing rectangle Move centre of enlargement to centre of display Increase t by 1 degree per frame Set the scale factor to 1.1 added to the sine of t

Transformation Matrices Every time you apply scale(), rotate() or translate(), you transform the co- ordinate system Such a transformation is stored as a table of 6 numbers called a matrix

pushMatrix() and popMatrix() Sometimes we want to store the current co- ordinate system transformation so that we can temporarily use another transformation and then return to the stored one We do this using pushMatrix() and popMatrix() – pushMatrix() stores the current matrix on the matrix stack – popMatrix “pops” the most recently stored matrix from the matrix stack Think of pushMatrix() as pushing down a new plate onto a spring-loaded plate stacker popMatrix() is like popping out the top plate on the stack of plates

Using pushMatrix() and popMatrix() Cyan rectangle rotates by 1 degree per frame around x axis Yellow rectangle rotates by 2 degrees per frame around y axis pushMatrix() stores the untransformed co- ordinate system popMatrix() restores the untransformed co- ordinate system

Independently rotating objects

A simple solar system