Requirements & Installation ] Conceptual Overview ] The Part Editor ] The Geometry Editor ] Importing 3ds models ] [ Examples ] OpenGL Subsystem ] Inside the Part Editor ] Input Device Details ] Inside CoolPool ] Inside Lunar Lander ] Deploying Applications ] Resources and Links ]

Simple Examples

Several application examples, included in package "CC ST3D Examples", are discussed below.

Creating a 3D Application Window

This first example illustrates the process of creating a simple 3D application from the ground up.

  1. Create a subclass of Shell. For the purposes of this discussion, we’ll name it "Test3DShell". Create a new view for the shell. View Composer should open on an empty shell view.

  2. Open the View Composer’s resource toolbox and add an instance of CcOpenglView by dragging the entry "CcOpenglPresenter->DefaultView" onto the shell view. (Resource name "DefaultView" is a double-buffered version of CcOpenglView while "single buffer" is the single buffered version. Most applications should use the default, double-buffered version).

  3. Resize the OpenglView so that it occupies the entire client area of the shell view and name it "view3D". A layout manager can also be initialized if desired.

  4. Save the view as "Default view" (make sure to spell this with the space between "Default" and "view" and lowercase "v" in "view").

  5. Return to the class browser and browse Test3DShell. Define instance variable "openglPresenter" and add the following two instance methods.

  6. Test3DShell>>createComponents

    super createComponents.
    openglPresenter := self add: CcOpenglPresenter new name: ‘view3D’

    Test3DShell>>onViewOpened

    | sceneRoot camera |

    super onViewOpened.
    sceneRoot := CcDefaultWorld new. "The root of the scene graph."
    sceneRoot addChild: CcVertexShape cube. "Add something to look at."

    openglPresenter
        model: sceneRoot;
        camera: sceneRoot addDefaultCamera; "Create a default camera."
        initDefaultRenderer "Init the default renderer for the presenter."

  7. Open the test shell by evaluating "Test3DShell show". In the client area of the shell, a white square (the cube) should be visible on a black background.

 

CcOpenglLab

CcOpenglLab can be thought of as an OpenGL-enabled workspace. It provides a means of experimenting with the various OpenGL commands wrapped by ST3D. CcOpenglLab can be opened with "CcOpenglLab show" or via menu item "Tools->ST3D->ST3D SampleApplications->CC OpenGL Lab".

OpenGL calls can be made by evaluating expressions in the workspace on the left-hand side of the shell. The CcOpenglView to the right displays the results of the OpenGL commands.

 

Figure 13. CcOpenglLab shell

CcSimpleSceneExample

CcSimpleSceneExample implements the bare minimum required to render an ST3D scene graph in a window. The example is opened using

shell := CcSimpleSceneExample show

Unless a shape is added to the shell’s model, the window will be empty (black). A shape can be added to the scene by sending #addChild: to the shell’s model with the desired shape as the argument. For example:

shell model addChild: CcSphere new

CcSimpleSceneExample contains a single CcOpenglPresenter/CcOpenglView pair.

The default model for the shell is an instance of CcDefaultWorld. A light and camera is added to the model in CcSimpleSceneExample>>onViewOpened and the CcOpenglPresenter is told to initialize its default render manager in CcSimpleSceneExample>>createComponents.

Two additional versions of #onViewOpened are provided which show how different types of cameras can be used (perspective or orthographic). To use one of the other versions, simply rename the method to #onViewOpened.

 

CcEditorExample

The CcEditorExample demonstrates the use of the CcEditor and its default view. The example can be opened with

shell := CcEditorExample show

To add a box to the editor, evaluate

shell model addChild: CcVertexShape box

The example does not provide any tools for manipulating objects in the editor view. The default CcEditor behavior does, however, support the selection of the box and its components.

 

CcQuadViewExample

CcQuadViewExample demonstrates how a single scene graph can be rendered by four different views. The example is opened with

    CcQuadlViewExample show

Figure 14. Quad view example

The top-left view uses a perspective camera.  The top, front and side views use orthographic cameras. The default tool in each view is a drag tool that allows the dragon to be moved within the plane perpendicular to the camera (or, in the case of the perspective view, within the xy plane).  The slider control at the top of the view can be used to adjust the zoom setting of the orthographic views.
 

Animation Examples

The CcAnimationExample1 and CcAnimationExample2 demonstrate simple scene animation. Both examples can be opened using icons in the ST3D Sample Applications folder.

Example #1 displays a spinning mountain shrouded in fog. The speed of rotation can be controlled using the left and right arrow keys on the keyboard or using a joystick if one is attached. Fog density can be controlled using the up and down arrow keys.

Example #2 displays a space probe approaching the planet Jupiter.  Jupiter and its moon each rotate about their own axis. The moon can be made to orbit Jupiter by pressing the up and down arrows on the keyboard.  The space probe can be made to rotate about its axis using the left/right arrows.

 

Figure 15. Simple animation example #2


ST3D makes use of OpenGL’s double buffering mode to animate a scene. In double buffer mode, two screen buffers are available but only one is visible at any given moment. The animation process is outlined below. For the purposes of this explanation, the two buffers will be referred to as A and B. Initially, buffer A is hidden and buffer B is visible.

  1. Render the scene graph to buffer A.

  2. Swap the buffer states so that buffer A is visible and buffer B is hidden. The scene rendered to the offscreen buffer in step 1 now becomes visible.

  3. Update the state of the nodes in the scene graph. Typically, the state change will be based on the amount of time elapsed since the previous rendering (in step 1).

  4. Render the updated scene graph to offscreen buffer B.

  5. Swap buffers, making B visible and A hidden.

  6. Update the state of the scene graph and repeat process starting at step 1.

CcAnimationExample creates a new process to perform the scene animation. The process is created in the #onViewOpened method as follows:

    animationProcess := [ self refreshViewLoop ] forkAt: 4.

The structure of the #refreshViewLoop method is shown below.

    [ "while view is open" ] whileTrue:

[ "Determine period of time elapsed since previous refresh.

Update state of objects based on elapsed time.

Render scene graph."]