Watching the Server


Defining Sprites

Sprite3D is the superclass for the local sprite class, TourSprite, and the distributed sprite class, DistTourSprite. Figure 32-4 shows the class hierarchy and all its public methods.

TourSprite and DistTourSprite offer a simplified interface for Sprite3D, setting the sprite's rate of movement and rotation increment. TourSprite contains networking code to send its details to the server.

The version of Sprite3D in NetTour3D is similar to the one in Tour3D. The main differences are in the subgraph created for a sprite, which looks like Figure 32-5.

The subgraph has a BranchGroup node at its top (objectBG), with capabilities set to make the branch detachable. This permits the sprite to be removed from the scene when the sprite's client leaves the world.

The other change is the addition of an OrientedShape3D shape holding the client's name and being set to rotate around the y-axis to follow the client's viewpoint. The shape is added to the transformGroup above the Switch node, which means that the sprite's name will remain on the screen if it is made inactive (invisible). The idea is that the sprite is unavailable but still present in the world.

Figure 32-4. The sprite classes


Figure 32-5. The subgraph for the Sprite3D sprite


The subgraph for the 3D model, together with its adjustments in size, position, and orientation, are handled by a PropManager object. Each sprite on the client uses a PropManager object to load a copy of the model.

The subgraph shown in Figure 32-5 is built in Sprite3D's constructor and makeName( ).

The movement and rotation code in Sprite3D works the same way as in Tour3D: changes are made to the top-level TRansformGroup, objectTG. Moves are first checked with the Obstacles object before being carried out.



Killer Game Programming in Java
Killer Game Programming in Java
ISBN: 0596007302
EAN: 2147483647
Year: 2006
Pages: 340

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net