CMSC427 Drawing and parametric curves T odays topics Where - - PowerPoint PPT Presentation

cmsc427 drawing and parametric curves t oday s topics
SMART_READER_LITE
LIVE PREVIEW

CMSC427 Drawing and parametric curves T odays topics Where - - PowerPoint PPT Presentation

CMSC427 Drawing and parametric curves T odays topics Where drawing happens: CPU vs. GPU Drawing a line Basics of drawing: putting a pixel PUTPIXEL(X,Y,R,G,B,A) Basics of drawing:


slide-1
SLIDE 1

CMSC427 ¡ Drawing ¡and ¡ parametric ¡curves

slide-2
SLIDE 2
  • Where ¡drawing ¡happens: ¡CPU ¡vs. ¡GPU
  • Drawing ¡a ¡line

T

  • day’s topics
slide-3
SLIDE 3

Basics of drawing: putting a pixel

PUTPIXEL(X,Y,R,G,B,A)

slide-4
SLIDE 4

Basics of drawing: putting a pixel

PUTPIXEL(X,Y,R,G,B,A) How much data to transfer? Position X,Y – 16 bits each Color – 8 bits each Red Green Blue Alpha (transparency) Total: 8 bytes x # of pixels

slide-5
SLIDE 5

Retaining state

SETCOLOR(R,G,B,A) PUTPIXEL(X,Y) PUTPIXEL(X,Y)

SETCOLOR() sets state of graphics card, doesn’t draw PUTPIXEL() draws Transfer color bits less often More we can ”preload” on graphics card, less we need to do on CPU and then transfer

slide-6
SLIDE 6

Delegating computation

SETCOLOR(R,G,B,A) DRAWCIRCLE(X,Y,R)

SETCOLOR() sets state of graphics card, doesn’t draw DRAWCIRCLE() draws by invoking routine on graphics card Less data transferred. Transfer

  • nly values x,y,R but get all

pixels in circle filled

slide-7
SLIDE 7

Drawing on CPU vs GPU

CPU

FRAMEBUFFER

GPU

Application Graphics library Shader

Hardware Software

Buffers

slide-8
SLIDE 8
  • Download ¡to ¡GPU ¡in ¡advance ¡terrain ¡model, ¡

character ¡model, ¡textures, ¡character ¡behaviors

  • In ¡gameplay ¡only ¡need ¡to ¡download ¡changes ¡in ¡

character ¡state ¡– movement, ¡weapons, ¡etc.

  • Significantly ¡reduce ¡network ¡bandwidth

Preloading for online game

slide-9
SLIDE 9

Beyond the pixel - curves, surfaces and solids

Curves Surfaces Solids

slide-10
SLIDE 10

Drawing a line segment

𝑧 = 𝑛𝑦 + 𝑐 𝑄0 = 𝑦0, 𝑧0 𝑄1 = 𝑦1, 𝑧1 𝑧 𝑦

for x = x0 to x1 y = mx+b putpixel(x,y)

𝑄0 𝑄1

slide-11
SLIDE 11

Drawbacks of standard formula: special cases

𝑧 = 𝑛𝑦 + 𝑐 𝑧 = 0𝑦 + 𝑐 𝑧 = ∞×𝑦 + 𝑐

slide-12
SLIDE 12

Solution: parametric form

𝑦 𝑧 𝑦 = 𝑢 ¡𝑒𝑦 + 𝑞𝑦 𝑧 = 𝑢 ¡𝑒𝑧 + 𝑞𝑧 𝑛 = ¡𝑒𝑧 𝑒𝑦 = ¡𝑧1 − 𝑧0 𝑦1 − 𝑦0 𝑄0 𝑄1 0 ≤ 𝑢 ≤ 1

  • r

𝑢 ∈ [0,1]

slide-13
SLIDE 13

Work for special cases?

𝑦 = 𝑢 ¡𝑒𝑦 + 𝑞𝑦 𝑧 = 𝑢 ¡𝑒𝑧 + 𝑞𝑧

slide-14
SLIDE 14

Work for special cases?

