Loading...
Logo
Processing Forum
davemonster's Profile
4 Posts
13 Responses
0 Followers

Activity Trend

Last 30 days

Loading Chart...

Show:
Private Message
    Does anyone know of a simple example where OPENGL creates real-time shadows?

    I know this is possible, but I have no idea how to implement it. 

    Here is a good starting point:

    1. import processing.opengl.*;

    2. void setup() {
    3. size(400, 400, OPENGL);
    4. camera(300, 300, 150, 100, 100, 50, 1, 1, 0);
    5. smooth();
    6. noStroke();
    7. }

    8. void draw() {
    9. rotateZ(frameCount/30.5);
    10. background(0);
    11. directionalLight(255, 255, 255, 0, -200, -100);
    12. fill(255);
    13. rect(-150, -150, 300, 300);
    14. sphere(50);
    15. //imitation shadow
    16. fill(10,100); translate(0,0,1); ellipse(0,-25,100,120); translate(0,0,-1);
    17. }
    Hello,

    I am using the GLModel library to make a model with several thousand lines ( example here). I am trying to make some lines appear thicker than others within the same model. 

    I saw the setLineWidth() function and like how it expands the line cylindrically. Unfortunately, it increases the size of all lines in the model. I saw the  linearComb() function from the PDBView example, but I could not figure out how to use it. Is there a way to increase the width of only certain lines within the model?

    Thank you so much for your help!!

    Dave
    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:

    1. //the hairy cube, dderiso@ucsd.edu, 2011

    2. import peasy.*;
    3. PeasyCam cam; //should i be using this?

    4. int screen_size = 800;
    5. int lines_max = 50000; //number of lines
    6. int[] lines_x1 = new int[lines_max];
    7. int[] lines_y1 = new int[lines_max];
    8. int[] lines_z1 = new int[lines_max];
    9. int[] lines_x2 = new int[lines_max];
    10. int[] lines_y2 = new int[lines_max];
    11. int[] lines_z2 = new int[lines_max];

    12. void setup() 
    13. {
    14.       size(screen_size, screen_size, P3D);
    15.       colorMode(HSB, 100);
    16.       cam = new PeasyCam(this, 2000);
    17.       strokeWeight(3);
    18.       //assign random xyz values for each vertex pair
    19.       for(int i=0; i<lines_max; i++)
    20.       {
    21.             lines_x1[i] = (int)random(-screen_size, screen_size);
    22.              lines_y1[i] = (int)random(-screen_size, screen_size);
    23.              lines_z1[i] = (int)random(-screen_size, screen_size);
    24.             lines_x2[i] = (int)random(-screen_size, screen_size);
    25.              lines_y2[i] = (int)random(-screen_size, screen_size);
    26.              lines_z2[i] = (int)random(-screen_size, screen_size);
    27.       }
    28. }

    29. void draw()
    30. {
    31.       background(0);
    32.        lights();
    33.        //having to re-draw every line is inefficient
    34.        for(int i=0; i<lines_max; i++)
    35.        {
    36.             stroke(i % 100, 100, 100, 5); //change color
    37.              line(lines_x1[i],lines_y1[i],lines_z1[i],lines_x2[i],lines_y2[i],lines_z2[i]);
    38.       }
    39. }