NO it doesn't work now ether.
import java.io.File;
import javax.vecmath.Color3f;
import javax.vecmath.Tuple3f;
import javax.vecmath.Vector3f;
import mygame.input.MyInputAdapter;
import org.xith3d.geometry.Line;
import org.xith3d.loaders.texture.TextureLoader;
import org.xith3d.loaders.texture.TextureStreamLocatorFile;
import org.xith3d.render.Canvas3D;
import org.xith3d.render.Canvas3DFactory;
import org.xith3d.render.base.Xith3DEnvironment;
import org.xith3d.render.loop.RenderLoop;
import org.xith3d.scenegraph.BranchGroup;
import org.xith3d.scenegraph.Group;
import org.xith3d.scenegraph.PointLight;
import org.xith3d.scenegraph.View;
import org.xith3d.ui.hud.HUD;
import org.xith3d.ui.hud.listeners.ButtonListener;
import org.xith3d.ui.hud.widgets.Button;
public class Test extends RenderLoop implements ButtonListener {
private Xith3DEnvironment env;
private View view;
private MyInputAdapter myAdapter;
private Tuple3f eyePosition;
private Tuple3f viewFocus;
private Tuple3f vecUp;
private int tileW = 2;
public void onButtonClicked(org.xith3d.ui.hud.widgets.Button button, Object userObject) {
if (userObject.equals("EXIT")) {
this.end();
}
}
private BranchGroup createScene(Xith3DEnvironment env) {
BranchGroup rootBranch = new BranchGroup();
// Let there be light
rootBranch.addChild(new PointLight(0.3f, 0.3f, 0.3f, 20f, 100f, 0f, 0.00001f));
// Draw grid
Tuple3f start = new Vector3f(0, 0.1f, 0);
Tuple3f end = new Vector3f(10, 0.01f, 0);
Color3f color = new Color3f(0.5f, 0.5f, 0.5f);
Group grid = new Group();
start.z = 20 * -1;
end.z =20;
for (int x = 0; x <= 20; x++) {
start.x = (x * tileW) - 20;
end.x = (x * tileW) - 20;
grid.addChild(new Line(start, end, 1f, color));
}
start.x = 20 * -1;
end.x = 20;
for (int z = 0; z <= 20; z++) {
start.z = (z * tileW) - 20;
end.z = (z * tileW) - 20;
grid.addChild(new Line(start, end, 1f, color));
}
// grid.updateBounds(false);
rootBranch.addChild(grid);
return (rootBranch);
}
protected void loopIteration(long gameTime, long frameTime) {
myAdapter.updateView(gameTime, frameTime);
super.loopIteration(gameTime, frameTime);
}
private HUD createHUD(Canvas3D canvas) {
HUD hud = new HUD(canvas, 800, 600, this.getOperationScheduler());
this.getInputManager().registerInputListener(hud);
Button button = new Button(90, 30, "Exit this app");
button.setUserObject("EXIT");
button.addButtonListener(this);
hud.addWidget(button, 10, 10);
return (hud);
}
public Test(String[] args) {
super(128L); // Note: 128 FPS limitation!
eyePosition = new Vector3f(5f, 10f, 5f);
viewFocus = new Vector3f(0.0f, 0.0f, 0.0f);
vecUp = new Vector3f(0.0f, 1.0f, 0.0f);
env = new Xith3DEnvironment(this);
view = env.getView();
// set camera
env.getView().lookAt(eyePosition, viewFocus, vecUp);
Canvas3D canvas;
canvas = Canvas3DFactory.createWindowed(1024, 768, "My Game");
// canvas = Canvas3DFactory.createFullscreen(1024,768);
// canvas = Canvas3DFactory.createFullscreen(1280, 1024);
env.addCanvas(canvas);
canvas.setBackgroundColor(Color3f.CYAN);
TextureLoader.getInstance().addTextureStreamLocator(new TextureStreamLocatorFile(new File("data/textures")));
env.addPerspectiveBranch(createScene(env));
env.addRenderPass(createHUD(canvas).getRenderPass());
this.getInputManager().registerKeyboard(canvas);
this.getInputManager().registerMouse(canvas);
this.myAdapter = new MyInputAdapter(view, canvas, 3.0f);
myAdapter.createDefaultKeyBindings(true);
myAdapter.setFixedPlaneEnabled(true);
this.getInputManager().registerInputListener(myAdapter);
// FirstPersonInputHandler fpHandler = new FirstPersonInputHandler( view,
// canvas, 1.0f, 1.0f, 3.0f );
// fpHandler.createDefaultKeyBindings( true );
// fpHandler.setFixedPlaneEnabled(true);
// // fpHandler.getInputManager().getMouse().setExclusive(false);
// this.getInputManager().addInputHandler( fpHandler );
this.begin();
}
/**
* @param args
*/
public static void main(String[] args) {
new Test(args);
}
}