/*
* Project Beknyou
* Copyright (c) 2010-2011 Saint Paul College, All Rights Reserved
* Redistributions in source code form must reproduce the above
* Copyright and this condition.
* The contents of this file are subject to the GNU General Public
* License, Version 2 (the "License"); you may not use this file
* except in compliance with the License. A copy of the License is
* available at http://www.opensource.org/licenses/gpl-license.php.
*/
package com.benkyou.client.systems;
import com.jme3.input.ChaseCamera;
import com.jme3.input.FlyByCamera;
import com.jme3.input.InputManager;
import com.jme3.renderer.Camera;
import com.jme3.scene.Spatial;
import com.jme3.math.*;
/**
*
* @author Austin Allman
*/
public class DefaultCamSystem {
private FlyByCamera flyCam;
private ChaseCamera chaser;
private Camera cam;
private InputManager inputManager;
/**
*
* @param flyCam
* @param cam
*/
public DefaultCamSystem(FlyByCamera flyCam, Camera cam) {
this.flyCam = flyCam;
this.cam = cam;
initDefaults();
}
/**
*
* @param chasee
* @param inputManager
*/
public void setupChaseCam(Spatial chasee, InputManager inputManager) {
flyCam.setEnabled(false);
chaser = new ChaseCamera(cam, chasee, inputManager);
chaser.setLookAtOffset(Vector3f.UNIT_Y.mult(5f));
chaser.setDefaultDistance(15f);
}
public void toggleFPV(){
if(chaser.getDistanceToTarget() < 2f){
chaser.setLookAtOffset(Vector3f.UNIT_Y.mult(5f));
chaser.setDefaultDistance(15f);
}
else{
chaser.setLookAtOffset(Vector3f.UNIT_Y.mult(10f));
chaser.setDefaultDistance(1f);
}
}
/**
*
*/
public void EnableChaseCam() {
flyCam.setEnabled(false);
chaser.setEnabled(true);
}
/**
*
*/
public void EnableflyCam() {
chaser.setEnabled(false);
flyCam.setEnabled(true);
}
/**
*
* @return
*/
public String currentCamera() {
if (flyCam.isEnabled()) {
return "FlyCam";
} else {
return "ChaseCam";
}
}
private void initDefaults() {
flyCam.setDragToRotate(true);
flyCam.setMoveSpeed(200);
}
/**
*
* @return
*/
public Vector3f getCamDir() {
return cam.getDirection().clone().multLocal(0.6f);
}
/**
*
* @return
*/
public Vector3f getCamLeft() {
return cam.getLeft().clone().multLocal(0.4f);
}
/**
*
* @return
*/
public Vector3f getLocation() {
return cam.getLocation();
}
/**
*
* @return
*/
public Vector3f getDirection() {
return cam.getDirection();
}
}