Here's the code, in all it's messy glory.
Basically, the emitter checks to see if it's created less lines than it's maximum value, and if it hasn't uses it's position/rotation information to pass onto the new line which is added to the emitter's lines array.
I've tried using the "this" keyword, but this doesn't seem to have any effect.
Code:
*****************spunLine****************************
class spunLine{
float force;
float sX,sY,sZ,eX,eY,eZ;
point3D pos,dim,rot;
color[] cols = new color[0];
warp[] warps = new warp[0];
//constants
final static byte DEBUG = 0;
final static byte BASIC = 1;
final static byte FULL = 2;
spunLine(point3D inPos, point3D inRot, point3D inDim, float inF){
pos=inPos;
rot=inRot;
dim=inDim;
force= inF;
}
void display(byte style){
//work out new position
calcPos();
//work out start and end points
calcPoints();
switch(style){
case 0:
//it's DEBUG Mode
println("sX:"+sX + ", sY:" + sY + ", sZ:"+sZ);
println("eX:"+eX + ", eY:" + eY + ", eZ:"+eZ);
line(sX,sY,sZ,eX,eY,eZ);
break;
case 1:
//it's BASIC mode
line(sX,sY,sZ,eX,eY,eZ);
break;
case 2:
//it's full mode
line(sX,sY,sZ,eX,eY,eZ);
break;
}
}
void calcPos(){
this.pos.x=this.pos.x+(sin(this.rot.x)*force);
this.pos.y=this.pos.y+(cos(this.rot.y)*force);
this.pos.z=this.pos.z+(sin(this.rot.z)*force);
}
void calcPoints(){
sX=this.pos.x+(sin(rot.x)*(dim.x/2));
sY=this.pos.y+(cos(rot.y)*(dim.x/2));
sZ=pos.z+(cos(rot.z)*(dim.x/2));
eX=pos.x-(sin(rot.x)*(dim.x/2));
eY=pos.y-(cos(rot.y)*(dim.x/2));
eZ=pos.z-(cos(rot.z)*(dim.x/2));
}
}
*****************Point3D***********************
class point3D{
float x,y,z;
point3D(float iX, float iY, float iZ){
x=iX;
y=iY;
z=iZ;
}
}
*******************Emitter Class***********************
class lineEmit {
float power,rate,randomness;
point3D pos,rot,dim;
int maxLines, lastUsedFrame;
// these params are used to automatically pass data to new lines created
color[] cols = new color[0];
spunLine[] lines = new spunLine[0];
warp[] warps = new warp[0];
lineEmit(point3D inPos, point3D inRot, point3D inDim, float iPow,int inMax){
pos=inPos;
rot=inRot;
dim=inDim;
power=iPow;
//rate in millis
rate=120;
//how much variation is allowed in creating new lines
randomness = 10;
maxLines = inMax;
}
void update(){
//this function checks whether it's ok to produce another line compared to the max allowed and
//whether it's been enough time since the last go
if ((frameNo-lastUsedFrame) > ((rate-(randomness/2) + random(randomness)))){
//it's ok to go
lastUsedFrame=frameNo;
if (lines.length < maxLines){
*************Here's where it creates a new line***********
//we can produce a new line using point3D information attached to the emitter
spunLine myNewLine = new spunLine(pos,rot,dim,power);
lines = (spunLine[]) append(lines,myNewLine);
myNewLine=null;
}
}
for(int i=0; i < lines.length; i++){
lines[i].display(spunLine.BASIC);
}
if (lines.length>0){
println("0:" + lines[0].pos.y);
if (lines.length>1){
println("1: " + lines[1].pos.y);
}
}
}
void addColor(color inCol){
//adds a colour to the cycle
cols = append(cols,inCol);
}
void setDir(float idX,float idY,float idZ){
rot=new point3D(idX,idY,idZ);
}
point3D getDir(){
return rot;
}
}
*****************HOW the emitter is set up **************
point3D inPos = new point3D(0,0,0);
point3D inRot = new point3D(0,0,0);
point3D inDim = new point3D(50,5,5);
myEmit = new lineEmit(inPos, inRot, inDim, 0.1,3);
*************Called each draw cycle ****************
myEmit.update();
thanks for the feedback
Martin
EDIT:Just cleaned a couple of things up