Jump to content

bounding box paint


Cloxygen

Recommended Posts

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

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...