Cube

II right side face glBegin GL_POLYGON glVertex3f length 2, -height 2, depth 2 g IVertex3f I e n gth 2, -height 2, -depth 2 g IVertex3f len gth 2, height 2, -depth 2 glVertex3f I length 2, height 2, depth 2 glEndO II back side face glBegin GL_POLYGON glVertex3f length 2, -height 2, -depth 2 glVertex3f length 2, height 2, -depth 2 g I Vertex3f length 2, height 2, -depth 2 glVertex3f I length 2, -height 2, -depth 2 glEndO II left side face glBegin GL_POLYGON glVertex3f -length 2, -height 2, depth...

Fig Specular reflection

The GL_SPECULAR parameter affects the color of the specular highlight. Let us see how to implement a specular lighting scheme in openGL. Typically, a real-world object such as a glass bottle has a specular highlight that is whitish. Therefore, if you want to create a realistic effect, set the GL_SPECULAR parameter of the light to a dull white. By default, GL SPECULAR is defined to be 1.0, 1.0, 1.0, 1.0 for GLLIGHTO and 0.0, 0.0, 0.0, 0.0 for any other light. We can modify Example6_3, by adding...

GLfloat GetLocationO return location private

GLfloat location 2 II meteor's location. location 0 x-, location - y- coordinate The location array stores the current x, -coordinates of the meteor. For this example, we let all meteors fall straight down along they-axis. The update function merely decrements the location l variable in order to make the meteor fall down. You can experiment with giving meteors an x-direction as well. The Draw routine draws a white colored point glVertex at the meteor's current location, whereas the...

Fig Application clipping area

and shapes, etc. Objects within the clipping area are drawn, and those outside this area are removed or clipped from the scene. The clipping area is mapped onto a physical region in the computer display by mapping the application boundaries to the physical pixel boundaries of the window. If the clipping area defined matches the physical resolution of the window, then each call to draw an x,y point with integer values in the world coordinate system will have a one-to-one mapping with a...

Shapes and Scan Converting

We are all familiar with basic shapes such as lines and polygons. They are easy enough to visualize and represent on paper. But how do we draw them on the computer The trick is in finding the right pixels to turn on The process by which an idealized shape, such as a line or a circle, is transformed into the correct on values for a group of pixels on the computer is called scan conversion and is also referred to as rasterizing. Over the years, several algorithms have been devised to make the...

Diffuse Reflectance

Surfaces with diffuse reflectance scatter light equally in all directions. The amount of light reflected is directly proportional to the angle of incidence of the incoming beam of light. Diffuse reflectance can be observed on dull objects such The exact math to calculate diffuse reflection was proposed by Lambert and so this reflectance is often referred to as Lambert reflectance. If we assume the light to have a diffuse color of R , Gz-j, Blcj and the surface to have a diffuse reflection...

The Magnitude of a Vector

is also referred to as its magnitude. The magnitude of a vector is the distance from the tail to the head of the vector. It is represented as Vj and is equal to - j x2 y2 It is very useful to scale a vector so that the resultant vector has a length of 1, with the same direction as the original vector. This process is called normalizing a vector. The resultant vector is called a unit vector. To normalize a vector V, we simply scale it by the value l Vj. The resultant unit vector is represented...

Homogenous Coordinates and Composition of Matrix Transformations

We have seen the different vector matrix representations for translation, scaling, and rotation. Unfortunately these all differ in their representations and cannot be combined in a consistent manner. To treat all transformations in a consistent way, the concept of homogenous coordinates was borrowed from geometry and applied to CG. With homogenous coordinates, we add a third coordinate to a 2D point. Instead of being represented by a pair of numbers x,y , each point is now represented by a...

The Martini Glass

Fig.8.8 The master contour of the martini glass Fig.8.8 The master contour of the martini glass If you find you need to edit the curve follow the steps below 2. Click down on the right mouse button until a new window called the Marking Menu pops up. The marking menu is used for context- related actions. The way to use it is to click the right mouse down till the menu shows up, and then drag the mouse to select the item desired. 3. Do not release the mouse. Drag the mouse to the menu item marked...

dont wait start flushing OpenGL calls to display buffer gIFIushO

