Guest User

Untitled

a guest
Jul 7th, 2013
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public void update(int delta)
  2.     {
  3.         float forward = 0f;
  4.         float strafe = 0f;
  5.         float vertical = 0f;
  6.  
  7.         if(Keyboard.isKeyDown(Keyboard.KEY_W))
  8.         {
  9.             forward += 1f;
  10.         }
  11.         else if(Keyboard.isKeyDown(Keyboard.KEY_S))
  12.         {
  13.             forward -= 1f;
  14.         }
  15.         else if(Keyboard.isKeyDown(Keyboard.KEY_A))
  16.         {
  17.             strafe -= 1f;
  18.         }
  19.         else if(Keyboard.isKeyDown(Keyboard.KEY_D))
  20.         {
  21.             strafe += 1f;
  22.         }
  23.         else if(Keyboard.isKeyDown(Keyboard.KEY_Q) && freeCam)
  24.         {
  25.             vertical -= 1f;
  26.         }
  27.         else if(Keyboard.isKeyDown(Keyboard.KEY_E) && freeCam)
  28.         {
  29.             vertical += 1f;
  30.         }
  31.  
  32.         int dx = Mouse.getDX();
  33.         int dy = Mouse.getDY();
  34.  
  35.         yrot += dx * 0.5f;
  36.         xrot -= dy * 0.5f;
  37.  
  38.         if(xrot > 90)
  39.             xrot = 90;
  40.         else if(xrot < -90)
  41.             xrot = -90;
  42.  
  43.         GL11.glRotatef(xrot, 1, 0, 0);
  44.         GL11.glRotatef(yrot, 0, 1, 0);
  45.  
  46.         //forward *= delta;
  47.         //strafe *= delta;
  48.  
  49.         Vector3f movement = new Vector3f();
  50.  
  51.         if(strafe == 0f || forward != 0)
  52.         {
  53.             movement.x += SPEED * forward * Math.cos(Math.toRadians(yrot + 90));
  54.  
  55.             if(freeCam)
  56.                 movement.y += SPEED * vertical;
  57.  
  58.             movement.z += SPEED * forward * Math.sin(Math.toRadians(yrot + 90));
  59.         }
  60.         else
  61.         {
  62.             movement.x += SPEED * strafe * Math.cos(Math.toRadians(yrot + 180));
  63.  
  64.             movement.z += SPEED * strafe * Math.sin(Math.toRadians(yrot + 180));
  65.         }
  66.  
  67.         movement.x *= delta;
  68.         movement.z *= delta;
  69.  
  70.         position.x -= movement.x;
  71.         position.z -= movement.z;
  72.  
  73.         bb.setVecMin(new Vector3f(position.x - BBSIZE, 0f, position.z - BBSIZE));
  74.         bb.setVecMax(new Vector3f(position.x + BBSIZE, 1f, position.z + BBSIZE));
  75.  
  76.         BoundingBox c = null;
  77.  
  78.         for(BoundingBox b : Game.level.bbs)
  79.         {
  80.             if(BoundingBox.isCollided(bb, b))
  81.             {
  82.                 c = b;
  83.                 break;
  84.             }
  85.         }
  86.  
  87.         if(c != null && !Keyboard.isKeyDown(Keyboard.KEY_LSHIFT))
  88.         {
  89.             //position.set(lastGoodPos);
  90.  
  91.             Vector3f reaction = new Vector3f();
  92.             reaction.x = c.normal.x * + (Vector3f.dot(c.normal, movement));
  93.             reaction.y = c.normal.y * + (Vector3f.dot(c.normal, movement));
  94.             reaction.z = c.normal.z * + (Vector3f.dot(c.normal, movement));
  95.  
  96.             Vector3f.add(movement, reaction, movement);
  97.  
  98.             Vector3f.add(movement, lastGoodPos, position);
  99.  
  100.             //position.set(lastGoodPos);
  101.  
  102.         }
  103.         else
  104.             lastGoodPos.set(position);
  105.  
  106.         GL11.glTranslatef(-position.x, -0.5f, -position.z);
  107.     }
Advertisement
Add Comment
Please, Sign In to add comment