this terms course last term we both worked on learning 2 things –processing –the concepts of...

63
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 – Graphics, 2D and 3D – Sound • The course will go more into the maths and theory

Upload: lance-stickels

Post on 14-Dec-2015

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 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

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– Graphics, 2D and 3D– Sound

• The course will go more into the maths and theory

Page 2: 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

Aims

• Understand Vectors– Position/displacement, direction, length

• Use Vectors in Processing programs– in 2D and 3D

• Understand Transforms

• Use Translations and Scales

• Use pushMatrix and popMatrix

Page 3: 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

Vectors

• x and y are the coordinates of points

• In maths we can group them together as a single object (x,y)

• This is called a vector

Page 4: 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

Vectors

• A vector can represent 2 things

Page 5: 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

Vectors

• A vector can represent 2 things

• A position on the screen

• (A position vector)

(x,y)

Page 6: 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

Vectors

• A vector can represent 2 things

• A displacement between two points

• (A displacement vector)

(x,y)

Page 7: 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

Vectors

• A position vector is really a displacement from the origin (0,0)

(x,y)

Page 8: 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

Vectors

• Position Vectors– drawing shapes– positions of object

• Displacement Vectors– Velocities, movements

Page 9: 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

Maths on Vectors

• You can do maths on vectors• Normally you do each operation on each

element separately• It normally help to think about vectors as

displacement vectors

Page 10: 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

Vector addition

• add vectors

• (x1, y1) + (x2, y2) = (x1+x2, y1+y2)

• do one displacement after another

(x1,y1)

(x2,y2)

(x1+x2,y1+y2)

Page 11: 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

Vector subtract

• subtract vector

• (x1, y1) - (x2, y2) = (x1-x2, y1-y2)

• The displacement of one position relative to another

• Very useful

(x1,y1)

(x2,y2)(x2+x1,y2+y1)

Page 12: 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

Length of a vector

• you can calculate the length (magnitude) of a vector using Pythagoras' theorem

• l2 = x2 + y2

• l = sqrt(x2 + y2)

x

yl

Page 13: 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

Length and direction

• You can think of a vector as having a length and a direction

• The direction is a vector that is in the same direction but of length 1

• Calculate it by dividing each component of a vector by the length– (x/sqrt(x2 + y2), y/sqrt(x2 + y2))

• Called normalising

Page 14: 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

Length and direction

• Very useful to be able to think about both• Length

– know the distance between two objects– know how fast an something is moving (e.g. for

setting a max speed)

• Direction– Move at a constant speed in a direction given

by two points– Turn an object to face the direction its moving

in

Page 15: 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

Vectors in 3D

• We can also do the same things in 3D• An extra item, z, represents depth• pass in an extra parameter OPENGL or

P3D to size• The maths works the same

– length is sqrt(x2 + y2 + z2)

Page 16: 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

Vectors in Processing

• dist() gives the distance between two points– length of the displacement between them

Page 17: 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

Vectors in Processing

• dist() gives the distance between two points– length of the displacement between them

• PVector is a class for representing vectors• Its new to the latest version of Processing

Page 18: 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

Exercises

• Rewrite my last example to use PVector• make it work in 3D

Page 19: 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

Aims

• Understand Vectors– Position/displacement, direction, length

• Use Vectors in Processing programs– in 2D and 3D

• Understand Transforms

• Use Translations and Scales

• Use pushMatrix and popMatrix

Page 20: 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

Transformations

• Translate

• Rotate

• Scale

Page 21: 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

Transformations

• Transformations act on the whole processing screen

Page 22: 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

Transformations

• Translate moves the whole coordinate system by a x and y direction

Page 23: 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

Transformations

• Translate moves the whole coordinate system by a x and y direction

Page 24: 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

Transformations

• Anything before the translate call is draw normally

Page 25: 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

Transformations

• Anything before the translate call is draw normally

• Anything after the call is drawn relative to the new transformed coordinate system

Page 26: 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

Transformations

• Scale will change the size of the coordinates relatives to the origin (0, 0)

Page 27: 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

Transformations

• Scale will change the size of the coordinates relatives to the origin (0, 0)

Page 28: 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

Transformations

• The order of transforms is very important

• Changing the order changes the result

Page 29: 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

Transformations

• A transform applies to all the code that happens after it

Page 30: 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

Transformations

• A transform applies to all the code that happens after it

• That means it also applies to other transforms

Page 31: 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

Transformations

• A transform applies to all the code that happens after it

• Translate()

• Translate()

