150 likes | 275 Vues
This document explores the principles of imaging with a pinhole camera model, detailing camera specifications such as position, orientation, focal length, and film size. It introduces the Sepinski gasket and methods for projecting 2-D triangular vertex points using a pen-plotter and OpenGL. Fundamental OpenGL functions for defining vertices, drawing geometric objects, and managing color and transformations are discussed. The material also covers viewing volumes and projection types, including orthographic and perspective projections, enhancing understanding of 3-D graphics rendering.
E N D
CS450 – Lect. 2 & 3 Figures and such
Camera Specification • Position • Orientation • Focal length • Film size • (field of view)
Sepinski Gasket • Recursively Subdivided Triangle • Approach 1 : Pen-Plotter • Calculate 2-D vertex projection points • Use moveto(x,y) & lineto(x,y) to draw triangles • Apprach 2 : OpenGL, etc. • Specify 3-D vertex positions of object • Specify camera model • System projects lines into 2-D and renders
OpenGL Types • Definitions found in gl.h and glu.h // samples … #define Glint int #define GLfloat float
Defining Vertices • Coordinate systems • World Coordinates (3-D) • Real numbers and any scale we desire • Device & Screen Coordinates • Integer positions of pixels • Functions that define 2-D & 3-D vertices • glVertex2i(Glint x, Glint y) • glVertex3f(GLfloat x, GLfloat y, GLfloat z) • glVertex3fv(vertex) // vertex[3] contains x,y,z • Etc …
Defining an Object Face (shape) • Geometric objects are specified by a sequence of vertices between begin and end function calls • Example: // line segment in 2-D from (x1,y1) to (x2,y2) glBegin(GL_LINES); glVertex2f(x1,y1); glVertex2f(x2,y2); glEnd();
OpenGL API Basics • Primitive Functions • Define WHAT (points, line segments, text, …) • Attribute Functions • Define HOW (color, texture, typeface, …) • Viewing Functions • Define CAMERA (location, orientation, clipping, focal length, …) • Transformation Functions • Object MODIFICATION (translation, rotation, scaling, …) • Input Functions • INPUTS (mouse, keyboard, trackball, …) • Control Functions • OpSys interaction (window management, error handling, …)
Function Naming • OpenGL • gl*() • Graphics Utility Functions • glu*() • GL Utility Toolkit (GLUT) • glut*() • #include <GL/glut.h>
Object Types • GL_LINES // each pair of vertices defines a lines • GL_LINE_STRIP // connected sequence of lines • GL_POLYGON // connected line seq. looping back to start • Must be simple, flat & convex to render correctly • GL_TRIANGLES // each triplet forms triangle • GL_QUADS // each quad of vertices forms quadrangle • GL_TRIANGLE_STRIP //each triplet forms a triangle • GL_QUAD_STRIP // each new vertex pair used with previous pair • GL_TRIANGLE_FAN // each vertex used with previous pair // general format of object definition glBegin( object_type ); glVertex*( … ); glVertex*( … ); … glEnd();
Color • Use RGB (additive) color model • Amount of Red, Green & Blue is specified as a value in the range 0.0 … 1.0 • Examples: // to set the current color glColor3f(R,G,B); // to set the clearing (background) color glClearColor(R,G,B,1.0); // the 4th value is opacity 0.0 .. 1.0 // to actually clear the display window glClear();
Viewing • Viewing (Clipping) Rectangle • Defines portion of world seeable from camera • Viewing Volume • Defines volume of world that is seeable • Viewing rectangle is the FRONT face of the viewing volume
Projections • Orthographic (parallel) • Specifying the viewing volume gluOrtho(left,right,bottom,top,near,far) gluOrtho2D(left,right,bottom,top) • Perspective