Apprentice Tutorial

Index:

Installation

Overview

Ex.1: Animation

Ex.2: Robot walking Trashcan

Under Construction indefinitely.

Installation

 ApTutor.zip is a self-contained download of the debug Apprentice dynamic link library and static library, Apprentice include directory, and example programs. ApTutor DOES NOT require that you download other zip files at this site.

 Dated June 7, 1997

Apprentice zip file

After downloading ApTutor.zip, use a 32-bit, long filename unzip utility to extract the ApTutor files to a permanent directory. Be sure to use the existing directory structure.

For WinZip 6.x, Extract All Files to C:\ or C:\MSDEV with the Use Folder Names box checked. The directories that will be created are:

C:\Apprentice\
Contains example program directories.

C:\Apprentice\include
 Contains complete Apprentice include directory

C:\Apprentice\lib
Contains ApprenticeD.LIB and ApprenticeD.DLL

Copy the ApprenticeD.DLL and the MSVCRTD.DLL (in the base directory of extraction, C:\  ) to the Windows System directory.

The project is created as a Win32 Console application by following these steps:

  1. Create a new project workspace named Anim. The initial directory should be the main Apprentice directory, such as C:\Apprentice, so that the project is created in C:\Apprentice\Anim.
  2. Add the file Anim.cpp to the project.
  3. Change the project settings by adding an additional include directory that points to "C:\Apprentice\include" or "../include"
  4. Change the project settings by adding an additional library (link settings) of "../lib/ApprenticeD.lib"
  5. Try to build it.

Please note, if you have downloaded ApTutor and created a project prior to this version, you should be able to simply replace all of the files in the old project directory.

If this process worked, do the same for Spline and Robot.


Overview

 A scene graph is a group of objects structured in a "directed acyclic graph" (DAG). A DAG is like a common tree, it has a root from which other nodes are attached (or grow, per se). One builds a scene graph by creating new objects and adding them to the root node, and possibly adding surrogate groups of nodes to the root node.  In Inventor and Apprentice, this is accomplished with Group nodes (SoGroup in OpenInventor, ApGroup in Apprentice, and Group in Inventor File Format).

A Separator is a class derived from Group that allows matrix transforms and other properties to be changed by its children, but the state of those properties is restored after all of its children have been rendered. We will use an ApSeparator node as the root node of our scene graph.

Apprentice include files are collected in the include/Apprentice subdirectory. The include directory needs to be  specified as an include directory in the Build Settings for the compiler.

The include directory that we will be dealing with contains all of the headers for nodes that may be added to the  scene graph. This includes shapes, group nodes, material, lighting and texture properties, cameras, and transforms. Each node has one or more fields that define attributes of the node such as the radius of a sphere, the colors that make up a material property, and the matrix to use for a transform.


Example 1: Animation

 


 /////////////////////////
//  anim.cpp example


#include <Apprentice/ApDB.h>
#include <Apprentice/Win/ApWin.h>
#include <Apprentice/Win/ApWinRenderArea.h>
#include <Apprentice/nodes/ApSeparator.h>
#include <Apprentice/nodes/ApRotation.h>


int main( int argc, char *argv[] )
{
        // ApWin::init() registers a window class and creates a window with the title example.
        // For Windows applications, it returns an HWND handle.
        // For unix, it would return a Widget.
        HWND myWindow = ApWin::init("example");
        if ( myWindow == NULL )
                return 1;

        // The ApInput object represents an input file.
        ApInput in;
        char* lpCmdLine = argv[1];

        // If the command line does not contain a filename, the default is input.iv
        if ( argc != 2 || strlen( argv[1] ) ref();

        // Look up nodes by name.

        // The first node we want to retrieve has the name leftTransform.  The node already exists,
        // hence the reason we are simply creating a pointer to it.  DO NOT create a new node.
        ApRotation *leftTransform;

        // The call ApNode::getByName() finds a node with a name equal to the string, returns NULL if none was found.
        if ( (leftTransform = (ApRotation*) ApNode::getByName( AbName( "leftTransform" ) )) == NULL )
                return 1;

        // The following calls set the scene graph for our window to our root node,
        // and show the window.
        ApWinRenderArea *myRenderArea = new ApWinRenderArea(myWindow);
        myRenderArea->setSceneGraph(root);
        myRenderArea->setTitle("Hello Cone");
        myRenderArea->show();

        ApWin::show(myWindow);

        // This is our animation loop.
        // For 20 frames, this loop increments the rotation angle around the x-axis.
        for ( int i = 0; i rotation.setValue( AbVec3f( 1.f, 0.f, 0.f ), angle );
                // redraw the window.
                myRenderArea->render();
        }

        // wait for the user to hit enter and quit.
        ApWin::mainLoop();
        return 0;
}
 

Example 2: Robot walking trashcan

 You should be surprised to see that it was rather simple. Several nodes are read in from the scene graph, two for interpolation and two that represent the different walk translations.



 

Copyright © 2004 Eric Powers.  All rights reserved.