cmsc427 drawing and parametric curves t oday s topics
play

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:


  1. CMSC427 ¡ Drawing ¡and ¡ parametric ¡curves

  2. T oday’s topics • Where ¡drawing ¡happens: ¡CPU ¡vs. ¡GPU • Drawing ¡a ¡line

  3. Basics of drawing: putting a pixel PUTPIXEL(X,Y,R,G,B,A)

  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

  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

  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 only values x,y,R but get all pixels in circle filled

  7. Drawing on CPU vs GPU Application Software Graphics library Shader CPU GPU Hardware FRAMEBUFFER Bu ff ers

  8. Preloading for online game • 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

  9. Beyond the pixel - curves, surfaces and solids Curves Surfaces Solids

  10. Drawing a line segment 𝑧 = 𝑛𝑦 + 𝑐 𝑄1 𝑄0 = 𝑦0, 𝑧0 𝑧 𝑄1 = 𝑦1, 𝑧1 𝑄0 for x = x0 to x1 y = mx+b putpixel(x,y) 𝑦

  11. Drawbacks of standard formula: special cases 𝑧 = ∞×𝑦 + 𝑐 𝑧 = 𝑛𝑦 + 𝑐 𝑧 = 0𝑦 + 𝑐

  12. Solution: parametric form 𝑦 = 𝑢 ¡𝑒𝑦 + 𝑞𝑦 𝑄1 𝑧 = 𝑢 ¡𝑒𝑧 + 𝑞𝑧 𝑧 𝑛 = ¡𝑒𝑧 𝑒𝑦 = ¡𝑧1 − 𝑧0 𝑄0 𝑦1 − 𝑦0 0 ≤ 𝑢 ≤ 1 or 𝑢 ∈ [0,1] 𝑦

  13. Work for special cases? 𝑦 = 𝑢 ¡𝑒𝑦 + 𝑞𝑦 𝑧 = 𝑢 ¡𝑒𝑧 + 𝑞𝑧

  14. Work for special cases? 𝑦 = 𝑢 ¡×𝟏 + 𝑞𝑦 𝑧 = 𝑢 ¡𝑒𝑧 + 𝑞𝑧 𝑦 = 𝑢 ¡𝑒𝑦 + 𝑞𝑦 𝑧 = 𝑢 ¡𝑒𝑧 + 𝑞𝑧 𝑦 = 𝑢 ¡𝑒𝑦 + 𝑞𝑦 𝑧 = 𝑢×𝟏 + 𝑞𝑧

  15. Using t for proportional placement (midpoint, etc) 𝑦 = 𝑢 ¡𝑒𝑦 + 𝑞𝑦 𝑄1 t = 1 𝑧 = 𝑢 ¡𝑒𝑧 + 𝑞𝑧 t = 0.75 t = 0.5 𝑄0 t = 0.25 t = 0

  16. Varying the range of t: line, line segment and ray B B B t in [0,1] t in [0,inf] t in [-inf,inf] A A A segment ray line

  17. Must a parametric line be linear? 𝑦 = 𝑢 7 ¡𝑒𝑦 + 𝑞𝑦 𝑄1 𝑧 = 𝑢 7 ¡𝑒𝑧 + 𝑞𝑧 𝑧 𝑄0 0 ≤ 𝑢 ≤ 1 or 𝑢 ∈ [0,1] 𝑦

  18. Any use to y=mx+b? Functional ¡line ¡equation 𝑄 𝑧 = 𝑛𝑦 + 𝑐 Are ¡P ¡and ¡P’ ¡above ¡or ¡ 𝑧 below ¡the ¡line? 𝑄′ 𝑦

  19. Any use to mx+b? Functional ¡line ¡equation 𝑄 𝑧 = 𝑛𝑦 + 𝑐 Are ¡P ¡and ¡P’ ¡above ¡or ¡ 𝑧 below ¡the ¡line? 𝑄′ 𝑧 > 𝑛𝑦 + 𝑐 above 𝑧 < 𝑛𝑦 + 𝑐 below 𝑦

  20. � Drawing a circle Implicit ¡equation 𝑦 7 + 𝑧 7 = 𝑆 7 R “Functional” ¡equation (multi-­‑valued) 𝑧 = ± 𝑦 7 + 𝑆 7

  21. Circle with trig Parametric ¡equation 𝑦 = 𝑆 ¡cos ¡ (𝑢) sin ¡ (𝑢) t 𝑧 = 𝑆 ¡sin ¡ (𝑢) cos ¡ (𝑢) 0 ≤ 𝑢 ≤ ¡? ?

  22. Circle with trig Parametric ¡equation 𝑦 = 𝑆 ¡cos ¡ (𝑢) sin ¡ (𝑢) t 𝑧 = 𝑆 ¡sin ¡ (𝑢) cos ¡ (𝑢) 0 ≤ 𝑢 ≤ 2 π

  23. Validating parametric equations Substitute ¡parametric ¡ into ¡implicit 𝑦 = 𝑆 ¡cos ¡ (𝑢) sin ¡ (𝑢) t 𝑧 = 𝑆 ¡sin ¡ (𝑢) cos ¡ (𝑢) (𝑆 cos 𝑢 ) ¡ 7 +(𝑆 ¡sin ¡ (𝑢) ¡ ) 7 = 𝑆 7 𝑆 7 (𝑑𝑝𝑡 7 𝑢 + 𝑡𝑗𝑜 7 𝑢 ) = 𝑆 7 𝑆 7 (1) = 𝑆 7

  24. Inside or outside? Implicit ¡equation 𝑦 7 + 𝑧 7 = 𝑆 7 R

  25. Inside or outside? Implicit ¡equation 𝑦 7 + 𝑧 7 = 𝑆 7 R 𝑦 7 + 𝑧 7 > 𝑆 7 out 𝑦 7 + 𝑧 7 < 𝑆 7 in

  26. Summary of curve equations • 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

  27. Coding parametric curves for t = 0 to 2 π by step 0.1 Circle x = R*cos(t) y = R*sin(t) putpixel(x,y) Generic for t = t0 to t1 by step dt given x = fx(t) y = fy(t) 𝑦 = 𝑔 M 𝑢 putpixel(x,y) 𝑧 = 𝑔 N (𝑢)

  28. Processing.org

  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");

  30. Playing with the code … 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 + 1.5* 1.5* r*cos(t); // Unequal r float y = height/2 + r*sin(t); strokeWeight(random(1,10)); ¡ ¡point(x,y); 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)); // Random point size point(x,y);

  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); }

  32. Next steps • Animate • Collect ¡more ¡parametric ¡curves • Cartesian • Polar • Add ¡third ¡dimension • Move ¡to ¡surfaces

  33. Superellipses Generalized ¡ellipse ¡that ¡can ¡take ¡different ¡shapes ¡based ¡on ¡exponent ¡n 7 𝑦 O + 𝑧 O = 𝑆 7 O 𝑢 𝑡𝑕𝑜(cos 𝑢 ) 𝑦 = 𝑆𝑑𝑝𝑡 7 O 𝑢 𝑡𝑕𝑜(sin 𝑢 ) 𝑧 = 𝑆𝑡𝑗𝑜 https://www.desmos.com/calculator https://en.wikipedia.org/wiki/Superellipse

  34. Andrew March supershapes

  35. What you should know after today 1. Where ¡drawing ¡happens ¡– software ¡rendering ¡ on ¡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

  36. T oday’s resources • 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

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend