I'm getting to grips with jbox2d in processing and there's one this that's bugging me.
How, once i've created a new body, do I reference that specific body to remove it later on? I know you can read through the list and test for certain things but that doesn't really help. Can you not give them a specific name or something when you create it?
I hope someone can help me on this project! Its giving me a headache!
I understand that the nature of processing means that if you move the camera position, you must redraw everything.
My problem is that I am generating a line that extends and occasionally splits off and changes course and i want the camera to always slowly be zooming out so that the content always fits the window. But ofcourse, when i move the camera, it messes up what the drawing..
Here's my sketch so far, any help would be greatly appreciated!
import processing.opengl.*;
Spiral[] mySpirals;
int xpos = 0;
int ypos = 0;
int spiralcount = 0;
int direction = 0;
void setup() {
size(800,600,OPENGL);
background(255);
smooth();
xpos = width/2;
ypos = height;
mySpirals = new Spiral[10];
for(int i = 0; i < 10; i++)
{
mySpirals[i] = new Spiral();
}
}
void draw(){
noStroke();
fill(0);
ellipse(xpos, ypos, 16, 16);
ypos -= 1;
for(int i = 0; i < 10; i++)
{
if(mySpirals[i].done==true)
mySpirals[i].drawit();
}
}
void mouseClicked() {
mySpirals[spiralcount].ypostart = ypos;
mySpirals[spiralcount].done=true;
spiralcount++;
if(direction==0){direction=1;}else{direction=0;}
}
class Spiral{
float r = 60;
float theta = 0;
float lt = 16;
float cize = random(0.2, 4);
float direction = int(random(0,2));
int ypostart = 0;
boolean done = false;
void drawit() {
//println(direction);
if(lt>0){
// Polar to Cartesian conversion
float x = 0;
if(direction==1){
x = r * cos(theta)*cize;} //change to a minus + add60*cizeinstead of minus below to flip