PShape, updateTessellation, matrix transformations #4662

Closed
diwi opened this Issue Sep 11, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@diwi

diwi commented Sep 11, 2016

Hi,

I've found some problematic behaviour with stacked PShape transformations. Especially this combination:
reset() -> rotate() -> translate()
as described in the comment, if rotate is not "zero" there is some unexpected transformation happening.
even worse, if rotation is PI/2 in the first round, it doesnt draw anything.

however, i figured that, if the protected updateTessellation() is called before that, it works. The "cheapest" workaround so far was to just call getVertexCount() to trigger updateTessellation().

  // issue: 
  // if "rotation" is anything else than zero before the first draw call
  // the matrix transformation gets messed up.
  // apparently "PShapeOpenGL.updateTessellation()" needs to be called before rotate().
  // but its protected, so as a workaround im calling "getVertexCount()" atm.
  float rotation = PI/2; 

  PShape particle;

  public void settings() {
    size(600, 600, P2D);
  }

  public void setup() {
    particle = createShape(LINE, 0, 0, 150, 0);
    particle.getVertexCount(); // uncomment to make the sketch work
  }

  public void draw() {  
    background(255);

    particle.resetMatrix();
    particle.rotate(rotation);
    particle.translate(width/2, height/2);
    shape(particle);

    rotation += 0.02f;

    // window center
    ellipse(width/2, height/2, 5,5);
  }

@diwi diwi changed the title from updateTessellation to PShape, updateTessellation, matrix transformations Sep 11, 2016

@diwi

This comment has been minimized.

Show comment
Hide comment
@diwi

diwi Sep 11, 2016

another testcase:

If the shapes are grouped, the parent needs to execute getTessellation() or the childs need to call getVertexCount() or getTessellation() to make it work - after they got added to the group.
... just anything that triggers updateTessellation() before any transformations are applied i guess.

  float rotation = PI/2; 

  PShape particle;
  PShape particlesystem;
  public void settings() {
    size(600, 600, P2D);
  }

  public void setup() {
    particle = createShape(LINE, 0, 0, 150, 0);


    particlesystem = createShape(PShape.GROUP);
    particlesystem.addChild(particle);

//    particlesystem.getTessellation(); // option 1: uncomment to make the sketch work
    particle.getVertexCount(); // option 2: uncomment to make the sketch work
  }

  public void draw() {  
    background(255);

    particle.resetMatrix();
    particle.rotate(rotation);
    particle.translate(width/2, height/2);


    shape(particlesystem);

    rotation += 0.02f;

    // window center
    ellipse(width/2, height/2, 5,5);
  }

diwi commented Sep 11, 2016

another testcase:

If the shapes are grouped, the parent needs to execute getTessellation() or the childs need to call getVertexCount() or getTessellation() to make it work - after they got added to the group.
... just anything that triggers updateTessellation() before any transformations are applied i guess.

  float rotation = PI/2; 

  PShape particle;
  PShape particlesystem;
  public void settings() {
    size(600, 600, P2D);
  }

  public void setup() {
    particle = createShape(LINE, 0, 0, 150, 0);


    particlesystem = createShape(PShape.GROUP);
    particlesystem.addChild(particle);

//    particlesystem.getTessellation(); // option 1: uncomment to make the sketch work
    particle.getVertexCount(); // option 2: uncomment to make the sketch work
  }

  public void draw() {  
    background(255);

    particle.resetMatrix();
    particle.rotate(rotation);
    particle.translate(width/2, height/2);


    shape(particlesystem);

    rotation += 0.02f;

    // window center
    ellipse(width/2, height/2, 5,5);
  }

@diwi diwi closed this Sep 11, 2016

@diwi diwi reopened this Sep 11, 2016

@benfry benfry added the opengl label Sep 12, 2016

@jeremydouglass jeremydouglass referenced this issue in processing-r/Processing.R Aug 9, 2017

Merged

reference: Add the missing images #205

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment