Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef PARTICLES_H
Toshihiro Shimizu 890ddd
#define PARTICLES_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tsmartpointer.h"
Toshihiro Shimizu 890ddd
#include "tspectrum.h"
Toshihiro Shimizu 890ddd
#include "trandom.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
struct particles_values {
Toshihiro Shimizu 890ddd
	int source_ctrl_val;
Toshihiro Shimizu 890ddd
	int bright_thres_val;
Toshihiro Shimizu 890ddd
	bool multi_source_val;
Toshihiro Shimizu 890ddd
	double x_pos_val;
Toshihiro Shimizu 890ddd
	double y_pos_val;
Toshihiro Shimizu 890ddd
	int unit_val;
Toshihiro Shimizu 890ddd
	double length_val;
Toshihiro Shimizu 890ddd
	double height_val;
Toshihiro Shimizu 890ddd
	double maxnum_val;
Toshihiro Shimizu 890ddd
	DoublePair lifetime_val;
Toshihiro Shimizu 890ddd
	int lifetime_ctrl_val;
Toshihiro Shimizu 890ddd
	int column_lifetime_val;
Toshihiro Shimizu 890ddd
	//double lifetimemin_val;
Toshihiro Shimizu 890ddd
	//double lifetimemax_val;
Toshihiro Shimizu 890ddd
	int startpos_val;
Toshihiro Shimizu 890ddd
	int randseed_val;
Toshihiro Shimizu 890ddd
	double gravity_val;
Toshihiro Shimizu 890ddd
	double g_angle_val;
Toshihiro Shimizu 890ddd
	int gravity_ctrl_val;
Toshihiro Shimizu 890ddd
	//  int gravity_radius_val;
Toshihiro Shimizu 890ddd
	double friction_val;
Toshihiro Shimizu 890ddd
	int friction_ctrl_val;
Toshihiro Shimizu 890ddd
	double windint_val;
Toshihiro Shimizu 890ddd
	double windangle_val;
Toshihiro Shimizu 890ddd
	int swingmode_val;
Toshihiro Shimizu 890ddd
	DoublePair randomx_val;
Toshihiro Shimizu 890ddd
	DoublePair randomy_val;
Toshihiro Shimizu 890ddd
	int randomx_ctrl_val;
Toshihiro Shimizu 890ddd
	int randomy_ctrl_val;
Toshihiro Shimizu 890ddd
	DoublePair swing_val;
Toshihiro Shimizu 890ddd
	DoublePair speed_val;
Toshihiro Shimizu 890ddd
	int speed_ctrl_val;
Toshihiro Shimizu 890ddd
	DoublePair speeda_val;
Toshihiro Shimizu 890ddd
	int speeda_ctrl_val;
Toshihiro Shimizu 890ddd
	bool speeda_use_gradient_val;
Toshihiro Shimizu 890ddd
	bool speedscale_val;
Toshihiro Shimizu 890ddd
	char *levelname_val;
Toshihiro Shimizu 890ddd
	int toplayer_val;
Toshihiro Shimizu 890ddd
	DoublePair mass_val;
Toshihiro Shimizu 890ddd
	DoublePair scale_val;
Toshihiro Shimizu 890ddd
	int scale_ctrl_val;
Toshihiro Shimizu 890ddd
	bool scale_ctrl_all_val;
Toshihiro Shimizu 890ddd
	DoublePair rot_val;
Toshihiro Shimizu 890ddd
	int rot_ctrl_val;
Toshihiro Shimizu 890ddd
	DoublePair trail_val;
Toshihiro Shimizu 890ddd
	double trailstep_val;
Toshihiro Shimizu 890ddd
	int rotswingmode_val;
Toshihiro Shimizu 890ddd
	double rotspeed_val;
Toshihiro Shimizu 890ddd
	DoublePair rotsca_val;
Toshihiro Shimizu 890ddd
	DoublePair rotswing_val;
Toshihiro Shimizu 890ddd
	bool pathaim_val;
Toshihiro Shimizu 890ddd
	DoublePair opacity_val;
Toshihiro Shimizu 890ddd
	int opacity_ctrl_val;
Toshihiro Shimizu 890ddd
	DoublePair trailopacity_val;
Toshihiro Shimizu 890ddd
	double mblur_val;
Toshihiro Shimizu 890ddd
	DoublePair scalestep_val;
Toshihiro Shimizu 890ddd
	int scalestep_ctrl_val;
Toshihiro Shimizu 890ddd
	double fadein_val;
Toshihiro Shimizu 890ddd
	double fadeout_val;
Toshihiro Shimizu 890ddd
	int animation_val;
Toshihiro Shimizu 890ddd
	int step_val;
Toshihiro Shimizu 890ddd
	TSpectrum gencol_val;
Toshihiro Shimizu 890ddd
	int gencol_ctrl_val;
Toshihiro Shimizu 890ddd
	double gencol_spread_val;
Toshihiro Shimizu 890ddd
	double genfadecol_val;
Toshihiro Shimizu 890ddd
	TSpectrum fincol_val;
Toshihiro Shimizu 890ddd
	int fincol_ctrl_val;
Toshihiro Shimizu 890ddd
	double fincol_spread_val;
Toshihiro Shimizu 890ddd
	double finrangecol_val;
Toshihiro Shimizu 890ddd
	double finfadecol_val;
Toshihiro Shimizu 890ddd
	TSpectrum foutcol_val;
Toshihiro Shimizu 890ddd
	int foutcol_ctrl_val;
Toshihiro Shimizu 890ddd
	double foutcol_spread_val;
Toshihiro Shimizu 890ddd
	double foutrangecol_val;
Toshihiro Shimizu 890ddd
	double foutfadecol_val;
Toshihiro Shimizu 890ddd
	TRandom *random_val;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool source_gradation_val;
Toshihiro Shimizu 890ddd
	bool reset_random_for_every_frame_val;
Toshihiro Shimizu 890ddd
	bool pick_color_for_every_frame_val;
Toshihiro Shimizu 890ddd
	bool perspective_distribution_val;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
struct particles_ranges {
Toshihiro Shimizu 890ddd
	float swing_range;
Toshihiro Shimizu 890ddd
	float randomx_range;
Toshihiro Shimizu 890ddd
	float randomy_range;
Toshihiro Shimizu 890ddd
	float rot_range;
Toshihiro Shimizu 890ddd
	float rotswing_range;
Toshihiro Shimizu 890ddd
	float rotsca_range;
Toshihiro Shimizu 890ddd
	float lifetime_range;
Toshihiro Shimizu 890ddd
	float speed_range;
Toshihiro Shimizu 890ddd
	float speeda_range;
Toshihiro Shimizu 890ddd
	float mass_range;
Toshihiro Shimizu 890ddd
	float scale_range;
Toshihiro Shimizu 890ddd
	float scalestep_range;
Toshihiro Shimizu 890ddd
	int trail_range;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
struct pos_dummy {
Toshihiro Shimizu 890ddd
	float x, y, a;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
typedef struct
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	TPixel32 col;
Toshihiro Shimizu 890ddd
	int rangecol;
Toshihiro Shimizu 890ddd
	double fadecol;
Toshihiro Shimizu 890ddd
} coldata;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class Particle
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	double x;
Toshihiro Shimizu 890ddd
	double y;
Toshihiro Shimizu 890ddd
	double oldx;
Toshihiro Shimizu 890ddd
	double oldy;
Toshihiro Shimizu 890ddd
	double vx; /*sono le velox iniziali*/
Toshihiro Shimizu 890ddd
	double vy; /*sono le velox iniziali*/
Toshihiro Shimizu 890ddd
	double mass;
Toshihiro Shimizu 890ddd
	double scale; /*potrebbe diventare la z*/
Toshihiro Shimizu 890ddd
	double angle;
Toshihiro Shimizu 890ddd
	double smswingx;
Toshihiro Shimizu 890ddd
	double smswingy;
Toshihiro Shimizu 890ddd
	double smswinga;
Toshihiro Shimizu 890ddd
	int smperiodx;
Toshihiro Shimizu 890ddd
	int smperiody;
Toshihiro Shimizu 890ddd
	int smperioda;
Toshihiro Shimizu 890ddd
	int lifetime;
Toshihiro Shimizu 890ddd
	int genlifetime;
Toshihiro Shimizu 890ddd
	int level;
Toshihiro Shimizu 890ddd
	int frame;
Toshihiro Shimizu 890ddd
	int signx;
Toshihiro Shimizu 890ddd
	int trail;
Toshihiro Shimizu 890ddd
	coldata gencol;
Toshihiro Shimizu 890ddd
	coldata fincol;
Toshihiro Shimizu 890ddd
	coldata foutcol;
Toshihiro Shimizu 890ddd
	int changesignx;
Toshihiro Shimizu 890ddd
	int signy;
Toshihiro Shimizu 890ddd
	int changesigny;
Toshihiro Shimizu 890ddd
	int signa;
Toshihiro Shimizu 890ddd
	int changesigna;
Toshihiro Shimizu 890ddd
	bool animswing;
Toshihiro Shimizu 890ddd
	TRandom random;
Toshihiro Shimizu 890ddd
	int seed;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 3bfa54
	Particle(int lifetime, int seed, const std::map<int, *="" ttile=""> porttiles, const particles_values &values, const particles_ranges &ranges, std::vector<std::vector<tpointd>> &myregions, int howmany, int first, int level, int last,</std::vector<tpointd></int,>
Shinya Kitaoka 3bfa54
			 std::vector<std::vector<int>> &myHistogram, std::vector<float> &myWeight);</float></std::vector<int>
Toshihiro Shimizu 890ddd
	//Constructor
Toshihiro Shimizu 890ddd
	~Particle() {}
Toshihiro Shimizu 890ddd
	//Destructor
Toshihiro Shimizu 890ddd
	void create_Animation(const particles_values &values, int first, int last);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int check_Swing(const particles_values &values);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void create_Swing(const particles_values &values,
Toshihiro Shimizu 890ddd
					  const particles_ranges &ranges,
Toshihiro Shimizu 890ddd
					  double randomxreference, double randomyreference);
Toshihiro Shimizu 890ddd
	void create_Colors(const particles_values &values,
Shinya Kitaoka 3bfa54
					   const particles_ranges &ranges, std::map<int, *="" ttile=""> porttiles);</int,>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
	void move(const std::map<int, *="" ttile=""> porttiles, const particles_values &values, const particles_ranges &ranges, float windx,</int,>
Toshihiro Shimizu 890ddd
			  float windy, float xgravity, float ygravity, float dpi, int lastframe);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void spread_color(TPixel32 &color, double range);
Toshihiro Shimizu 890ddd
	void update_Animation(const particles_values &values, int first, int last, int keep);
Toshihiro Shimizu 890ddd
	void update_Swing(const particles_values &values,
Toshihiro Shimizu 890ddd
					  const particles_ranges &ranges,
Toshihiro Shimizu 890ddd
					  struct pos_dummy &dummy,
Toshihiro Shimizu 890ddd
					  double randomxreference, double randomyreference);
Toshihiro Shimizu 890ddd
	void update_Scale(const particles_values &values,
Toshihiro Shimizu 890ddd
					  const particles_ranges &ranges,
Toshihiro Shimizu 890ddd
					  double scalereference, double scalestepreference);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double set_Opacity(std::map<int, *="" ttile=""> porttiles,</int,>
Toshihiro Shimizu 890ddd
					   const particles_values &values,
Toshihiro Shimizu 890ddd
					   float opacity_range, double dist_frame);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void modify_colors(TPixel32 &color, double &intensity);
Toshihiro Shimizu 890ddd
	void modify_colors_and_opacity(const particles_values &values,
Toshihiro Shimizu 890ddd
								   float curr_opacity, int dist_frame, TRaster32P raster);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool canHandle(const TRenderSettings &info, double frame) { return false; }
Toshihiro Shimizu 890ddd
	void get_image_reference(TTile *ctrl1, const particles_values &values,
Toshihiro Shimizu 890ddd
							 double &imagereference, int type);
Toshihiro Shimizu 890ddd
	void get_image_reference(TTile *ctrl1, const particles_values &values,
Toshihiro Shimizu 890ddd
							 TPixel32 &color);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void get_image_gravity(TTile *ctrl1, const particles_values &values,
Toshihiro Shimizu 890ddd
						   float &gx, float &gy);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class ComparebySize
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	bool operator()(const Particle &f1,
Toshihiro Shimizu 890ddd
					const Particle &f2)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if ((f1.scale - f2.scale) > 0)
Toshihiro Shimizu 890ddd
			return 1;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		return 0;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class ComparebyLifetime
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	bool operator()(const Particle &f1,
Toshihiro Shimizu 890ddd
					const Particle &f2)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if ((f1.lifetime - f1.genlifetime - f2.lifetime + f2.genlifetime) > 0)
Toshihiro Shimizu 890ddd
			return 1;
Toshihiro Shimizu 890ddd
		return 0;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif