600 likes | 749 Views
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
E N D
COS 397 Computer Graphics SvetlaBoytcheva AUBG, Spring 2013
Outline • Colors • Solid Shapes
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
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
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
http://mynasadata.larc.nasa.gov/science-processes/electromagnetic-diagram/http://mynasadata.larc.nasa.gov/science-processes/electromagnetic-diagram/
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
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)
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
Other factors • Light • Colors of other objects • Relative colors interpretation
Light blue and Red are Actually different interpretations of Gray color
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
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".
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.
Transformations • RGB • CMYK
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
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)
RGB →Grayscale • Different transformations • Average • Weights for different colors
RGB ↔ CMYK • Complement colors in range 0..1 • Relation
RGB ↔ HSV • HSVis“diagonal” projection of RGB 120о 0о 240о
Example • “The Great Wave off Kanagawa”, Hokusai's most famous print, the first in the series 36 Views of Mount Fuji
#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();
// 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(); • }
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; • }
Solid cube with lightening • We need to calculate normal vectors • glNormal() • To process lightening • glEnable()
#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();
// 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(); • }
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; • }
#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(); • }
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; • }
#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; • } • }
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; • }
#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);
// 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; } }