Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
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  
  Help with picking for a n00b :)  (Read 2016 times)
0 Members and 1 Guest are viewing this topic.
Offline pinkman

Junior Newbie




Java games rock!


« Posted 2003-12-22 21:29:26 »

Hi All,

I am new 3D programming, so bear with me here.

I have installed Xith3D and all relating libraries and I can run the demo's fine. However, I am having problems with "picking" on models that are loaded eitheir with TDSLoader or the ASE loader.

I thought it may have been my code so went back and "moded" the example for picking (http://www.xith.org/tutes/GettingStarted/html/picking.html).

Specifically I took out left, middle and right plane shapes, and loaded an ase model, which displays fine, but I cant pick it!

This is the code I have used to get the model out, the rest of the code is the same as the picking example:

   AseFile af = new AseFile();
   try
   {
     AseReader r = new AseReader(new BufferedReader(new FileReader("model/cube.ase")), af);
     af.parse(r);
   }
   catch (IOException e)
   {
     System.out.println("Error reading ase file");
   }

   // Extracts list of named nodes
   java.util.Hashtable views = af.getNamedNodes();

   for (Enumeration e = views.keys(); e.hasMoreElements();)
   {
     String current = (String)e.nextElement();
     BranchGroup group = (BranchGroup)views.get((Object)current);
     group.setPickable(true);
     sw.addChild(group);
   }

Or something along those lines, basically from the tank example.

I have gone through and recursively got the parents to make sure that they are all set to pickable, and tried numerous other things but it just wont work!

Please help, what am I missing here?

Cheers,
Pinkman!
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #1 - Posted 2003-12-22 23:21:29 »

1  
  BranchGroup group = (BranchGroup)views.get((Object)current); 


Should be:
1  
  Group group = (Group)views.get((Object)current); 


That's a mistake in the tute which has been fixed and must be re-uploaded.

Will.

Offline pinkman

Junior Newbie




Java games rock!


« Reply #2 - Posted 2003-12-22 23:44:20 »

Thanks William, but still no luck. I thought it may have been something todo with the model I am using, so I changed it to the origincube.ase, and again no luck. This is the exact code I am using:

   AseFile af = new AseFile();
   FileReader fileReader = null;
   BufferedReader bufferedReader = null;
   AseReader r = null;
   try
   {
     fileReader = new FileReader("C:/origincube.ASE");
     bufferedReader = new BufferedReader(fileReader);
     r = new AseReader(bufferedReader, af);
     af.parse(r);
   }
   catch (IOException e)
   {
     log.error("Error reading ase file");
   }
   finally
   {
     try
     {
       fileReader.close();
       bufferedReader.close();
       r.close();
     }
     catch (IOException e1)
     {
       e1.printStackTrace(System.err);
     }
   }
   // Extracts list of named nodes
   java.util.Hashtable views = af.getNamedNodes();

   for (Enumeration e = views.keys(); e.hasMoreElements()Wink
   {
     String current = (String)e.nextElement();
     System.out.println("Node name: " + current);
     Group group = (Group)views.get((Object)current);
     group.setPickable(true);
     sw.addChild(group);
   }

I gets the group fine, outputs the name ("Box01") and even displays it, but I still cannot "pick it", I get zero hits on it.

Any ideas?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #3 - Posted 2003-12-23 00:38:06 »

Not sure I'm afraid - I don't use picking myself.  Jens (who wrote that tute) should see this thread in a few hours and might be able to help you Smiley

Will.

Offline Yuri Vl. Gushchin

Senior Member




Speak Java!


« Reply #4 - Posted 2003-12-23 06:13:05 »

Do Xith3D picking tests (Xith3DSwitchNodeTest and Xith3DPickRenderTest) work for you?

Yuri

Yuri Vl. Gushchin
JProof Group
Offline Preston

Senior Member


Medals: 4



« Reply #5 - Posted 2003-12-23 12:21:12 »

Did you issue "setPickable(true)" to the Shape3D as well as all its parent transform/branch groups?
Offline pinkman

Junior Newbie




Java games rock!


« Reply #6 - Posted 2003-12-23 17:48:53 »

That did the trick Preston ta  Grin. I could have sworn I had tried that, but there you go.

To me it would make more sense if you could set a whole group pickable and it would recurse through the children to the leaf nodes.

I understand that this would not always be usefull, and could be annoying, but maybe a setGroupPickable() would be handy.

Anyway, thanks a lot guys, back to Xith...
Offline kevglass

JGO Kernel


Medals: 122
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #7 - Posted 2003-12-23 17:52:55 »

This might help then:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
public void setPickable(Node n) {
    n.setPickable(true);
    if (n instanceof Group) {
         Group g = (Group) n;

         for (int i=0;i<g.numChildren();i++) {
                  setPickable(g.getChild(i));
              }
    }
}


Assuming I haven't screwed anything up there then that'll do recursive pickable set.

Kev

Offline pinkman

Junior Newbie




Java games rock!


« Reply #8 - Posted 2003-12-23 18:22:17 »

I have just writen this code, perhaps not as elegant:

 /**
  * Simon Pink
  * Sets all children nodes to pickable
  * @param group
  */
 private void setGroupPickable(Group group)
 {
   Node child = null;

   for (Enumeration childrenEnum = group.getAllChildren(); childrenEnum.hasMoreElements();)
   {
     child = (Node)childrenEnum.nextElement();
     child.setPickable(true);
     if (child.getClass() != Shape3D.class)
       setGroupPickable((Group)child);
   }
 }

Seems to do the trick nicely tho.
Offline pinkman

Junior Newbie




Java games rock!


« Reply #9 - Posted 2003-12-23 18:23:50 »

P.S. how do I inset the code when I post (yes I am a n00b to these forums  Smiley )
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline kevglass

JGO Kernel


Medals: 122
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #10 - Posted 2003-12-23 18:26:38 »

You can use the tags:

[ code ]

Code in here
[ /code ]

(without spaces) to indent code blocks

Kev

Offline pinkman

Junior Newbie




Java games rock!


« Reply #11 - Posted 2003-12-23 18:40:40 »

Thanks Kev.

I cant believe how active this forum is! Really is great. Cheers for help guys.
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #12 - Posted 2003-12-23 21:08:26 »

this would be a good tip to add to the tute Smiley

Will.

Offline pinkman

Junior Newbie




Java games rock!


« Reply #13 - Posted 2003-12-23 23:08:11 »

Yeah I agree, it seems like a bit of a trap for new commers like me. Eitheir that or add the "setGroupPickable()" method to the API, or both...
Offline Jens

Senior Member




Java for games!


« Reply #14 - Posted 2003-12-24 08:32:16 »

Quote
Not sure I'm afraid - I don't use picking myself.  Jens (who wrote that tute) should see this thread in a few hours and might be able to help you Smiley


Currently I'm not doing any coding (it's christmas Smiley), but I wrote similar helper methods like the ones mentioned above. If I don't forget it, I can include this in the tutorial when I have access to my dev machine again. Some helper methods for this in Xith3D would be nice, because scenegraph traversal is needed quite often.

Xith3D Getting Started Guide (PDF,HTML,Source)
Offline Yuri Vl. Gushchin

Senior Member




Speak Java!


« Reply #15 - Posted 2003-12-24 13:19:55 »

As of scene traversal, I would vote for Visitor design pattern: define unified traverser and Visitor interface which one will implement to perform application-specific tasks.

Yuri

Yuri Vl. Gushchin
JProof Group
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.

CogWheelz (18 views)
2014-07-30 21:08:39

Riven (26 views)
2014-07-29 18:09:19

Riven (15 views)
2014-07-29 18:08:52

Dwinin (13 views)
2014-07-29 10:59:34

E.R. Fleming (34 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (43 views)
2014-07-24 01:59:36

Riven (44 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54
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!