Not possible to see back edges of boxes with transparent sides in OpenGL ?
in
Core Library Questions
•
2 years ago
The following code creates rotating boxes with evolving transparency.
When a box is transparent one can see the edges of boxes which are behind however he cannot see those edges of the box itself which are behind.
Is it possible to change that ?
When a box is transparent one can see the edges of boxes which are behind however he cannot see those edges of the box itself which are behind.
Is it possible to change that ?
- /*
- ROTATING TRANSLUCENT CUBES 2
- EACH CUBE PULSES AT A DIFFERENT RATE
- */
- import processing.opengl.*;
- // VARIABLES
- int numCubes = 100;
- int maxDistance = 300;
- PVector[] places = new PVector[numCubes]; // stores positions of cubes
- PVector[] angles = new PVector[numCubes]; // stores orientations of cubes
- float[] pulsFreq = new float[numCubes]; // stores pulsation frequency for alpha
- int rate = 120; // set frameRate here
- int transparency = 0; // cube alpha
- float xRotateFrequency = 0.503 ; //frequency for rotation around x axis
- float yRotateFrequency = 0.307 ; //frequency for rotation around y axis
- float zRotateFrequency = 0.409 ; //frequency for rotation around z axis
- void setup() {
- size (500, 500, OPENGL);
- frameRate(rate);
- //lights();
- stroke(255, 255, 255, 128);
- strokeWeight(2);
- for (int i = 0; i < numCubes; i++) {
- places[i] = new PVector (random(0, maxDistance), random(0, maxDistance), random(-100, maxDistance)) ;
- angles[i] = new PVector (random(0, TWO_PI), random(0, TWO_PI), random(0, TWO_PI)) ;
- pulsFreq[i] = pow(10., random(-0.25, 0.25)) ;
- }
- }
- void draw() {
- background (0, 0, 0, 0);
- smooth();
- translate(width/2, height/2, 0);
- rotateX(xRotateFrequency * float(frameCount) / float(rate));
- rotateY(yRotateFrequency * float(frameCount) / float(rate));
- rotateZ(zRotateFrequency * float(frameCount) / float(rate));
- for (int i = 0; i < numCubes; i++) {
- pushMatrix() ;
- smooth();
- rotateX(angles[i].x);
- rotateY(angles[i].y);
- rotateZ(angles[i].z);
- translate(places[i].x, places[i].y, places[i].z);
- transparency = 50 + int(206. * (0.5 + (0.5 * (sin((((pulsFreq[i] * float(frameCount) / float(rate)) * TWO_PI) % TWO_PI))))));
- fill(255, 96, 128, transparency) ;
- box(30);
- popMatrix() ;
- }
- }
1