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

Maybe I can’t do that right now , I got to write the collision result now since the deadline is around the corner. Sorry about that, so could you tell me the key words I could search?

Maybe I’ll post my code later.

And I also have a problem wen initializing Lemur. That I always got the error like this:

Uncaught exception thrown in Thread[jME3 Main,5,main]
NoClassDefFoundError: org/slf4j/LoggerFactory

What is that about?

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

Just to check the method " public int[] getGrid() ",and help me to get real result of the method.

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?