Hi,
I wrote that with the help of a toxiclibs tutorial. I want all the particles moving upwards to make cylindrical mesh. But in my sketch, particles moves horizontally. What should I change to move particles and springs vertically?
Thank you so much
import toxi.geom.*;
import toxi.math.*;
import toxi.physics2d.*;
import toxi.physics2d.behaviors.*;
import toxi.physics2d.constraints.*;
import toxi.physics3d.*;
import toxi.physics3d.constraints.*;
import toxi.processing.*;
import processing.opengl.*;
import peasy.*;
PeasyCam cam;
VerletPhysics3D physics;
VerletParticle3D particles;
Creator unit;
void setup() {
size(800, 600,P3D);
cam = new PeasyCam(this, 100);
physics = new VerletPhysics3D();
Vec3D cen = new Vec3D (0,0,0);
unit = new Creator(cen);
//for(int i = 0; i < 40; i++){
//VerletParticle3D p = new VerletParticle3D(i *10,0,0);
//if(i ==0){
// p.lock();
//}
//physics.addParticle(p);
//}
//
//
//for (int i = 1; i < physics.particles.size(); i++){
// VerletParticle3D vp1 = (VerletParticle3D) physics.particles.get(i);
// VerletParticle3D vp2 = (VerletParticle3D) physics.particles.get(i-1);
//VerletSpring3D sp = new VerletSpring3D(vp1, vp2, 10, 0.1);
//physics.addSpring(sp);
//}
}
void draw() {
background(0);
stroke(255);
strokeWeight(1);
noFill();
box(600);
unit.run();
drawParticles();
drawSprings();
physics.update();
}
void drawSprings(){
for(int i = 0; i < physics.springs.size(); i++){
VerletSpring3D sp = (VerletSpring3D) physics.springs.get(i);
stroke(255);
strokeWeight(1);
line(sp.a.x,sp.a.y, sp.a.z, sp.b.x,sp.b.y, sp.b.z);
}
}
void drawParticles(){
for(int i = 0; i < physics.particles.size(); i++){
VerletParticle3D vp = (VerletParticle3D) physics.particles.get(i);
strokeWeight(5);
if(vp.isLocked()){
stroke(255,0,0);
}
else{
stroke(0,255,200);
}
point(vp.x, vp.y, vp.z);
}
}
class Creator {
Vec3D loc = new Vec3D();
Vec3D cen;
float angle = 0;
float radius = 200;
float z = 0;
int count = 0;
float speed = 0.07;
Creator(Vec3D _cen){
cen = _cen;
}
void run(){
calcLoc();
moveUpdate();
dropParticles();
dropSprings();
display();
}
void dropSprings(){
int dif = int(TWO_PI/speed);
if(z > 0){
if(count > 1){
VerletParticle3D p0 = (VerletParticle3D) physics.particles.get(count-1);
VerletParticle3D p1 = (VerletParticle3D) physics.particles.get(count-2);
VerletParticle3D p2 = (VerletParticle3D) physics.particles.get(count-1-dif);
VerletSpring3D sp = new VerletSpring3D(p0, p1, 10, 0.1);
physics.addSpring(sp);
VerletSpring3D sp2 = new VerletSpring3D(p0, p2, 10, 0.1);
physics.addSpring(sp2);
}
}
}
void dropParticles(){
VerletParticle3D p = new VerletParticle3D(loc.x,loc.y,loc.z);
if(z == 0) {
p.lock();
}
physics.addParticle(p);
count ++;
}
void moveUpdate(){
angle += speed;
if(angle >= TWO_PI){
angle = 0;
z++;
}
}
void calcLoc(){
loc = new Vec3D(cos(angle)*radius, sin(angle)*radius, 0);
}
void display() {
strokeWeight(8);
stroke(0,0,255);
point(loc.x,loc.y,loc.z);
}
}