Virtual Reality Applications and Research (MAE - 574) Spring '09

Dept. of Mechanical and Aerospace Eng., University at Buffalo

Instructor: Govindarajan Srimathveeravalli

Home            Course Schedule and Materials        Resources        Source Code        Anno/net/wings/info/www/courses/sp07/mae/574-410 uncements         Staff and Contact           

Home            Course Schedule and Materials       Source Code        Staff Contact        Sundry VR Links           Best HW Submissions 

 

Sample programs for Class 1

A collection of programs that show the basic way to setup a GLUT window that will support OpenGL drawings. Demonstrate use of  key GLUT functions such as glutReshape and glutDisplayFunc etc.

Helloworld.cpp

First.cpp:

1. Change the window size, what happens to the square ? Why ?
2. Alter the color of the background color.
3. Try altering the polygon, add more points and change the color
4. Copy the polygon code and add a second polygon on the screen

Reshape.cpp:

1. Alter the values provided in glOrtho() command and see what it affects in the output

Singlebuffer.cpp

1. Add a second polygon in the denoted area in the display function. Does it rotate ?
2. Why does the screen flicker ? How to reduce the speed of revolution ?

Doublebuffer.cpp

1. What does the command glutSwapBuffers() do ?
2. What happens when you try to resize the window or click on the frame and move it ? Why does it happen so ?

 

Sample programs for Class 2

Three programs demonstrate drawing of basic 2D primitives (points, lines and polygons) using OpenGL. A demonstration of GLUT for integrating Mouse and Keyboard is also included. Try the following in given code.

Points.cpp:

1. Why do we use glVertex3f instead of say glVertex3i ?
2. Plot and ellipse with center at (0,0) instead of the circle.
3. Why does the sinusoid plotted seem skewed ?
4. Instead of the sinusoid try plotting e^t*cos(2*pi*t)

Lines.cpp:

1. Uncomment the different codes in the init function to alter the world view. How do the mouse clicks values vary accordingly ?
2. The line drawn using the code will get erased when the window is altered (resized etc.) How do you retain the graphics rendered on the screen ?

Polygons.cpp:

1. scale the objects to some random value, use the rand() function used for the color code to achieve this.

Sample programs for Class 4

A program to demonstrate the effect of viewport - window mapping in 2D and scaling operations that need to be performed on mouse click values.

Windows.cpp

1. Relocate the "origin" of the world wrt to the window
2. What happens to drawn images when the window is not in a 1:1 ratio, how do you fix this using the viewports?
3. Turn of the function where mouse clicks points are scaled according to the window size
4. Can you write an inverse function where from window points you can work back to points in the world?

Sample programs for Class 5

Programs to demonstrate projection and transformation basics within OpenGL. The "solar system" code demonstrates how perspective and clipping operations work within OGL and the effect viewports have on the appearance of the final image. The robot code demonstrates how push-pop functions can be used in sequence to bring about complex movements and reuse objects.

Solarsys.cpp

