1 / 60

COS 397 Computer Graphics

COS 397 Computer Graphics. Svetla Boytcheva AUBG, Spring 2013. Lecture 3 Solid Shapes, Colors, Lightening. Outline. Colors Solid Shapes. Colors. What is the color?. Definitions Physics : frequency of electro-magnetic waves Biology: three color receptors of the human eye

dixon
Download Presentation

COS 397 Computer Graphics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COS 397 Computer Graphics SvetlaBoytcheva AUBG, Spring 2013

  2. Lecture 3Solid Shapes, Colors, Lightening

  3. Outline • Colors • Solid Shapes

  4. Colors

  5. What is the color? • Definitions • Physics: frequency of electro-magnetic waves • Biology: three color receptors of the human eye • Psychology: color is an interpretation in the human brain

  6. Physical Fundamentals • Electromagnetic Spectrum shortwaves Wave length 1000 m АМ radio 100 m Short radio waves 1 m TV&FMradio waves Radars (and microwaves) 1 cm

  7. Infrared rays 1000 nm Visible Roentgen waves (X-rays) 100 nm Ultraviolet rays 0.1 nm Gamma rays 400 nm 500 nm 600 nm 700 nm

  8. http://mynasadata.larc.nasa.gov/science-processes/electromagnetic-diagram/http://mynasadata.larc.nasa.gov/science-processes/electromagnetic-diagram/

  9. Biological Fundamentals

  10. Different perception • Three types of “cones” • L- The first responds the most to light of long wavelengths, peaking at a reddish color; this type is sometimes designated L for long. • M - The second type responds the most to light of medium-wavelength, peaking at a green color, and is abbreviated M for medium. • S - The third type responds the most to short-wavelength light, of a bluish color, and is designated S for short. • Brain receives information • Only data about activity of these three types of “cones” • There is no direct sensitivity for orange color

  11. Chromatics • Ability for color perception through different color channels • Monochromatic • Bichromatic – two base colors • Trichromatic – three base colors • Tetrachromatic– four base colors • Pentachromatic – five or more base colors (pigeons, butterflyes)

  12. People • Chromatics • People in general are trichromatic(red, green, blue) • For some deceases - monochromatic • Some people are partially tetrachromatic(more often women) Note: There are trichromatic with other base colors - some insects – green, blue, ultraviolet

  13. Other factors • Light • Colors of other objects • Relative colors interpretation

  14. Light blue & Red

  15. This is gray

  16. Light blue and Red are Actually different interpretations of Gray color

  17. hue • The color of the color(hue) • Hue defines pure color in terms of "red", "green" or "magenta". • Characteristics that allows us to recognize whether the color is yellow or green

  18. intensity, brightness, lightness • Lightness defines a range from dark (0%) to fully illuminated (100%). • Any original hue has the average lightness level of 50%. • Intensity is a synonym for magnitude, degree or strength. It can therefore be used in conjunction with any color property. Nevertheless, it carries special meaning in certain contexts. • Brightness is an attribute of our perception which is mainly influenced by a color's lightness. This is probably why brightness and lightness are often mixed up. Brightness is not a color property, if used "correctly".

  19. saturation • Saturation defines a range from pure color (100%) to gray (0%) at a constant lightness level. A pure color is fully saturated. • From a perceptional point of view saturation influences the grade of purity or vividness of a color/image. • A desaturated image is said to be dull, less colorful or washed out but can also make the impression of being softer.

  20. Transformations • RGB • CMYK

  21. Other Models • YIQ (forNTSC) • Four components • HSV • H (hue) – 0 to 360 degrees (0=R, 120=G) • S (saturation)– from 0 to 1 • V (value) from 0=black to 1=normal brightness

  22. Other • HSL • H (hue) – 0 to 360 degrees (0=R, 120=G) • S (saturation)- 0 to 1 • L (lightness) - 0=black to 1=white • YUV (YCbCr, …) • Y (luma) • U(Cb)/V(Cr) (chrominance)

  23. RGB →Grayscale • Different transformations • Average • Weights for different colors

  24. RGB ↔ CMYK • Complement colors in range 0..1 • Relation

  25. RGB ↔ HSV • HSVis“diagonal” projection of RGB 120о 0о 240о

  26. Two versions of color wheel

  27. Opposite

  28. Uniform

  29. Splitting or Neighbors

  30. Example • “The Great Wave off Kanagawa”, Hokusai's most famous print, the first in the series 36 Views of Mount Fuji

  31. SOLID SHAPES

  32. Solid Cube - Example

  33. #include <cstdlib> • #include <GL/glfw.h> • #include “COS397lib.h" • void drawSolidCube (float x,floaty,floatz,float a) • { • a = a/2; • // Drawing side -X • glColor3ub( 255, 0, 0 ); • glBegin( GL_POLYGON ); • glVertex3f(x-a, y-a, z-a); • glVertex3f(x-a, y-a, z+a); • glVertex3f(x-a, y+a, z+a); • glVertex3f(x-a, y+a, z-a); • glEnd(); • // Drawing side +X • glColor3ub( 0, 255, 0 ); • glBegin( GL_POLYGON ); • glVertex3f(x+a, y-a, z-a); • glVertex3f(x+a, y-a, z+a); • glVertex3f(x+a, y+a, z+a); • glVertex3f(x+a, y+a, z-a); • glEnd(); • // Drawing side -Y • glColor3ub( 0, 0, 255 ); • glBegin( GL_POLYGON ); • glVertex3f(x-a, y-a, z-a); • glVertex3f(x-a, y-a, z+a); • glVertex3f(x+a, y-a, z+a); • glVertex3f(x+a, y-a, z-a); • glEnd();

  34. // Drawing side +Y • glColor3ub( 255, 0, 255 ); • glBegin( GL_POLYGON ); • glVertex3f(x-a, y+a, z-a); • glVertex3f(x-a, y+a, z+a); • glVertex3f(x+a, y+a, z+a); • glVertex3f(x+a, y+a, z-a); • glEnd(); • // Drawing side -Z • glColor3ub( 255, 255, 0 ); • glBegin( GL_POLYGON ); • glVertex3f(x-a, y-a, z-a); • glVertex3f(x-a, y+a, z-a); • glVertex3f(x+a, y+a, z-a); • glVertex3f(x+a, y-a, z-a); • glEnd(); • // Drawing side +Z • glColor3ub( 0, 255, 255 ); • glBegin( GL_POLYGON ); • glVertex3f(x-a, y-a, z+a); • glVertex3f(x-a, y+a, z+a); • glVertex3f(x+a, y+a, z+a); • glVertex3f(x+a, y-a, z+a); • glEnd(); • }

  35. int main() • { • init(); • glClearColor( 1.0f, 1.0f, 1.0f, 1.0f ); • glEnable( GL_DEPTH_TEST ); • while( running() ) • { • glClear( GL_COLOR_BUFFER_BIT+GL_DEPTH_BUFFER_BIT ); • glRotatef( 0.2, 0.4, -0.2, 0.7); • drawSolidCube( 0.0, 0.0, 0.0, 5 ); • glfwSwapBuffers(); • } • finit(); • return 0; • }

  36. Solid Cube Lightening

  37. Solid cube with lightening • We need to calculate normal vectors • glNormal() • To process lightening • glEnable()

  38. #include <cstdlib> • #include <GL/glfw.h> • #include “COS397lib.h" • void drawSolidCube (float x,floaty,floatz,float a) • { • a = a/2; • // side -X • glBegin( GL_POLYGON ); • glNormal3f(-1.0, 0.0, 0.0); • glVertex3f(x-a, y-a, z-a); • glVertex3f(x-a, y-a, z+a); • glVertex3f(x-a, y+a, z+a); • glVertex3f(x-a, y+a, z-a); • glEnd(); • // side +X • glBegin( GL_POLYGON ); • glNormal3f(+1.0, 0.0, 0.0); • glVertex3f(x+a, y-a, z-a); • glVertex3f(x+a, y-a, z+a); • glVertex3f(x+a, y+a, z+a); • glVertex3f(x+a, y+a, z-a); • glEnd(); • // side -Y • glBegin( GL_POLYGON ); • glNormal3f(0.0, -1.0, 0.0); • glVertex3f(x-a, y-a, z-a); • glVertex3f(x-a, y-a, z+a); • glVertex3f(x+a, y-a, z+a); • glVertex3f(x+a, y-a, z-a); • glEnd();

  39. // side +Y • glBegin( GL_POLYGON ); • glNormal3f(0.0, +1.0, 0.0); • glVertex3f(x-a, y+a, z-a); • glVertex3f(x-a, y+a, z+a); • glVertex3f(x+a, y+a, z+a); • glVertex3f(x+a, y+a, z-a); • glEnd(); • // side -Z • glBegin( GL_POLYGON ); • glNormal3f(0.0, 0.0, -1.0); • glVertex3f(x-a, y-a, z-a); • glVertex3f(x-a, y+a, z-a); • glVertex3f(x+a, y+a, z-a); • glVertex3f(x+a, y-a, z-a); • glEnd(); • // side +Z • glBegin( GL_POLYGON ); • glNormal3f(0.0, 0.0, +1.0); • glVertex3f(x-a, y-a, z+a); • glVertex3f(x-a, y+a, z+a); • glVertex3f(x+a, y+a, z+a); • glVertex3f(x+a, y-a, z+a); • glEnd(); • }

  40. int main() • { • init(); • glClearColor( 1.0f, 1.0f, 1.0f, 1.0f ); • glEnable( GL_DEPTH_TEST ); • glEnable( GL_LIGHTING ); • glEnable( GL_COLOR_MATERIAL ); • glEnable( GL_LIGHT0 ); • while( running() ) • { • glClear( GL_COLOR_BUFFER_BIT+GL_DEPTH_BUFFER_BIT ); • glRotatef( 0.05, 0.4, -0.2, 0.7); • glColor3ub( 255, 0, 0 ); • drawSolidCube( 0.0, 0.0, 0.0, 5 ); • glfwSwapBuffers(); • } • finit(); • return 0; • }

  41. Circle approximation with polygon

  42. #include <cstdlib> • #include <math.h> • #include <GL/glfw.h> • #include “COS397lib.h" • void drawCircleXY( float x, float y, float z, float r ) • { • int n = 64; • float alpha = 0.0; • float dalpha = 2*M_PI/n; • glBegin( GL_LINE_LOOP ); • for( inti=0; i<n; i++) • { • glVertex3f( x+r*cos(alpha), y+r*sin(alpha), z ); • alpha += dalpha; • } • glEnd(); • }

  43. int main() • { • init(); • glClearColor( 1.0f, 1.0f, 1.0f, 1.0f ); • glEnable( GL_DEPTH_TEST ); • while( running() ) • { • glClear( GL_COLOR_BUFFER_BIT+GL_DEPTH_BUFFER_BIT ); • glRotatef( 0.05, 0.4, -0.2, 0.7); • glColor3ub( 0, 0, 0 ); • drawOxyz(); • glColor3ub( 255, 0, 0 ); • drawCircleXY( 0, 0, -2, 3 ); • drawCircleXY( 0, 0, 0, 3 ); • drawCircleXY( 0, 0, +2, 3 ); • glfwSwapBuffers(); • } • finit(); • return 0; • }

  44. Cone

  45. #include <cstdlib> • #include <math.h> • #include <GL/glfw.h> • #include “COS397lib.h" • void drawCone ( float x, float y, float z, float r, float h ) • { • int n = 32; • float alpha = 0.0; • float dalpha = 2*M_PI/n; • for( inti=0; i<n; i++) • { • float dx1 = r*cos(alpha); • float dy1 = r*sin(alpha); • float dx2 = r*cos(alpha+dalpha); • float dy2 = r*sin(alpha+dalpha); • // surface • glBegin( GL_LINE_LOOP ); • glVertex3f( x+dx1, y+dy1, z ); • glVertex3f( x+dx2, y+dy2, z ); • glVertex3f( x, y, z+h ); • glEnd(); • // bottom • glBegin( GL_LINE_LOOP ); • glVertex3f( x, y, z ); • glVertex3f( x+dx1, y+dy1, z ); • glVertex3f( x+dx2, y+dy2, z ); • glEnd(); • alpha += dalpha; • } • }

  46. int main() • { • init(); • glClearColor( 1.0f, 1.0f, 1.0f, 1.0f ); • glEnable( GL_DEPTH_TEST ); • while( running() ) • { • glClear( GL_COLOR_BUFFER_BIT+GL_DEPTH_BUFFER_BIT ); • glRotatef( 0.05, 0.4, -0.2, 0.7); • glColor3ub( 0, 0, 0 ); • drawOxyz(); • glColor3ub( 255, 0, 0 ); • drawCone( 0, 0, -3, 3, 6 ); • glfwSwapBuffers(); • } • finit(); • return 0; • }

  47. Cylinder

  48. #include <cstdlib> #include <math.h> #include <GL/glfw.h> #include “COS397lib.h" void drawCylinder ( float x, float y, float z, float r, float h ) { int n = 32; float alpha = 0.0; float dalpha = 2*M_PI/n; for( int i=0; i<n; i++) { float dx1 = r*cos(alpha); float dy1 = r*sin(alpha); float dx2 = r*cos(alpha+dalpha); float dy2 = r*sin(alpha+dalpha);

  49. // surface glBegin( GL_LINE_LOOP ); glVertex3f( x+dx1, y+dy1, z ); glVertex3f( x+dx2, y+dy2, z ); glVertex3f( x+dx2, y+dy2, z+h ); glVertex3f( x+dx1, y+dy1, z+h ); glEnd(); // bottom glBegin( GL_LINE_LOOP ); glVertex3f( x, y, z ); glVertex3f( x+dx1, y+dy1, z ); glVertex3f( x+dx2, y+dy2, z ); glEnd(); // top glBegin( GL_LINE_LOOP ); glVertex3f( x, y, z+h ); glVertex3f( x+dx1, y+dy1, z+h ); glVertex3f( x+dx2, y+dy2, z+h ); glEnd(); alpha += dalpha; } }

More Related