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;
}
}
}