Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import processing.opengl.*;
- import javax.media.opengl.*;
- import peasy.*;
- PGraphicsOpenGL pgl;
- GL gl;
- PeasyCam cam;
- float interPupilaryDistance = 6000;
- Blobb[] blobbs = new Blobb[10];
- void setup()
- {
- size(800, 600, OPENGL);
- cam = new PeasyCam(this, 1000);
- cam.setRotations(.8, 0, 0);
- cam.setMinimumDistance(50);
- cam.setMaximumDistance(4000);
- for(int i = 0; i < blobbs.length; i++)
- {
- blobbs[i] = new Blobb(3000, new PVector(random(-2000, 2000), random(-2000, 2000), random(-2000, 2000)));
- }
- }
- void draw()
- {
- glStuff();
- background(0);
- noFill();
- for(int i = 0; i < blobbs.length; i++)
- {
- blobbs[i].move();
- blobbs[i].drawDof();
- }
- }
- void glStuff()
- {
- pgl = (PGraphicsOpenGL) g;
- gl = pgl.beginGL();
- gl.glDisable(GL.GL_DEPTH_TEST);
- gl.glEnable(GL.GL_BLEND);
- gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);
- gl.setSwapInterval(1);
- pgl.endGL();
- }
- class Blobb
- {
- int detail;
- float dia;
- float radius;
- PVector rotationSpeed = new PVector(random(-radians(1), radians(1)), random(-radians(1), radians(1)), random(-radians(1), radians(1)));
- PVector angles = new PVector(0,0,0);
- PVector pos;
- PVector dofi = new PVector();
- Blobb(float radius, PVector pos)
- {
- this.detail = (int)random(2, 10);
- this.dia = random(100, 800);
- this.radius = radius;
- this.pos = pos;
- }
- void move()
- {
- pos.x+=(random(-4, 4));
- pos.y+=(random(-4, 4));
- pos.z+=(random(-4, 4));
- angles.x+=rotationSpeed.x;
- angles.y+=rotationSpeed.y;
- angles.z+=rotationSpeed.z;
- pos.x = constrain(pos.x, -radius+dia, radius-dia);
- pos.y = constrain(pos.y, -radius+dia, radius-dia);
- pos.z = constrain(pos.z, -radius+dia, radius-dia);
- }
- void calcDof()
- {
- float focalDistance = 2000;
- float[] tCamPos = cam.getPosition();
- // float[] tCamPos = ocdCam.position();
- PVector camPos = new PVector(tCamPos[0], tCamPos[1], tCamPos[2]);
- // float dia = constrain(map(abs(PVector.dist(pos, camPos)-focalDistance), 0, 1000, 1, 10), 1, 10);
- float dia = map(abs(PVector.dist(pos, camPos)-focalDistance), 0, 3000, 1, 20);
- float alpha = map(dia, 1, 20.1, 255, 3);
- // alpha = sqrt(alpha);
- dofi.set(dia, alpha, 0);
- }
- void drawDof()
- {
- float[] cRots = cam.getRotations();
- float camTangent = interPupilaryDistance/(float)cam.getDistance();
- float cAngle = atan(camTangent);
- calcDof();
- noFill();
- strokeWeight(dofi.x);
- stroke(180, 0, 0, dofi.y/2);
- fill(180, 0, 0, dofi.y/6);
- pushMatrix();
- translate(pos.x, pos.y, pos.z);
- rotateX(angles.x);
- rotateY(angles.y);
- rotateZ(angles.z);
- sphereDetail(detail);
- sphere(dia);
- popMatrix();
- cam.setRotations(cRots[0]+radians(cAngle), 0, radians(90));
- stroke(0, 160, 255, dofi.y/2);
- fill(0, 160, 255, dofi.y/6);
- pushMatrix();
- translate(pos.x, pos.y, pos.z);
- rotateX(angles.x);
- rotateY(angles.y);
- rotateZ(angles.z);
- sphereDetail(detail);
- sphere(dia);
- popMatrix();
- cam.setRotations(cRots[0], 0, radians(90));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment