/*  $Id: collision_outline_generic.h,v 1.5 2004/05/08 21:20:19 harry Exp $
**
**  ClanLib Game SDK
**  Copyright (C) 2003  The ClanLib Team
**  For a total list of contributers see the file CREDITS.
**
**  This library is free software; you can redistribute it and/or
**  modify it under the terms of the GNU Lesser General Public
**  License as published by the Free Software Foundation; either
**  version 2.1 of the License, or (at your option) any later version.
**
**  This library is distributed in the hope that it will be useful,
**  but WITHOUT ANY WARRANTY; without even the implied warranty of
**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
**  Lesser General Public License for more details.
**
**  You should have received a copy of the GNU Lesser General Public
**  License along with this library; if not, write to the Free Software
**  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
**
*/

#ifndef header_surface_outline_generic
#define header_surface_outline_generic

#include "API/Display/Collision/collision_outline.h"
#include "API/Display/Collision/contour.h"
#include "API/Display/Collision/outline_circle.h"
#include "API/Display/Collision/outline_accuracy.h"
#include "API/Core/Math/rect.h"

class CL_OutlineProvider;

class CL_CollisionOutline_Generic
{
//! Construction:
public:
	CL_CollisionOutline_Generic();
	CL_CollisionOutline_Generic( CL_OutlineProvider *provider, CL_OutlineAccuracy accuracy );
	
	~CL_CollisionOutline_Generic();

//! Attributes:
public:
	std::vector<CL_Contour> contours;
	CL_Contour obb; // object bounding box
	bool do_obb_test, do_inside_test;

	int width, height;
	float angle;
	float radius;

	CL_Pointf position;
	CL_Pointf scale_factor;
	CL_Pointf translation_offset;
	CL_Origin translation_origin;
	CL_Pointf rotation_hotspot;
	CL_Origin rotation_origin;
	CL_Pointf rotation_hotspot_offset;

	bool collision_info;
	bool collision_info_normals;

	std::vector<CL_Pointf> collision_points;
	std::vector<CL_Pointf> collision_normals;

//! Operations:
 public:
	void set_translation(float x, float y, bool offset_points=false);
	void set_scale(float sx, float sy);
	void set_angle(float angle);
	void rotate(float angle);

	void optimize(unsigned char check_distance, float corner_angle);
	void save(const std::string &filename, CL_OutputSourceProvider *provider) const;

	bool collide( const CL_CollisionOutline &outline );
	bool point_inside( const CL_Pointf &point ) const;
	bool point_inside_contour( const CL_Pointf &point, const CL_Contour &contour) const;
	bool contours_collide(const CL_Contour &contour1, const CL_Contour &contour2, bool do_subcirle_test=true);

	void calculate_obb();
	void calculate_radius();
	void update_obb();
	void calculate_sub_circles();

	inline bool line_bounding_box_overlap( const std::vector<CL_Pointf> &rect1, const std::vector<CL_Pointf> &rect2, int i, int j ) const;
	bool obb_overlap( const CL_Contour &other_obb );
	CL_Rectf orig_obb;
};

#endif
