May 2005
Intermediate to advanced
998 pages
26h
English
createSceneGraph() starts the main tasks of WrapNetTour3D: the 3D scene is created, contact is made with the server, and a local sprite is initialized:
void createSceneGraph(String userName, String tourFnm,
double xPosn, double zPosn)
{ sceneBG = new BranchGroup();
bounds = new BoundingSphere(new Point3d(0,0,0), BOUNDSIZE);
// allow clients to be added/removed from the world at run time
sceneBG.setCapability(Group.ALLOW_CHILDREN_READ);
sceneBG.setCapability(Group.ALLOW_CHILDREN_WRITE);
sceneBG.setCapability(Group.ALLOW_CHILDREN_EXTEND);
lightScene(); // add the lights
addBackground(); // add the sky
sceneBG.addChild( new CheckerFloor().getBG() ); // add the floor
makeScenery(tourFnm); // add scenery and obstacles
makeContact(); // contact server (after Obstacles object created)
addTourist(userName, xPosn, zPosn);
// add the user-controlled 3D sprite
sceneBG.compile(); // fix the scene
}Capability bits are set to allow distributed sprites to be added to and removed from the scene at runtime.
makeContact() sets up an input and output stream to the server and passes the input stream to TourWatcher to monitor. TourWatcher creates distributed sprites when requested by the server, and so must know about the obstacles present in the world:
private void makeContact() { try { sock = new Socket(HOST, PORT); in = new BufferedReader( new InputStreamReader( sock.getInputStream() )); out = new PrintWriter( sock.getOutputStream(), true); new TourWatcher(this, in, ...