Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (600)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Problem with HUD code  (Read 4532 times)
0 Members and 1 Guest are viewing this topic.
Offline williamsellick

Senior Newbie





« Posted 2006-10-30 19:30:53 »

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...
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
// 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

1  
2  
3  
4  
5  
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
Offline Amos Wenger

Senior Devvie




Everything's possible, but not everything's fun...


« Reply #1 - Posted 2006-10-30 19:41:18 »

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

"Once you start working on something, don't be afraid of failure and don't abandon it. People who work sincerely are the happiest"
Offline Marvin Fröhlich

Senior Devvie




May the 4th, be with you...


« Reply #2 - Posted 2006-10-30 19:47:59 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
First of all some comments about imports:

[code]

// 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


1  
        //this.registerInputListner(hud);

Uncomment this line to make the HUD able to hande input events.

        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();
    }
}
[/code]

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.

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

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

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.

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

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

Marvin
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline williamsellick

Senior Newbie





« Reply #3 - Posted 2006-10-31 09:41:05 »

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
Offline Amos Wenger

Senior Devvie




Everything's possible, but not everything's fun...


« Reply #4 - Posted 2006-10-31 12:57:25 »

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

"Once you start working on something, don't be afraid of failure and don't abandon it. People who work sincerely are the happiest"
Offline rafa_es

Junior Devvie





« Reply #5 - Posted 2006-11-01 00:06:24 »

... but when I try to run it I get the following error

1  
2  
3  
4  
5  
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)


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
Offline Marvin Fröhlich

Senior Devvie




May the 4th, be with you...


« Reply #6 - Posted 2006-11-01 00:44:50 »

... but when I try to run it I get the following error

1  
2  
3  
4  
5  
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)


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
Offline williamsellick

Senior Newbie





« Reply #7 - Posted 2006-11-12 14:00:38 »

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
1  
2  
3  
4  
5  
       RenderPass scenePass = new RenderPass(RenderPass.PERSPECTIVE_PROJECTION);
        env.addChild(create3DScene(), scenePass);
        RenderPass hudPass = new RenderPass(RenderPass.PARALLEL_PROJECTION);
        env.addChild(createHUD(canvas), hudPass);
 


to

1  
2  
3  
4  
       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.

1  
2  
3  
4  
5  
6  
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
Offline Marvin Fröhlich

Senior Devvie




May the 4th, be with you...


« Reply #8 - Posted 2006-11-12 20:34:51 »

I found that the code in XIN may need adjusting as I had to change
1  
2  
3  
4  
5  
       RenderPass scenePass = new RenderPass(RenderPass.PERSPECTIVE_PROJECTION);
        env.addChild(create3DScene(), scenePass);
        RenderPass hudPass = new RenderPass(RenderPass.PARALLEL_PROJECTION);
        env.addChild(createHUD(canvas), hudPass);
 


to

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


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 Huh.
I'll update the HUD chapter again later to explain each single Widget in detail.

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.

1  
2  
3  
4  
5  
6  
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?

Strange Huh. 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
Offline Amos Wenger

Senior Devvie




Everything's possible, but not everything's fun...


« Reply #9 - Posted 2006-11-13 17:49:42 »

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

"Once you start working on something, don't be afraid of failure and don't abandon it. People who work sincerely are the happiest"
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Marvin Fröhlich

Senior Devvie




May the 4th, be with you...


« Reply #10 - Posted 2006-11-13 18:33:41 »

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
Offline Amos Wenger

Senior Devvie




Everything's possible, but not everything's fun...


« Reply #11 - Posted 2006-11-14 17:31:07 »

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.

"Once you start working on something, don't be afraid of failure and don't abandon it. People who work sincerely are the happiest"
Offline Marvin Fröhlich

Senior Devvie




May the 4th, be with you...


« Reply #12 - Posted 2006-11-14 20:37:56 »

That's confusing.

Yes, maybe it is Smiley. 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
Offline Amos Wenger

Senior Devvie




Everything's possible, but not everything's fun...


« Reply #13 - Posted 2006-11-14 22:35:06 »

That's confusing.

Yes, maybe it is Smiley. 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?
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).

"Once you start working on something, don't be afraid of failure and don't abandon it. People who work sincerely are the happiest"
Offline Marvin Fröhlich

Senior Devvie




May the 4th, be with you...


« Reply #14 - Posted 2006-11-14 22:45:41 »

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 Huh 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
Offline Amos Wenger

Senior Devvie




Everything's possible, but not everything's fun...


« Reply #15 - Posted 2006-11-14 23:09:38 »

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 Huh 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...
I mean to leave the existing addPerspectiveBranch() and addParallelChild() functions AND to add their counterpart ( addPerspectiveChild() and addParallelBranch() )

"Once you start working on something, don't be afraid of failure and don't abandon it. People who work sincerely are the happiest"
Offline Marvin Fröhlich

Senior Devvie




May the 4th, be with you...


« Reply #16 - Posted 2006-11-14 23:13:21 »

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

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

Marvin
Offline Amos Wenger

Senior Devvie




Everything's possible, but not everything's fun...


« Reply #17 - Posted 2006-11-14 23:27:13 »

Good.

"Once you start working on something, don't be afraid of failure and don't abandon it. People who work sincerely are the happiest"
Offline williamsellick

Senior Newbie





« Reply #18 - Posted 2006-11-18 21:19:41 »

Hi,

I am using the following code to set the theme

1  
2  
3  
4  
5  
6  
7  
 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.
Offline Marvin Fröhlich

Senior Devvie




May the 4th, be with you...


« Reply #19 - Posted 2006-11-18 21:46:18 »

Hi,

I am using the following code to set the theme

1  
2  
3  
4  
5  
6  
7  
 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
Offline Marvin Fröhlich

Senior Devvie




May the 4th, be with you...


« Reply #20 - Posted 2006-11-18 22:10:06 »

I've fixed the TextureStreamLocatorZIP. Please check if it works now.

Unfortunately I had to break the API to do it. You now have to pass a URL to the WidgetTheme constructor instead of an InputStream. But it is only one line to change. Here is the new code to use:
1  
2  
3  
4  
5  
6  
7  
 try {
            URL url = myClassLoader.getResource("net/worship/GTK.xwt");
            System.out.println("is null::" + (url == null));
            HUD.setTheme(new WidgetTheme(url));
 } catch(Exception e){
            e.printStackTrace();
 }


Hope this fixed you problem.

Marvin
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (29 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (40 views)
2014-12-09 22:41:13

BurntPizza (75 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (50 views)
2014-12-03 16:27:13

CopyableCougar4 (46 views)
2014-11-29 21:32:03

toopeicgaming1999 (113 views)
2014-11-26 15:22:04

toopeicgaming1999 (100 views)
2014-11-26 15:20:36

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!