I am working on migrating the Xith3D demos to the xith-tk project and modifying them so they implement a common demo framework.
The demo framework is org.xith3d.test.Xith3DTestCanvas. This canvas allows either the LWJGL or JOGL renderer to be chosen (from the command line), as well as adjusting the height and width of the frame.
Minor modifications are made to the demos including changing the input system to HIAL (which supports both LWJGL and JOGL) and removing the canvas setup code.
The xith-tk build script creates a sepertate .jar file for the demos (xith-demos.jar) which allows people to easily leave out that .jar when distributing a project.
Once migrated, I will update xith.org so that one can choose either LWJGL or JOGL when launching via JWS. I will also add RunDemo .bat and shell scripts to the project.
It is also planned to add some of Java Cool Dude’s demos to this package.
here’s an example of the changes, Xith3DLineAttributeTest:
-public class Xith3DLineAttributesTest
+public class Xith3DLineAttributesTest extends Xith3DTestCanvas
{
Transform3D testRotateY = new Transform3D();
@@ -267,65 +263,38 @@
public void init() throws Exception
{
- // Prepare full-screen canvas adapted for current resolution
- Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
-
- VirtualUniverse universe = new VirtualUniverse();
- view = new View();
+ this.createCanvas("Xith3D Line Attributes Test");
+
+ view = getView();
view.setBackClipDistance(100f);
view.setProjectionPolicy(View.PERSPECTIVE_PROJECTION);
view.getTransform().lookAt(
new Vector3f(0, 0, 3),
new Vector3f(0, 0, 0),
new Vector3f(0, 1, 3));
- Locale locale = new Locale();
- universe.addLocale(locale);
- universe.addView(view);
-
- RenderPeer renderPeer = new RenderPeerImpl();
- CanvasPeer canvasPeer =
- renderPeer.makeCanvas(
- null,
- screenSize.width - 200,
- screenSize.height - 200,
- 16,
- true);
- canvasPeer.getWindow().setLocation(100, 100);
- Canvas3D canvas = new Canvas3D();
- canvas.set3DPeer(canvasPeer);
- view.addCanvas3D(canvas);
-
- class KeyboardEventListener implements AWTEventListener
- {
- public void eventDispatched(AWTEvent event)
- {
- if (event instanceof KeyEvent)
- {
- KeyEvent e = (KeyEvent) event;
- if ((e.getID() == KeyEvent.KEY_TYPED) && (e.getKeyChar() == 27))
- {
- System.exit(0);
- e.consume();
- }
- else if ((e.getID() == KeyEvent.KEY_TYPED) && (e.getKeyChar() == 32))
- {
- // Change the projection policy
- if (view.getProjectionPolicy() == View.PERSPECTIVE_PROJECTION)
- view.setProjectionPolicy(View.PARALLEL_PROJECTION);
- else
- view.setProjectionPolicy(View.PERSPECTIVE_PROJECTION);
- e.consume();
+
+ getKeyboard().registerListener(new KeyboardListener() {
+
+ public void keyPressed(int key) {
+ if (key == KeyCode.VK_ESCAPE) {
+ System.exit(0);
+ } else if (key == KeyCode.VK_SPACE) {
+ // Change the projection policy
+ if (view.getProjectionPolicy() == View.PERSPECTIVE_PROJECTION) {
+ view.setProjectionPolicy(View.PARALLEL_PROJECTION);
+ } else {
+ view.setProjectionPolicy(View.PERSPECTIVE_PROJECTION);
}
- }
+ }
}
- }
-
- Toolkit.getDefaultToolkit().addAWTEventListener(
- new KeyboardEventListener(),
- AWTEvent.KEY_EVENT_MASK);
+ public void keyReleased(int key) {
+ // ignore
+ }
+ });
+
BranchGroup scene = createSceneGraph();
- locale.addBranchGraph(scene);
+ getSceneRoot().addChild(scene);
runTest();
}
@@ -337,6 +306,8 @@
while (true)
{
view.renderOnce();
+ getKeyboard().update();
+
try
{
Thread.sleep(10L);
Cheers,
Will.

