Archive for September, 2007

createEnvirons( switchNode ); //create a DistanceLOD that will (Windows 2003 server web)

Wednesday, September 26th, 2007

createEnvirons( switchNode ); //create a DistanceLOD that will select the child of the Switch //node based on distance. Here we are selecting child 0 (high res)if //we are closer than 180 units to 0,0,0 and child 1 (low res) //otherwise. float[] distanceArray = {180}; DistanceLOD distanceLod = new DistanceLOD( distanceArray ); distanceLod.setSchedulingBounds( getApplicationBounds() ); distanceLod.addSwitch( switchNode ); g.addChild( distanceLod ); g.addChild( switchNode ); return hiResGroup; } //create a high resolution representation of the world: //a single texture mapped square and a larger (water colored) //square to act as a horizon. public Group createLand( Group g ) { Land land = new Land( this, g, ComplexObject.GEOMETRY | ComplexObject.TEXTURE ); Group hiResGroup = land.createObject( new Appearance(), new Vector3d(), new Vector3d( LAND_WIDTH,1,LAND_LENGTH ) , “boston.gif”, null, null ); Appearance app = new Appearance(); app.setColoringAttributes( new ColoringAttributes( WATER_COLOR_RED/255f, WATER_COLOR_GREEN/255f, WATER_COLOR_BLUE/255f, ColoringAttributes.FASTEST ) ); Land base = new Land( this, hiResGroup, ComplexObject.GEOMETRY ); base.createObject( app, new Vector3d(0,-5,0), new Vector3d( 2 * LAND_WIDTH,1,2 * LAND_LENGTH ), null, null, null ); return hiResGroup; } //create a low resolution version of the world and //applies the low resolution satellite image public Group createEnvirons( Group g ) { Land environs = new Land( this, g, ComplexObject.GEOMETRY | ComplexObject.TEXTURE ); return environs.createObject( new Appearance(), new Vector3d(), new Vector3d( 2 * LAND_WIDTH,1, 2 * LAND_LENGTH) , “environs.gif”, null, null ); } 11.10 Summary This chapter has introduced the Java 3D behavior model and described the most common built-in behaviors for UI interaction as well as the LODand Billboardbehaviors. The next chapter will introduce another important class of behaviors Interpolator used to vary objects within your scene as a function of time. 194
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.

DistanceLOD Class java.lang.Object | (Hosting your own web site) +–javax.media.j3d.SceneGraphObject | +–javax.media.j3d.Node |

Tuesday, September 25th, 2007

DistanceLOD Class java.lang.Object | +–javax.media.j3d.SceneGraphObject | +–javax.media.j3d.Node | +–javax.media.j3d.Leaf | +–javax.media.j3d.Behavior | +–javax.media.j3d.LOD | +–javax.media.j3d.DistanceLOD LODitself is an abstract class. The only class derived from it is DistanceLODwhich implements a LOD behavior based on the distance of the viewer from a point. Conceivably you could derive your own custom LODbehaviors from the abstract base class to implement application specific LODfunctionality, or to switch the state of objects based on UI input. The SplineInterpolatorTestexample application uses a simple DistanceLODbehavior. Two versions of the 3D world are created, a high resolution version to be used when the viewer is less than 180 meters away and a low resolution version to be used when the viewer is more than 180 meters away. The two versions of the world are created within separate Groupsand added to a single Switch Node the high resolution world is added first. A DistanceLODobject is then created and initialized with an array of distances as we only have two versions of the world we just have to pass in a single distance value to select between them. If we had n distance values in the distances array, and hence n + 1 models in the Switch Node, the formula for selecting between them is shown in table 11.5. Table 11.5 Index selected Distance (d) 0 if d <= distances[0] i if distances[I 1] < d <= distances[i] n if d > distances[n 1] The DistanceLODis then passed a reference to the Switch Nodethat it is going to control using the LOD.addSwitchmethod. From SplineInterpolatorTest.java //create a Switch group that contains two versions of the world: //the first is a high resolution version, the second is a lower //resolution version. public Group createLodLand( Group g ) { Switch switchNode = new Switch(); switchNode.setCapability( Switch.ALLOW_SWITCH_WRITE ); Group hiResGroup = createLand( switchNode ); 193
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.

