Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > java 3d picking

Reply
Thread Tools

java 3d picking

 
 
Angus Parvis
Guest
Posts: n/a
 
      06-13-2005
Hi,

I have a very simple 3D-app with a couple of cubes in the scene which I
want to pick. I dont want to rotate, translate or scale them, I just
want to pick one of them and know which one was picked. (It's for a
battleship-like game, just want to choose a cube to know at which one to
"shoot" at.)

Could anyone suggest me a solution to the problem? All I want is to know
which object was picked. That's all. Hope someone can help, this work
has to be done really soon ..

thx for your kind help,

Angus
 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      06-14-2005
On Tue, 14 Jun 2005 00:19:40 +0200, Angus Parvis wrote:

> I have a very simple 3D-app..


Try the group that specialises in it.
<http://www.physci.org/codes/javafaq.jsp#clj3>

HTH

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
 
Reply With Quote
 
 
 
 
Martijn Mulder
Guest
Posts: n/a
 
      06-14-2005
> I have a very simple 3D-app with a couple of cubes in the scene which I
> want to pick. I dont want to rotate, translate or scale them, I just
> want to pick one of them and know which one was picked. (It's for a
> battleship-like game, just want to choose a cube to know at which one to
> "shoot" at.)
>
> Could anyone suggest me a solution to the problem? All I want is to know
> which object was picked. That's all. Hope someone can help, this work
> has to be done really soon ..



You typically construct a Behavior node in your app and let it wake up on a
mouse event.
Send your code for us to shoot at.


 
Reply With Quote
 
Angus Parvis
Guest
Posts: n/a
 
      06-14-2005
Andrew Thompson wrote:
> On Tue, 14 Jun 2005 00:19:40 +0200, Angus Parvis wrote:
>
>
>>I have a very simple 3D-app..

>
>
> Try the group that specialises in it.
> <http://www.physci.org/codes/javafaq.jsp#clj3>
>
> HTH


j3d doesn't have a lot of traffic, can't expect much help there ..
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      06-14-2005
On Tue, 14 Jun 2005 17:27:06 +0200, Angus Parvis wrote:
> Andrew Thompson wrote:
>> On Tue, 14 Jun 2005 00:19:40 +0200, Angus Parvis wrote:
>>
>>>I have a very simple 3D-app..

>>
>> Try the group that specialises in it.
>> <http://www.physci.org/codes/javafaq.jsp#clj3>

...
> j3d doesn't have a lot of traffic, can't expect much help there ..


So you reckon they are all hanging out ..here?

It might make sense to cross-post, but direct follow-ups to c.l.j.3d.

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
 
Reply With Quote
 
Angus Parvis
Guest
Posts: n/a
 
      06-14-2005
Martijn Mulder wrote:
>
> You typically construct a Behavior node in your app and let it wake up on a
> mouse event.
> Send your code for us to shoot at.
>



I know my code could be better-looking, but atm I just try to make it
run. All I have atm are 4*4 color cubes that should be replaces by some
single-colored boxes you can click at to shoot at them.

... here it is - and thx for your help :

package battleships.gui3d;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GraphicsConfiguration;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.Shape3D;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.KeyStroke;
import javax.vecmath.Vector3f;

import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.SimpleUniverse;

public class Simple3DGame extends JFrame {

JLabel _statusBarTextLabel = new JLabel("Game status ...");

public Simple3DGame() {
super("Battleships 3D");

JMenuBar menuBar = new JMenuBar();

JMenu menu = new JMenu("Game");
menu.setMnemonic(KeyEvent.VK_G);
menuBar.add(menu);

JMenuItem menuItem = new JMenuItem("New Game", KeyEvent.VK_N);
menu.add(menuItem);
menuItem.setAccelerator(KeyStroke.getKeyStroke(Key Event.VK_N,
ActionEvent.CTRL_MASK));
menuItem = new JMenuItem("Exit Game", KeyEvent.VK_X);
menu.add(menuItem);
menuItem.setAccelerator(KeyStroke.getKeyStroke(Key Event.VK_X,
ActionEvent.CTRL_MASK));

setSize(600, 600);

setJMenuBar(menuBar);
setLayout(new BorderLayout());
add(BorderLayout.CENTER, create3DPanel());
add(BorderLayout.PAGE_END, createStatusBar());
}

public JPanel createStatusBar() {
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
panel.add(_statusBarTextLabel);
return panel;
}

public JPanel create3DPanel() {
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
GraphicsConfiguration config = SimpleUniverse
.getPreferredConfiguration();
Canvas3D canvas3D = new Canvas3D(config);
panel.add(BorderLayout.CENTER, canvas3D);

BranchGroup scene = createSceneGraph(canvas3D);
scene.compile();

// SimpleUniverse is a Convenience Utility class
SimpleUniverse simpleU = new SimpleUniverse(canvas3D);

simpleU.addBranchGraph(scene);

return panel;
} // end of HelloJava3Da (constructor) public BranchGroup

public BranchGroup createSceneGraph(Canvas3D canvas) {
// Create the root of the branch graph
BranchGroup objRoot = new BranchGroup();

int MAX_CUBES_X = 4;
int MAX_CUBES_Y = 4;

for (int x = 0; x < MAX_CUBES_X; x++) {
for (int y = 0; y < MAX_CUBES_Y; y++) {
BranchGroup objGroup = new BranchGroup();
objRoot.addChild(objGroup);
Transform3D transform = new Transform3D();
float newX = (MAX_CUBES_X / -2) * 0.3f + 0.15f + (0.3f * x);
float newY = (MAX_CUBES_Y / -2) * 0.3f + 0.15f + (0.3f * y);
System.out.println(newX + " " + newY);
transform.setTranslation(new Vector3f(newX, newY, -3.0f));
TransformGroup objRotate = new TransformGroup(transform);
objRotate.setCapability(TransformGroup.ALLOW_TRANS FORM_WRITE);
objRotate.setCapability(TransformGroup.ALLOW_TRANS FORM_READ);
objRotate.setCapability(TransformGroup.ENABLE_PICK _REPORTING);
objGroup.addChild(objRotate);
Shape3D shape = new ColorCube(0.1);
objRotate.addChild(shape);
// XXX add behavior here?
// PickRotateBehavior pickRotate = new PickRotateBehavior(
// objGroup, canvas, shape.getBounds());
// objRotate.addChild(pickRotate);
}
}

// Let Java 3D perform optimizations on this scene graph.
objRoot.compile();

return objRoot;
}

public static void main(String args[]) {
JFrame gameFrame = new Simple3DGame();
gameFrame.setVisible(true);
}
}

 
Reply With Quote
 
