|
![]() "Extending VRML 2 with Java," Vol. 1, Issue 1, p. 42 Then, the Java Virtual Machine can run on its own as you rely on the EAI to pass events to your Applet-extended Java class. You just have to provide the interesting event handling routines and embed the realistic physics in each object you want to behave on its own. Consider putting each of those objects into separate classes should you want to reuse them in other projects. As your project gets more complex, create an Animator class to manage the interactions between objects and a Timer class to provide control over how fast things run. Long term, you can create a Java server and connect your world to others using Java networking classes. Java makes networking worlds relatively easy compared to other programming languages. Using The EAI in a Virtual Kaleidoscope
The kaleidoscope, when first loaded in the CosmoPlayer VRML 2 viewer (downloadable from http://vrml.sgi.com), appears as shown in Figure 1. The kaleidoscope, in the upper left of Figure 1 consists of eight shapes chosen randomly from a shape palette. You design the eight shapes you want to use in the kaleidoscope and create them as standard VRML 2 shape nodes. Each shape appears in a random color. The same eight shapes appear as a horizontal palette below the kaleidoscope. Below the eight shapes palette is a color palette. To the right appears a control panel with 16 buttons. The buttons provide tools a user can use to interact with the kaleidoscope. Figure 2 shows the significance of each control panel button. A user interacts with the kaleidoscope by clicking on a shape in the kaleidoscope, redesigning the shape using the shape palette, color palette and control panel, and then putting the new shape into the kaleidoscope in place of the old. The three white buttons from left to right allow a user to replace a shape, start the kaleidoscope animation and stop the kaleidoscope animation. The rest of the control panel, from top to bottom allows users to modify a shape they are designing by decreasing the intensity of color, increasing the intensity of color, increasing scale or rotating the shape. Figure 2 recaps the significance of the control panel buttons. Note that the left-most white button will choose a random new shape if a user clicks on it without designing his or her own new shape first. You can build the kaleidoscope by following the steps outlined above. I will walk you through the basic steps here, but you should study the complete project code which includes the VRML 2 file (K.wrl), Java file (K.java) and HTML file (K.html). Not all lines of code are covered by this condensed explanation. 1. Create the VRML 2 world of your dreams following the syntax of VRML 2. Every visible object you see in Figure 1 exists as a DEF-defined Transform node in a single VRML 2 file. Note that each Shape node is a simple primitive VRML 2 shape except for the shapes you use in the kaleidoscope. Those eight shapes can be any shapes you want to design. I just happened to include a star, heart, guitar body and vase as examples. Each Transform node in the Kaleidoscope world contains a TouchSensor node in order to connect the shape to an event handling routine that will affect the world upon a user’s mouse click. In my VRML 2 file, K.wrl, I use the following Transform naming conventions: The color controls have names that begin with TC, the white animation control buttons begin with T0, the scale controls start with TSCALE, the rotation controls start with TROT, the shape palette controls have a T followed by a shape name (such as TGUITAR) and the color palette items start with a CM. Each kaleidoscope control is a Transform node similar to the following, which shows a color palette control’s Transform node. Note that you can use the USE keyword to reuse geometry or appearance field nodes as I do to reuse the geometry for each color palette square: DEF CM2 Transform { children [
Copyright 1998 by SYS-CON Publications, Inc.
|