We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, i try to animate particles along a path with the ani library from Benedict Gross. I made my own particle class, where every particle should know it´s path and create some Ani.sequence for displaying. But it doesn´t work, nothing moves. I know there is an example for playing animations from classes that comes with ani, but i really don´t get the point, where i´m wrong. the sketch uses also the HE_Mesh library, because i will need it for my overall goal of visualising some acoustic rays. Thanks for any help
//===============================================================
import wblut.math.*;
import wblut.processing.*;
import wblut.core.*;
import wblut.hemesh.*;
import wblut.geom.*;
import de.looksgood.ani.*;
import de.looksgood.ani.easing.*;
//===============================================================
WB_Render3D render;
WB_GeometryFactory factory;
ArrayList<WB_Point> vertices;
WB_PolyLine poly;
Path path;
AniSequence sequence;
Particle p;
//===============================================================
void setup(){
size(1024,748,P3D);
Ani.init(this);
render = new WB_Render3D(this);
factory = WB_GeometryFactory.instance();
//create some arbitrary polyline
vertices = new ArrayList<WB_Point>();
vertices.add(new WB_Point(100,20,0));
vertices.add(new WB_Point(width-300,height/2,0));
vertices.add(new WB_Point(width-100,height-20,0));
poly = factory.createPolyLine(vertices);
//create path and Particle
path = new Path(poly);
p = new Particle(this,poly.getPoint(0),poly,10.0);
}
//===============================================================
//===============================================================
void draw(){
background(255);
pushStyle();
noFill();
stroke(0);
strokeWeight(0.5);
render.drawPolyLine(poly);
popStyle();
p.display();
}
//===============================================================
//===============================================================
class Particle extends WB_Point4D{
//------------------------------------------------------------------
float size;
Path path;
WB_Vector posTemp;
float x,y,z;
ArrayList<WB_Coordinate> sequencePts;
//------------------------------------------------------------------
public Particle(PApplet applet,WB_Coordinate pos,WB_PolyLine poly,float size){
super(pos,0.0);
this.size = size;
this.path = new Path(poly);
posTemp = null;
//create Ani.sequence from every point in tne path
sequencePts = path.getSequencePoints();
x = sequencePts.get(0).xf();
y = sequencePts.get(0).yf();
z = sequencePts.get(0).zf();
WB_Coordinate pt = null;
sequence = new AniSequence(applet);
sequence.beginSequence();
for(int i=1;i<sequencePts.size();i++){
pt = sequencePts.get(i);
sequence.add(Ani.to(applet,10,"x",pt.xf(),Ani.LINEAR));
sequence.add(Ani.to(applet,10,"y",pt.yf(),Ani.LINEAR));
sequence.add(Ani.to(applet,10,"z",pt.zf(),Ani.LINEAR));
}
sequence.endSequence();
sequence.start();
}
//------------------------------------------------------------------
public void display(){
pushStyle();
noFill();
stroke(255,0,0);
strokeWeight(this.size);
beginShape(POINTS);
vertex(x,y,z);
endShape();
popStyle();
}
//------------------------------------------------------------------
}
//===============================================================
//===============================================================
class Path{
WB_PolyLine polyline;
//------------------------------------------------------------------
public Path(WB_PolyLine polyline){
this.polyline = polyline;
}
//------------------------------------------------------------------
//get all points of the path
public ArrayList<WB_Coordinate> getSequencePoints(){
ArrayList<WB_Coordinate> output = new ArrayList<WB_Coordinate>();
for(int i=0;i<polyline.getNumberOfPoints();i++){
output.add(polyline.getPoint(i));
}
return output;
}
}
//===============================================================
Answers
Just had a brief experience w/ Ani library. And never used AniSequence before.
Mixing up w/ HE_Mesh library won't make things easier to answer either!
This is my only Ani example I have though:
http://forum.Processing.org/two/discussion/4416/moving-circles-at-different-speed-when-scroll-using-ani
yes sorry i know HE_Mesh doesn´t make it more easy, but i really need it. I´m shooting rays at an architectural mesh model to get the reflections, which are the pathes i use for the animation. Maybe i can break it down some more and repost it. thanks anyway
i deleted some class methods that weren´t needed. i hope it is more readable now.