Angus Parvis
Guest
Posts: n/a
 
      06-14-2005
Andrew Thompson wrote:
> On Tue, 14 Jun 2005 17:27:06 +0200, Angus Parvis wrote:
>
> So you reckon they are all hanging out ..here?


Telling from the traffic in the other groups ... yes.
Telling from the answers I got to 3D-related postings ... yes.

> It might make sense to cross-post, but direct follow-ups to c.l.j.3d.


Wouldn't know how to do that ..
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      06-15-2005
On Tue, 14 Jun 2005 21:35:23 +0200, Angus Parvis wrote:

> Andrew Thompson wrote:
>> On Tue, 14 Jun 2005 17:27:06 +0200, Angus Parvis wrote:
>>
>> So you reckon they are all hanging out ..here?

>
> Telling from the traffic in the other groups ... yes.
> Telling from the answers I got to 3D-related postings ... yes.


It is a pity that 3D is so quite.

>> It might make sense to cross-post, but direct follow-ups to c.l.j.3d.

>
> Wouldn't know how to do that ..


That would depend on your user agent (news reader) -
Mozilla Thunderbird 1.0.2.

40tude Dialog presents a number of fields when posting,
including 'Newsgroups' and a separate field (with a
drop down that defaults to) 'Follow-Up To'..

To X-post I would put the X-posted groups in 'Newsgroups'
separated by a comma, with one of those listed in the
'F-U To' field.

If it's any help I'll demonstrate (though really you need to
figure how to do it with your own software)

HTH

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
 
Reply With Quote
 
Thomas Weidenfeller
Guest
Posts: n/a
 
      06-15-2005
Angus Parvis wrote:
> j3d doesn't have a lot of traffic, can't expect much help there ..


The amount of traffic says nothing about the quality of a group.

/Thomas


--
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/...g/java/gui/faq
 
Reply With Quote
 
Rolf Gabler-Mieck
Guest
Posts: n/a
 
      06-16-2005
Hi Angus,
at first:
http://www.javadesktop.org/forums/forum.jspa?forumID=55
is absolutley nice frequented and it's just one topic... java3d.

second:
you have to set UserData (String) to your Shape3d/BranchGroup or what
ever, then you have to write your pickingBehavior using AWTEvent as
criteria for wakeUp.
if pickray hits, you'll get the userData. I believe that there must
anything like this in the demos - I believe TicTacToe will do it - maybe
another picking result.
best regards
rolf

Angus Parvis wrote:
> Hi,
>
> I have a very simple 3D-app with a couple of cubes in the scene which I
> want to pick. I dont want to rotate, translate or scale them, I just
> want to pick one of them and know which one was picked. (It's for a
> battleship-like game, just want to choose a cube to know at which one to
> "shoot" at.)
>
> Could anyone suggest me a solution to the problem? All I want is to know
> which object was picked. That's all. Hope someone can help, this work
> has to be done really soon ..
>
> thx for your kind help,
>
> Angus

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
IDS 4215 Picking up Net Sweep-echo Chris Cisco 2 05-05-2005 04:14 PM
DWL-122 not picking up DHCP with new modem =?Utf-8?B?QnJhbmRvbg==?= Wireless Networking 7 03-13-2005 04:13 PM
Not picking up Access Points, Delete Reg Entries & Reinstall? Al Franz Wireless Networking 1 03-04-2005 04:17 PM
Picking up unwanted networks =?Utf-8?B?Q2hyaXMgT3N0ZXI=?= Wireless Networking 9 10-09-2004 06:23 PM
Cisco AS5200 not picking up! Stephen Smith Cisco 1 12-06-2003 02:21 AM



Advertisments