Note that with OpenGL, the description of the shape of an object being drawn is independent of the description of its color. Whenever a particular geometric object is drawn, it is drawn using the currently specified coloring scheme. Until the color or coloring scheme is changed, all objects are drawn in the current coloring scheme. Similarly, until the point or line sizes are changed, all such primitives will be drawn using the most currently specified size. Try composing your own objects by...

glFlushl

forces all previously issued OpenGL commands to begin execution. If you are writing your program to execute within a single machine, and all commands are truly executed immediately on the server, glFlush might have no effect. However, if you're writing a program that you want to work properly both with and without a network, include a call to glFlush at the end of each frame or scene. Note that glFlush doesn't wait for the drawing to complete it just forces the drawing to begin execution. Voila...

Making Them Move 1

In the last few sections, we saw how to model objects and render them to create photo-realistic images. Our next task is to give life to our creations by making them move animation When you see a cartoon on TV, you see characters in motion. This motion is just an illusion the strip itself is actually composed of a sequence of still images or frames which when played back in rapid succession gives the illusion of motion. The most popular way to create animation is by generating a number of...

Advanced Rendering Techniques

Shading techniques such as those discussed in Chapter 6 go a long way towards creating colorful images. But they fall short of achieving photorealism. Real objects cast shadows shadowing , some of them reflect other objects reflection , and some of them allow light to pass partially or wholly through them transmission . There are ways to cheat such effects. We have seen a saw a way to use texture mapping to render objects reflecting their environment. There are even techniques to fake shadows,...

Law of Reflection

reflecting off a flat mirror, then the behavior of the light as it reflects would follow the the law of reflection. As shown in Fig.6.5, a ray of light, , approaches the mirror and is called the incident ray. The ray of light, R, that leaves the mirror, is known as the reflected ray. At the point of incidence where the ray strikes the mirror, we can define a normal, N, to the surface of the mirror. The normal is perpendicular to the surface at the point of incidence and divides the angle...

Pinhole Camera

further away, gets mapped on as Y' and is actually smaller in size. Objects such as Z, whose intersecting rays of light do not pass through H, are not photographed. Notice that the image formed is inverted The classic computer graphics version of the camera places the film in front of the pinhole. This placement ensures among other things, that the image is right side up. We rename the pinhole as the eye, viewpoint, or camera position and the film as the image plane, as shown in Fig.5.21. The...

Basic Mapping Scheme

Typically, basic shapes are used to define the mapping from world space to texture space. Depending on the mapping situation, we project the object's coordinates onto the geometry of a basic shape such as a plane, a cube, or a sphere. It's useful to transform the bounding geometry so that it's coordinates range from zero to one and use this value as the s,t coordinates into the texture Fig.6.30 Planar Texture mapping mapping an image to a vase. Fig.6.30 Planar Texture mapping mapping an image...

void gluLookAtlGLdouble eyex GLdouble eyey GLdouble eyez GLdouble center

This call defines a viewing matrix such that the desired viewpoint is located at eyex, eyey, eyez . The centerx, centery, and centerz arguments specifies a point in the scene that is being looked at. The upx, upy, and upz arguments indicate which direction is up that is, the direction from the bottom to the top of the viewing volume . This matrix is then multiplied to the current modelview matrix. In the default position, the camera is at the origin, is looking down the negative z-axis, and has...

Polygon mesh

Polygons have limited usefulness by themselves. The real power of polygons comes when they are used together in a mesh structure to make a more complex shape. A polygon mesh referred to as strips in openGL is a collection of polygons In Example 5_3, we saw a pyramid defined by triangular polygons. Since the triangles actually share their edges, we can think of the polygons forming a solid model defined by the triangular mesh. Ideally, triangles share edges, so the shared edges need not be...

Previewing the animation

To play a preview of the movie in 30 fps, we will use the Play blast option provided by Maya. Playblast enables you to preview the current animation. When you run Playblast on an animtion, the Playblast outputs a series of individual frames into a movie file format such as .avi Windows , .iff IRIX and Linux , and .qt Mac OS X . This is an option is used for preview only From the menu bar, choose Window gt PlayBlast gt 1 K Time Range C Time Slider S StartTime 0 0000 By default, Playblast...

Rotation

