|
|
|
Several application examples, included in package "CC ST3D
Examples", are discussed below. Creating a 3D Application WindowThis first example illustrates the process of creating a simple 3D application from the ground up.
Test3DShell>>createComponents
Test3DShell>>onViewOpened
CcOpenglLabCcOpenglLab 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 CcSimpleSceneExampleCcSimpleSceneExample 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 shells model, the window will be empty (black). A shape can be added to the scene by sending #addChild: to the shells 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.
CcEditorExampleThe 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.
CcQuadViewExampleCcQuadViewExample 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 ExamplesThe 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
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:
|