arbitrary clipping planes

edited October 2013 in How To...

Hello, I need to create arbitrary clipping planes to clip PShapes. Similar to this http://www.java-tips.org/other-api-tips/jogl/demonstration-of-arbitrary-clipping-planes.html. Is it possible? Thank you

Tagged:

Answers

  • Answer ✓

    Hello, You can use the perspective() method: http://processing.org/reference/perspective_.html

  • i'm not sure perspective() will work. it does allow you to specify front and back planes, but not arbitrary clipping planes...

  • Thanks koogs, you're right. I read the question too fast.

    Interesting... :-?

  • edited October 2013

    Thanks for the comments. I think it can be done like this

    PGraphicsOpenGL pg;
    
    public void setup() {
          size(400, 400,OPENGL);
          pg = (PGraphicsOpenGL) createGraphics(400, 400, OPENGL);
    }
    
    public void draw() {
          pg.beginDraw();
          pg.background(0); 
          pg.color(1.0f, 1.0f, 1.0f);
          pg.pushMatrix();
          pg.translate(width/2, height/2);
          pg.clip(80.0f, 100.0f, 100.0f, 100.0f);
          pg.sphere(100.0f);
          pg.popMatrix();
          pg.endDraw();
          image(pg, 0, 0, width, height);
    }
    

    The question is now if we could rotate the camera and look inside of the trimmed sphere.

  • have you tried peasycam?

  • edited November 2013

    This is the working example of clipping two opengl planes. It does not work with Processing 2.1, because of an error in gl = pgl.beginPGL().gl.getGL2(). Works fine in 2.0.3, so there is some change in 2.1 that i did not see documented in the opengl examples. Now I have to figure how to make this work for an imported obj model.

    import processing.opengl.PGraphicsOpenGL; import javax.media.opengl.GL2; import peasy.*;

    PGraphicsOpenGL pgl; GL2 gl; PeasyCam cam;

    public void setup() {

          size(800, 600,OPENGL);
          cam = new PeasyCam(this, 150);
          pgl  = (PGraphicsOpenGL) g;
          gl    =  pgl.beginPGL().gl.getGL2();        
    }
    
    public void draw() {
    
          background(255);
          pgl.beginPGL();
          double eqn [] = {0.10, 0.0, 1.0, 0.0};
          gl.glColor4f(0.7f, 0.7f, 0.7f, 0.8f);
          gl.glTranslatef(width/2f, height/2f, 0f);
          gl.glClipPlane(gl.GL_CLIP_PLANE0, eqn,0);
          gl.glEnable(gl.GL_CLIP_PLANE0);
          gl.glRectf(-200, -200, 200, 200);
          gl.glRotatef(90, 1, 0, 0);
          gl.glRectf(-200, -200, 200, 200);      
          pgl.endPGL();
    }
    
  • edited November 2013

    One issue in Processing 2.1 occurs with that code because the codebase has altered slightly. You can no longer use that command to get the GL2 object.

    So this has changed in Processing 2.1, which I was able to ascertain from the updated Processing Javadoc. Now, PJOGL is a new class that uses the functionality to get the GL2 object, and the PJOGL class extends from the PGL class

    To correct this, you need to update how you get the GL2 object:

    gl = ((PJOGL) pgl.beginPGL()).gl.getGL2();
    

    That will, at least, fix your OpenGL issues in Processing 2.1. I am unclear if there is a better method that is backwards-compatible, however.

  • edited November 2013

    Thank you.

Sign In or Register to comment.