0

I have created a way to draw a selection box on the screen when you click and drag the mouse. Like in most strategy games. When the mouse is pressed, i call my draw method which creates a quad mesh and adds it to the guiNode. (Flat on screen).

While the mouse is still pressed, the following update method is called:

    Main.gui.getChild("Selection Box").removeFromParent();
    xMouseCur = inputManager.getCursorPosition().x;
    yMouseCur = inputManager.getCursorPosition().y;

    if (xMouseCur < xMouse) {
    }

    quad = new Quad(xMouseCur - xMouse, yMouseCur - yMouse, false);

    geom = new Geometry("Selection Box", quad);
    geom.setLocalTranslation(new Vector3f(xMouse, yMouse, 0));
    geom.setMaterial(mat1);
    geom.setCullHint(CullHint.Never);
    Main.gui.attachChild(geom);

The method creates a new Quad based on the first click location of the mouse and the current location of the mouse. Now the issue is that when i try to click and drag to the left, the square doesnt show. However when i drag to the right, it does.

My assumption is that when it is on the left side, the width parameter when creating a new Quad is a negative number, and that is causing issues for the Quad class. BUt im not sure. How could i fix this? Rotate the Quad? Any alternatives?

Thank you very Much

1 Answers1

0

Your issue is BackFace Culling. when the width (or height) of the Quad is negative you will be seeing the back side of tyhe object, which is culled by default PER-TRIANGLE. The geom.setCullHint is for frustrum culling (draw when the camera isn't looking at you), something that the gui node won't worry about.

Either force the quad to be of positive size: Setting the position and size appropriately each frame.

Or use mat1.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off) to tell the material to draw the back side. It will be drawing both sides all the time though, which would exacerbate the garbage collection of using a new geometry every frame.