[New] Trouble when check the picking results & [SOLVED] Trouble in putting many models(will be operated) together

maybe U made a mistake . I mean the closest has already been found, and what I should do is to match this closest to any of the spatials in my “shootable” list.

Maybe U can see my code below and give some advice on the match.

Very appreciated!

sl4j jar file is missing, head for mavenCentral() To download it, its used for logging inside lemur

https://mvnrepository.com/artifact/org.slf4j/slf4j-api

I cannot understand you, could you illustrate using a sample snippet or drawing ?

Maybe you can check the method " public int[] getGrid() " here, that is my picking method.

3D-MineSweeping/MainFrame.java at src · BAO-Jiale/3D-MineSweeping (github.com)

public int[] getGrid(){
CollisionResults results = new CollisionResults();
Ray ray = new Ray(cam.getLocation(), cam.getDirection());
shootables.collideWith(ray, results);
if (results.size() > 0){
int [] cor=new int[2];
CollisionResult closest = results.getClosestCollision();
for (Spatial e:shootables.getChildren()){
if (closest.getGeometry().equals(e)){
loop:for (int i =0;i< mineField.getRow();i++){
for (int j=0;j< mineField.getCol();j++){
if (e.equals(temp[i][j])){cor[0]=i;cor[1]=j;break loop;}
}
}
}
}

            return cor;
    }
        else {return null;}
    }

You can ignore the Chinese text, that is similar to that in Hello Picking. I just wanna check the collision result with the models in my minefield so that I can act on them by listener.

Then add it to where? Directly into the Dependencies?

1 Like

For using Lemur someday the best way to get started is to read the “Getting started” documentation which will help you figure out how to get started:

For future reference, here is how you do code blocks:

public int[] getGrid() {
    CollisionResults results = new CollisionResults();
    Ray ray = new Ray(cam.getLocation(), cam.getDirection());
    shootables.collideWith(ray, results);
    if (results.size() > 0) {
        int [] cor=new int[2];
        CollisionResult closest = results.getClosestCollision();
        for (Spatial e:shootables.getChildren()) {
            if (closest.getGeometry().equals(e)) {
                loop:
                for (int i =0;i< mineField.getRow();i++) {
                    for (int j=0;j< mineField.getCol();j++) {
                        if (e.equals(temp[i][j])) {
                            cor[0]=i;
                            cor[1]=j;
                            break loop;
                        }
                    }
                }
            }
        }
        return cor;
    }  else {
        return null;
    }
}

Probably the geometry you get is the child of the shootable… so when you fail to find it in the shootables children then you should check its parent.

…or even better, just getParent() until you find the shootables and then use the previous one.

Spatial hit = null;
while( hit.getParent() != shootables ) {
   hit = hit.getParent();
}

…which is why I suggested using getParent() before.

In general, it seems like you might be pretty new to Java and your code seems to be doing everything the very hardest way possible. In the future, you may want to focus more on learning coding basics before attempting a 3D game.

As practical advice, you could remove a lot of code there by storing the row and column right on the shootable children when you create them using setUserData().

1 Like

& in case getParent() returns the rootNode, that is obviously because you aren’t using Nodes in your code, please refractor your code to use Nodes.

He’s colliding with shootables. If it finds anything at all then it will be a child of shootables.

As far as I know, he was having problems with getParent(), because of not grouping shootables into nodes.

No, he wasn’t using it correctly.

If you collideWith() shootables and find a geometry then it’s impossible to reach the rootNode without passing through shootables first.

I firstly add my models to the shootable, then attach shootable to rootnode. So the collision result should be a child of shootable, and shootable is a child of rootnode.

Is there any mistakes?

No. Pavl_G just isn’t reading clearly in this case.

Use the advice I give in my post above.

Now I got a new trouble. How can I set the dialog box to get user’s input message in Lemur? OptionPanel seems great but I have no idea about the parameter I should do even though I’ve seen the doc. Is there any example code or any better ways to it?

There is also one question in picking. I saw that in your PickDemo you firstly set five boxes but the same name geom. However, when you add you listener you just use one step. Is that means I can add listener to a series of Geometry and then act one of them by using the parameter “Target”?

Add a listener to each shootable. I’m not sure your skills are to the point to do anything more complicated.

So how can I set my dialog block ? I still had no idea

Do the thing with the code I cannot see.

Edit: did you even look at the lemur demos I linked above?

Yeah, I’ve checked the OptionPanelDemo ,but I don’t know how to manage that with only OptionPanel.

So what are the style & message about in the constructor

public OptionPanel(java.lang.String title, java.lang.String message, java.lang.String style, [Action])

And where & how can I set my dialog box that reads the String message from users?

Maybe I can put the dialog box in the Action?

What do you mean “with only OptionPanel”.

Do you know how to find the code?

Style is the style. null for default style. message is the message. Not sure how else to describe the “text that appears in the message box”.

You have to make one. Add a text field, etc…

There are lots of applications that use Lemur if you want to look at examples. I suspect that it will be too much for you to look at because you seem to want to do as little reading as possible… and unfortunately, I do not have time for one-on-one “walk you through every step” tech support today.

I think all of these examples use Lemur in some way:

…some even have pop-up message boxes for entering text.

For a really complex example, you can also look here:

…but in the end, you will create a container, add the stuff you want to it, position it on screen, then GuiGlobals.getInstance().showModalPopup(yourContainer)

Container LoadWin=new Container();
                guiNode.attachChild(LoadWin);
                LoadWin.setLocalTranslation(300, 300, 0);
                LoadWin.scale(50.0f,50.0f,0);
                LoadWin.addChild(new Label("Save Or Load"));

                OptionPanel optionPanel=new OptionPanel("Option Panel Demo",
                        JOptionPane.showInputDialog(this), Styles.ROOT_STYLE
                        ,new CallMethodAction("Ok", this, "close"));

                String fileName = optionPanel.getMessage();
                System.out.println("fileName :"+fileName);

I use JOptionPane here since I don’t how to set dialog box in the Lemur