ref1: Davison, Andrew, "Killer Game Programming in Java", O'Reilly Media, Inc., 2005
Playing Around with the Java 3D View Used by the Client
To get a better understanding of how Java 3d work (Davison's code), I'm going to try to limit the rotational operations so that you can't look under the ground plane.
All of this will be done with the KGPch15 project set up earlier (see
Hmm...the camrea movement seems to be controlled by the OrbitBehavior class, which the author does away with later. So may be better to work through chapter 16 first.
Refactoring the package name to core3d since it will expand through
many chanpter of the book.
First up. Extract the files for ch16. Then take a look at LoaderInfo3D.java as a starting point.
This has the main() in it and does about the same thing as Checkers3D.java did with the addition of reading in command line parameters. It also creates a WrapLoaderInfo3D opject instead of a WrapCheckers3D object.
The big change in WrapLoaderInfo3D from WrapCheckers3D is the replacing of the floatingSphere with loadModel() and the examine model code. Sooo...I guess I'll just replace WrapCheckers3D.java with WrapLoaderInfo3D.java and call the WrapLoaderInfo3D constructor instead of the WrapCheckers3D one.
WrapCheckers3D w3d = new WrapCheckers3D(); // panel holding the 3D canvas
WrapLoaderInfo3D w3d = new WrapLoaderInfo3D(fn, adaptNo);
Also replace WrapCheckers3D.java with WrapLoaderInfo3D.java in the NetBeans project.
Add the models directory from ch16 also with all of its files. The project Source Packages will look like this when all done..
<all the files that were in the models folder>
to the top of WrapLoaderInfo3D.java since it is now part of the package.
Since WrapLoaderInfo3D uses the NCSA loaders, add the portfolio.jar file to the Libraries by RMC the project Libraries and browse to where the jar file was downloaded.
Because WrapLoaderInfo3D needs a model filename and a adapt number, will add these members to Checkers3D.java
public String modelFile = "models/Coolrobo.3ds";
public int adNo = 0; // 0=blue
so the call is now
WrapLoaderInfo3D w3d = new WrapLoaderInfo3D(modelFile, adNo);
hmm...very strange..got a ClassNotFound error..commented out the w3d make and add, built, and got a small window. Closed, uncommented, built and it ran, but no model was loaded..may have a
file path problem..try all CAPS, since the file name is..hmm....ahh..error message in Output window..
File not found..so it is a path problem..try filepath based on where the jar file ends up (in dist directory)
this one worked...woo hoo...robo in da house....
So far so good...playing with the adNo values..3 is for texture..oops..need to fix path..
private static final String TEXTURE_FN = "models/stone.jpg";
private static final String TEXTURE_FN = "src/core3d/models/stone.jpg";
ah..mucho better...ok, all 5 work now..
Looking at the code. WrapLoaderInfo3D.loadModel( <filename> ) is the guy that brings in a model...duh..The model is brought in as a scene and then the Branch Group is extracted from its scene. The scene has lights, backgrounds, etc. We only need the model itself though.
Going to modify the code to raise the robo to floor level. Let's try
t3d.setTranslation(new Vector3d(0, 10, 0));
a bit too high..(0, 7.3, 0) puts it right on the floor..can also move x and z also..cool.
Hmm..what if I extact or copy a loadedBG2 object and try to add it.
Well, worked after I loaded the model twice.
loadedScene = loader.load(fn); // the loaded scene
loadedScene2 = loader.load(fn); // the loaded scene
Apparently it all linkes back to the model source..will verify by looking in to the other chapters with multiple models..Ch18 has Tour3D which developes the Sprite3D class to allow multiple copies.
Time for more reading..
and it says the answers are in the secod part of ch16. Specifically, the Sprite3D class and the PropManager class. PropManager provides the methods to move the model around.
A look at Loader3D files shows we need to add
to the project. In fact, going to add Loader3D as the main, replacing Checker3D, now as well.
Use WrapLoaderInfo3D class instead of WrapLoader3D class for w3d..bah..add WrapLoader3D also..
Going to use Loader3D as main() now, so copy fixes from Checkers3D over to it.
public String modelFile = "src/core3d/models/COOLROBO.3DS";
change to use fixed filename and comment out the comand line args parsing.
// w3d = new WrapLoader3D(filename, hasCoordsInfo);
w3d = new WrapLoader3D(modelFile, hasCoordsInfo);
Delete Checkers3D, WrapLoaderInfo3D and use Loader3D main file..build and see what we got..hmm..
private String pathModels = "src/core3d/models/";
// s = modelLoader.load("models/"+fnm); // handles many types of file
s = modelLoader.load(pathModels+fnm); // handles many types of file
and try again..oops. Had partial path in file name string..doh..
public String modelFile = "src/core3d/models/COOLROBO.3DS";
public String modelFile = "COOLROBO.3DS";
and it works..excellent..but no button icons..ah..path and no files..add icons folder to src and set up
a pathIcons String element.
private String pathIcons = "src/core3d/icons/";
ImageIcon upIcon = new ImageIcon(pathIcons+"up.gif");
ImageIcon downIcon = new ImageIcon(pathIcons+"down.gif");
ImageIcon leftIcon = new ImageIcon(pathIcons+"left.gif");
ImageIcon rightIcon = new ImageIcon(pathIcons+"right.gif");
ImageIcon inIcon = new ImageIcon(pathIcons+"in.gif");
ImageIcon outIcon = new ImageIcon(pathIcons+"out.gif");
to use new path..build and run..much better..look how he handles GUI for ideas for improving the Client..hmm...biggest thing is to build up all the small stuff first, then add upper level..so build from insideout up instead of adding empty containers and filling them in..switching over to Tour3D now Ch18. Replacing Losder3D and WrapLoader3D with Tour3D and WrapTour3D files. Addng Sprite3D and model files also.
Add to all new files.
The tour textfile will now be the world file for the game. It will have the models and setup information.
Calling it worldSetup.txt for now. PropManager handles loading now, so it has the path variables. Just have to worry about filenames only.
Set Tour3D to have main..set comand line filename as ctour.txt and comment out parser code..
after finding all the hardcoded paths and ficed them..works pretty good...keyboard controls are backwards, but action is smooth..
This looks like the core of what is needed. Ch32 show how they are used with his game server and message system. Ch32 will be used for reference. Time to get back to the Client.
on to ch18 and Sprite3D..