Plane Clipping / ClipState

Maybee someone can help me with this:

I have made a HUD, and are trying to clip a child node of a hud.

The clipping kind of works, but not in the coordinate system of my child node…

Equation…



cs.setClipPlaneEquation(0,-1f,0f,0,100f);



The clipping planes are in the coordinarte system of the root HUD node. This is possible to get around, by getting the right coordinates for my subnode… BUT… When I change the sign of the x-value in the equation:



cs.setClipPlaneEquation(0,1f,0f,0,100f);



…nothing is clipped at all… I would expect "the other side" to be clipped…

What am I missing?? Any ideas??






















if you want the plane to be at the same position you would have to change the offset value too…like this:

cs.setClipPlaneEquation(0,1f,0f,0,-100f);

Thanks Mr. Coder!! It works…

This makes the HUD gymnastics code much more clean! Here is a helper class I made, that clips a HUD spatial with a rectangle:




import com.jme.scene.Spatial;
import com.jme.scene.state.ClipState;
import com.jme.system.DisplaySystem;

/**
 * @author TOMMYS
 */
public class ClipRectangleHUD {
    private Spatial spat;
    private ClipState cs;
    private float width = 0;
    private float height = 0;
   
    public ClipRectangleHUD(Spatial spat, float width, float height) {
        this.spat = spat;
        cs = DisplaySystem.getDisplaySystem().getRenderer().createClipState();
        updateEquations(width, height);
        for (int i = 0; i < 4; i++) {
            cs.setEnableClipPlane(i, true);
        }
        spat.setRenderState(cs);
        spat.updateRenderState();
    }

    public void updateEquations(float wi, float he) {
        spat.updateWorldVectors();
        float x0 = spat.getWorldTranslation().x - wi / 2;
        float x1 = spat.getWorldTranslation().x + wi / 2;
        float y0 = spat.getWorldTranslation().y - he / 2;
        float y1 = spat.getWorldTranslation().y + he / 2;
        cs.setClipPlaneEquation(0,1f,0f,0,-x0);
        cs.setClipPlaneEquation(1,-1f,0f,0,x1);
        cs.setClipPlaneEquation(2,0f,1f,0,-y0);
        cs.setClipPlaneEquation(3,0f,-1f,0,y1);
    }
}