x128

Ping Pong #mksh2016

Aug 18th, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.33 KB | None | 0 0
  1. import damkjer.ocd.*;
  2.  
  3. Camera camera;
  4.  
  5.  
  6. float rotation = 0;
  7.  
  8. float phi,theta;
  9. float phiStart = 0.5, thetaStart = 2;
  10. float xstart,ystart;
  11.  
  12. final float height_setka = 40;
  13. final float height_table = 5;
  14. final float long_table = 500;
  15. final float width_table = 300;
  16. float XposCircle = - 200;
  17. float YposCircle = -50;//-7.5;
  18. float ZposCircle = 0;
  19. float radius = 5;
  20.  
  21. float xspeed = 3, yspeed = 0, zspeed = 0;
  22.  
  23. float gravity = 0.02;
  24.  
  25. final float thin_setka = 2;
  26.  
  27. float orbitRadius = 0;
  28. float ypos = 130;
  29. float xpos= cos(rotation)*orbitRadius;
  30. float zpos= sin(rotation)*orbitRadius;  
  31.  
  32. float scale = 1;
  33.  
  34. int mashtab;
  35.  
  36. float yFloor;
  37.  
  38. float x_set = 0, y_set = 0, z_set = 0;
  39.  
  40. void setup() {
  41.   size(1000, 700, P3D);
  42.  
  43.     camera = new Camera(this, -80,0,-55);
  44.    
  45.     camera.feed();
  46.    
  47.     updateView();
  48. }
  49.  
  50. void draw() {
  51.   lights();
  52.  
  53.   camera.feed();
  54.  
  55.   background(130);
  56.   stroke(255);
  57.   fill(53, 88, 53);
  58.  
  59.   yFloor = height_table/2 + 100;
  60.  
  61.   //camera(xpos, ypos, zpos, width/2.0, height/2.0, 0, 0, 1, 0);
  62.  
  63.   //0 0 0
  64.   translate(width/2.0, height/2.0, 0);
  65.   box(long_table, height_table, width_table);
  66.  
  67.  
  68.   drawSetka();
  69.   drawLegs();
  70.   drawFloor();
  71.   drawWalls();
  72.  
  73.   fill(255);
  74.   noStroke();
  75.   //pushMatrix();
  76.   translate(XposCircle, YposCircle, ZposCircle);
  77.   sphere(radius);
  78.  
  79.   XposCircle += xspeed;
  80.   YposCircle += yspeed;
  81.   ZposCircle += zspeed;
  82.  
  83.   xspeed *= 0.998;
  84.   yspeed *= 0.998;
  85.   zspeed *= 0.998;
  86.  
  87.   yspeed += gravity;
  88.  
  89.   if (XposCircle + radius > thin_setka/2 && YposCircle+radius>- height_table/2 - height_setka) {
  90.     XposCircle = thin_setka/2 - radius;
  91.     xspeed = xspeed * -0.5;
  92.   }
  93.  
  94.  //<>// //<>//
  95.  //println(YposCircle + radius, height_table/2);
  96.  //<>//
  97.   if (YposCircle + radius > -height_table/2 && XposCircle-radius<0 + long_table/2 && XposCircle + radius > 0 - long_table/2 && ZposCircle + radius > - width_table/2 &&  ZposCircle - radius < width_table/2) { //<>//
  98.     yspeed = -yspeed * 0.9;
  99.     YposCircle = -height_table/2 - radius;
  100.   }
  101.  
  102.  
  103.   //popMatrix();
  104. }
  105.  
  106. void drawSetka() {
  107.   pushMatrix();
  108.   translate(0, - height_table/2 - height_setka/2, 0);
  109.   fill(0, 0, 0, 100);
  110.   box(thin_setka, height_setka, width_table);
  111.   popMatrix();
  112. }
  113.  
  114. void drawLegs() {
  115.   fill(0);
  116.   stroke(72);
  117.  
  118.   pushMatrix();
  119.  
  120.   translate(long_table/2 - 2, height_table/2 + 50, -width_table/2 + 2);
  121.   box(4, 100, 4);
  122.  
  123.   popMatrix();
  124.  
  125.   pushMatrix();
  126.  
  127.   translate(-long_table/2 + 2, height_table/2 + 50, -width_table/2 + 2);
  128.   box(4, 100, 4);
  129.  
  130.   popMatrix();
  131.  
  132.   pushMatrix();
  133.  
  134.   translate(long_table/2 - 2, height_table/2 + 50, width_table/2 - 2);
  135.   box(4, 100, 4);
  136.  
  137.   popMatrix();
  138.  
  139.   pushMatrix();
  140.  
  141.   translate(-long_table/2 + 2, height_table/2 + 50, width_table/2 - 2);
  142.   box(4, 100, 4);
  143.  
  144.   popMatrix();
  145. }
  146.  
  147. void drawFloor() {
  148.   pushMatrix();
  149.   fill(251,17,17);
  150.   stroke(150,0,0);
  151.   translate(-1000,100 + height_table/2,-1000);
  152.   box(4000,1,4000);
  153.   popMatrix();
  154. }
  155.  
  156. void drawWalls() {
  157.   pushMatrix();
  158.   fill(250,190,0);
  159.   stroke(250,190,0);
  160.   translate( - 1000,yFloor - 1000,-1000);
  161.   box(1,4000,4000);
  162.   popMatrix();
  163.  
  164.   pushMatrix();
  165.   fill(250,190,0);
  166.   stroke(250,190,0);
  167.   translate( - 1000,yFloor - 1000,1000);
  168.   box(4000,4000,1);
  169.   popMatrix();
  170.  
  171.   pushMatrix();
  172.   fill(250,190,0);
  173.   stroke(250,190,0);
  174.   translate(0,yFloor - 1000,-1000);
  175.   box(4000,4000,1);
  176.   popMatrix();  
  177.  
  178.   pushMatrix();
  179.   fill(250,190,0);
  180.   stroke(250,190,0);
  181.   translate(1000,yFloor - 1000,0);
  182.   box(1,4000,4000);
  183.   popMatrix();  
  184. }
  185.  
  186. void mouseDragged() {
  187.   updateView();
  188.   camera.feed();
  189.   cursor(HAND);
  190. }
  191.  
  192.  
  193. void mouseReleased() {
  194.   cursor(ARROW);  
  195. }
  196.  
  197. void mousePressed() {
  198.   xstart = mouseX;
  199.   ystart = mouseY;
  200.   phiStart = phi;
  201.   thetaStart = theta;
  202.   camera.feed();
  203. }
  204.  
  205. void mouseWheel(MouseEvent event) {
  206.   scale = event.getCount();
  207.   mashtab += scale;
  208.   //updateView();
  209. }
  210.  
  211. void updateView() {
  212.   phi = phiStart + map(mouseX - xstart,0,width,-PI/2,PI/2);
  213.   theta = thetaStart + map(mouseY - ystart,0,height,0,PI);
  214.   if (theta < 0.1)
  215.     theta = 0.1;
  216.   else if (theta > PI)
  217.     theta = PI;
  218.  
  219.   println(phi, theta);
  220.  
  221.   float r = 100;
  222.  
  223.   float x = r * sin(theta) * cos(phi);
  224.   float y = r * sin(theta) * sin(phi);
  225.   float z = r * cos(theta);
  226.  
  227.   println(x, "   ",y ,"   ",z);
  228.  
  229.   camera.jump(x, z, y);
  230.   camera.feed();
  231. }
Add Comment
Please, Sign In to add comment