/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package detectiongame.proto;
import engine.Entity;
import engine.GfxEngine;
import engine.Light;
import engine.Vec3f;
import engine.model.Material;
import java.util.Vector;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import static org.lwjgl.opengl.GL11.*;
import org.lwjgl.opengl.GL13;
/**
*
* @author
* knasaari
*/
public class Proto extends GfxEngine {
private Light light;
private StarField starfield;
private Streets streets,streets1,streets2,streets3;
private Entity box, target, floor, skybox;
private Vector<Entity> stars;
private Vector<Vec3f> starPoints;
private Vector<Seeker> seekers;
private Vector<Integer> seekerHits;
private boolean moveLight = true;
private boolean drawFOV = true;
private float vision_rad = (float)Math.toRadians(90)/2;
private float vision_range = 50f;
private int seekerCount = 30;
float phase = 0;
public void processKeyboard() {
float xrotrad,yrotrad,mul=appSpeed();
if(Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) == true) {
mul *= 5;
}
mul *= 0.1;
xrotrad = (float)Math.toRadians(this.camera.getRot().x);
yrotrad = (float)Math.toRadians(this.camera.getRot().y);
if(Keyboard.isKeyDown(Keyboard.KEY_W)) {
camera.move((float)Math.sin(yrotrad)*mul, -(float)Math.sin(xrotrad)*mul, -(float)Math.cos(yrotrad)*mul);
}
if(Keyboard.isKeyDown(Keyboard.KEY_S)) {
camera.move(-(float)Math.sin(yrotrad)*mul, (float)Math.sin(xrotrad)*mul, (float)Math.cos(yrotrad)*mul);
}
if(Keyboard.isKeyDown(Keyboard.KEY_A)) {
camera.move(-(float)Math.cos(yrotrad)*mul, 0f, -(float)Math.sin(yrotrad)*mul);
}
if(Keyboard.isKeyDown(Keyboard.KEY_D)) {
camera.move((float)Math.cos(yrotrad)*mul, 0f, (float)Math.sin(yrotrad)*mul);
}
if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)){
if(Keyboard.isKeyDown(Keyboard.KEY_ADD)) {
vision_range = (vision_range < 100f)?vision_range+0.5f:100f;
}
else if(Keyboard.isKeyDown(Keyboard.KEY_SUBTRACT)) {
vision_range = (vision_range > 0f)?vision_range-0.5f:0f;
}
}
else {
if(Keyboard.isKeyDown(Keyboard.KEY_ADD)) {
vision_rad = (vision_rad+0.025f < Math.toRadians(180))?vision_rad+0.025f:(float)Math.toRadians(180);
}
else if(Keyboard.isKeyDown(Keyboard.KEY_SUBTRACT)) {
vision_rad = (vision_rad-0.025f > 0)?vision_rad-0.025f:0f;
}
}
if(Keyboard.isKeyDown(Keyboard.KEY_LEFT)) {
//light.move(0.0f, 0.0f, -1.0f);
target.rotate(0, 2.5f, 0);
}
else if(Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) {
//light.move(0.0f, 0.0f, 1.0f);
target.rotate(0, -2.5f, 0);
}
if(Keyboard.isKeyDown(Keyboard.KEY_UP)) {
//light.move(0.0f, 0.0f, -1.0f);
target.localmove(0, 0, 0.5f);
}
else if(Keyboard.isKeyDown(Keyboard.KEY_DOWN)) {
//light.move(0.0f, 0.0f, -1.0f);
target.localmove(0, 0, -0.5f);
}
if(Keyboard.isKeyDown(Keyboard.KEY_L)) {
light.move(1f,0,0);
}
else if(Keyboard.isKeyDown(Keyboard.KEY_J)) {
light.move(-1f,0,0);
}
if(Keyboard.isKeyDown(Keyboard.KEY_I)) {
light.move(0,0,-1f);
}
else if(Keyboard.isKeyDown(Keyboard.KEY_K)) {
light.move(0,0,1f);
}
if(Keyboard.isKeyDown(Keyboard.KEY_U)) {
light.move(0,-1f,0);
}
else if(Keyboard.isKeyDown(Keyboard.KEY_O)) {
light.move(0,1f,0);
}
while( Keyboard.next() ){
int key = Keyboard.getEventKey();
boolean down = Keyboard.getEventKeyState();
boolean repeat = Keyboard.isRepeatEvent();
char c = Keyboard.getEventCharacter();
if(c == '1' && repeat == false) {
this.toggleWireframes();
}
else if(c == '2' && repeat == false) {
this.moveLight = (this.moveLight == true)?false:true;
//this.drawFOV = (this.drawFOV == true)?false:true;
}
else if(c == 'r' && repeat == false) {
reloadShaders();
}
else if(c == 'g' && repeat == false) {
}
else if(c == 'h' && repeat == false) {
}
if(Keyboard.getEventKeyState()){
if(key == Keyboard.KEY_DELETE){
System.gc();
}
}
}
}
public void processMouse() {
//camry = -(Mouse.getY()/2.0f+0.0f);
//camera.getRot().x = ((Mouse.getY()-300)/2.0f+0.0f);
//camrx = -(Mouse.getX()/2.0f);
//camera.getRot().y = (Mouse.getX()/2.0f);
if(Mouse.isButtonDown(0)) {
if( Keyboard.isKeyDown(Keyboard.KEY_RSHIFT) ||
Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
//camera.getPos().x -= (float)Mouse.getDX();
camera.move(-(float)Mouse.getDX()*2, -(float)Mouse.getDY()*2, 0f);
//camera.getPos().y -= (float)Mouse.getDY();
}
else if(Keyboard.isKeyDown(Keyboard.KEY_RCONTROL) ||
Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)) {
//camera.getPos().x -= (float)Mouse.getDX();
camera.move(0f, -(float)Mouse.getDY()*2, -(float)Mouse.getDX()*2);
//camera.getPos().y -= (float)Mouse.getDY();
}else {
camera.getRot().x -= (float)Mouse.getDY()*0.5;
camera.getRot().x = Math.min(90.0f, camera.getRot().x);
camera.getRot().x = Math.max(-90.0f, camera.getRot().x);
camera.getRot().y += (float)Mouse.getDX()*0.5;
}
}
/*
if(Mouse.isButtonDown(1)) {
this.pick(Mouse.getX(), Mouse.getY());
}
*/
}
@Override
public void init() {
//this.starfield = new StarField();
this.light = new Light(0);
light.move(0f, 3f, 0f);
loadModel("chamfer_box.obj").setDefaultMaterial(loadMaterial("box_normal.mat"));
loadModel("plane.obj").setDefaultMaterial(loadMaterial("plane.mat"));
Material cubebox = loadMaterial("box_cubemap.mat");
box = new Entity();
box.setModel(loadModel("chamfer_box.obj"));
box.setMaterial(cubebox);
box.setPos(0,3,0);
box.setScale(3f);
stars = new Vector<>();
starPoints = new Vector<>();
float sinx,cosz,rany,seed,rot;
for(int x=0; x<100; x++){
// stars.add(new Entity());
// stars.lastElement().setModel(loadModel("1x1plane.obj"));
rany = (float)(Math.random()*100);
seed = (float)(Math.random()*2*3.141);
//rot = (float)(360f*(seed/(2*3.141)));
sinx = (float)Math.sin(seed)*200*((100-rany)/100);
cosz = (float)Math.cos(seed)*200*((100-rany)/100);
starPoints.add(new Vec3f(sinx, rany+110, cosz));
// stars.lastElement().setPos(sinx, rany+100, cosz);
// stars.lastElement().setRot(0, rot/2, 0);
}
skybox = new Entity();
skybox.setScale(3000f);
skybox.setModel(loadModel("skybox.obj"));
target = new Entity();
target.setModel(loadModel("drake.obj"));
//target.setMaterial(tilebox);
target.setScale(5f);
target.setPos(0,0f,0);
floor = new Entity();
floor.setModel(loadModel("plane.obj"));
floor.setScale(10f);
float seekerFovs[] = {30,60,90};
seekers = new Vector<>();
for(int i=0; i<this.seekerCount; i++){
seekers.add(new Seeker());
seekers.lastElement().spawn(new Vec3f((float)Math.random()*30-15,0,(float)Math.random()*30-15), (float)Math.random()*40+15, seekerFovs[(int)(Math.random()*3)]);
}
seekerHits = new Vector<>();
streets = new Streets(loadMaterial("street.mat"),4,0.5f);
streets1 = new Streets(loadMaterial("street.mat"),1,1f);
streets2 = new Streets(loadMaterial("street.mat"),2,0.5f);
streets3 = new Streets(loadMaterial("street.mat"),3,0.5f);
camera.setPos(21, 3, 6);
camera.setRot(45, 190, 0);
}
@Override
public void update() {
box.rotate(0f, 0.25f*appSpeed(), 0f);
if(this.moveLight == true) {
phase += appSpeed()*0.025;
}
float x,z;
x = (float) (Math.sin(phase)*9);
z = (float) (Math.cos(phase)*9);
light.setPos(x, 3, z);
if(Display.isVisible()) {
this.processKeyboard();
this.processMouse();
}
/*
this.seekerHits.clear();
for(int i=0; i<this.seekerCount; i++){
if(seekers.elementAt(i).updateLogic(this.target.getPos().x, this.target.getPos().z) == true){
this.seekerHits.add(i);
}
}
*/
}
@Override
public void drawEntities(){
skybox.exist();
streets.exist();
//streets1.exist();
//streets2.exist();
//streets3.exist();
/*
target.exist();
floor.exist();
light.drawDebug();
box.exist();
for(int i=0; i<this.seekers.size(); i++){
if(this.seekerHits.contains(i) == false) {
this.seekers.get(i).exist(0, false);
}
}
for(int i=0; i<this.seekerHits.size(); i++){
this.seekers.get(this.seekerHits.get(i)).exist(i, true);
}
*/
//box.existDebug();
//this.starfield.exist();
}
@Override
public void drawOverlay(){
}
@Override
public void lights(){
light.exist();
}
}