References:

  1. Orange BookThe Inventor Mentor: Programming Object-Oriented 3D Graphics with Open Inventor, Release 2
  2. Coin3d Document: Choose the latest stable version.
  3. Green Book: Open Inventor C++ Reference Manual: The Official Reference Document for Open Inventor, Release 2
  4. Purple Book: The Inventor Toolmaker
  5. Red Book: OpenGL Programming 
  6. Blue Book: OpenGL Reference Manual 
  7. OpenGL at SGI, at opengl'sopenES
  8. Qt reference at CS-UNR's SEM 252 Linux machines:


News Group and Mailing List:

  1. Inventor news group:   http://www.mailgate.org/comp/comp.graphics.api.inventor     
  2. Coin3d mailing list:    http://www.coin3d.org/support/lists/   (Coin Inventor is still under development and has bugs. Before posting help-questions or reporting bugs, browse the lists' contents. Probably, answers are already there.)


How to Use the References




Open Inventor Sampler (based on Ref. 1 above)

We can save much time, by beginning with some examples, to know what Open Inventor can do for us, especially for those who have little experience in graphics programming, instead of first explaining some boring strange terms and then speeding with the examples.

But if you are impatient with this practice-first-theory-second methology, go to Coin SoQt and have look at the relationship among hardware, OS, OpenGL, Coin3d/Open Inventor, Qt, and user's application.

In the following presentation of examples, pay attention to the documentations in the code program. Read them carefully, painstakingly. It also helps  to read every line of the code conscientiously, which will give you a quick start in writing your Inventor program. If you meet some strange Open Inventor terms at this time, just ignore them if you cannot catch their meaning during 2 seconds. In fact, most of the terms give very accurate implications by their very names.

If you have experiences with data structure or database, good luck for you: Inventor does nothing but data management. Once "data structure" get into your brain, the "tree structure" follows immediately. Now start our journey of a special data base of a "scene graph" of a red cone: how it moves or is moved by you. The scene is represented by a "root" in the structure and its child nodes are its properties (color, light, viewing point, ...) and shape (a simple cone).

First Example: A Red Cone

Our first example program illustrates the basic steps in writing an Inventor program. The code is taken from  Ref.1-example2-1.
  1. Create a window where the scene will be rendered. This example uses SoXtRenderArea, the Inventor Xt window.
  2. Build the scene graph by creating property and shape nodes and combining them into groups.

//----------------------------------------------------
//    Remember (in our first homework) where those "include" files reside??
//-----------------------------------------------------
//
//Using Inventor Xt window
//
#include <Inventor/Xt/SoXt.h>
#include <Inventor/Xt/SoXtRenderArea.h>
//
//Using Inventor "nodes".
// Inventor "node" is the basic element of a scene graph: data methods that define some specific 3D shape, property, or grouping.
//Here, we have:
//           Shape node: a cone by "SoCone"
//          Property nodes: a light source by "SoDirectionLight"
//                                    material definition by "SoMaterial" (of ambient color, diffuse color, shininess... on the material surface)
//                                    a camera by "SoPerspectiveCamera"
//          Gouping node:  "SoSeparator"---Please remember this node name--"SoSeparator", which is widely used in Inventor animation programing.
//
#include <Inventor/nodes/SoCone.h>
#include <Inventor/nodes/SoDirectionalLight.h>
#include <Inventor/nodes/SoMaterial.h>
#include <Inventor/nodes/SoPerspectiveCamera.h>
#include <Inventor/nodes/SoSeparator.h>

