Blob Blame Raw
#ifndef PERSPECTIVE_H
#define PERSPECTIVE_H

#include <vector>
#include <string>

#include "vector.h"
#include "matrix.h"
#include "surface.h"


class Perspective {
public:
	class Layer {
	public:
		IntPair2   dst_bounds;
		Pair2      src_bounds;
		IntVector2 src_size;
		Matrix3    back_matrix;
		Matrix3    back_alpha_matrix;
	};
	
	typedef std::vector<Layer> LayerList;
	
	
	static Matrix3 make_matrix(
		const Vector2 &p0,
		const Vector2 &px,
		const Vector2 &py,
		const Vector2 &p1 );
	
	static Matrix3 normalize_matrix(
		const Matrix3 &matrix );
	
	static int truncate_line(
		Vector2 *out_points,
		const Pair2 &bounds,
		Real a,
		Real b,
		Real c );

	static Vector2 calc_optimal_resolution(
		const Vector2 &ox,
		const Vector2 &oy );

	static Vector3 make_alpha_matrix_col(
		Real w0,
		Real w1,
		const Vector3 &w_col );

	static Matrix3 make_alpha_matrix(
		Real aw0, Real aw1,
		Real bw0, Real bw1,
		const Vector3 &w_col );
	
	static void calc_raster_size(
		Pair2 &out_bounds,
		IntVector2 &out_raster_size,
		Matrix3 &out_raster_matrix,
		const Vector2 &resolution,
		const Pair2 &bounds,
		const Vector2 &dst_size );

	static void create_layers(
		LayerList &out_layers,
		const Matrix3 &matrix,
		const IntPair2 &dst_bounds,
		const Real step = 4.0 );
	
	static Real find_optimal_step(
		const Matrix3 &matrix,
		const IntPair2 &dst_bounds );
	
	static void add_premulted(
		const Layer &layer,
		Surface &src_surface,
		Surface &dst_surface );
	
	
	static void print_layer(const Layer &layer, const std::string &prefix = std::string());
	static void print_layers(const LayerList &layers, const std::string &prefix = std::string());
};







#endif