Problem with HUD code

Hi,

I’ve been having a look at the HUD guide in the Xith in a Nutshell documentation and have been trying to
get some of the example code working. However I don’t seem to be able to find any compatible code /
libraries to get it working.

My code…



// Xith3D
import com.xith3d.scenegraph.Geometry;
import com.xith3d.scenegraph.Shape3D;
import com.xith3d.scenegraph.Appearance;
import com.xith3d.scenegraph.BranchGroup;
import org.xith3d.test.*;
import org.xith3d.ui.hud.*;
import org.xith3d.ui.swingui.*;
// use Jogl
import com.xith3d.render.*;
import com.xith3d.render.jsr231.*;
import org.xith3d.render.loop.*;
import org.xith3d.render.base.*;
import org.xith3d.render.canvas.*;


/**
 *
 * @author William
 */
public class MyHUD extends ExtRenderLoop implements WidgetActionListener {
    public void actionPerformed(String actionCommand) {
        if (actionCommand.equals("EXIT")) {
            System.exit(0);
        }
    }
    
    
    private HUD createHUD(Canvas3D canvas) {
        HUD hud = new HUD(canvas, 1000, 1000,this);
        //this.registerInputListner(hud);
        Button button = new Button(300, 100, "Exit this app");
        button.setActionCommand("EXIT");
        button.addActionListener(this);
        hud.addWidget(button, 400, 400);
        return(hud);
    }
    
    public MyHUD() {
        super(128L);
        ExtXith3DEnvironment env = new ExtXith3DEnvironment();
        
        Canvas3DWrapper canvas = Canvas3DWrapper.createStandalone(Canvas3DWrapper.Resolution.RES_800X600,"My HUD");
        env.addCanvas(canvas);
        
        this.registerKeyboardAndMouse(canvas);
        
        RenderPassConfigProvider persConfigProvider = new RenderPassConfig(RenderPassConfig.PERSPECTIVE_PROJECTION);
        Geometry geo = Cube.createCubeViaTriangles(0, 0, 0, 1, true);
	Shape3D sh = new Shape3D(geo, new Appearance());
        BranchGroup bg = new BranchGroup();
        bg.addChild(sh);
        
        RenderPass scenePass = new RenderPass(bg,persConfigProvider);
        env.addRenderPass(scenePass);
        
        RenderPassConfigProvider  paraConfigProvider = new RenderPassConfig(RenderPassConfig.PARALLEL_PROJECTION);
        BranchGroup parallelBranchGroup = new BranchGroup();
        parallelBranchGroup.addChild(createHUD(canvas));

        RenderPass hudPass = new RenderPass(parallelBranchGroup,paraConfigProvider);
        env.addRenderPass(hudPass);
        
        this.begin();
    }
}

I had a lot of problems to begin with and have changed the code to try and update it. I checked out
a new copy of xith3d and xith-tk from CVS, built new jars and added them to my project but then I
got a missing class error from net.jtank.input.InputListener. I managed to fix this by finding the class
in an earlier release of xith. My project now compiles but when I try to run it I get the following error


Exception in thread "main" java.lang.NoSuchMethodError: javax.vecmath.Matrix4f.setTranslation(Ljavax/vecmath/Tuple3f;)V
        at com.xith3d.scenegraph.Transform3D.lookAt(Transform3D.java:691)
        at com.xith3d.scenegraph.View.lookAt(View.java:422)
        at com.xith3d.scenegraph.View.<init>(View.java:781)
        at org.xith3d.render.base.Xith3DEnvironment.<init>(Xith3DEnvironment.java:1381)

Is there a different version of vecmaths I need to download?

Also is there an easier way to try the examples from the “Xith in a nutshell” as I have found
it really difficult.

Thanks,
William

Two possible solutions :

  • You use Sun’s vecmath whereas vecmath_kh.jar (Kenji Hiranabe’s version) is recommended
  • You use java 1.5.0_07 which is buggy. Please upgrade to 1.5.0_09
First of all some comments about imports:


// Xith3D
import org.xith3d.test.; // unnecessary
import org.xith3d.ui.hud.HUD; // better
import org.xith3d.ui.hud.widgets.
; // better
import org.xith3d.ui.swingui.; // unnecessary
// use Jogl
import com.xith3d.render.
; // unnecessary
import com.xith3d.render.jsr231.*; // unnecessary
import org.xith3d.render.loop.ExtRenderLoop; // better
import org.xith3d.render.base.ExtXith3DEnvironment; // better
import org.xith3d.render.canvas.Canvas3DWrapper; // better

[quote="williamsellick,post:1,topic:28676"]

    //this.registerInputListner(hud);
[/quote]
Uncomment this line to make the HUD able to hande input events.
[quote="williamsellick,post:1,topic:28676"]
        RenderPassConfigProvider persConfigProvider = new RenderPassConfig(RenderPassConfig.PERSPECTIVE_PROJECTION);
        Geometry geo = Cube.createCubeViaTriangles(0, 0, 0, 1, true);
	Shape3D sh = new Shape3D(geo, new Appearance());
        BranchGroup bg = new BranchGroup();
        bg.addChild(sh);
        
        RenderPass scenePass = new RenderPass(bg,persConfigProvider);
        env.addRenderPass(scenePass);
        
        RenderPassConfigProvider  paraConfigProvider = new RenderPassConfig(RenderPassConfig.PARALLEL_PROJECTION);
        BranchGroup parallelBranchGroup = new BranchGroup();
        parallelBranchGroup.addChild(createHUD(canvas));

        RenderPass hudPass = new RenderPass(parallelBranchGroup,paraConfigProvider);
        env.addRenderPass(hudPass);
        
        this.begin();
    }
}

[/quote]
It is necessary to also add the BranchGroup to the environment. I’ve updated the code to gat away from this necessarity. So this part of your code will be fine now.

The project is now hosted on sourceforge.net. Please recheckout SVN from sourceforge. Refer to this thread to know, how to. And make sure, you use vecmath-kh.jar and not vecmath.jar. I’d suggest, we remove vecmath.jar from SVN.

I very sorry for the insufficient HUD documentation in XIN. I’ll update this chapter soon.

Marvin

I’m still having a few issues with xith-tk. I took your advise Marvin and checked out the latest build of
xith-tk using subversion from sourceforge but when I imported the project into eclipse it gave me
over 8000 errors. I double checked I had all the libraries and everything was referenced correctly
and couldn’t find any problem with them. I investigated the source of the problems and it seems
they originate from the import statements in most files. I found that a lot com.xith3d… had been
changed to org.xith3d and in the majority of cases the required classes weren’t in org (toolkit)
so couldn’t be referenced.

Could you please tell me where I can download a copy of xith-tk with the HUD code in it as I
seem to be quite unlucky with the code at the moment.

Thanks,
William

Also check out a fresh xith3d from subversion. (All com.xith3d have been changed to org.xith3d)

Hi William,

I think your problem is related with your video card. I got this same error when i tryed to run my game on college.
It can be fixed by getting the latest driver for you card

Rafael

Maybe you’re right. But it looks exactly like he is using Sun’s vecmath library. vecmath-kh.jar should be used.

Marvin

Thanks for everyones help with the HUD code. I got it working a while ago but have been bogged
down with work so haven’t managed to post recently.

I found that the code in XIN may need adjusting as I had to change


       RenderPass scenePass = new RenderPass(RenderPass.PERSPECTIVE_PROJECTION);
        env.addChild(create3DScene(), scenePass);
        RenderPass hudPass = new RenderPass(RenderPass.PARALLEL_PROJECTION);
        env.addChild(createHUD(canvas), hudPass);
 

to


       env.addParallelChild(createHUD(canvas));
        BranchGroup b = new BranchGroup();
        b.addChild(this.create3DScene());
        env.addPerspectiveBranch(b);

As a side point everytime I run my code I get an exception from the getTheme method in
HUD. I thought this might be because I hadn’t set a Theme but even if I set one I still get
the same error.


java.io.IOException: mark/reset not supported
        at java.io.InputStream.reset(InputStream.java:331)
        at org.xith3d.loaders.texture.TextureStreamLocatorZip.cacheNames(TextureStreamLocatorZip.java:106)
        at org.xith3d.loaders.texture.TextureStreamLocatorZip.<init>(TextureStreamLocatorZip.java:134)
        at org.xith3d.ui.hud.utils.WidgetTheme.<init>(WidgetTheme.java:485)
        at net.worship.ui.MyHUD.createHUD(MyHUD.java:48)

It doesn’t seem to effect the actual running of the code but I’m guessing when I want to
theme components I may run into problems. Does anyone know the cause of this problem?

Thanks,
Wiliam

I updated the HUD section in XIN today. Please reread the new version (the new Multipass rendering chapter, too), if it now fits your needs. Curiously it should have worked before, too ???.
I’ll update the HUD chapter again later to explain each single Widget in detail.

Strange ???. It is not necessary to add a theme to the HUD, if you don’t use one. Could you please quote, how you add the Theme to the HUD?

Marvin

addParallelChild() and addPerspectiveBranch() should be harmonized. I tend for the branch version.

These two methods behave differently. addParallelChild() adds a Node to an existing BranchGroup and only creates a new one if not breviously done. It will try to reuse a previously created one.
addParallelChild() will always use the given BranchGroup as a new branch and RenderPass.

Marvin

That’s confusing.

Yes, maybe it is :). But these are two methods, that both make sense and have a reason to be there. Maybe you have a better name for one of them?

Marvin

No but what about creating addPerspectiveChild() and addParallelBranch() so that the confusion is partly gone (the remaining is up to the users to read the javadoc… or not).

Do I understand you right, that you actually want addPerspectiveBranch() and addParallelChild() to be removed ??? Wouldn’t this confuse even more? And what if I want to add a HUD to the environment and don’t want to handle the BranchGroup stuff myself? Then I do need addParallelChild().

But I will anyway check the JavaDoc and maybe add some lines…

Marvin

I mean to leave the existing addPerspectiveBranch() and addParallelChild() functions AND to add their counterpart ( addPerspectiveChild() and addParallelBranch() )

Ooops! You’re partly right :o. addParallelBranch() already existed, but addPerspectiveChild() didn’t ???. I’ll commit the change together with the improved JavaDoc. Thanks for the hint.

Marvin

Good.

Hi,

I am using the following code to set the theme


 try {
            FileInputStream fis = new FileInputStream("net/worship/GTK.xwt");
            System.out.println("is null::" + (fis == null));
            HUD.setTheme(new WidgetTheme(fis));
 } catch(Exception e){
            e.printStackTrace();
 }

where I have put the file in “src.net.worship” and set the classpath to my
src directory.

I get the same error if I set the theme or not.

Well, do I get you right, that you have created a new theme and called it “GTK”? I guess I haven’t catched the case, that someone tries to add two themes with the same name. So I don’t know how it could behave. The default theme’s name is “GTK” and your theme’s name seems to be “GTK” also. Please rename your theme to something different. And keep in mind, that the name base of the file “ABC.xwt” must equal the name set in the theme properties file (in this case “ABC”).

I’m currently working on the ZIP texture loader. I hope this will solve your problem. Please do a checkout, when I post, that I’ve fixed the loader (possibly this night).

Marvin