/*
  Copyright (c) 2015 Alex Diener
  
  This software is provided 'as-is', without any express or implied
  warranty. In no event will the authors be held liable for any damages
  arising from the use of this software.
  
  Permission is granted to anyone to use this software for any purpose,
  including commercial applications, and to alter it and redistribute it
  freely, subject to the following restrictions:
  
  1. The origin of this software must not be misrepresented; you must not
     claim that you wrote the original software. If you use this software
     in a product, an acknowledgment in the product documentation would be
     appreciated but is not required.
  2. Altered source versions must be plainly marked as such, and must not be
     misrepresented as being the original software.
  3. This notice may not be removed or altered from any source distribution.
  
  Alex Diener alex@ludobloom.com
*/

#ifndef __SingleFrameScreen3D_H__
#define __SingleFrameScreen3D_H__
#ifdef __cplusplus
extern "C" {
#endif

typedef struct SingleFrameScreen3D SingleFrameScreen3D;
#define SingleFrameScreen3D_superclass Screen

#include "collision/CollisionResolver.h"
#include "collision/IntersectionManager.h"
#include "gamemath/Quaternionx.h"
#include "gamemath/Vector3x.h"
#include "font/BitmapFont.h"
#include "renderer/Renderable.h"
#include "renderer/Renderer.h"
#include "renderer/RenderPipelineConfiguration.h"
#include "shadercollection/ShaderConfiguration2DTexture.h"
#include "shadercollection/ShaderConfiguration3DLit.h"
#include "screenmanager/Screen.h"

#define OBJECT_COUNT_3D 8

#define SingleFrameScreen3D_ivars \
	Screen_ivars \
	\
	CollisionObject * objects[OBJECT_COUNT_3D]; \
	Renderer * renderer; \
	RenderLayer * renderLayer3D; \
	RenderLayer * renderLayer2D; \
	RenderPipelineConfiguration renderPipelineConfiguration2D; \
	RenderPipelineConfiguration renderPipelineConfiguration3D; \
	ShaderConfiguration3DLit * shaderConfiguration3D; \
	ShaderConfiguration2DTexture * shaderConfiguration2D; \
	Renderable * meshRenderable; \
	bool meshDirty; \
	Renderable * textRenderable; \
	IntersectionManager * intersectionManager; \
	CollisionResolver * resolver; \
	BitmapFont * font; \
	bool draggingCamera; \
	bool draggingRay; \
	size_t selectedObjectIndex; \
	Vector3x cameraFocus; \
	Quaternionx cameraDirection; \
	fixed16_16 cameraDistance; \
	CollisionRecord collisions[OBJECT_COUNT_3D]; \
	Vector3x rayStart; \
	Vector3x rayEnd; \
	fixed16_16 rayIntersection1; \
	fixed16_16 rayIntersection2; \
	bool drawSweeps; \
	bool wireframe;

#define SingleFrameScreen3D_vtable(self_type) \
	Screen_vtable(self_type)

stemobject_declare(SingleFrameScreen3D)

SingleFrameScreen3D * SingleFrameScreen3D_create(Renderer * renderer);
bool SingleFrameScreen3D_init(SingleFrameScreen3D * self, Renderer * renderer);
void SingleFrameScreen3D_dispose(SingleFrameScreen3D * self);

void SingleFrameScreen3D_activate(SingleFrameScreen3D * self, Screen * lastScreen, const char * transitionName);
void SingleFrameScreen3D_deactivate(SingleFrameScreen3D * self, Screen * nextScreen, const char * transitionName);

#ifdef __cplusplus
}
#endif
#endif
