Drawing 120000 spheres each frame? (Introduction into OpenGL?)
in
Core Library Questions
•
3 months ago
For the past year I've been learning about Processing and working with it (at first just simple sketches, then on to conditional design, then data visualisation and then I build my own pen plotter in combination with Arduino). I enjoyed data visualisation and wanted to do something more complex just to kill some time during the holidays.
I got my hands on the HYG database (download:
http://www.astronexus.com/node/34), which has coordinates of about 120000 stars. Using a very simple sketch I draw 1000 stars each frame, but I'd be cool if all of the stars would be drawn each frame, that way it could be shaped into an application with which people can more easily interact and explore the galaxy.
I know that Processing doesn't like drawing 20000+ 2D shapes each frame, let alone 120000 3D shapes. I guess OpenGL could handle this, but I know nothing about it. So what it all comes down to: how to do this? Or if someone can get this to work, is there any way to explain how? I'd love to learn more about visualising lots and lots of data, but I have no idea where to begin.
// xlow: -9995039.0 : xhigh: 9983610.0
// ylow: -9997925.0 : yhigh: 9996325.0
// zlow: -9986775.0 : zhigh: 9986251.0
ArrayList Stars;
Table starsInUniverse;
PVector location = new PVector();
int starID;
int starsPerFrame = 1000;
int starsDrawn = 0;
int starsLoading = starsPerFrame;
void setup() {
size(displayWidth, displayHeight, P3D);
colorMode(HSB, 360, 100, 100, 100);
background(0);
smooth();
Stars = new ArrayList();
starsInUniverse = loadTable("HYG.csv", "header");
for (TableRow row: starsInUniverse.rows()) {
starID = row.getInt("StarID");
location.x = row.getFloat("X");
location.y = row.getFloat("Y");
location.z = row.getFloat("Z");
star s = new star(starID, location);
Stars.add(s);
}
}
void draw() {
for (int i = starsDrawn; i < starsDrawn + starsLoading; i++) {
star s = (star) Stars.get(i);
s.display();
}
starsLoading = starsPerFrame;
starsDrawn += starsLoading;
if (starsDrawn + starsLoading > Stars.size()) {
starsLoading = (Stars.size() - starsDrawn);
}
}
class star {
PVector location = new PVector(0, 0, 0);
int starID;
star(int starID, PVector location) {
this.starID = starID;
this.location.x = map(location.x, -10000000.0, 10000000.0, 500, 2300);
this.location.y = map(location.y, -10000000.0, 10000000.0, 0, 1800);
this.location.z = map(location.z, -10000000.0, 10000000.0, 900, -900);
sphereDetail(5);
stroke(0, 0, 100, 50);
fill(0, 0, 100, 25);
}
void display() {
pushMatrix();
translate(location.x, location.y, location.z);
sphere(5);
popMatrix();
}
}
1