[N-World Contents] [Book Contents] [Prev] [Next] [Index]

Welcome to Nichimen's Wide Open World (WOW), a new world of convenience, simplicity, and power for game developers. Open means just that: there are no arbitrary API boundaries to keep you from doing what you want with your data. You can use WOW to drive any N·World operation, or create your own. For example, you can:

and much, much more, as we shall see.


Opening the Door

The next few examples will show you how to manipulate objects in the N·World environment, and provide a little instant gratification.

1. Launch Xemacs.

The exact procedure for doing this depends on how your system is set up. In general, if Xemacs is installed on your system, you can launch it by entering the following command at any UNIX prompt.

xemacs &

Xemacs is a powerful, interactive Lisp code editor. Running N·World from within Xemacs places many development tools and utilities at your disposal.

When Xemacs finishes loading, you'll see a window that looks like this:

Figure 1.1 The Xemacs window

We'll explain in detail what all these parts are later. For now, focus on:

2. When Xemacs is loaded, (CLICK-L) on NGC>Run N-World.

This menu operation loads and runs N-World.

For our first example, we'll need a Geometry object to manipulate, so let's create one.

3. In the GeoMenus, (CLICK-L) on New Object>Tetrahedron.

4. In N-Geometry, (CLICK-L) on the bodies in the sensitivity bar.

5. (CLICK-L) on the tetrahedron.

6. At the Xemacs Lisp prompt, type 3d:?, followed by ENTER.

USER(1): 3d:?

Lisp returns something like this:

#<POLYHEDRON 7>

This is the actual Lisp data structure which defines the body of your tetrahedron. In WOW, the special variable 3d:? is always bound to the last item selected in the Geometry window.

Note: Typing something into the Lisp listener and pressing Return is called evaluation. When we say to evaluate something, that's what we mean.

7. (CLICK-L) on Face in the element sensitivity bar in the Geometry window.

8. (CLICK-L) on a face in your tetrahedron.

9. At the Lisp prompt, evaluate 3d:? again.

Now Lisp returns a symbol for the face you selected, something like

#<FACE 1>

The 3d:? variable is now bound to this face, because it is the most recently selected N-Geometry element.

10. At the Lisp prompt, evaluate 3d:??.

USER(3): 3d:??

The special variable 3d:?? is bound to the second most recently selected element. In this case, it is bound to the polyhedron we selected in step 5:

#<POLYHEDRON 7>

11. (CLICK-L) on Edge in the element sensitivity bar in the Geometry window.

Evaluate 3d:? again. Lisp returns a symbol for the edge you selected, something like:

<EDGE 7>

12. Evaluate 3d:??? at the Lisp prompt.

USER (4): 3d:???

The special variable 3d:??? is bound to the third most recently selected object in the World. In this case, it's bound to the polyhedron itself. 3d:?? is now bound to the face we selected in step 9.

Now we know how to reference objects using Lisp. This is what Wide Open World is all about. The special variables 3d:?, 3d:??, and 3d:??? provide a simple and easy-to-use bridge between what you can see in the Geometry window and Lisp.

But the simple names returned by evaluating 3d:? don't really provide us with very much information. These labels are intended to serve mainly as tags, or stand-ins for the objects they represent. They aren't very interesting or useful in and of themselves. To find out more about an object, we'll have to use a Lisp function.

1. (CLICK-L) on the Tetrahedron again.

This binds the tetrahedron to 3d:?.

2. At the Lisp prompt, evaluate (describe 3d:?).

Lisp returns a detailed description of the tetrahedron, something like this:

#<POLYHEDRON 7> is an instance of #<STANDARD-CLASS POLYHEDRON>:

 The following slots have :INSTANCE allocation:

  PROPERTY-LIST 					(DRAWBLOCKS

	(#<GL-DRAWSELF-DRAWBLOCK for #<POLYHEDRON 9>>) SISTERS T HISTORY #<BODY-HISTORY
@#x189f967a> VERSION (101 9))

	      ATTRIBUTE-PLIST       NIL

	      SISTERS                       (#<BDI (Tetrahedron) @ #x189fafda>)

      SOURCE-FILE               NIL

      FLAGS                           167343104

      SERIAL-NUMBER           9

      PROPERTY-CACHE       #(2041

                                          #(NIL #(-8.164966 -3.3333335 -4.714045)

                                          #(8.164966 10.0 9.42809) NIL NIL NIL
NIL NIL NIL NIL))

    PARTS                             NIL

    STANDIN-BODIES           ((:DEFAULT #<POLYHEDRON 10> NIL))

    CURRENT-STANDIN         :DEFAULT

    FACE-RING-BASE           #<RING-BASE (FACE)>

    SEGMENT-RING-BASE     #<RING-BASE (EDGE)>

    POINT-RING-BASE         #<RING-BASE (VERTEX)>

#<POLYHEDRON 9>

Where we see a tetrahedron in the Geometry window, Lisp sees the data structures that define the tetrahedron. You can also see how this data is organized within the computer. For example, the last section of the description details things like the face-ring-base and element-ring-base. These are integral parts of the winged-edge database structure used by N·World to manage geometrical information, which we'll examine in greater detail later.

Describe is a function. Most functions perform operations on one or more arguments (often shortened to args by lazy UNIX developers). An argument is data supplied to a function when it is called. In this example, the special variable ? was supplied as an argument to the describe function. Together, the function and its arguments comprise a form. In Lisp, forms are enclosed between parentheses.


Defining Your Own Functions

Functions are what you'll use to travel through the Wide Open World. The language you'll speak there is Common Lisp, the only ANSI approved object oriented programming language. Lisp has a large vocabulary of built-in functions, which you can use to build functions of your own. For example:

1. (CLICK-L) on the tetrahedron.

3d:? now refers to the tetrahedron. In WOW, we say that 3d:? is bound to it.

2. Type the following at the Lisp prompt:

(loop for faces in (collect-my-faces 3d:?) do (extrude faces)(move-out faces 5.0))

A quick check in the Geometry window reveals that all the faces in the tetrahedron have been extruded.

By typing the Lisp form in step 2, you've created your own function by combining several Lisp functions. Typing in forms directly at the Lisp prompt works well for things you only want to do once. If you want to use this function again, you'll need some way of saving it. You can do this with a Xemacs buffer.


Using Buffers

A Xemacs buffer is basically a workspace where you can work on your Lisp code. To create one:

1. Type (CTRL-X CTRL-F).

2. Type mybuffer.lisp on the minibuffer line.

Figure 1.2 Creating a buffer

Now you're facing a blank screen. This is a buffer. Because you used .lisp as the extender for the name of the buffer, Xemacs knows to treat the text in the buffer as Lisp code. For example, type the following in the buffer:

(in-package "3D")

(defun my-extrude (body)

  (le::loop+ for faces in (collect-my-faces body) do

             (extrude faces)(move-out faces 5.0)))

Notice that Xemacs automatically:

3. When you've typed in the function, type ALT-CTRL-X.

This key combination compiles the current form. Now, your new function, MY-EXTRUDE, is available for use at the Lisp prompt. Let's try it:

4. (CLICK-L) on Buffers>*common lisp* in the Xemacs menus.

5. Type :pa 3D at the Lisp prompt.

In WOW, functions are organized into packages. To use one, you need to be in the correct package (Actually, there's more to it than this, but only a little. Packages are described in more detail in "Packages," on page 2-3).

6. At the Lisp prompt, type (my-extrude).

Well, this isn't going to work. If you enter the function without any arguments, Lisp complains:

Error: MY-EXTRUDE got 0 args, wanted 1 arg.

  [condition type: PROGRAM-ERROR]

Why? Because we didn't give the function the argument it wanted, which is a body to work on. Plus, now there's an annoying numeral 1 in brackets to the left of the Lisp prompt. This 1 indicates that an error has occurred. We'll learn more about what it represents and how it relates to debugging programs later on. For now, type :reset at the Lisp prompt. This clears all errors.

Finding Arguments

What if we can't remember what arguments(my-extrude)requires? Well, it's simple enough, really.

1. At the Lisp prompt, type (my-extrude), but don't press ENTER.

2. With the cursor just to the right of the function, type CTRL-SHIFT-A.

Lisp asks you a question on the minibuffer line:

Arglist for: (default my-extrude)

3. Since this is the function we want args for, press ENTER.

Lisp responds with the argument list for (my-extrude):

MY-EXTRUDE's arglist: (BODY)

Note. This brings up an interesting point. The fact that we named our argument BODY, as opposed to, say, 68-CAMARO, helps us to know what it is that the function requires.
So we know that for the function to work properly, we have to feed it a body. Let's try it again:

1. (CLICK-L) on the tetrahedron in the Geometry window.

2. At the Lisp prompt, type (my-extrude ?).

This time the function should perform as advertised.

Saving your New Function

OK, so now we've defined, compiled, and used our first function. Let's save it so we can have it bronzed when we really strike it rich in the game development industry.

To save a buffer to a file:

1. Switch to the buffer you want to save.

2. (CLICK-L) on File>Save in the Xemacs menu.

Xemacs will save the buffer to a file with the same name as the buffer.


Welcome to the Wide Open World!

Well, here we are only on page 7, and we've already:

Who says programming is hard?? And in WOW, it's not.



[N-World Contents] [Book Contents] [Prev] [Next] [Index]

Another fine product from Nichimen documentation!

Copyright © 1996, Nichimen Graphics Corporation. All rights reserved.