We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hello all, i am new to processing and Fisica library. i wrote a little program for simulating bodies falling on a static one. ( very simple one), the shapes are geometric SVG that i import ( using lines from an existing example). everything is working fine, at the end of the simulation i am trying to export the result to vector file ( PDF would be perfect). exporting PDF is not working and i can figure out how to do it , is there any possible solution?) i thought about solving the problem by myself, so the solution i thought about is getting the position , rotation , and scale of every existing body in the simulation and redrawing everything as polygons which will get me the same result but with the possibility of exporting to PDF this time. when i use the Fpoly.getX() in the draw loop i get a nullPointerException. so my question is : - is there a way to export to PDF in Fisica? - if not, can you help me with the coordinate thing at the end of my simulation, getX(), getY(),...
to make it simple i wrote the sketch with just one shape.
import processing.pdf.*;
import fisica.*;
import geomerative.*;
FWorld world;
FPoly poly;
String filename = "zel1.svg";
RShape m_shape;
RShape fullSvg;
RShape outline;
RPoint[] points;
float xx,yy;
void setup(){
size(400,400);
smooth();
frameRate(60);
Fisica.init(this);
Fisica.setScale(10);
RG.init(this);
RG.setPolygonizer(RG.ADAPTATIVE);
FPoly poly = new FPoly();
world = new FWorld();
world.setEdges(this,color(0));
world.setGravity(0,300);
RShape fullSvg = RG.loadShape(filename);
RShape outline = fullSvg.getChild("outline");
RPoint[] points = outline.getPoints();
for (int i=0; i<points.length; i++) { poly.vertex(points[i].x, points[i].y);}
poly.setFill(120, 30, 90);
poly.setPosition(width/2,50);
poly.setDensity(10);
poly.setRestitution(0.5);
world.add(poly);
xx=poly.getX(); // it is working here
println(xx);
}
void draw() {
background(255);
world.step();
world.draw(this);
yy=poly.getY(); // getting an NPE erro here
xx= poly.getX();// getting an NPE erro here
}
Answers
line 27 redefines the poly in line 8 which means the poly in line 8 isn't initialised. this is why you have problems on line 61/62
remove the first FPoly on line 27 and that should fix that.
(but you've done the same on lines 31 and 32 with other variables)
(and line 35)
thank you Koogs, it was helpful!
i managed to export to PDF using this little trick
first in my sketch i declared a table
give the bodies a name before adding to the world
the parameters of the table
in the draw() function at after world.setup()
a routine to write to the table
a routine to redraw the result to screen from my SVGs and exporting to PDF
et voilà working like a charm hope this will be helpful