Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void update(int delta)
- {
- float forward = 0f;
- float strafe = 0f;
- float vertical = 0f;
- if(Keyboard.isKeyDown(Keyboard.KEY_W))
- {
- forward += 1f;
- }
- else if(Keyboard.isKeyDown(Keyboard.KEY_S))
- {
- forward -= 1f;
- }
- else if(Keyboard.isKeyDown(Keyboard.KEY_A))
- {
- strafe -= 1f;
- }
- else if(Keyboard.isKeyDown(Keyboard.KEY_D))
- {
- strafe += 1f;
- }
- else if(Keyboard.isKeyDown(Keyboard.KEY_Q) && freeCam)
- {
- vertical -= 1f;
- }
- else if(Keyboard.isKeyDown(Keyboard.KEY_E) && freeCam)
- {
- vertical += 1f;
- }
- int dx = Mouse.getDX();
- int dy = Mouse.getDY();
- yrot += dx * 0.5f;
- xrot -= dy * 0.5f;
- if(xrot > 90)
- xrot = 90;
- else if(xrot < -90)
- xrot = -90;
- GL11.glRotatef(xrot, 1, 0, 0);
- GL11.glRotatef(yrot, 0, 1, 0);
- //forward *= delta;
- //strafe *= delta;
- Vector3f movement = new Vector3f();
- if(strafe == 0f || forward != 0)
- {
- movement.x += SPEED * forward * Math.cos(Math.toRadians(yrot + 90));
- if(freeCam)
- movement.y += SPEED * vertical;
- movement.z += SPEED * forward * Math.sin(Math.toRadians(yrot + 90));
- }
- else
- {
- movement.x += SPEED * strafe * Math.cos(Math.toRadians(yrot + 180));
- movement.z += SPEED * strafe * Math.sin(Math.toRadians(yrot + 180));
- }
- movement.x *= delta;
- movement.z *= delta;
- position.x -= movement.x;
- position.z -= movement.z;
- bb.setVecMin(new Vector3f(position.x - BBSIZE, 0f, position.z - BBSIZE));
- bb.setVecMax(new Vector3f(position.x + BBSIZE, 1f, position.z + BBSIZE));
- BoundingBox c = null;
- for(BoundingBox b : Game.level.bbs)
- {
- if(BoundingBox.isCollided(bb, b))
- {
- c = b;
- break;
- }
- }
- if(c != null && !Keyboard.isKeyDown(Keyboard.KEY_LSHIFT))
- {
- //position.set(lastGoodPos);
- Vector3f reaction = new Vector3f();
- reaction.x = c.normal.x * + (Vector3f.dot(c.normal, movement));
- reaction.y = c.normal.y * + (Vector3f.dot(c.normal, movement));
- reaction.z = c.normal.z * + (Vector3f.dot(c.normal, movement));
- Vector3f.add(movement, reaction, movement);
- Vector3f.add(movement, lastGoodPos, position);
- //position.set(lastGoodPos);
- }
- else
- lastGoodPos.set(position);
- GL11.glTranslatef(-position.x, -0.5f, -position.z);
- }
Advertisement
Add Comment
Please, Sign In to add comment