Advertisement
Guest User

Untitled

a guest
Jul 21st, 2018
25
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.81 KB | None
  1. boolean td=false;
  2. boolean tl=false;
  3. boolean tu=false;
  4. boolean tr=false;
  5. boolean w,a,s,d;
  6. PVector loc = new PVector();
  7. float x2=1600/2;
  8. float y2=900/2;
  9. float z2=0;
  10. float camRotZ;
  11. float camRotX = 75;
  12. float frotZ,frotY;
  13. float spd=10;
  14.  
  15. void setup(){
  16.   size(1600,900,P3D);
  17.   background(0);
  18.   frameRate(30);
  19. }
  20.  
  21. void draw(){
  22.   moveCam();
  23.   move();
  24.   textSize(25);
  25.   fill(255);
  26.   stroke(255);
  27.   background(0);
  28.   pushMatrix();
  29.     translate(x2,y2,z2);
  30.     rotateX(radians(camRotX));
  31.     rotateZ(radians(camRotZ));
  32.     pushMatrix();
  33.       rotateZ(radians(frotZ));
  34.       translate(0,0,-150);
  35.       fill(100,100,100);
  36.       rectMode(RADIUS);
  37.       rect(loc.x,loc.y,1000,1000);
  38.     popMatrix();
  39.     pushMatrix();
  40.       noFill();
  41.       stroke(200);
  42.       sphere(25);
  43.       line(0,0,0,-100);
  44.     popMatrix();
  45.   popMatrix();
  46.   fill(255);
  47.   stroke(255);
  48.   text("x: "+loc.x+", y: "+loc.y+", z: "+loc.z+"\n"+"x2: "+x2+", y2: "+y2+", z2: "+z2+"\n"+"frotZ: "+frotZ+", to rad: "+radians(frotZ)+"\nsin(rad(frotZ)): "+sin(radians(frotZ))+"\ncamRotZ: "+camRotZ+", camRotX: "+camRotX,20,40);
  49. }
  50.  
  51. void mouseWheel(MouseEvent event) {
  52.   float e = event.getCount();
  53.   if(e != 0) {
  54.     if(e < 0) {
  55.       z2+=10;
  56.     } else if(e > 0) {
  57.       z2-=10;
  58.     }
  59.   }
  60. }
  61.  
  62. void keyPressed(){
  63.   if(key == 'a' || key == 'A'){
  64.     a=true;
  65.   } else if(key == 'd' || key == 'D'){
  66.     d=true;
  67.   } else if(key == 'w' || key == 'W'){
  68.     w=true;
  69.   } else if(key == 's' || key == 'S'){
  70.     s=true;
  71.   }
  72. }
  73.  
  74. void keyReleased(){
  75.   if(key == 'a' || key == 'A'){
  76.     a=false;
  77.   } else if(key == 'd' || key == 'D'){
  78.     d=false;
  79.   } else if(key == 'w' || key == 'W'){
  80.     w=false;
  81.   } else if(key == 's' || key == 'S'){
  82.     s=false;
  83.   }
  84. }
  85.  
  86. void mouseDragged(){
  87.   if(pmouseX>mouseX){
  88.     tl=false;
  89.     tr=true;
  90.   } if(pmouseX<mouseX){
  91.     tr=false;
  92.     tl=true;
  93.   } if(pmouseY>mouseY){
  94.     tu=true;
  95.     td=false;
  96.   } if(pmouseY<mouseY){
  97.     td=true;
  98.     tu=false;
  99.   }
  100. }
  101.  
  102. void mouseReleased(){
  103.   tr=false;
  104.   tl=false;
  105.   tu=false;
  106.   td=false;
  107. }
  108.  
  109. void moveCam(){
  110.   //cam Z
  111.   if(tl){
  112.     if(camRotZ-((mouseX-pmouseX)/5)<0) { camRotZ+=360; }
  113.     camRotZ+=(pmouseX-mouseX)/5;
  114.   } else if(tr) {
  115.     if(camRotZ+((pmouseX-mouseX)/5)>360) { camRotZ-=360; }
  116.     camRotZ-=(mouseX-pmouseX)/5;
  117.   }
  118.  
  119.   //cam X
  120.   if(td){
  121.     if(camRotX+((pmouseY-mouseY)/5)>=360) { camRotX-=360; }
  122.     camRotX+=(pmouseY-mouseY)/5;
  123.   } else if(tu){
  124.     if(camRotX-((mouseY-pmouseY)/5)<=0) { camRotX+=360; }
  125.     camRotX-=(mouseY-pmouseY)/5;
  126.   }
  127. }
  128.  
  129. void move(){
  130.   if(w){
  131.     loc.sub(spd * sin(frotZ), 0.0, spd * cos(frotZ));
  132.   } if(s){
  133.     loc.add(spd * sin(frotZ), 0.0, spd * cos(frotZ));
  134.   }
  135.   if(a){
  136.     if(frotZ+1>360){
  137.       frotZ=0;
  138.     }
  139.     frotZ+=1;
  140.   } if(d){
  141.     if(frotZ-1<0){
  142.       frotZ=360;
  143.     }
  144.     frotZ-=1;
  145.   }
  146. }
Advertisement
RAW Paste Data Copied
Advertisement