𝑦 = 𝑢 ¡𝑒𝑦 + 𝑞𝑦 𝑧 = 𝑢 ¡𝑒𝑧 + 𝑞𝑧 𝑦 = 𝑢 ¡𝑒𝑦 + 𝑞𝑦 𝑧 = 𝑢×𝟏 + 𝑞𝑧 𝑦 = 𝑢 ¡×𝟏 + 𝑞𝑦 𝑧 = 𝑢 ¡𝑒𝑧 + 𝑞𝑧

slide-15
SLIDE 15

Using t for proportional placement (midpoint, etc)

t = 0 t = 0.25 t = 0.75 t = 1 t = 0.5

𝑦 = 𝑢 ¡𝑒𝑦 + 𝑞𝑦 𝑧 = 𝑢 ¡𝑒𝑧 + 𝑞𝑧 𝑄0 𝑄1

slide-16
SLIDE 16

Varying the range of t: line, line segment and ray

A B t in [0,1] segment A B t in [0,inf] ray A B t in [-inf,inf] line

slide-17
SLIDE 17

Must a parametric line be linear?

𝑦 𝑦 = 𝑢7 ¡𝑒𝑦 + 𝑞𝑦 𝑧 = 𝑢7 ¡𝑒𝑧 + 𝑞𝑧 𝑄0 𝑄1 0 ≤ 𝑢 ≤ 1

  • r

𝑢 ∈ [0,1] 𝑧

slide-18
SLIDE 18

Any use to y=mx+b?

𝑧 = 𝑛𝑦 + 𝑐 𝑦 𝑧

Functional ¡line ¡equation

𝑄 𝑄′

Are ¡P ¡and ¡P’ ¡above ¡or ¡ below ¡the ¡line?

slide-19
SLIDE 19

Any use to mx+b?

𝑧 = 𝑛𝑦 + 𝑐 𝑦 𝑧

Functional ¡line ¡equation

𝑄 𝑄′

Are ¡P ¡and ¡P’ ¡above ¡or ¡ below ¡the ¡line?

𝑧 > 𝑛𝑦 + 𝑐 above 𝑧 < 𝑛𝑦 + 𝑐 below

slide-20
SLIDE 20

Drawing a circle

Implicit ¡equation

𝑦7 + 𝑧7 = 𝑆7

R

“Functional” ¡equation (multi-­‑valued)

𝑧 = ± 𝑦7 + 𝑆7

slide-21
SLIDE 21

Circle with trig

Parametric ¡equation

t

𝑦 = 𝑆 ¡cos ¡ (𝑢) 𝑧 = 𝑆 ¡sin ¡ (𝑢)

cos ¡ (𝑢) sin ¡ (𝑢)

0 ≤ 𝑢 ≤ ¡? ?

slide-22
SLIDE 22

Circle with trig

Parametric ¡equation

t

𝑦 = 𝑆 ¡cos ¡ (𝑢) 𝑧 = 𝑆 ¡sin ¡ (𝑢)

cos ¡ (𝑢) sin ¡ (𝑢)

0 ≤ 𝑢 ≤ 2π

slide-23
SLIDE 23

Validating parametric equations

Substitute ¡parametric ¡ into ¡implicit

t

𝑦 = 𝑆 ¡cos ¡ (𝑢) 𝑧 = 𝑆 ¡sin ¡ (𝑢)

cos ¡ (𝑢) sin ¡ (𝑢)

(𝑆 cos 𝑢 ) ¡7+(𝑆 ¡sin ¡ (𝑢) ¡)7= 𝑆7 𝑆7(𝑑𝑝𝑡7 𝑢 + 𝑡𝑗𝑜7 𝑢 ) = 𝑆7 𝑆7(1) = 𝑆7

slide-24
SLIDE 24

Inside or outside?

Implicit ¡equation

𝑦7 + 𝑧7 = 𝑆7

R

slide-25
SLIDE 25

Inside or outside?

Implicit ¡equation

𝑦7 + 𝑧7 = 𝑆7

R

𝑦7 + 𝑧7 > 𝑆7

  • ut

𝑦7 + 𝑧7 < 𝑆7 in

slide-26
SLIDE 26
  • Implicit

f(x,y) ¡= ¡0

  • Inside/Outside ¡tests
  • Parametric

x ¡= ¡fx(t) y ¡= ¡fy(t)

  • Drawing/Intersection ¡tests
  • Functional

y ¡= ¡f(x)

  • Dual ¡purpose: ¡drawing, ¡testing