A shape can be rotated about any of the three axes. A rotation about the z-axis will actually rotate the shape in the ry-plane, which is what we desire in our 2D world. The points are rotated through an angle about the world origin as shown in Fig.2.9. Mathematically, a rotation about the z-axis by an angle 0 would result in point P x,y transforming to P' x',y' as defined below x' xcos 8 - ysin 0 y' xsin 0 - ycos 0 Where R is the rotation matrix shown above. Positive angles are measured...

Non Linear Interpolation

For most animation situations, linear interpolation is not an effective animation technique. More complex non-linear interpolation techniques are employed for simulating effects in nature. Recall the nonlinear paramateric equations from Chapter 7. y t Ctyt3 byf Cyt 4 z t a bzt2 czt dz 0 lt t lt 1 As useful as these equations are in modeling, they are even more useful in animation Instead of interpolating vertex points of a model, we can interpolate key frame positions of an animation using the...

GluNewQuadric

In our game, the cylinders are drawn with a texture map wrapped around them, as shown in Fig. 10.3. This map causes the cylinders to look like buildings with lit-up windows Fig.10.3 Texture map for the cylinders Fig.10.3 Texture map for the cylinders void draw_Cylinder GLfloat position glBindTexture GL_TEXTURE_2D, texturelDs 1 gIPushMatrixO glTranslatef position 0 ,position 1 3,position 2 gluCylinderl cylinder, 1.,1., 7., 30,30 You can make the game a lot more interesting by defining more...

Fig Magnification and Minification of texels

should be used and how they should be averaged or interpolated. There are a number of generalizations to this basic texture-mapping scheme. The texture image to be mapped need not be two-dimensional the sampling and filtering techniques may also be applied for both one- and three-dimensional images. In fact ID texture mapping is a specialized version of 2D mapping. The texture may not be stored as an array but may be procedurally generated. Finally, the texture may not represent color at all...

This function will scale up the image by the specified x and y factors

The code to draw the background pixmap is shown below if bgpixels glRasterPos2i 0,01 II scale the image appropriately and then draw the background image glPixelZoom 0.5,0.8 bginfo- gt bmiHeader.biHeight, GL_BGR_EXT, GLJJNSIGNEDJYTE, bgpixels The motion of the smiley face is the same as in Example3_2. The entire code can be found in Example3_3 ExampIe3_3.cpp. In the above example, we redraw the entire background image at every call to the display function. Unfortunately, this approach leads to...

Hidden Surface Removal

In the previous chapter, we looked at wire frame representations of models. The models we constructed were see through we could see through the polygons. We learned how to eliminate the back-facing polygonal surfaces of our model using a technique called back-face culling. But what about those surfaces that are obscured by other objects in front of them as shown in Fig Fig. 6.2 A sphere obstructing a cone back-face culling is on In a wire frame mode, it probably is still okay to see through the...

Final Position Initial Position velocityelapsed time

The camera position is updated at every tick of the game logic. The velocity of the motion is determined at every tick by checking the state of the arrow keys on the keyboard. If the up arrow is being pressed, then velocity is positive, causing forward motion. If the down key is being pressed, velocity is negative, causing backward motion. If nothing is being pressed, then velocity is 0, causing no motion to happen. The difference between the last timer tick and the current one gives the...

Staging 1

1. Choose Create gt Cameras gt Camera from the main menu. 3. Open the Attributes Editor. In the Attributes Editor, you will see the transformation attributes as well as a tab section to define the camera List Selected Focus Attributes Help_ 4. Rename the camera as AnimationCamera by clicking inside the box with the camera name. 5. Set the transforms of this camera to be Translate 6., 8, 14 , Rotation -10, 30, 0 . 6. Choose the four panel layout if it is not already chosen . 7. We don't need the...

FrontFacing and BackFacing Polygons

Just as a piece of cardboard has two sides to it, a polygon has two sides or faces, referred to as the front-face and the back-face. In CG, the order in which you specify the vertices of the polygon defines the orientation of the polygon. By convention, when polygon vertices are defined in counterclockwise order on the screen the polygon is said to be front facing. If you reverse the order of the vertices, the polygon is back facing that is its back face is facing the viewer. If you turn a...

AntiAliasing

