PShape.rotateZ() bug?

Hi.

New to Processing & this forum.

Been playing with the former about a week or so, really loving it.

Loving the video tutorials & OpenProcessing site: between these 2 resources & the Coding Train channel on Youtube, making solid progress …

I started playing with 3D a few hours ago, & i think i have found a bug.

I was attempting to try & ‘fork’ my cobbled together particle system example (made using the Nature of Code book …) to work in 3D space, hence utilising PShape for my base object & attempting to spray a few around the canvas.

I was successfully able to myShape.rotateX() & myShape.rotateY(), but myShape.rotateZ() yields the following error …

ClassCastException: processing.core.PMatrix3D cannot be cast to processing.core.PMatrix2D

i have copied the code below. I hope i have formatted it correctly for display in the forum.

If i am doing something silly here, i welcome the solution. But based on the message, & the fact that rotateX & rotateY behave as expected, i suspect there is an issue here that requires resolution.

Thanks in advance & i hope to continue making progress with Processing going forward, as far as time & my ambitions permit at least

& I hope i have formatted this post correctly with respect to the coding example …

Tim.

ArrayList<Particle> particles;
 
void setup() {
  size(640,640,P3D);
  particles = new ArrayList<Particle>();
}
 
void draw() {
  
  background(255);
  
  // LIGHTING MUST PRECEDE SHAPE DRAWING
  
  //ambientLight(32,32,32);
  directionalLight(0, 128, 0, 0.9,-0.9, 0.9);
  directionalLight(0, 0, 128, 0.5, 0.25, -0.5);
  
  //lights();
  
  //frameRate(16);
  
  if (frameCount % 24 == 0) {
    particles.add(new Particle(new PVector(random(0,width),random(0,height),random(-200,0))));
  }
  
  for (int i = particles.size()-1; i >= 0; i--) {
    Particle p = (Particle) particles.get(i);
    p.run();
    if (p.isDead()) {
      particles.remove(i);
    }
  }
 
}

class Particle {
  
  PShape s;
  PVector location;
  PVector velocity;
  PVector acceleration;
  float lifespan;
  float rot;
  int dim = 150;
  int dir = 1;
  
  Particle(PVector l) {

     velocity = new PVector(random(-1,1),random(-1,1),random(-1,1));
    location = l.copy();
// 0.0? it's OK, see below ...
    lifespan = 0.0;
    rot = random(-0.01,0.01);
  
    s = createShape();
    s.beginShape();
   s.fill(255);
   s.noStroke();
   
   
   float c =random(4,7);
   for (int i = 0; i < c; i++) {
     s.curveVertex(random(-dim,dim),random(-dim,+dim),random(-dim,0));
   }
   
   s.endShape(CLOSE);
   
  }
 
  void update() {
    
    location.add(velocity);
    if (dir == 1) {lifespan += 0.8;}
    if (lifespan > 250) {dir = -1;}
   
  }
 
  void display() {
    
    
    s.setFill(color(255,lifespan));
    //s.setStroke(color(255,lifespan));
    
    pushMatrix();
    
    // ******** BUG ?? ******** 
    s.rotateZ(rot);
    translate(location.x,location.y,location.z);
    shape(s);
    
    popMatrix();
    
  }

void run() {
    update();
    display();
  }
  
 boolean isDead() {
    if (lifespan < 0.0) {
      return true;
    } else {
      return false;
    }
  }
}
1 Like

Hey @Tim_Mortimer!
I tried to run the sketch and I didn’t see any error!
I run it on Processing 3.4, Windows 10

Hello,

Welcome to the Processing forum.

There is a rotateZ() bug in versions 3.5.*

It is fixed in the 4.0 alpha 1 Pre-Release.

Workaround:

    // ******** BUG ?? ******** 
    //s.rotateZ(rot);            // Bug
    s.rotate(rot, 0, 0, 1);      // Rotates about z-axis
    translate(location.x,location.y,location.z);
    shape(s);

References:
Cannot run rotateZ() within the PShape class #5770

https://discourse.processing.org/t/rotate-function-with-4-arguments/5652

http://processing.github.io/processing-javadocs/core/ has some references:
image
image

:slight_smile:

3 Likes

great thanks (to you both).

i did search this forum for rotateZ() but didn’t see anything. (the online forum ‘UI’ almost feels a bit overcooked in terms of display of links & references for me … it breaks the continuity a bit, but i’m sure i’ll get used to it …)

(I’m on OSX 10.11 & Processing 3.5.4 incidentally … )

I agree in part and cleaned my post up a bit… :slight_smile:

I like references so I can explore the sources of information; I did a lot of exploration into this and shared what I found.

I did make the links “just links” and not a window into the site; this shows up automatically with some links. It also takes more effort to do this.

I am getting into the habit of posting references at the bottom.

References:
The source code for Processing is full of references to rotate for the ambitious to explore.

1 Like

thanks GLV.

i certainly wasn’t remarking on your reply, which was very much appreciated, orderly & to the point.

Just simply that in attempting to find the details through a quick independent search i wasn’t able to find the same info.

But hey, i’m new here … :grinning:

1 Like

Your feedback was an encouragement to clean up my own posts and taken positively; it also reflected what I see at times here in the forums.

I appreciated the “orderly & to the point”.

:slight_smile:

Hi,
I am also new to the forum and have little knowledge of Processing with a similar problem.
I have a program I took from Instructables that loads a .txt that contains the XYZ coordinates representing the length, the bend angle and the rotation angle which shows interactive 3D visualization and sends as commands to the Arduino to move a 3D wire bender .
In 2D, everything is going well, but the 3D visualizations have cluttered dots and the machine follows.
Can anyone take a look at this?
I will send a link with the videos and the sketch.

https://drive.google.com/drive/folders/1-VvIdpDYNPRsH2V-9pQqGBzdetRUhO7M
Thanks.