• Translates everything twice

Page 32: 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

Transformations

• A transform applies to all the code that happens after it

• Translate()

• Translate()

• Translates everything twice

Page 33: 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

Transformations

• A transform applies to all the code that happens after it

• A translate followed by a rotate means “apply the translate to the result of rotate”

Page 34: 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

Transformations

• The order of transforms is very important

• Translate()

• Rotate()

• Means translate the result of rotating

Page 35: 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

Transformations

• The order of transforms is very important

• Translate()

• Rotate()

• Means translate the result of rotating

Page 36: 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

Transformations

• The order of transforms is very important

• Translate()

• Rotate()

• Means translate the result of rotating

Page 37: 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

Transformations

• The order of transforms is very important

• Rotate()

• Translate()

• Means rotate the result of translating

Page 38: 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

Transformations

• The order of transforms is very important

• Rotate()

• Translate()

• Means rotate the result of translating

Page 39: 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

Transformations

• The order of transforms is very important

• Rotate()

• Translate()

• Means rotate the result of translating

Page 40: 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

Transformations

• This is the opposite order you would expect

• Translate()

• Rotate()

• Is a bit like rotating then translating

Page 41: 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

Order of transforms

The normal best order is

Translate

Rotate

Scale

This means that an object is scaled the same why no matter how it is rotated

It is translated the same way no matter how it is rotated

Page 42: 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

Order of transforms

• Rotate

• Translate

Page 43: 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

Order of transforms

• Rotate

• Translate

Page 44: 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

Order of transforms

• Rotate

• Translate

• Doesn’t end up at the end point of translating

Page 45: 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

Order of transforms

• Translate

• Rotate

Page 46: 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

Order of transforms

• Translate

• Rotate

Page 47: 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

Order of transforms

• Translate

• Rotate

• Rotates about its centre– if you use

rectMode(CENTER)

• Translates to the correct position

Page 48: 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

Order of transforms

• Similarly if you scale an object differently along x and y and as well as rotating the order matters

• If you do – Scale()– Rotate()

• The result is no longer a rectangle (skewed)

• (see program)

Page 49: 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

Multiple transforms

• But what if we want to draw more than one thing?

Page 50: 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

Multiple transforms

• But what if we want to draw more than one thing?

• If we transform the first one then the second, the first transform will apply to the second as well

Page 51: 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

Transform Matrices

• A transform is represented internally as a matrix

• A 3D array of number

• The details of how doesn’t matter at the moment

Page 52: 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

Transform Matrices

• Up to now we have only had 1 matrix

• All transforms are combined together into this matrix

• To draw more than one object we need more than one matrix

Page 53: 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

Transform Matrices

• Up to now we have only had 1 matrix

• All transforms are combined together into this matrix

• To draw more than one object we need more than one matrix

• Multiple matrices are stored in a “Stack”

Page 54: 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

Stacks

• A Stack is like a stack of paper

1

2

3

4

Page 55: 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

Stacks

• A Stack is like a stack of paper

• You can put things on it– “Push” it on a stack

1

2

3

4

5

Page 56: 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

Stacks

• A Stack is like a stack of paper

• You can put things on it

• And take things off– “Pop” it off the stack

1

2

3

4

Page 57: 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

Stacks

• A Stack is like a stack of paper

• You can put things on it

• And take things off– “Pop” it off the stack

1

2

3

Page 58: 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

Stacks

• The last thing to be put on is the first to be taken off

• Last in, first out

1

2

3

Page 59: 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

Matrix Stacks

• Storing matrices as a stack means that the most recent transforms are the ones you remove first

• Generally what you want

• Global transforms that affect the whole picture are at the bottom

• Transforms that only affect a single object at the top

Page 60: 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

Pushing and Popping Matrices

• PushMatrix() creates a new matrix and puts it on the top of the stack

• You can then do any transforms you like

• PopMatrix() will then remove the matrix from the stack

• i.e. it will remove all the transforms you have done

Page 61: 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

Multiple Objects

• For multiple objects:– PushMatrix() before drawing each object– Do all the transforms for that object– PopMatrix() to get rid of the transforms before

moving on to the next matrix

Page 62: 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

Transforms in 3D

• Translation works exactly the same in 3D• need an x,y and z for the translation vector• rotation is more complex: next lecture

Page 63: 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

Exercises

• Draw a rectangle, rotating, translating and scaling it

• Draw multiple rectangles in multiple positions using PushMatrix and PopMatrix

• Do the same with boxes in 3D