The problem with most of the scan conversion routines is that the conversion is jagged. This effect is an unfortunate consequence of our all or nothing approach to illuminating pixels. At high resolutions, where pixels are close together, thi effect is not noticeable, but on low-resolution monitors, it produces a harsh, jagged look. Aliasing can be a huge problem in computer generated movies, when you can sometimes actually see jagged lines crawling from scene to scene, creating a disturbing...

Hierarchical Modeling Using Transformations

Models are usually not constructed as monolithic blobs. They usually have a hierarchical structure smaller models called shapes components are used as building blocks to create higher-level entities, which in turn serve as building blocks for higher-level entities, and so on. A hierarchy enables the creation of complex objects in a modular fashion, typically by repetitive invocation of building blocks. The model hierarchy can be symbolized as a tree, with the components defined as nodes of the...

Texture Mapping

Texture mapping can dramatically alter the surface characteristics of an object. It adds vitality to models and can provide great visual cues for even simple models. For example, if we map a woodgrain image to a model of a chair, the chair will look like it is made out of fine wood grain. Texture mapping an image of a brick wall onto a single polygon would give the impression that the polygon had been modeled with many individual bricks, as shown in Fig,6.26. 1 - - __ - , - 1 - - __ - , -...

Automatic Texture Generation

OpenGL has three automatic texture generation mode. One is used when doing spherical environment mapping. The other two are eye linear and object linear. In eye linear mode, a texture coordinate is generated from a vertex position by computing the distance of the vertex from a plane specified in eye coordinates. In object linear mode, a texture coordinate is generated from a vertex position by computing the distance of the vertex from a plane specified in object coordinates. We shall use object...

D Modeling Primitive Shapes

Primitive shapes have a well-defined mathematical formula that defines the shape of their outer hull. Objects such as spheres, cubes, cones, etc. fall into this category. These surfaces are also called implicit surfaces, since they are defined by an implicit formula. Polygon meshes can be easily used to construct these shapes. For the sake of convenience, most graphics software provide these shapes as primitive objects in their own right. Let us look into some of these shapes in more detail....

Bulletint ulD int x int y Define a new bullet at locationxy

virtual Bullet void Drawl void Updated boot OutOfScreenO bool Collide Meteor GLfloat ID private returns true if Bullet is out of screen returns true if Bullet collides with Meteor The Draw routine draws a red-colored point glVertex at the bullet's current location, whereas the DrawCollision routine draws a bigger red colored point to indicate a collision. The update function merely increments the location l variable, thereby moving the bullet up. All bullets created are entered into a BulletMap...

Vertex Shaders

No discussion on rendering would be complete without talking about vertex shaders. The concept of shaders is nothing new to the graphics industry, Pixar has used it for years in their phenomenal films such as Toy Story and The Incredibles. However till now, vertex shading effects were so computationally complex that they could only be processed offline using server farms. With the current generation of semiconductor technology, developers can program realtime Vertex Shaders to breathe life and...

Lights

Lights are used for much more than just illumination of the scene. The lighting in a shot can frame the characters, punch up the main idea models of the shot, and define the mood of the scene. Wow and you thought lights were an afterthought. In Chapter 8, we defined certain mood lighting that matches what we wish to portray here. We shall keep much of that same lighting. We add in a couple more lights to punch up the fish, and the martini glass. To punch up the main characters, we define three...

Light from Lampl

We want to simulate lights from the lamps that we have modeled. Let us first consider lamp 1. A point light is a good light to simulate light bulbs, which emit light in all directions. We shall create a point light and position it at the center of lampl. 1. Choose the Rendering gt Point Light icon from the shelf. 2. A point light icon will appear at the center of the grid. You can move the light just as you move objects. Translate the point light to be located where the shade of lamp 1 is. 3....

Light from Lamp

Lamp2 can also be thought of as simulating a light bulb. However, since it has metallic shades, the light is not spread in all directions it is restricted to a cone defined by the shade. Spotlights create a cone of light and will be ideal to define the lights of lamp2. 1. Select the spotlight icon from the rendering shelf 2. This creates a spotlight. An icon for this light will display at the center of the grid. The light points toward the back wall. 3 If you look at the spotlight icon from...

The Meteor object

First, let us consider the meteor object. A meteor has a location, which identifies it's x,y coordinates on the screen. Based on the location, the meteor object needs to be able to draw itself. It needs to be able to update its location within every loop of the code sometimes referred to as a tick of the game. It also needs to be able to identity whether it is out of the screen in which case we destroy it or whether it has hit planet Earth. The meteor class can defined as follows

