Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. void setup() {
  2. size(1024, 512, P3D);
  3. }
  4.  
  5. void draw() {
  6. background(200);
  7.  
  8. //cam variables
  9. float fov = PI / 3;
  10. float cameraEyeZ = (height / 2) / (tan(fov / 2));
  11. float angle = (mouseY * 1.0 / height) * 2 * PI; //cam rotation angle around the origin [0, 2*PI]
  12.  
  13. resetMatrix();
  14. camera(
  15. cameraEyeZ * sin(angle), 0.0, cameraEyeZ * cos(angle), //position
  16. 0.0, 0.0, 0.0, //centre
  17. 0.0, 1.0, 0.0); //up
  18.  
  19. { //perspective
  20. //float m = 0.10;
  21. //frustum(-width/2*m, width/2*m, -height/2*m, height/2*m, cameraEyeZ * m, cameraEyeZ * 100.0);
  22. }
  23. { //ortho
  24. float m = 1.0;
  25. ortho(-width/2 * m, width/2 * m, -height/2 * m, height/2 * m, cameraEyeZ * 0.10, cameraEyeZ * 100.0);
  26. //translate(0, 0, cameraEyeZ); //TRY THIS
  27. }
  28. stroke(0);
  29. fill(255);
  30. box(30, 30, 30);
  31.  
  32. fill(255, 0, 0);
  33. pushMatrix();
  34. translate(0, 0, cameraEyeZ * 0.86); //Very close to cameraEyeZ, close to the rotation origin
  35. box(30, 30, 30);
  36. popMatrix();
  37.  
  38. fill(0, 0, 255);
  39. pushMatrix();
  40. translate(0, 0, cameraEyeZ * -0.86);
  41. box(30, 30, 30);
  42. popMatrix();
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement