Guest User

Jakob Penca

a guest
Mar 21st, 2010
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.00 KB | None | 0 0
  1. import processing.opengl.*;
  2. import javax.media.opengl.*;
  3. import peasy.*;
  4.  
  5. PGraphicsOpenGL pgl;
  6. GL gl;
  7. PeasyCam cam;
  8.  
  9. float interPupilaryDistance = 6000;
  10.  
  11. Blobb[] blobbs = new Blobb[10];
  12.  
  13. void setup()
  14. {
  15.     size(800, 600, OPENGL);
  16.     cam = new PeasyCam(this, 1000);
  17.     cam.setRotations(.8, 0, 0);
  18.     cam.setMinimumDistance(50);
  19.     cam.setMaximumDistance(4000);
  20.    
  21.     for(int i = 0; i < blobbs.length; i++)
  22.     {
  23.         blobbs[i] = new Blobb(3000, new PVector(random(-2000, 2000), random(-2000, 2000), random(-2000, 2000)));
  24.     }
  25.  
  26. }
  27.  
  28. void draw()
  29. {
  30.     glStuff();
  31.    
  32.     background(0);
  33.     noFill();
  34.    
  35.     for(int i = 0; i < blobbs.length; i++)
  36.     {
  37.         blobbs[i].move();
  38.         blobbs[i].drawDof();
  39.     }
  40.    
  41. }
  42.  
  43. void glStuff()
  44. {
  45.     pgl = (PGraphicsOpenGL) g;
  46.     gl = pgl.beginGL();
  47.     gl.glDisable(GL.GL_DEPTH_TEST);
  48.     gl.glEnable(GL.GL_BLEND);
  49.     gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);
  50.     gl.setSwapInterval(1);
  51.     pgl.endGL();
  52. }
  53.  
  54. class Blobb
  55. {
  56.     int detail;
  57.     float dia;
  58.     float radius;
  59.     PVector rotationSpeed = new PVector(random(-radians(1), radians(1)), random(-radians(1), radians(1)), random(-radians(1), radians(1)));
  60.     PVector angles = new PVector(0,0,0);
  61.     PVector pos;
  62.     PVector dofi = new PVector();
  63.    
  64.     Blobb(float radius, PVector pos)
  65.     {
  66.         this.detail = (int)random(2, 10);
  67.         this.dia = random(100, 800);
  68.         this.radius = radius;
  69.         this.pos = pos;
  70.     }
  71.    
  72.     void move()
  73.     {
  74.         pos.x+=(random(-4, 4));
  75.         pos.y+=(random(-4, 4));
  76.         pos.z+=(random(-4, 4));
  77.        
  78.         angles.x+=rotationSpeed.x;
  79.         angles.y+=rotationSpeed.y;
  80.         angles.z+=rotationSpeed.z;
  81.        
  82.         pos.x = constrain(pos.x, -radius+dia, radius-dia);
  83.         pos.y = constrain(pos.y, -radius+dia, radius-dia);
  84.         pos.z = constrain(pos.z, -radius+dia, radius-dia);
  85.     }
  86.    
  87.     void calcDof()
  88.     {
  89.         float focalDistance = 2000;
  90.         float[] tCamPos = cam.getPosition();
  91.         // float[] tCamPos = ocdCam.position();
  92.         PVector camPos = new PVector(tCamPos[0], tCamPos[1], tCamPos[2]);
  93.         // float dia = constrain(map(abs(PVector.dist(pos, camPos)-focalDistance), 0, 1000, 1, 10), 1, 10);
  94.         float dia = map(abs(PVector.dist(pos, camPos)-focalDistance), 0, 3000, 1, 20);
  95.         float alpha = map(dia, 1, 20.1, 255, 3);
  96.         // alpha = sqrt(alpha);
  97.         dofi.set(dia, alpha, 0);
  98.     }
  99.    
  100.     void drawDof()
  101.     {
  102.         float[] cRots = cam.getRotations();
  103.         float camTangent = interPupilaryDistance/(float)cam.getDistance();
  104.         float cAngle = atan(camTangent);
  105.        
  106.         calcDof();
  107.         noFill();
  108.         strokeWeight(dofi.x);
  109.  
  110.         stroke(180, 0, 0, dofi.y/2);
  111.         fill(180, 0, 0, dofi.y/6);
  112.        
  113.         pushMatrix();
  114.         translate(pos.x, pos.y, pos.z);
  115.         rotateX(angles.x);
  116.         rotateY(angles.y);
  117.         rotateZ(angles.z);
  118.         sphereDetail(detail);
  119.         sphere(dia);
  120.         popMatrix();
  121.        
  122.         cam.setRotations(cRots[0]+radians(cAngle), 0, radians(90));
  123.        
  124.         stroke(0, 160, 255, dofi.y/2);
  125.         fill(0, 160, 255, dofi.y/6);
  126.        
  127.         pushMatrix();
  128.         translate(pos.x, pos.y, pos.z);
  129.         rotateX(angles.x);
  130.         rotateY(angles.y);
  131.         rotateZ(angles.z);
  132.         sphereDetail(detail);
  133.         sphere(dia);
  134.         popMatrix();
  135.        
  136.         cam.setRotations(cRots[0], 0, radians(90));
  137.     }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment