Jump to content
Cloxygen

bounding box paint

Recommended Posts

For some reason the paint for bounding box is off. I used the same code for detecting clicks inside the bounding box and that works in the correct positions, but the paint is offset from the actual. Would anyone know why?

boundingbox.PNG

Edit: They seem to be lining up diagonally

boundingbox2.PNG.3d85eb5a643c0ab42654e295b3ef261c.PNG

Edited by Cloxygen
Link to comment
Share on other sites

1 minute ago, Vilius said:

I mean, it would be great if you would show us your code.

 
This Works:

private MouseListener clickListener = new MouseListener() {
    @Override
    public void mouseClicked(MouseEvent e) {
        if (startButton.contains(e.getPoint())) {
            started = true;
        } else if (!started) {
            for (int i = 0; i < selectedTrees.size(); i++) {
                if (selectedTrees.get(i).getModel().getBoundingBox(selectedTrees.get(i).getGridX(), selectedTrees.get(i).getGridY(), selectedTrees.get(i).getZ()).contains(e.getPoint())) {
                    selectedTrees.remove(selectedTrees.get(i));
                    return;
                }
            }
            for (int i = 0; i < nearbyTrees.size(); i++) {
                if (nearbyTrees.get(i).getModel().getBoundingBox(nearbyTrees.get(i).getGridX(), nearbyTrees.get(i).getGridY(), nearbyTrees.get(i).getZ()).contains(e.getPoint())) {
                    selectedTrees.add(nearbyTrees.get(i));
                    return;
                }
            }
        }
    }

    @Override
    public void mousePressed(MouseEvent e) {

    }

    @Override
    public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }
};

This Doesn't:


public void onPaint(final Graphics2D g) {

if (choppingArea.contains(myPlayer())) {
    //Paints nearby trees
    if (!started) {
        g.setColor(Color.WHITE);
        g.drawString("PLEASE SELECT ORE.", 195, 305);
        g.setColor(Color.GRAY);
        for (int i = 0; i < nearbyTrees.size(); i++) {
                checkTree = nearbyTrees.get(i);
                model = checkTree.getModel();
                g.draw(model.getBoundingBox(checkTree.getGridX(),checkTree.getGridX(),checkTree.getZ()));
        }
        g.drawImage(startButtonimg, 645, 452, null);
    }

    g.setColor(Color.WHITE);
    for(int i = 0;i < selectedTrees.size();i++){
        if(selectedTrees.get(i) != null){
            checkTree = selectedTrees.get(i);
            model = checkTree.getModel();
            g.draw(model.getBoundingBox(checkTree.getGridX(),checkTree.getGridX(),checkTree.getZ()));
        }
    }

}

Link to comment
Share on other sites

35 minutes ago, Cloxygen said:


 

This Works:

private MouseListener clickListener = new MouseListener() {
    @Override
    public void mouseClicked(MouseEvent e) {
        if (startButton.contains(e.getPoint())) {
            started = true;
        } else if (!started) {
            for (int i = 0; i < selectedTrees.size(); i++) {
                if (selectedTrees.get(i).getModel().getBoundingBox(selectedTrees.get(i).getGridX(), selectedTrees.get(i).getGridY(), selectedTrees.get(i).getZ()).contains(e.getPoint())) {
                    selectedTrees.remove(selectedTrees.get(i));
                    return;
                }
            }
            for (int i = 0; i < nearbyTrees.size(); i++) {
                if (nearbyTrees.get(i).getModel().getBoundingBox(nearbyTrees.get(i).getGridX(), nearbyTrees.get(i).getGridY(), nearbyTrees.get(i).getZ()).contains(e.getPoint())) {
                    selectedTrees.add(nearbyTrees.get(i));
                    return;
                }
            }
        }
    }

    @Override
    public void mousePressed(MouseEvent e) {

    }

    @Override
    public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }
};

This Doesn't:


public void onPaint(final Graphics2D g) {

if (choppingArea.contains(myPlayer())) {
    //Paints nearby trees
    if (!started) {
        g.setColor(Color.WHITE);
        g.drawString("PLEASE SELECT ORE.", 195, 305);
        g.setColor(Color.GRAY);
        for (int i = 0; i < nearbyTrees.size(); i++) {
                checkTree = nearbyTrees.get(i);
                model = checkTree.getModel();
                g.draw(model.getBoundingBox(checkTree.getGridX(),checkTree.getGridX(),checkTree.getZ()));
        }
        g.drawImage(startButtonimg, 645, 452, null);
    }

    g.setColor(Color.WHITE);
    for(int i = 0;i < selectedTrees.size();i++){
        if(selectedTrees.get(i) != null){
            checkTree = selectedTrees.get(i);
            model = checkTree.getModel();
            g.draw(model.getBoundingBox(checkTree.getGridX(),checkTree.getGridX(),checkTree.getZ()));
        }
    }

}

"

g.draw(model.getBoundingBox(checkTree.getGridX(),checkTree.getGridX(),checkTree.getZ()));

"

You're using #getGridX() twice here in the painting.

  • Like 2
Link to comment
Share on other sites

12 hours ago, Cloxygen said:

 wow i feel dumb, thanks


You can see the pattern of that in how the rectangles are drawn all in a "line" kinda. for future reference

boundingbox2.PNG.3d85eb5a643c0ab42654e295b3ef261c.PNG

Also you don't really wanna use a rectangle because of these red areas

JSBZlxS.png

Edited by dmmslaver
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...