22. translation & rotation i

14
From last time… Solar System (with 2 constructors) Using sin() on size, color, and position Using Perlin noise() in 2 and 3 dimensions Let’s talk about recursion

Upload: joseph-murphy

Post on 15-Jan-2015

94 views

Category:

Education


5 download

DESCRIPTION

 

TRANSCRIPT

Page 1: 22. Translation & Rotation I

From last time…• Solar System (with 2 constructors)!

• Using sin() on size, color, and position!

• Using Perlin noise() in 2 and 3 dimensions!

• Let’s talk about recursion…

Page 2: 22. Translation & Rotation I

Recursion• A method which calls itself…

myMethod() { doSomething(); }

doSomething() { print(“Hey!”); }

myMethod() { myMethod(); }

myMethod() { myMethod(); }

myMethod() { myMethod(); }

myMethod() { myMethod(); }

An infinite loop. FOREVER.! This is bad.

Page 3: 22. Translation & Rotation I

Recursion• Therefore you must provide an exit condition!

• “I’m going to keep calling myself until I reach my exit condition.”!

• This is similar to while and for loops!

• Demo: Recursive Square

Page 4: 22. Translation & Rotation I

CAP 3032

Translation &!Rotation I

Page 5: 22. Translation & Rotation I

The Z Axis

+ x– x

+ y

– y

+ z

– z

Page 6: 22. Translation & Rotation I

translate()• translate() shifts the origin of our sketch

temporarily–for the current draw loop!

• Use P3D or OPENGL rendering:!

! size(500, 500, P3D);

• Tell it how far you want to move the origin:!

translate(moveX, moveY, moveZ);

Page 7: 22. Translation & Rotation I

Demo!Translate

Page 8: 22. Translation & Rotation I

Vertex Shapes• To draw arbitrary shapes, use three methods:!

beginShape();

// POINTS, LINES, TRIANGLES, TRIANGLE_FAN, TRIANGLE_STRIP, QUADS, or QUAD_STRIP

vertex(); OR curveVertex();

endShape(); OR endShape(CLOSE);

Page 9: 22. Translation & Rotation I

Demo!Trapezoid

Page 10: 22. Translation & Rotation I

Vertex Shapes

In 3D!In 3D!• Basically the same method, but compose a 3D

volume out of component shapes in 3D space!

• For example, a cube would be 6 squares placed in 3D space

Page 11: 22. Translation & Rotation I

Demo!Top of the Pyramid

Page 12: 22. Translation & Rotation I

‘Simple’ Rotation

• Rotating using the rotation(); method!

• Processing rotates around the point of origin!

• But the point of origin can move with the translate() method…

Page 13: 22. Translation & Rotation I

Demo!Pyramid Rotation

Page 14: 22. Translation & Rotation I

For next time…

• Iteration 2: present on Monday!!

• Shiffman, p. 239–252 (Translation/Rotation II)!

• Homework 4: moved until after Iteration 2