joemckay

obsessive camera question

Sep 23rd, 2014
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. import damkjer.ocd.*;
  2. Camera camera1;
  3. boolean moveleft, moveright, moveforward, movebackward, turnleft, turnright, lookup, lookdown;
  4. float thrust, sidethrust, turn, lookY;
  5.  
  6. void setup() {
  7. size(640, 360, P3D);
  8. camera1 = new Camera(this, 100, 0, 300);
  9. }
  10.  
  11.  
  12. void draw() {
  13. // set the lights
  14. lights();
  15. ambientLight(200, 102, 102);
  16. background(255);
  17.  
  18. // move and orient the camera
  19. camera1.truck(sidethrust); // side step
  20. camera1.pan(radians(turn) / 2.0); // look left right
  21. camera1.tilt(radians(lookY)/ 2.0); // look up down
  22. camera1.dolly(thrust); // moves along the way we are looking, including up into the Y asix :(
  23. camera1.feed();
  24.  
  25. // draw boxes
  26. for (int i = 0; i < 20; i ++) {
  27. for (int j = 0; j < 20; j ++) {
  28. pushMatrix();
  29. translate(i * 300, -20, j * 300);
  30. box(40, 600, 40);
  31. popMatrix();
  32. }
  33. }
  34.  
  35. // look at key press booleans
  36. if (turn > TWO_PI) {
  37. turn = TWO_PI - turn;
  38. }
  39. if (turn < TWO_PI * -1) {
  40. turn = (TWO_PI * -1) - turn;
  41. }
  42. if (moveleft == true) {
  43. // moveX -= 15;
  44. sidethrust = -15;
  45. }
  46. if (moveright == true) {
  47. // moveX += 15;
  48. sidethrust = 15;
  49. }
  50. if (moveright == false && moveleft == false) {
  51. sidethrust = 0;
  52. }
  53. if (moveforward == true) {
  54. // moveZ -= 5;
  55. thrust = -15;
  56. } else if (movebackward == true) {
  57. thrust = 15;
  58. } else {
  59. thrust = 0;
  60. }
  61.  
  62.  
  63. if (turnleft == true) {
  64. turn = -5;
  65. } else if (turnright == true) {
  66. turn = 5;
  67. } else {
  68. turn = 0;
  69. }
  70.  
  71.  
  72. if (lookup == true) {
  73. lookY = -5;
  74. } else if (lookdown == true) {
  75. lookY = +5;
  76. } else {
  77. lookY = 0;
  78. }
  79. }
  80.  
  81. void keyPressed() {
  82. // println(keyCode); // 38 up , 40 down
  83. if (key == 'a') {
  84. moveleft = true;
  85. }
  86. if (key == 'd') {
  87. moveright = true;
  88. }
  89. if (key == 'w') {
  90. moveforward = true;
  91. }
  92. if (key == 's') {
  93. movebackward = true;
  94. }
  95.  
  96. if (key == 'j' || keyCode == 37) {
  97. turnleft = true ;
  98. }
  99. if (key == 'k' || keyCode == 39) {
  100. turnright = true;
  101. }
  102.  
  103. if (keyCode == 38) {
  104. lookup = true ;
  105. }
  106. if (keyCode == 40) {
  107. lookdown = true;
  108. }
  109. }
  110.  
  111. void keyReleased() {
  112. if (key == 'a') {
  113. moveleft = false;
  114. }
  115. if (key == 'd') {
  116. moveright = false;
  117. }
  118.  
  119. if (key == 'w') {
  120. moveforward = false;
  121. }
  122. if (key == 's') {
  123. movebackward = false;
  124. }
  125.  
  126. if (key == 'j' || keyCode == 37) {
  127. turnleft = false ;
  128. }
  129. if (key == 'k' || keyCode == 39) {
  130. turnright = false;
  131. }
  132. if (keyCode == 38) {
  133. lookup = false ;
  134. }
  135. if (keyCode == 40) {
  136. lookdown = false;
  137. }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment