Hey guys! I am recently working on a 3D data visualization project. But I got some problems in the current developing status and would like to ask for your suggestions.
I have programmed a Processing sketch as the prototype (drawing 100+ spheres and manipulating them by parsing a JSON data, with OpenGL and peasycam libraries imported). It works well on my desktop. But it shows significant delay when I run it on the project platform, which is a 5760 px X 3240 px screen. Will the delay issue be gone if I switch to Openframeworks?
I learned ofSketch last fall and found it’s pretty useful. But does ofEasyCam work well in it?
ofEasyCam cam;
// Create collections of spheres, their velocities and colors.
// You could also create a sphere class that holds all of this stuff (see the ofSketch HelloWorld example).
std::vector<ofSpherePrimitive> spheres;
std::vector<ofVec3f> velocities;
std::vector<ofColor> colors;
void setup() {
ofSetWindowShape(1024, 1024);
// Initialize the spheres, velocities and colors.
for (std::size_t i = 0; i < 500; ++i)
{
ofSpherePrimitive sphere;
sphere.setPosition(ofVec3f(ofRandom(-500,500),
ofRandom(-500,500),
ofRandom(-500,500)));
sphere.setRadius(ofRandom(5, 10));
spheres.push_back(sphere);
velocities.push_back(ofVec3f(ofRandom(-10,10),
ofRandom(-10,10),
ofRandom(-10,10)));
colors.push_back(ofColor(ofRandom(255),
ofRandom(255),
ofRandom(255)));
}
}
void update() {
// Update everything.
for (std::size_t i = 0; i < spheres.size(); ++i)
{
// Add the velocity to the position of each sphere.
ofVec3f newPosition = spheres[i].getPosition() + velocities[i];
// Make the sphere bounce off the edge of the bounding cube by switching its velocity.
if (newPosition.x > 500 || newPosition.x < -500) velocities[i].x *= -1.0;
if (newPosition.y > 500 || newPosition.y < -500) velocities[i].y *= -1.0;
if (newPosition.z > 500 || newPosition.z < -500) velocities[i].z *= -1.0;
// Update its position with the new value.
spheres[i].setPosition(newPosition);
}
}
void draw() {
ofBackground(0);
// Start the camera!
cam.begin();
// Draw each sphere with its color.
for (std::size_t i = 0; i < spheres.size(); ++i)
{
ofSetColor(colors[i]);
spheres[i].draw();
}
// End the camera!
cam.end();
}
You can zoom in and out, rotate, etc by holding ctrl, drag, etc.