References:
- Orange Book: The Inventor Mentor: Programming
Object-Oriented 3D Graphics with Open Inventor, Release 2
- Coin3d Document: Choose the
latest stable version.
- Coin Inventor:
Choose links on the headline.
- Coin SoQt:
Coin3d's GUI toolkit that combines Qt and Coin3d Inventor.
- Green Book: Open
Inventor C++ Reference Manual: The Official Reference Document for Open
Inventor, Release 2
- Purple Book: The
Inventor Toolmaker
- Red Book: OpenGL Programming
- Blue Book: OpenGL Reference Manual
- OpenGL at SGI, at opengl's, openES,
- Qt reference at CS-UNR's SEM 252 Linux machines:
- Start a browser,
- "Ctrl-O" (Open File),
- Type in the file name: "
/usr/share/doc/qt-devel-3.1.1/html/index.html "
News Group and Mailing List:
- Inventor news group: http://www.mailgate.org/comp/comp.graphics.api.inventor
- 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
- The first two references listed above: the Orange Book and Online Coin3d Document. The Green Book will be a useful complement book, which
sometimes provides more detailed descriptions of Inventor classes.
- You can find very good example codes for the use of some Inventor
classes with Coin3d Document.
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.
- Create a window where the scene will be rendered. This example
uses SoXtRenderArea, the Inventor Xt
window.
- 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:
- A window is created
- A "rendering area" is created which is placed in the "window".
Furthermore, the scene graph "root" will display in this rendering area
- A (perspective) camera is created, which is "looking" at
everything in the scene "root" and what it sees is transformed into
images on the "viewport region" on the "rendering area" we have built
- The relationship among
the window, the render area/viewport region, the camera, the scene
graph ("root")
- The "root"'s child nodes: first set up the property nodes and the
create the shape node (the cone), thus when the shape was created it
had already predefined "properties"
- "ref()"
- Most of the created nodes use their default values (we define
only the color--"red")
- Compile and run this program (see
Homework 2)
Second Example: Using Engines to Make the Cone Spin
- The example is here
- We use an engine "SoElapsedTime" to make the cone move
- Try to make out the engine's "driving mechanism" through: a
transform node "SoRotaionXYZ", the output "timeOut" of the engine, and
their connection through node's FIELD's "connectFrom()"
- Compile and run this program (see
Homework 2)
Third Example: Adding a Trackball Manipulator
- The example is here
- Compile and run this program (see
Homework 2)
- Left-click on the red cone and move mouse to "manipulate the cone"
Fourth Example: Adding the Examiner View
- Compile and run this program (see
Homework 2)
- We now have an interactive GUI. Using the buttons to test their
functionalities on the cone
- This program is much simpler than the first three programs: we
don't have to create a camera, a rendering area. They are embedded in
"SoXtExaminerViewer". What is more we have a very useful interface.
- This "examinerViewer" is often used to test simple 3D models.
Read carefully the description of the class "SoXtExaminerViewer" (i.e.
"SoQtExaminerViewer") and its (grand) parent class "SoXtViewer" (i.e.
"SoQtViewer) in the Green
Book and/or Coin3d
Manual
Homework 2:
- The Qt version codes of
the sampler example codes are 2.1.cpp,
2.2.cpp, 2.3.cpp, 2.4.cpp.
- 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.).
- Use "diff" command to find the differences between the above Qt version codes and their original
codes in the Orange Book: Example
2-1, Example
2-2, Example
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(...)".
- 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,
- Do not use
"copy-paste". Type them in letter-by-letter unless you have Inventor
background.
- Try to figure out the "tree structure" and order embedded in
the programs. The suggestive terms are "root", "addChild"...
- 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.
- 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.