//Scene.h

#include "Vector.h"
#include "Ray.h"

#pragma once

class ISerializer;

class CCamera
{
public:
	CVector3 Pos, Forward, Right, Up;
	float MinFlat, MaxFlat, ViewAngle;

	int Width, Height;
	CVector3 FlatCenter;
	float PixelWidth, PixelHeight;

	CCamera();

	void SetCamera(CVector3 &Pos, CVector3 &LookAt);
};

class CMaterial
{
public:
	CVector3 Ambient, Diffuse, Specular, Reflectivity;
	float Exponent;

	CMaterial();

	void CreateStandard();
	void CreateColored(CVector3 &Color, CVector3 &Reflectivity = _0);
};

class CFlat
{
public:
	CVector3 Pos;

	CMaterial Material;

	CFlat();

	void CheckCollision(CRay &Ray, CRay &NewRay, CVector3 &Normal);
};

class CSphere
{
public:
	CVector3 Pos;
	float Radius;

	CMaterial Material;

	CSphere();

	void CheckCollision(CRay &Ray, CRay &NewRay, CVector3 &Normal);
};

class CLight
{
public:
	CVector3 Pos;
	CVector3 Color;
	float ConstAttenuation, LinearAttenuation, QuadricAttenuation;

	CLight();
};

class CScene
{
public:
	CFlat * Flats;
	int nFlats;
	CSphere * Spheres;
	int nSpheres;
	CLight * Lights;
	int nLights;

	bool bAmbient, bDiffuse, bSpecular;

	CCamera Camera;

	CScene();
	~CScene();

	void Init();
	void Create(int Width, int Height, int nFlats, int nSpheres, int nLights);
	void Destroy();

	void CheckCollision(CRay &Ray, CRay &NewRay, CVector3 &Normal, CMaterial &Material, float MinDist = 0, float MaxDist = 1e8);
	CVector3 CountPixel(int i, int j);
	CVector3 GetRayColor(CRay & Ray, int RecLevel);

};