Summary of curve equations

slide-27
SLIDE 27

Coding parametric curves

for t = 0 to 2π by step 0.1 x = R*cos(t) y = R*sin(t) putpixel(x,y) for t = t0 to t1 by step dt x = fx(t) y = fy(t) putpixel(x,y) Circle Generic given 𝑦 = 𝑔

M 𝑢

𝑧 = 𝑔

N(𝑢)

slide-28
SLIDE 28

Processing.org

slide-29
SLIDE 29

Processing.org

size(400,400); float r = 100; strokeWeight(5); // Set point size in pixels for (float t = 0; t < 2*PI; t += 0.1) { float x = width/2 + r*cos(t); float y = height/2 + r*sin(t); point(x,y); } save("curve.jpg");

slide-30
SLIDE 30

Playing with the code …

float x = width/2 + 1.5* 1.5*r*cos(t); // Unequal r float y = height/2 + r*sin(t); for (float t = 0; t < 2*PI; t += 0.3 0.3) { // Change increment for (float t = 0; t < PI; t += 0.3 0.3) { // Change limits float x = width/2 + 10*t 10*t*cos(t); // Varying r float y = height/2 + 10*t 10*t*sin(t); strokeWeight(random(1,10)); ¡ ¡point(x,y);

strokeWeight(random(1,10)); // Random point size point(x,y);

slide-31
SLIDE 31

Animate

// Infinity Rainbow // from Jason Labbe (jasonlabbe3d.com) void setup setup() { size(600,600); colorMode(HSB,255); // Hue/Saturation/Brightness background(255); noStroke(); } void draw draw() { fill(frameCount % 255,255,255); float x = (width/2)+100*sin(frameCount/20.0); float y = (height/2)+200*sin(frameCount/10.0); ellipse(x,y,20,20); }

slide-32
SLIDE 32
  • Animate
  • Collect ¡more ¡parametric ¡curves
  • Cartesian
  • Polar
  • Add ¡third ¡dimension
  • Move ¡to ¡surfaces

Next steps

slide-33
SLIDE 33

Superellipses

https://en.wikipedia.org/wiki/Superellipse https://www.desmos.com/calculator

Generalized ¡ellipse ¡that ¡can ¡take ¡different ¡shapes ¡based ¡on ¡exponent ¡n

𝑦 O + 𝑧 O = 𝑆7 𝑦 = 𝑆𝑑𝑝𝑡

7 O 𝑢 𝑡𝑕𝑜(cos 𝑢 )

𝑧 = 𝑆𝑡𝑗𝑜

7 O 𝑢 𝑡𝑕𝑜(sin 𝑢 )

slide-34
SLIDE 34

Andrew March supershapes

slide-35
SLIDE 35

1. Where ¡drawing ¡happens ¡– software ¡rendering ¡

  • n ¡CPU, ¡hardware ¡rendering ¡on ¡GPU, ¡

preloading 2. Why ¡functional ¡equations ¡are ¡problematic 3. How ¡to ¡draw ¡a ¡line ¡and ¡circle ¡with ¡parametric ¡ equation 4. How ¡to ¡use ¡ranges ¡of ¡t ¡for ¡segments, ¡rays ¡and ¡ lines 5. Using ¡implicit ¡and ¡functional ¡equations ¡for ¡ shape ¡inside/outside ¡tests 6. How ¡to ¡validate ¡parametric ¡equations 7. Using ¡powers ¡of ¡fractions ¡to ¡bias ¡curves 8. Using ¡parametric ¡equations ¡for ¡curves, ¡shapes, ¡ animations ¡and ¡other ¡purposes

What you should know after today

slide-36
SLIDE 36
  • Desmos
  • https://www.desmos.com/calculator
  • 2D ¡graphing ¡with ¡parametric ¡curves
  • Andrew ¡Marsh’s ¡supershapes
  • http://andrewmarsh.com/apps/staging/supersha

pes.html

  • Super ¡ellipsoids ¡and ¡similar ¡shapes
  • Processing
  • https://processing.org
  • Resource ¡for ¡quick ¡program ¡“sketches”, ¡concepts
  • Sketches ¡Circle.pde, ¡InfinityRainbow.pde, ¡

HelixFly.pde

T

  • day’s resources