Efficient Rendering of Multiple Lines
in
Programming Questions
•
2 years ago
Hello,
I am drawing over 30,000 lines and want to make the rendering process more efficient. When I rotate the stage in 3D, I currently have to re-draw every singe line, which causes heavy lags.
I know theres got to be a more efficient way to do this, and I was hoping you might have some advice.
Thanks you so much for your time and input!
Below is a simple sketch that illustrates the re-draw inefficiency:
- //the hairy cube, dderiso@ucsd.edu, 2011
- import peasy.*;
- PeasyCam cam; //should i be using this?
- int screen_size = 800;
- int lines_max = 50000; //number of lines
- int[] lines_x1 = new int[lines_max];
- int[] lines_y1 = new int[lines_max];
- int[] lines_z1 = new int[lines_max];
- int[] lines_x2 = new int[lines_max];
- int[] lines_y2 = new int[lines_max];
- int[] lines_z2 = new int[lines_max];
- void setup()
- {
- size(screen_size, screen_size, P3D);
- colorMode(HSB, 100);
- cam = new PeasyCam(this, 2000);
- strokeWeight(3);
- //assign random xyz values for each vertex pair
- for(int i=0; i<lines_max; i++)
- {
- lines_x1[i] = (int)random(-screen_size, screen_size);
- lines_y1[i] = (int)random(-screen_size, screen_size);
- lines_z1[i] = (int)random(-screen_size, screen_size);
- lines_x2[i] = (int)random(-screen_size, screen_size);
- lines_y2[i] = (int)random(-screen_size, screen_size);
- lines_z2[i] = (int)random(-screen_size, screen_size);
- }
- }
- void draw()
- {
- background(0);
- lights();
- //having to re-draw every line is inefficient
- for(int i=0; i<lines_max; i++)
- {
- stroke(i % 100, 100, 100, 5); //change color
- line(lines_x1[i],lines_y1[i],lines_z1[i],lines_x2[i],lines_y2[i],lines_z2[i]);
- }
- }
1