|
Computer Graphics |
Fall 2000
|
Computer Graphics
Homework 07
6 hours
Copyright © 2000 David C. Banks
Look at this Inventor file using ivview. The scene graph has a root node, two children, and six leaf nodes.
Then look at it using ~banks/bin/gview , which shows both the rendered image and the scene graph. Double-click on a node in the scene graph to expand it. You must be in the "select" mode, not the "grab" mode -- hit [escape] if your click isn't effective. Double-click each leaf node and edit its attributes. Under menu:Node:Create, create some additional nodes and put them in the scene graph. Take a /usr/sbin/snapshot of the gview window showing the modifications you've made. Put the image on your Web page.
Type man sosphere under Irix to see the man page(s) about the SoSphere class in Open Inventor. Copy ~banks/bin/iv into your ~/bin directory. Then type iv sosphere to see a code fragment you can edit and include in your Inventor program.
Type iv socube. Notice that there are two classes that contain this substring. Type iv (with no arguments) to see how to force an exact match.
Print a copy of /usr/include/Inventor/nodes/SoSphere.h and put it in your notebook. This is the header file you include if you use an SoSphere in your program.
Here is an example of an Open Inventor program that creates a scene graph like the example above. I compiled it under Irix with this Makefile. Modify this example to match the scene graph you constructed from within gview. Make a snapshot of it running. Put the image on your Web page.
Copy and compile this Inventor program (using the same Makefile). It makes a sphere bounce around inside a cube. The cube is represented by an indexed line set. Type man soindexedlineset for details. This node expects an SoVertexProperty to appear before it in the scene graph. Type man sovertexproperty for details. "VertexProperty" is an awkward name for this node: it contains an array of points.
Notice that the animate routine maintains the state information for updating the sphere as it bounces. That information should be part of a Sphere class. Create a Sphere class with variables and methods needed to permit a sphere's position and velocity to be updated. Then make the number of spheres be a command line argument. Start each sphere with a random size, color, and velocity. Note that they will pass through each other, but bounce off the cube's faces.
Run /usr/sbin/insight -v Inv_Mentor for a tutorial on Open Inventor.
Use /usr/sbin/mediarecorder on an Onyx or an O2 to record your bouncing spheres. Choose your favorite animation format and link to it from your Web page. Use /usr/sbin/mediaconvert to change formats.
Convert the iv csh script into perl (with comments).
Two spheres collide if the distance between their centers is less than or equal to the sum of their radii. Make each sphere loop over all the other spheres in the scene (or over all the spheres that haven't looped over it) to check for a collision. Make colliding spheres change colors during their collision.
Find an introductory physics text (or search the Web) to see what happens when two spheres experiance elastic collision. Endow each sphere with a mass. When two spheres collide, make them bounce according to physical laws (conserving momentum). Compute the point on each sphere where the collision occurred. Compute the normal at the contact point of each of the two spheres. Compute the reflection (bounce) vectors. Compute the transferred momentum. Update the velocity.