1. Why does Jupiter seem to move slower than the rest ? Is there any problem with the transformations set up ?
2. Change the viewing parameters on the glFrustum, experiment and determine the effect of each parameter.
3. A simple fly through of the scene can be made by making the parameters in gluLookAt into variables and changing them using the keyboard.
4. The sun, is obviously missing from the whole set up. Add a sun, add an appropriate light at that point. Will adding an ambient light for the whole set up through glLightModelfv a good idea ?
5. Add comments visiting systems, (they follow a rather elongated elliptical path, their path within the system is seemingly parabolic.
6. Each planet has a characteristic color and luminosity. Try adding this feature using glMaterials

Robot.cpp

1. Note the use of translation to the origin and back when performing certain rotation operations. Why are they used so ?
2. Add functionality to manipulate the two arms separately without using a new drawLinks routine
3. Make the robot look fancy by the changing the links to cylinders with spheres to represent the joints.

Sample programs for Class 6 and 7

This code here demonstrates the impact of adding light(s) to a scene, effect shading has on the appearance of objects and the interaction between various parts of light of and the material added onto the object. This also demonstrates the effect of specular material property on final appearance, the use of glPush/PopAttrib and animation of light sources.

Litmat.cpp

1. Disable the depth buffer and see what happens to the spheres. Why does this happen? Look at the code for clues with order of rendering.
2. Remove the specular material property of the red sphere, but leave it on the light. How does its appearance change now?
3. What would happen if the lights are not disabled before drawing the axis?
4. Play with the color of the sides. What would happen if a new sphere is draw just outside the sides push-popattrib? What would its color be?
5. What will happen if you turn the push popattrib off for the 3rd sphere?

Sample programs for Class 8 and 9

These programs demonstrate framebuffer and pixel related operations in OGL. Specifically it shows the use of blending operations and texturing.

Blending.cpp

1. Change the fog effect such that everything is set to the background clear color. How do the objects look like with respect to the background now?
2. Change the ordering of the polygons offset such that the smaller polygons are offset and  not the larger ones.
3. Play around with different combination of choices for the glBlendFunc and notice what happens

Texture-basic.cpp

1. Play around with the clamp, repeat, decal/replace/modulate parameters of the texture.
2. Try replacing the existing texture by altering the makeCheckImage() function

Texture-images.cpp

1. Note that lighting has been disabled and yet the scene renders correctly, notice that texture mode has been set to DECAL
2. Play with parameters in CLAMP and REPEAT and see what happens in the first case.
3. How would you put a texture such that image appears only once (in reduced size) and at exactly the center of the polygon?

Texture-multi-lightmaps.cpp

1. Notice how lighting is disabled for the textured background, yet there seems to be an illumination effect. Would enabling the spotlight for the background make any  difference?

Support material, TGA reader (.h and .cpp) and images (wall and light).

Sample programs for Class 10 - 12

Source  code to demonstrate how to use vertex arrays and display lists in OpenGl. The code also provides an adaptation of Paul Bourke's Delaunay triangulation algorithm.

STL reader

1. Try reading in multiple STL objects, you will need to maintain a separate stlMesh for every one of them.
2. Would it be better to encapsulate various object properties (mesh, normals, material texture etc.) in a single class?

OBJ reader

Grayscale triangle strips

1. The surface does not have any normals defined. Try enabling GL Auto normals and GL normalize is there significant difference in the appearance of the surface?
2. Use the code that you previously wrote to determine normals and explicitly set those normals within the draw function. What do you notice now? Is the appearance of the surface now different from the
previous case?
3. How would you rewrite the following code to render the same using Quads?

Delaunay

1. Feed the point values from the "decimation" routine to the algorithm to render.
2. Enable normals and see if a nice shaded surface can be rendered.
3. Why are triangles with poor aspect ratio is formed by the algorithm? Think in terms of edge flipping.
 

 

Supplement programs for 10-12

The standard template library provides a convenient way to store geometric information for graphic applications. This code can be used with the supplemental slides (class 12) to get an understanding on the workings of STL.

STL - vectors

Sample programs for Class 14 and 15

Parametric curves are a very useful and powerful way of representing complex surfaces or approximating difficult to model objects. Following code demonstrates the use of Bezier's and NURBS for doing simple curves and surfaces.

Bezier

1. Play around with the curve, we know that since the curves are Bezier, they will always pass through the start and end. See if other properties of Bezier curves (convexity,  linearity etc.) can be simulated using a good choice of points.

 

Sample programs for Class 16 - 19

This code gives a quick demonstration of two things, collision detection (through ray-plane intersection and subsequent point in polygon testing) and giving simple, but dynamically accurate physics response. All objects move under two forces, gravity and a air friction - dissipative force. Collisions are almost elastic (direction vectors are not completely preserved).
 

Bouncer

1. Obviously, the collision detection is not fool proof. After a number of iterations, it fails, and the balls slip through the plane. How to fix this?
2. The spheres do not interact with each other. Add a sphere-sphere intersection algorithm to handle this. How will you modify the struct-functions for ball to handle collision forces coming in from other spheres?

The code gives a simple demonstration of using mass-damper systems for simulating particle physics. The implementation follows Baraff's notes, and provides a simple object oriented structure for the simulation system.

Pendulum

 

 

   
NOTE:  Code provided here is for use to reinforce concepts taught in class. (Most, quite intentionally) Some of the source code may be incomplete. Hints are given to the student to complete the code using concepts taught in class and as a learning exercise. Use at your own risk.