The Android

Let us define the Android we saw in earlier Chapters to be part of this world. Maybe the object of the game is to locate Andy our favorite Android We define Andy with a golden metallic material. The code to draw the Android at a given position defined in an array called position is shown below void draw_Andy GLfloat position int i,j glMaterialfv GL_FR0NT, GLJPECULAR, mat_specular glMaterialfvlGLJRONT, GLJHININESS, low_shininess glMaterialfv GL_FR0NT, GL_AMBIENT, mat_ambient...

Kinematics

Kinematics is the study of motion independent of the underlying forces that produce the motion. It is an important technique used to define articulated fig. animations. Usually, a defined model is applied that has a skeleton structure consisting of a hierarchy of rigid links or bones connected at joints. Each link corresponds to certain patches of the model surface, also called the model skin. A joint can be rotated, causing the corresponding surface and the attached children bones to rotate...

What is GLUT

GLUT pronounced like the glut in gluttony is the OpenGL Utility Toolkit, a window system independent toolkit for writing OpenGL programs. It implements a simple windowing application programming interface API for OpenGL. GLUT makes it considerably easier to leam about and explore OpenGL programming. GLUT is designed for constructing small to medium sized OpenGL programs. While GLUT is well-suited to learning OpenGL and developing simple OpenGL applications, GLUT is not a full-featured toolkit...

Viewport Transformations

We looked into details of the viewport transformation in Section 1. The viewport transformation transforms the image plane into the specified region of the window. By default the viewport is set to the entire pixel rectangle of the window that is open. You can also use the glViewport command to also choose a smaller drawing region for example, you can subdivide the window to create a split-screen effect for multiple views in the same window. Try experimenting with different viewport settings...

glutSolid Sphere glPopMatrixl II pop back to original state

By default, we translate the base of the snowman up by 1.5 units, so its base is resting at the origin. Transformations to the bottom component are applied by modifying the botXforms array. The pivot point for each component and its children is very important in a hierarchical model. Each component has a pivot point based on the location of the origin in its local object space. This point is also called the local origin. Local transformations for components are applied using this pivot point....

Matrices

A matrix is an array of numbers. The number of rows m and columns n in the array defines the cardinality of the matrix mxn . In reality, a vector is simply a matrix with one column or a one-dimensional matrix . We saw how displays are just a matrix of pixels. A frame buffer is a matrix of pixel values for each pixel on the display. Matrices can be added component wise, provided they have the same cardinality Multiplication of a matrix by a scalar is simply the multiplication of its components...

The CG Camera

The steps needed to generate the CG image can be defined analogously to the steps we would take a photograph in the real world. We need to define the following The viewing transformation sets the viewing position and is analogous to positioning and aiming a camera. The modeling transformations are used to position and orient the model within the world. This process is akin to arranging the scene to be photographed into the desired composition. For example, you can rotate, translate, or scale...

Viewing Transformation

A viewing transformation changes the position and orientation of the viewpoint itself. Essentially, the viewing transformation repositions the camera and the direction it is looking. As discussed earlier, to achieve a certain scene composition in the final image or photograph, you can either move the camera or move all the objects in the opposite direction. In Example5_9, the translation routine can be thought of as actually moving the camera position by 4 units towards the object, instead of...

glulookAt Cbi

and the other is by making calls to the gl transformation functions glTranslate, glScale etc but in the opposite direction of the intended motion. Recall from Chapter 5, that moving the camera is the same transformation as moving the objects in the opposite direction. In OpenGL, the camera viewing matrix and the model transformation matrix are combined into one for this reason. We shall see how to animate the camera using both techniques. Which technique you use is depends on how easy it is for...

Parallel Projection Orthographic

Orthographic Projection View Volume

Parallel projections are projections whose center of projection is at infinity. These projections ignore the location of the current viewpoint in their calculations. The projectors used are parallel lines. The output of a parallel projection is not realistic because objects retain their size no matter where they are located. It is very useful for calculating measurements and sizes of objects and is often used when modeling objects, in engineering drawing, and in blue prints of architectural...

typedef struct tagBITMAPINFOHEADER