/***********      .---.         .-"-.      *******************\
* -------- *     /   ._.       / ´ ` \     * ---------------- *
* Author's *     \_  (__\      \_°v°_/     * humus@rogers.com *
*   note   *     //   \\       //   \\     * ICQ #47010716    *
* -------- *    ((     ))     ((     ))    * ---------------- *
*          ****--""---""-------""---""--****                  ********\
* This file is a part of the work done by Humus. You are free to use  *
* the code in any way you like, modified, unmodified or copy'n'pasted *
* into your own work. However, I expect you to respect these points:  *
*  @ If you use this file and its contents unmodified, or use a major *
*    part of this file, please credit the author and leave this note. *
*  @ For use in anything commercial, please request my approval.      *
*  @ Share your work and ideas too as much as you can.                *
\*********************************************************************/

#include "../Framework3/OpenGL/OpenGLApp.h"
#include "../Framework3/CPU.h"

#include "Engine.h"

struct Vertex {
	Vertex(const vec3 v, const vec2 t){
		vertex = v;
		texCoord = t;
	}
	vec3 vertex;
	vec2 texCoord;
};

struct Kicker {
	Kicker(const vec3 &v0, const vec3 &v1, const vec3 &v3, const vec3 &dir){
		vertices[0] = v0;
		vertices[1] = v1;
		vertices[2] = v1 + v3 - v0;
		vertices[3] = v3;

		center = 0.5f * (v1 + v3);

		normal = normalize(cross(v1 - v0, v3 - v0));
		offset = -dot(v0, normal);

		kickDir = dir;
		kickTime = 0;
	}

	vec3 vertices[4];
	vec3 normal;
	float offset;
	vec3 center;

	vec3 kickDir;


	float kickTime;
};

class App : public OpenGLApp {
public:
	char *getTitle() const { return "GameEngine II"; }

	void resetCamera();
	void controls();

	bool onKey(const uint key, const bool pressed);
	bool onMouseButton(const int x, const int y, const MouseButton button, const bool pressed);

	bool init();
	void exit();

	bool load();
	void unload();

	void drawFrame();

protected:
	Engine *engine;

	vec3 camDir;
	Array <Kicker> kickers;

	CheckBox *useClipPlanes;
	CheckBox *useScissor;
	CheckBox *useStencilBranch;
	CheckBox *useSpecular;
	CheckBox *useParallax;
	CheckBox *useShadow;
	CheckBox *useSelfShadow;
	CheckBox *useVolumetric;
	Slider *soundVolume;
	Slider *musicVolume;

	float shootTime;

	bool freeFly, showDebug;
};
