//////////////////////////////////////////////////////////////////////////////////////////////////
// 
// File: camera.h
// 
// Author: Frank Luna (C) All Rights Reserved
// Edited by: Chris Kaynor
//
// System: AMD Athlon 1800+ XP, 512 DDR, Geforce 3, Windows XP, MSVC++ 7.0 
//
// Desc: Defines a camera's position and orientation.
//         
//////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef __cameraH__
#define __cameraH__

#include "object.h"
#include <Frustum.h>

namespace CBK
{
	class Camera : public Object
	{
	public:
		enum CameraType { LANDOBJECT, AIRCRAFT };

		Camera(CameraType cameraType = AIRCRAFT, IDirect3DDevice9* device = 0);
		~Camera();

		virtual Object& load(const std::string& name);
		virtual void apply(void);

		Camera& strafe(const float& units); // left/right
		Camera& fly(const float& units);    // up/down
		Camera& walk(const float& units);   // forward/backward
		
		Camera& pitch(const float& angle); // rotate on right vector
		Camera& yaw(const float& angle);   // rotate on up vector
		Camera& roll(const float& angle);  // rotate on look vector

		const D3DXMATRIX& getViewMatrix(void);
		const cbk::Frustum& getViewFrustum(const D3DXMATRIX& projection, const D3DVIEWPORT9& viewport);

		Camera& setCameraType(const CameraType cameraType); 

		const D3DXVECTOR3& getPosition(void) const;
		Camera& setPosition(const D3DXVECTOR3& pos); 
		Camera& setPosition(const float& x, const float& y, const float& z);

		Camera& setRotation(const D3DXVECTOR3& pos); 
		Camera& setRotation(const float& yaw, const float& pitch, const float& roll);

		const D3DXVECTOR3& getRight(void) const;
		const D3DXVECTOR3& getUp(void) const;
		const D3DXVECTOR3& getLook(void) const;

		const D3DXVECTOR3& getRotation(void) const;

		virtual Object& reset(void);

		const float& getTerrainOffset(void) const;
		Camera& setTerrainOffset(const float& offset);

	private:
		CameraType  _cameraType;
		D3DXVECTOR3 _right;
		D3DXVECTOR3 _up;
		D3DXVECTOR3 _look;
		D3DXVECTOR3 _pos;
		D3DXVECTOR3 _rotation;
		float _terrainOffset;

		mutable cbk::Frustum* viewFrust;
		mutable D3DXMATRIX* viewMatrix;
	};
}

#endif // __cameraH__