mouseScale.setMinScale( new Point3d( 0.5,0.5,0.5 ) ); mouseScale.setMaxScale( new (Web and email hosting)

Tuesday, September 18th, 2007

mouseScale.setMinScale( new Point3d( 0.5,0.5,0.5 ) ); mouseScale.setMaxScale( new Point3d( 2,2,2 ) ); mouseScale.setObject( objTrans ); mouseScale.setChangeListener( this ); mouseScale.setSchedulingBounds( getApplicationBounds() ); objTrans.addChild( mouseScale ); //create the mouse rotate behavior TornadoMouseRotate mouseRotate = new TornadoMouseRotate( 0.001, 0.001 ); mouseRotate.setObject( objTrans ); mouseRotate.setChangeListener( this ); mouseRotate.setSchedulingBounds( getApplicationBounds() ); objTrans.addChild( mouseRotate ); //create the mouse translate behavior and set limits TornadoMouseTranslate mouseTrans = new TornadoMouseTranslate( 0.005f ); mouseTrans.setObject( objTrans ); mouseTrans.setChangeListener( this ); mouseTrans.setMinTranslate( new Point3d( -4,-4,-4 ) ); mouseTrans.setMaxTranslate( new Point3d( 4,4,4 ) ); mouseTrans.setSchedulingBounds( getApplicationBounds() ); objTrans.addChild( mouseTrans ); //add the small cube objTrans.addChild( new ColorCube(0.5) ); //create some axes for the world to show it has been rotated, //and just use a larger wireframe ColorCube ColorCube axis = new ColorCube(5.0); Appearance app = new Appearance(); app.setPolygonAttributes( new PolygonAttributes( PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_NONE, 0 ) ); axis.setAppearance( app ); objTrans1.addChild( axis ); //add the TransformGroup we are controlling with the mouse to //the parent TransformGroup objTrans1.addChild( objTrans ); 11.8 Billboard behavior java.lang.Object | +–javax.media.j3d.SceneGraphObject | +–javax.media.j3d.Node | +–javax.media.j3d.Leaf | +–javax.media.j3d.Behavior | +–javax.media.j3d.Billboard The following is from Sun s Java 3D documentation: The Billboardbehavior node operates on the TransformGroupnode to cause the local +z axis of the TransformGroupto point at the viewer s eye position. This is done regardless of the transforms above the specified TransformGroupnode in the scene graph. Billboardnodes provide the most benefit for complex, roughly symmetric objects. A typical use 189
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

Kids web site - These interfaces allow the MouseNavigateTestexample to display the

Tuesday, September 18th, 2007

These interfaces allow the MouseNavigateTestexample to display the rotation, translation, and scale of an object in UI elements while the user is manipulating the object. One significant problem with the built-in MouseTranslatebehavior is that it always moves objects in the x-y plane. This does not cause any problems when the MouseTranslatebehavior is added at the top of the scenegraph hierarchy. However, if a TransformGroupis used to rotate the scene such that the x-y plane is no longer parallel to the screen, and a child TransformGroupis added with an attached MouseTranslatebehavior, the objects beneath the child TransformGroupwill still move in the x-y plane and not parallel to the screen. The Tornadomouse behaviors have built-in support for fixing this problem, and the abstract method TornadoMouseBehavior.isRelativeToObjectCoordinatescontrols whether object movement should compensate for TransformGroupsabove the TransformGroupbeing manipulated using the mouse. This is pretty hard to describe in words, so I suggest you run the MouseNavigateTestexample and you will see that the small cube is translated along a plane parallel to the screen, even though it is a child of a TransformGroupthat has itself had a rotation applied. The Tornado mouse behaviors also put a clamp on the range of changes permitted using translation or scaling. It is very easy using the built-in behaviors to lose objects because they are either translated outside the visible world or scaled wrong (too large or too small). The TornadoMouseTranslateand TornadoMouseScalebehaviors accept minimum and maximum values for translation and scaling in the x, y, and z axes and will ensure that the objects are kept within these limits. In the MouseNavigateTest example, it is not possible to translate the small cube outside of the larger cube, and scaling is permitted only between 50 and 200 percent along each axis. More explicit control over the speed of scaling, rotation, and translation is also offered, since each of the constructors accepts various scaling parameters. Moreover, the Tornado mouse behaviors are not coded to specifically affect a TransformGroupbut to accept a generic object via the setObjectmethod. A runtime check is made on the class type of the Object, and if the object is a TransformGroup(which is typical), the TransformGroupis modified using an updated Transform3D. If the Objectis not a TransformGroup, it is up to the developer to modify the Objectin some way based on interface notifications or in a derived class. The classes were designed with derivation in mind and are highly customizable, so they form a good basis for application-specific derived classes. Example usage of the new behaviors, from MouseNavigateTest.java //Note that we are creating a TG above the TG that is being //controlled by the mouse behaviors. The Sun mouse translate behavior //would fail in this instance because all movement would be in the //x-y plane irrespective of any TG above the object. The //TornadoMouseTranslate behavior always moves an object parallel //to the image plane TransformGroup objTrans1 = new TransformGroup(); Transform3D t3d = new Transform3D(); objTrans1.getTransform( t3d ); t3d.setEuler( new Vector3d(0.9,0.8,0.3) ); objTrans1.setTransform( t3d ); TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); //create the mouse scale behavior and set limits TornadoMouseScale mouseScale = new TornadoMouseScale( 5, 0.1f ); 188
You want to have a cheap webhost for your apache application, then check apache web hosting services.

TornadoMouseRotate TornadoMouseTranslate TornadoMouseScale (Web server setup) The behaviors,

Tuesday, September 18th, 2007

TornadoMouseRotate TornadoMouseTranslate TornadoMouseScale The behaviors, defined in the org.selman.java3d.bookpackage, have a number of advantages over the built-in behaviors (figure 11.7). Each of the Tornadomouse behaviors can have a registered TornadoChangeListenerto receive notifications of mouse behavior processing. The TornadoChangeListenerinterface allows the following notifications to be handled: Figure 11.7 The MouseNavigateTest example enables the user to interactively rotate, translate, and scale a ColorCube object within the boundaries of the larger cube. The current position, rotation, and scale of the object are displayed in the UI elements below the Canvas3D onStartDrag called when a mouse drag is started onEndDrag called when a mouse drag is completed onApplyTransform called when manipulation is complete and an object is being updated onAdjustTransform called when a new Transform3D is being calculated In addition, the three behaviors also accept behavior-specific interfaces: RotationChangeListener Allows TornadoMouseRotateto pass the new angles about the x, y, and z axes to the caller. ScaleChangeListener Allows TornadoMouseScaleto pass the new scales along the x, y, and z axes to the caller. TranslationChangeListener Allows TornadoMouseTranslateto pass the new translation along the x, y, and z axes to the caller. 187
Check Tomcat Web Hosting services for best quality webspace to host your web application.

java.lang.Object | +–javax.media.j3d.SceneGraphObject | +–javax.media.j3d.Node | +–javax.media.j3d.Leaf | (Web server on xp)

Monday, September 17th, 2007

java.lang.Object | +–javax.media.j3d.SceneGraphObject | +–javax.media.j3d.Node | +–javax.media.j3d.Leaf | +–javax.media.j3d.Behavior | +–com.sun.j3d.utils.behaviors.mouse.MouseBehavior Since the basic mouse behaviors are fairly easy to use, you merely create the behavior object passing in the TransformGroupthat the behavior is to affect, optionally set the behavior s scheduling bounds, add the behavior to the scenegraph, and voila! The objects underneath the TransformGroupshould now move, rotate, or scale based on your mouse movements, as shown in the following code example. //create a TransformGroup that we will be rotating TransformGroup subTg = new TransformGroup(); //The WRITE capability must be set so that the behavior can //change the Transform3D in the TransformGroup subTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); //add a ColorCube as a child of the TransformGroup subTg.addChild( new ColorCube(10.0) ); //attach a MouseRotate behavior so we can rotate the color cube //with the left mouse button MouseRotate mouseRot = new MouseRotate( subTg ); subTg.addChild( mouseRot ); The three built-in mouse behaviors are fine for simple applications or quick prototyping; however, they have a number of drawbacks in serious applications. Section 11.7.3 will define three new mouse behaviors that fix some of these problems and provide a more robust framework to use in applications. The Java 3D VRML viewer (see http://www.j3d.org for details) also includes a number of mouse and keyboard behaviors and full source code. In particular, it defines behaviors appropriate for VRML world navigation: FlightBehavior.java allows the user to fly through a 3D world, controlling roll, pitch, yaw, and velocity. KeyBehavior.java is another keyboard navigation class. So, don t reinvent the wheel; consult, modify, or derive from the available navigation behaviors whenever you can. Building improved mouse behaviors The built-in mouse behaviors are pretty basic in their functionality and often don t offer enough flexibility for use in a real-world application. Application developers typically rewrite these behaviors from scratch, using the source code for the built-in mouse behaviors as a guide in order to integrate mouse processing into UI display logic or implement application-specific features. I have included three mouse behaviors that fix a number of problems and extend the built-in behaviors. These behaviors classes are: 186
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.

Sun will be improving the support for transparent (Web site developers)

Monday, September 17th, 2007

Sun will be improving the support for transparent objects in the 1.3 release of Java 3D. (Sun demonstrated an application that rendered multiple transparent objects from multiple viewpoints at JavaOne 2001.) Conclusions I have discussed a lot more than keyboard navigation and have arguably strayed off topic. However, I hope you found the real-world discussion of how to integrate first-person keyboard navigation into an immersive world interesting. Section 11.7 describes mouse behaviors and focuses on manipulating individual objects within the world using the mouse. 11.7 Using mouse behaviors A mouse behavior is typically used to allow the user to interactively manipulate a graphical object within a 3D scene. Using a standard 2D mouse as a 3D input device can be problematic and has been extensively studied by human computer interaction (HCI) experts. Although I don t think that anyone could claim that any of the techniques are intuitive, a number of usable standards have emerged for translating mouse movements into changes in translation, rotation, and scale in three dimensions. If you decide to use the standard 2D mouse as a 3D input device, I suggest you review the literature and study the 3D applications that your target audience is likely to be familiar with. Emulate the paradigms that your users are experienced with wherever possible it is unlikely that your application is so unique that no one has previously encountered your UI problems. The simplest way to implement direct manipulation using the mouse is to use Java 3D s built-in mouse behaviors. Be aware, however, that this is only one solution to a problem that is an ongoing research topic. As an aside, you can also purchase a 3D mouse, which is a virtual reality input device that can track its position within three dimensions. The 3D mice fall outside the scope (and budget) of this text; however, it should be possible to integrate them with Java 3D using the Java 3D Sensor architecture. Java 3D and the mouse So, all this begs the question, how does Java 3D support the standard mouse as an input device? The answer is that the behavior model again comes into play. Mouse behaviors respond to AWT events such as mouse-click, mouse-drag, and mouse-release and convert the mouse events x and y pixel coordinates into changes that are applied to a Transform3D, which is in turn applied to a TransformGroup. Any child Nodesbeneath the TransformGroupwill be moved, scaled, or rotated based on the changes in their parents TransformGroup. Java 3D s mouse behaviors are included in the Java 3D utility package (com.sun.j3d.utils.behaviors.mouse), which underscores their status as works in progress. The three basic mouse behaviors are MouseRotate: Rotates an object when the left mouse button is pressed. MouseTranslate: Translates an object when the right mouse button is pressed. MouseScale: Scales an object when the left mouse button is pressed and the ALT key is held down. The Java 3D mouse behaviors are all derived from a common base class, MouseBehavior. 185
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.

Http web server - WakeupCriterion wakeUp = (WakeupCriterion) criteria.nextElement(); if( wakeUp instanceof

Sunday, September 16th, 2007

WakeupCriterion wakeUp = (WakeupCriterion) criteria.nextElement(); if( wakeUp instanceof WakeupOnElapsedTime ) { //make a small random change to the Transform3D and apply it //to the TextureAttributes m_Transform3D.rotY( Utils.getRandomNumber( 0.4, 0.4 ) ); m_TextureAttributes.setTextureTransform( m_Transform3D ); } } //assign the next WakeUpCondition, so we are notified again wakeupOn( m_WakeupCondition ); } } Note that the Lightobjects do not use a shared Appearanceobject, or else all the random changes to the Lighttexture images would be synchronized. When the example application is run, sometimes the Water objects and the Lightobjects are not rendered in the correct order. This is because both objects are transparent, and Java 3D does not have (full) built-in support for determining the rendering order of transparent objects. An application-specific fix for the example application would be to force the Water objects (which are always on the floor) to render before the Lightobjects (which are always off the floor) using an OrderedGroup, as shown in figure 11.6. Figure 11.6 A frame rendered by KeyNavigateTest with the small_map.gif world loaded. Note that the middle torch is rendered behind the water on the ground 184
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.

m_TextureAttributes = new TextureAttributes( TextureAttributes.REPLACE, new Transform3D(), new (Web site template)

Sunday, September 16th, 2007

m_TextureAttributes = new TextureAttributes( TextureAttributes.REPLACE, new Transform3D(), new Color4f(0,0,0,1), TextureAttributes.FASTEST ); app.setTextureAttributes( m_TextureAttributes ); //apply the texture image if( (m_nFlags ComplexObject.TEXTURE) == ComplexObject.TEXTURE ) setTexture( app, szTextureFile ); //create the geometry for the Light a simple Cone Cone cone = new Cone( 1, 1, Primitive.GENERATE_TEXTURE_COORDS, app ); //add the geometry to its parent group g.addChild( cone ); //add a behavior to animate the TextureAttributes attachBehavior( new TextureAnimationBehavior( m_TextureAttributes ) ); return g; } } The TextureAnimationBehaviorperforms the work of modifying the Transform3Dwithin Light s TextureAttributesobject. Every 300 milliseconds, the Transform3Dis randomly modified to move the texture image around the Y-axis of the Cone. class TextureAnimationBehavior extends Behavior { //the wake up condition for the behavior protected WakeupCondition m_WakeupCondition = null; protected Transform3D m_Transform3D = null; protected TextureAttributes m_TextureAttributes = null; public TextureAnimationBehavior( TextureAttributes texAttribs ) { m_TextureAttributes = texAttribs; m_Transform3D = new Transform3D(); m_TextureAttributes.setCapability( TextureAttributes.ALLOW_TRANSFORM_WRITE ); //create the WakeupCriterion for the behavior WakeupCriterion criterionArray[] = new WakeupCriterion[1]; criterionArray[0] = new WakeupOnElapsedTime( 300 ); //save the WakeupCriterion for the behavior m_WakeupCondition = new WakeupOr( criterionArray ); } public void initialize() { //apply the initial WakeupCriterion wakeupOn( m_WakeupCondition ); } public void processStimulus( java.util.Enumeration criteria ) { while( criteria.hasMoreElements() ) { 183
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.

Figure 11.5 The texture images used by the (Remote web server)

Saturday, September 15th, 2007

Figure 11.5 The texture images used by the KeyNaviagateTest example application. Floor 128 128 (1), ceiling 128 x 128 (2), walls 32 32 transparent background (3), lights 32 32 transparent background (4), bookcases 32 32 (5), and water 32 32 (6) The sample s Lightclass defines the geometry and simple texture animation behavior for the light. Light is derived from the reusable ComplexObjectclass (defined in the org.selman.java3d.book package). From Light.java public class Light extends ComplexObject { private TextureAttributes m_TextureAttributes = null; public Light( Component comp, Group g, int nFlags ) { super( comp, g, nFlags ); } protected Group createGeometryGroup( Appearance app, Vector3d position, Vector3d scale, String szTextureFile, String szSoundFile ) { Group g = new Group(); //draw all the faces of the object app.setPolygonAttributes( new PolygonAttributes( PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0, false ) ); //The texture image for the light includes transparent areas for //the background. By making the object fully transparent, we can just //draw an irregularly shaped texture image. app.setTransparencyAttributes( new TransparencyAttributes( TransparencyAttributes.BLENDED, 1.0f ) ); //assign a TextureAttributes object to the Appearance and keep //a reference to it so we can modify it 182
You want to have a cheap webhost for your apache application, then check apache web hosting services.