//Please note, "Xxxx.h" file gives a class "Xxxx"
//
main(int , char **argv)
{
// Initialize Inventor. This returns a main window to use.
// If unsuccessful, exit.
Widget myWindow = SoXt::init(argv[0]); // pass the app name
if (myWindow == NULL) exit(1);

// Make a scene containing a red cone
//From now on, keep in mind that a scene (graph) is but a data structure.
//When you are going to create a scene, you know how many objects (data set) in the scene, the relationship (distance, or moving speed) among those objects, the material properties attach to every object, and so on. Therefore, those objects and their properties are logically connected with each other with a TREE STRUCTURE.
//There is ORDER in the tree structure when you adding "child" nodes to their father, though it doesn't matter with property "nodes" belonging to same object (shape node).

//Our job is to create such a data tree structure of a scene graph, here, a simple red cone.

// Of course we should have a "root"
SoSeparator *root = new SoSeparator;

//Some child nodes:
SoPerspectiveCamera *myCamera = new SoPerspectiveCamera;
SoMaterial *myMaterial = new SoMaterial;

root->ref(); //VERY IMPORTANT!!!--------- "ref()"

//Add child nodes (properties), though order here is not important, it is a good practice to add them in certain order.
root->addChild(myCamera);
root->addChild(new SoDirectionalLight);
myMaterial->diffuseColor.setValue(1.0, 0.0, 0.0); // Red color
root->addChild(myMaterial);

//Add the shape object node
//IMPORTANT: this node should be added into root as the "LAST" one: all the above property node will not produce the effect unless they "meet" one real shape node.
root->addChild(new SoCone);

// Create a renderArea in which to see our scene graph.
// The render area will appear within the main window---"myWindow".
SoXtRenderArea *myRenderArea = new SoXtRenderArea(myWindow);

// Make myCamera see everything.
myCamera->viewAll(root, myRenderArea->getViewportRegion());

// Put our scene in myRenderArea, change the title
myRenderArea->setSceneGraph(root);
myRenderArea->setTitle("Hello Cone");
myRenderArea->show();

SoXt::show(myWindow); // Display main window
SoXt::mainLoop(); // Main Inventor event loop
}


This program cannot be compiled on our Linux machine, why? (see Homework 2).

Now, if you have NOT had the following in your mind, please go over the above program code once again:


Second Example: Using Engines to Make the Cone Spin


Third Example: Adding a Trackball Manipulator


Fourth Example: Adding the Examiner View







Homework 2:

  1. The Qt version codes of the sampler example codes are 2.1.cpp, 2.2.cpp, 2.3.cpp, 2.4.cpp.
    1. Compile and run them (for compiling and linking, use "soqt-config --build xx xx.cpp". If you would like to create your Makefile, use "soqt-config --help" to find how to get the Inventor's libs/includes paths, for example, "soqt-config --ldflags" gives the libs' paths. Go to Homework 1.3 for help.).
    2. Use "diff" command to find the differences between the above Qt version codes and their original codes in the Orange Book:  Example 2-1Example 2-2Example 2-3,   Example 2-4. The Coin3d Inventor is cross platformed: you can port your prorgrams to Qt, Xt/Unix, Win/Windows by only changing Qt to Xt, or Win, or vice versa. And please pay attention to the different initializations in the different systems: in Windows, it is "HAND mainwin = SoWin::init(...)", in Qt,  "QWidget *mainwin = SoQt::init(...)", and in Xt, "Widget mainwin = SoXt::init(...)".
    3. Read Chapter 2 of the Orange Book. Write 4 Inventor programs that are exactly same as 2.1.cpp, 2.2.cpp, 2.3.cpp, 2.4.cpp. But,
      1. Do not use "copy-paste". Type them in letter-by-letter unless you have Inventor background.
      2. Try to figure out the "tree structure" and order embedded in the programs. The suggestive terms are "root", "addChild"...
  2. For every Inventor class in 2.1.cpp, 2.2.cpp, 2.3.cpp, 2.4.cpp, consult the Green Book and/or Coin3d Manual for class' description and usage. Pay particular attention to the class's inheritance structure and the class functions that are used in the example. Make sure you can use the class' methods that occurred in the examples in your own programming.
  3. Try to replace the cone with other Inventor shape primitives, for example, cube, sphere... And do the same with the color. For 2.2.cpp, change the rotation speed, rotation axis.