Exemplo n.º 1
0
 @Override
 public void input(Window window, MouseInput mouseInput) {
   cameraInc.set(0, 0, 0);
   if (window.isKeyPressed(GLFW_KEY_W)) {
     cameraInc.z = -1;
   } else if (window.isKeyPressed(GLFW_KEY_S)) {
     cameraInc.z = 1;
   }
   if (window.isKeyPressed(GLFW_KEY_A)) {
     cameraInc.x = -1;
   } else if (window.isKeyPressed(GLFW_KEY_D)) {
     cameraInc.x = 1;
   }
   if (window.isKeyPressed(GLFW_KEY_Z)) {
     cameraInc.y = -1;
   } else if (window.isKeyPressed(GLFW_KEY_X)) {
     cameraInc.y = 1;
   }
   if (window.isKeyPressed(GLFW_KEY_LEFT)) {
     angleInc -= 0.05f;
   } else if (window.isKeyPressed(GLFW_KEY_RIGHT)) {
     angleInc += 0.05f;
   } else {
     angleInc = 0;
   }
   if (window.isKeyPressed(GLFW_KEY_SPACE)) {
     monster.nextFrame();
   }
 }
Exemplo n.º 2
0
 @Override
 public void input(Window window, MouseInput mouseInput) {
   cameraInc.set(0, 0, 0);
   if (window.isKeyPressed(GLFW_KEY_W)) {
     cameraInc.z = -1;
   } else if (window.isKeyPressed(GLFW_KEY_S)) {
     cameraInc.z = 1;
   }
   if (window.isKeyPressed(GLFW_KEY_A)) {
     cameraInc.x = -1;
   } else if (window.isKeyPressed(GLFW_KEY_D)) {
     cameraInc.x = 1;
   }
   if (window.isKeyPressed(GLFW_KEY_Z)) {
     cameraInc.y = -1;
   } else if (window.isKeyPressed(GLFW_KEY_X)) {
     cameraInc.y = 1;
   }
   if (window.isKeyPressed(GLFW_KEY_LEFT)) {
     angleInc -= 0.05f;
     soundMgr.playSoundSource(Sounds.BEEP.toString());
   } else if (window.isKeyPressed(GLFW_KEY_RIGHT)) {
     angleInc += 0.05f;
     soundMgr.playSoundSource(Sounds.BEEP.toString());
   } else {
     angleInc = 0;
   }
 }
Exemplo n.º 3
0
  @Override
  public void update(float interval, MouseInput mouseInput) {
    // Update camera based on mouse
    if (mouseInput.isRightButtonPressed()) {
      Vector2f rotVec = mouseInput.getDisplVec();
      camera.moveRotation(rotVec.x * MOUSE_SENSITIVITY, rotVec.y * MOUSE_SENSITIVITY, 0);
    }

    // Update camera position
    Vector3f prevPos = new Vector3f(camera.getPosition());
    camera.movePosition(
        cameraInc.x * CAMERA_POS_STEP,
        cameraInc.y * CAMERA_POS_STEP,
        cameraInc.z * CAMERA_POS_STEP);
    // Check if there has been a collision. If true, set the y position to
    // the maximum height
    float height = terrain != null ? terrain.getHeight(camera.getPosition()) : -Float.MAX_VALUE;
    if (camera.getPosition().y <= height) {
      camera.setPosition(prevPos.x, prevPos.y, prevPos.z);
    }

    lightAngle += angleInc;
    if (lightAngle < 0) {
      lightAngle = 0;
    } else if (lightAngle > 180) {
      lightAngle = 180;
    }
    float zValue = (float) Math.cos(Math.toRadians(lightAngle));
    float yValue = (float) Math.sin(Math.toRadians(lightAngle));
    Vector3f lightDirection = this.scene.getSceneLight().getDirectionalLight().getDirection();
    lightDirection.x = 0;
    lightDirection.y = yValue;
    lightDirection.z = zValue;
    lightDirection.normalize();
  }
Exemplo n.º 4
0
 public void movePosition(float offsetX, float offsetY, float offsetZ) {
   if (offsetZ != 0) {
     position.x += (float) Math.sin(Math.toRadians(rotation.y)) * -1.0f * offsetZ;
     position.z += (float) Math.cos(Math.toRadians(rotation.y)) * offsetZ;
   }
   if (offsetX != 0) {
     position.x += (float) Math.sin(Math.toRadians(rotation.y - 90)) * -1.0f * offsetX;
     position.z += (float) Math.cos(Math.toRadians(rotation.y - 90)) * offsetX;
   }
   position.y += offsetY;
 }
Exemplo n.º 5
0
 public void moveRotation(float offsetX, float offsetY, float offsetZ) {
   rotation.x += offsetX;
   rotation.y += offsetY;
   rotation.y += offsetZ;
 }