|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//#include "stdfx.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tfxparam.h"
|
|
Toshihiro Shimizu |
890ddd |
//#include "tpixelutils.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "trop.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "particles.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "particlesengine.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "hsvutil.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "timage_io.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tofflinegl.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*-----------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
void Particle::create_Animation(const particles_values &values,
|
|
Toshihiro Shimizu |
890ddd |
int first, int last)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
switch (values.animation_val) {
|
|
Toshihiro Shimizu |
890ddd |
case ParticlesFx::ANIM_CYCLE:
|
|
Toshihiro Shimizu |
890ddd |
__OR ParticlesFx::ANIM_S_CYCLE : frame = first;
|
|
Toshihiro Shimizu |
890ddd |
animswing = 0; /*frame <0 perche' c'e' il preroll dialmeno un frame*/
|
|
Toshihiro Shimizu |
890ddd |
CASE ParticlesFx::ANIM_SR_CYCLE : frame = (int)(first + (random.getFloat()) * (last - first));
|
|
Toshihiro Shimizu |
890ddd |
animswing = random.getFloat() > 0.5 ? 1 : 0;
|
|
Toshihiro Shimizu |
890ddd |
DEFAULT:
|
|
Toshihiro Shimizu |
890ddd |
frame = (int)(first + (random.getFloat()) * (last - first));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
Particle::Particle(int g_lifetime, int seed, map<int, *="" ttile=""> porttiles, const particles_values &values,</int,>
|
|
Toshihiro Shimizu |
890ddd |
const particles_ranges &ranges, vector<vector<tpointd>> &myregions,</vector<tpointd>
|
|
Toshihiro Shimizu |
890ddd |
int howmany, int first, int level, int last,
|
|
Toshihiro Shimizu |
890ddd |
vector<vector<int>> &myHistogram,</vector<int>
|
|
Toshihiro Shimizu |
890ddd |
vector<float> &myWeight)</float>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double random_s_a_range, random_speed;
|
|
Toshihiro Shimizu |
890ddd |
map<int, double=""> imagereferences;</int,>
|
|
Toshihiro Shimizu |
890ddd |
random = TRandom(seed);
|
|
Toshihiro Shimizu |
890ddd |
double randomxreference = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
double randomyreference = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
create_Animation(values, 0, last);
|
|
Toshihiro Shimizu |
890ddd |
//lifetime=values.lifetime_val.first+ranges.lifetime_range*random->getFloat();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
this->level = level;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*- 初期座標値をつくる -*/
|
|
Toshihiro Shimizu |
890ddd |
/*-- Perspective DistributionがONかつ、SizeのControlImageが刺さっている場合 --*/
|
|
Toshihiro Shimizu |
890ddd |
if (myregions.size() &&
|
|
Toshihiro Shimizu |
890ddd |
values.scale_ctrl_val != ParticlesFx::CTRL_NONE &&
|
|
Toshihiro Shimizu |
890ddd |
values.perspective_distribution_val) {
|
|
Toshihiro Shimizu |
890ddd |
float size = myWeight[255];
|
|
Toshihiro Shimizu |
890ddd |
/*- 候補の中のIndex -*/
|
|
Toshihiro Shimizu |
890ddd |
float partindex = size * random.getFloat();
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < 256; i++) {
|
|
Toshihiro Shimizu |
890ddd |
if (myWeight[i] > partindex) {
|
|
Toshihiro Shimizu |
890ddd |
int m = 255 - i;
|
|
Toshihiro Shimizu |
890ddd |
/*- 明度からサイズ サイズから重みを計算 -*/
|
|
Toshihiro Shimizu |
890ddd |
float scale = values.scale_val.first + ranges.scale_range * (float)m / 255.0f;
|
|
Toshihiro Shimizu |
890ddd |
float weight = 1.0f / (scale * scale);
|
|
Toshihiro Shimizu |
890ddd |
if (i > 0)
|
|
Toshihiro Shimizu |
890ddd |
partindex -= myWeight[i - 1];
|
|
Toshihiro Shimizu |
890ddd |
int index = myHistogram[m][(int)(partindex / weight)];
|
|
Toshihiro Shimizu |
890ddd |
x = myregions[0][index].x + (double)random.getFloat() - 0.5;
|
|
Toshihiro Shimizu |
890ddd |
y = myregions[0][index].y + (double)random.getFloat() - 0.5;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*- 領域がある かつ 発生領域のControlImageが刺さっている場合 -*/
|
|
Toshihiro Shimizu |
890ddd |
else if (myregions.size() && values.source_ctrl_val != ParticlesFx::CTRL_NONE) {
|
|
Toshihiro Shimizu |
890ddd |
/*- howmany:発生Particlesのうち、何番目に発生させたものか。
|
|
Toshihiro Shimizu |
890ddd |
myregionが複数有る場合は、均等に割り振ることになる。 -*/
|
|
Toshihiro Shimizu |
890ddd |
int regionindex = howmany % myregions.size();
|
|
Toshihiro Shimizu |
890ddd |
/*- ウェイトを足しこむ -*/
|
|
Toshihiro Shimizu |
890ddd |
float size;
|
|
Toshihiro Shimizu |
890ddd |
if (values.source_gradation_val && !values.multi_source_val && myregions.size() == 1)
|
|
Toshihiro Shimizu |
890ddd |
size = myWeight[254];
|
|
Toshihiro Shimizu |
890ddd |
else /*- ウェイトがすべて1の場合 -*/
|
|
Toshihiro Shimizu |
890ddd |
size = (float)myregions[regionindex].size();
|
|
Toshihiro Shimizu |
890ddd |
/*- 候補の中のIndex -*/
|
|
Toshihiro Shimizu |
890ddd |
int partindex = (int)(size * random.getFloat());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*- ウェイトを引いていき、負になったインデックスを選択 -*/
|
|
Toshihiro Shimizu |
890ddd |
if (values.source_gradation_val && !values.multi_source_val && myregions.size() == 1) {
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < 255; i++) {
|
|
Toshihiro Shimizu |
890ddd |
if (myWeight[i] > partindex) {
|
|
Toshihiro Shimizu |
890ddd |
int m = 255 - i;
|
|
Toshihiro Shimizu |
890ddd |
if (i > 0)
|
|
Toshihiro Shimizu |
890ddd |
partindex -= myWeight[i - 1];
|
|
Toshihiro Shimizu |
890ddd |
int index = myHistogram[m][(int)(partindex / m)];
|
|
Toshihiro Shimizu |
890ddd |
x = myregions[regionindex][index].x + (double)random.getFloat() - 0.5;
|
|
Toshihiro Shimizu |
890ddd |
y = myregions[regionindex][index].y + (double)random.getFloat() - 0.5;
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} else /*- ウェイトがすべて1の場合 -*/
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
x = myregions[regionindex][(int)partindex].x + (double)random.getFloat() - 0.5;
|
|
Toshihiro Shimizu |
890ddd |
y = myregions[regionindex][(int)partindex].y + (double)random.getFloat() - 0.5;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
x = values.x_pos_val + values.length_val * (random.getFloat() - 0.5);
|
|
Toshihiro Shimizu |
890ddd |
y = values.y_pos_val + values.height_val * (random.getFloat() - 0.5);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (std::map<int, *="" ttile="">::iterator it = porttiles.begin(); it != porttiles.end(); ++it) {</int,>
|
|
Toshihiro Shimizu |
890ddd |
if (
|
|
Toshihiro Shimizu |
890ddd |
(values.lifetime_ctrl_val == it->first ||
|
|
Toshihiro Shimizu |
890ddd |
values.speed_ctrl_val == it->first ||
|
|
Toshihiro Shimizu |
890ddd |
values.scale_ctrl_val == it->first ||
|
|
Toshihiro Shimizu |
890ddd |
values.rot_ctrl_val == it->first
|
|
Toshihiro Shimizu |
890ddd |
/*- Speed Angleを明るさでコントロールする場合 -*/
|
|
Toshihiro Shimizu |
890ddd |
|| (values.speeda_ctrl_val == it->first && !values.speeda_use_gradient_val)) &&
|
|
Toshihiro Shimizu |
890ddd |
it->second->getRaster()) {
|
|
Toshihiro Shimizu |
890ddd |
double tmpvalue;
|
|
Toshihiro Shimizu |
890ddd |
get_image_reference(it->second, values, tmpvalue, ParticlesFx::GRAY_REF);
|
|
Toshihiro Shimizu |
890ddd |
imagereferences[it->first] = tmpvalue;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (values.lifetime_ctrl_val) {
|
|
Toshihiro Shimizu |
890ddd |
double lifetimereference = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
lifetimereference = imagereferences[values.lifetime_ctrl_val];
|
|
Toshihiro Shimizu |
890ddd |
lifetime = g_lifetime * lifetimereference;
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
lifetime = g_lifetime;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//lifetime=g_lifetime;
|
|
Toshihiro Shimizu |
890ddd |
genlifetime = lifetime;
|
|
Toshihiro Shimizu |
890ddd |
if (values.speed_ctrl_val && (porttiles.find(values.speed_ctrl_val) != porttiles.end())) {
|
|
Toshihiro Shimizu |
890ddd |
double speedreference = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
speedreference = imagereferences[values.speed_ctrl_val];
|
|
Toshihiro Shimizu |
890ddd |
random_speed = values.speed_val.first + (ranges.speed_range) * speedreference;
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
random_speed = values.speed_val.first + (ranges.speed_range) * random.getFloat();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*- Speed Angleの制御。RangeモードとGradientモードがある -*/
|
|
Toshihiro Shimizu |
890ddd |
if (values.speeda_ctrl_val && (porttiles.find(values.speeda_ctrl_val) != porttiles.end())) {
|
|
Toshihiro Shimizu |
890ddd |
if (values.speeda_use_gradient_val) {
|
|
Toshihiro Shimizu |
890ddd |
/*- 参照画像のGradientを得る関数を利用して角度を得る -*/
|
|
Toshihiro Shimizu |
890ddd |
float dir_x, dir_y;
|
|
Toshihiro Shimizu |
890ddd |
get_image_gravity(porttiles[values.speeda_ctrl_val], values, dir_x, dir_y);
|
|
Toshihiro Shimizu |
890ddd |
if (dir_x == 0.0f && dir_y == 0.0f)
|
|
Toshihiro Shimizu |
890ddd |
random_s_a_range = values.speed_val.first;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
random_s_a_range = atan2f(dir_x, -dir_y);
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
double speedareference = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
speedareference = imagereferences[values.speeda_ctrl_val];
|
|
Toshihiro Shimizu |
890ddd |
random_s_a_range = values.speeda_val.first + (ranges.speeda_range) * speedareference;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} else /*- Control Imageが無ければランダム -*/
|
|
Toshihiro Shimizu |
890ddd |
random_s_a_range = values.speeda_val.first + (ranges.speeda_range) * random.getFloat();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
trail = (int)(values.trail_val.first + (ranges.trail_range) * random.getFloat());
|
|
Toshihiro Shimizu |
890ddd |
vx = random_speed * sin(random_s_a_range);
|
|
Toshihiro Shimizu |
890ddd |
vy = -random_speed * cos(random_s_a_range);
|
|
Toshihiro Shimizu |
890ddd |
oldx = 0;
|
|
Toshihiro Shimizu |
890ddd |
oldy = 0;
|
|
Toshihiro Shimizu |
890ddd |
mass = values.mass_val.first + (ranges.mass_range) * random.getFloat();
|
|
Toshihiro Shimizu |
890ddd |
if (values.scale_ctrl_val && (porttiles.find(values.scale_ctrl_val) != porttiles.end())) {
|
|
Toshihiro Shimizu |
890ddd |
double scalereference = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
scalereference = imagereferences[values.scale_ctrl_val];
|
|
Toshihiro Shimizu |
890ddd |
scale = values.scale_val.first + (ranges.scale_range) * scalereference;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
/*- ONのとき、かつ、ScaleにControlが無い場合、粒子サイズが小さいほど(遠くにあるので)多く分布するようになる。-*/
|
|
Toshihiro Shimizu |
890ddd |
if (values.perspective_distribution_val) {
|
|
Toshihiro Shimizu |
890ddd |
scale = (values.scale_val.first * values.scale_val.second) /
|
|
Toshihiro Shimizu |
890ddd |
(values.scale_val.second - (ranges.scale_range) * random.getFloat());
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
scale = values.scale_val.first + (ranges.scale_range) * random.getFloat();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (values.rot_ctrl_val && (porttiles.find(values.rot_ctrl_val) != porttiles.end())) {
|
|
Toshihiro Shimizu |
890ddd |
double anglereference = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
anglereference = imagereferences[values.rot_ctrl_val];
|
|
Toshihiro Shimizu |
890ddd |
angle = -(values.rot_val.first) - (ranges.rot_range) * anglereference;
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
angle = -(values.rot_val.first) - (ranges.rot_range) * random.getFloat();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (values.randomx_ctrl_val)
|
|
Toshihiro Shimizu |
890ddd |
randomxreference = imagereferences[values.randomx_ctrl_val];
|
|
Toshihiro Shimizu |
890ddd |
if (values.randomy_ctrl_val)
|
|
Toshihiro Shimizu |
890ddd |
randomyreference = imagereferences[values.randomy_ctrl_val];
|
|
Toshihiro Shimizu |
890ddd |
//if(check_Swing(values))
|
|
Toshihiro Shimizu |
890ddd |
create_Swing(values, ranges, randomxreference, randomyreference);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
create_Colors(values, ranges, porttiles);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (scale < 0.001)
|
|
Toshihiro Shimizu |
890ddd |
scale = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
int Particle::check_Swing(const particles_values &values)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return (values.randomx_val.first || values.randomx_val.second ||
|
|
Toshihiro Shimizu |
890ddd |
values.randomy_val.first || values.randomy_val.second ||
|
|
Toshihiro Shimizu |
890ddd |
values.rotsca_val.first || values.rotsca_val.second);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*-----------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void Particle::create_Swing(const particles_values &values,
|
|
Toshihiro Shimizu |
890ddd |
const particles_ranges &ranges,
|
|
Toshihiro Shimizu |
890ddd |
double randomxreference, double randomyreference)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
changesignx = (int)(values.swing_val.first + random.getFloat() * (ranges.swing_range));
|
|
Toshihiro Shimizu |
890ddd |
changesigny = (int)(values.swing_val.first + random.getFloat() * (ranges.swing_range));
|
|
Toshihiro Shimizu |
890ddd |
changesigna = (int)(values.rotswing_val.first + random.getFloat() * (ranges.rotswing_range));
|
|
Toshihiro Shimizu |
890ddd |
if (values.swingmode_val == ParticlesFx::SWING_SMOOTH) {
|
|
Toshihiro Shimizu |
890ddd |
if (values.randomx_ctrl_val)
|
|
Toshihiro Shimizu |
890ddd |
smswingx = abs((int)values.randomx_val.first) + randomxreference * (ranges.randomx_range);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
smswingx = abs((int)values.randomx_val.first) + random.getFloat() * (ranges.randomx_range);
|
|
Toshihiro Shimizu |
890ddd |
if (values.randomy_ctrl_val)
|
|
Toshihiro Shimizu |
890ddd |
smswingy = abs((int)values.randomy_val.first) + randomyreference * (ranges.randomy_range);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
smswingy = abs((int)values.randomy_val.first) + random.getFloat() * (ranges.randomy_range);
|
|
Toshihiro Shimizu |
890ddd |
smperiodx = changesignx;
|
|
Toshihiro Shimizu |
890ddd |
smperiody = changesigny;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (values.rotswingmode_val == ParticlesFx::SWING_SMOOTH) {
|
|
Toshihiro Shimizu |
890ddd |
smswinga = abs((int)(values.rotsca_val.first + random.getFloat() * (ranges.rotsca_range)));
|
|
Toshihiro Shimizu |
890ddd |
smperioda = changesigna;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
signx = random.getInt(0, 1) > 0 ? 1 : -1;
|
|
Toshihiro Shimizu |
890ddd |
signy = random.getInt(0, 1) > 0 ? 1 : -1;
|
|
Toshihiro Shimizu |
890ddd |
signa = random.getInt(0, 1) > 0 ? 1 : -1;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*-----------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void Particle::create_Colors(const particles_values &values,
|
|
Toshihiro Shimizu |
890ddd |
const particles_ranges &ranges,
|
|
Toshihiro Shimizu |
890ddd |
map<int, *="" ttile=""> porttiles)</int,>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
//TPixel32 color;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (values.genfadecol_val) {
|
|
Toshihiro Shimizu |
890ddd |
TPixel32 color;
|
|
Toshihiro Shimizu |
890ddd |
if (values.gencol_ctrl_val && (porttiles.find(values.gencol_ctrl_val) != porttiles.end()))
|
|
Toshihiro Shimizu |
890ddd |
get_image_reference(porttiles[values.gencol_ctrl_val], values, color);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
color = values.gencol_val.getPremultipliedValue(random.getFloat());
|
|
Toshihiro Shimizu |
890ddd |
gencol.fadecol = values.genfadecol_val;
|
|
Toshihiro Shimizu |
890ddd |
if (values.gencol_spread_val)
|
|
Toshihiro Shimizu |
890ddd |
spread_color(color, values.gencol_spread_val);
|
|
Toshihiro Shimizu |
890ddd |
gencol.col = color;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
gencol.col = TPixel32::Transparent;
|
|
Toshihiro Shimizu |
890ddd |
gencol.fadecol = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (values.finfadecol_val) {
|
|
Toshihiro Shimizu |
890ddd |
TPixel32 color;
|
|
Toshihiro Shimizu |
890ddd |
if (values.fincol_ctrl_val && (porttiles.find(values.fincol_ctrl_val) != porttiles.end()))
|
|
Toshihiro Shimizu |
890ddd |
get_image_reference(porttiles[values.fincol_ctrl_val], values, color);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
color = values.fincol_val.getPremultipliedValue(random.getFloat());
|
|
Toshihiro Shimizu |
890ddd |
fincol.rangecol = (int)values.finrangecol_val;
|
|
Toshihiro Shimizu |
890ddd |
fincol.fadecol = values.finfadecol_val;
|
|
Toshihiro Shimizu |
890ddd |
if (values.fincol_spread_val)
|
|
Toshihiro Shimizu |
890ddd |
spread_color(color, values.fincol_spread_val);
|
|
Toshihiro Shimizu |
890ddd |
fincol.col = color;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
fincol.col = TPixel32::Transparent;
|
|
Toshihiro Shimizu |
890ddd |
fincol.rangecol = 0;
|
|
Toshihiro Shimizu |
890ddd |
fincol.fadecol = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (values.foutfadecol_val) {
|
|
Toshihiro Shimizu |
890ddd |
TPixel32 color;
|
|
Toshihiro Shimizu |
890ddd |
if (values.foutcol_ctrl_val && (porttiles.find(values.foutcol_ctrl_val) != porttiles.end()))
|
|
Toshihiro Shimizu |
890ddd |
get_image_reference(porttiles[values.foutcol_ctrl_val], values, color);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
color = values.foutcol_val.getPremultipliedValue(random.getFloat());
|
|
Toshihiro Shimizu |
890ddd |
;
|
|
Toshihiro Shimizu |
890ddd |
foutcol.rangecol = (int)values.foutrangecol_val;
|
|
Toshihiro Shimizu |
890ddd |
foutcol.fadecol = values.foutfadecol_val;
|
|
Toshihiro Shimizu |
890ddd |
if (values.foutcol_spread_val)
|
|
Toshihiro Shimizu |
890ddd |
spread_color(color, values.foutcol_spread_val);
|
|
Toshihiro Shimizu |
890ddd |
foutcol.col = color;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
foutcol.col = TPixel32::Transparent;
|
|
Toshihiro Shimizu |
890ddd |
foutcol.rangecol = 0;
|
|
Toshihiro Shimizu |
890ddd |
foutcol.fadecol = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*-----------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
/*-- modify_colors_and_opacityから呼ばれる。
|
|
Toshihiro Shimizu |
890ddd |
lifetime: 粒子の現在の年齢
|
|
Toshihiro Shimizu |
890ddd |
gencol/fincol/foutcolから色を決める --*/
|
|
Toshihiro Shimizu |
890ddd |
void Particle::modify_colors(TPixel32 &color, double &intensity)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
float percent = 0;
|
|
Toshihiro Shimizu |
890ddd |
if ((gencol.fadecol || fincol.fadecol) &&
|
|
Toshihiro Shimizu |
890ddd |
(genlifetime - lifetime) <= fincol.rangecol) {
|
|
Toshihiro Shimizu |
890ddd |
if (fincol.rangecol)
|
|
Toshihiro Shimizu |
890ddd |
percent = (genlifetime - lifetime) / (float)(fincol.rangecol);
|
|
Toshihiro Shimizu |
890ddd |
//color=gencol.col+percent*(fincol.col-gencol.col);
|
|
Toshihiro Shimizu |
890ddd |
color = blend(gencol.col, fincol.col, percent);
|
|
Toshihiro Shimizu |
890ddd |
intensity = gencol.fadecol + percent * (fincol.fadecol - gencol.fadecol);
|
|
Toshihiro Shimizu |
890ddd |
} else if (foutcol.fadecol && lifetime <= foutcol.rangecol) {
|
|
Toshihiro Shimizu |
890ddd |
if (foutcol.rangecol)
|
|
Toshihiro Shimizu |
890ddd |
percent = 1 - (lifetime - 1) / (float)(foutcol.rangecol);
|
|
Toshihiro Shimizu |
890ddd |
if (fincol.rangecol && fincol.fadecol) {
|
|
Toshihiro Shimizu |
890ddd |
color = blend(fincol.col, foutcol.col, percent);
|
|
Toshihiro Shimizu |
890ddd |
intensity = fincol.fadecol + percent * (foutcol.fadecol - fincol.fadecol);
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
color = blend(gencol.col, foutcol.col, percent);
|
|
Toshihiro Shimizu |
890ddd |
intensity = gencol.fadecol + percent * (foutcol.fadecol - gencol.fadecol);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
if (fincol.fadecol && fincol.rangecol) {
|
|
Toshihiro Shimizu |
890ddd |
color = fincol.col;
|
|
Toshihiro Shimizu |
890ddd |
intensity = fincol.fadecol;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
color = gencol.col;
|
|
Toshihiro Shimizu |
890ddd |
intensity = gencol.fadecol;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*-----------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
/*- do_render から呼ばれる。各粒子の描画の直前に色を決める -*/
|
|
Toshihiro Shimizu |
890ddd |
void Particle::modify_colors_and_opacity(const particles_values &values,
|
|
Toshihiro Shimizu |
890ddd |
float curr_opacity, int dist_frame, TRaster32P raster32)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double intensity = 0;
|
|
Toshihiro Shimizu |
890ddd |
TPixel32 col;
|
|
Toshihiro Shimizu |
890ddd |
if (gencol.fadecol || fincol.fadecol || foutcol.fadecol) {
|
|
Toshihiro Shimizu |
890ddd |
modify_colors(col, intensity);
|
|
Toshihiro Shimizu |
890ddd |
int j;
|
|
Toshihiro Shimizu |
890ddd |
raster32->lock();
|
|
Toshihiro Shimizu |
890ddd |
for (j = 0; j < raster32->getLy(); j++) {
|
|
Toshihiro Shimizu |
890ddd |
TPixel32 *pix = raster32->pixels(j);
|
|
Toshihiro Shimizu |
890ddd |
TPixel32 *endPix = pix + raster32->getLx();
|
|
Toshihiro Shimizu |
890ddd |
while (pix < endPix) {
|
|
Toshihiro Shimizu |
890ddd |
double factor = pix->m / 255.0;
|
|
Toshihiro Shimizu |
890ddd |
pix->r = (UCHAR)(pix->r + intensity * (factor * col.r - pix->r));
|
|
Toshihiro Shimizu |
890ddd |
pix->g = (UCHAR)(pix->g + intensity * (factor * col.g - pix->g));
|
|
Toshihiro Shimizu |
890ddd |
pix->b = (UCHAR)(pix->b + intensity * (factor * col.b - pix->b));
|
|
Toshihiro Shimizu |
890ddd |
pix->m = (UCHAR)(pix->m + intensity * (factor * col.m - pix->m));
|
|
Toshihiro Shimizu |
890ddd |
++pix;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
raster32->unlock();
|
|
Toshihiro Shimizu |
890ddd |
//pop_rgbfade(pars, 0, 0, raster, raster, 1);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (curr_opacity != 1.0)
|
|
Toshihiro Shimizu |
890ddd |
TRop::rgbmScale(raster32, raster32, 1, 1, 1, curr_opacity);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*-----------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
void Particle::update_Animation(const particles_values &values,
|
|
Toshihiro Shimizu |
890ddd |
int first, int last, int keep)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
switch (values.animation_val) {
|
|
Toshihiro Shimizu |
890ddd |
case ParticlesFx::ANIM_RANDOM:
|
|
Toshihiro Shimizu |
890ddd |
frame = (int)(first + random.getFloat() * (last - first));
|
|
Toshihiro Shimizu |
890ddd |
CASE ParticlesFx::ANIM_R_CYCLE : __OR ParticlesFx::ANIM_CYCLE : if (!keep || frame != keep - 1)
|
|
Toshihiro Shimizu |
890ddd |
frame = first + (frame + 1) % (last - first);
|
|
Toshihiro Shimizu |
890ddd |
CASE ParticlesFx::ANIM_S_CYCLE : __OR ParticlesFx::ANIM_SR_CYCLE:
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!keep || frame != keep - 1) {
|
|
Toshihiro Shimizu |
890ddd |
if (!animswing && frame < last - 1) {
|
|
Toshihiro Shimizu |
890ddd |
frame = (frame + 1);
|
|
Toshihiro Shimizu |
890ddd |
if (frame == last - 1)
|
|
Toshihiro Shimizu |
890ddd |
animswing = 1;
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
frame = (frame - 1);
|
|
Toshihiro Shimizu |
890ddd |
if (frame <= first) {
|
|
Toshihiro Shimizu |
890ddd |
animswing = 0;
|
|
Toshihiro Shimizu |
890ddd |
frame = first;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*-----------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
void Particle::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 |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (values.swingmode_val == ParticlesFx::SWING_SMOOTH) {
|
|
Toshihiro Shimizu |
890ddd |
if (smperiodx)
|
|
Toshihiro Shimizu |
890ddd |
dummy.x = smswingx * randomxreference * sin((TConsts::pi * changesignx) / smperiodx);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
dummy.x = 0;
|
|
Toshihiro Shimizu |
890ddd |
if (smperiody)
|
|
Toshihiro Shimizu |
890ddd |
dummy.y = smswingy * randomyreference * sin((TConsts::pi * changesigny) / smperiody);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
dummy.y = 0;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
if (values.randomx_ctrl_val)
|
|
Toshihiro Shimizu |
890ddd |
dummy.x = (values.randomx_val.first + (ranges.randomx_range) * randomxreference);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
dummy.x = (values.randomx_val.first + (ranges.randomx_range) * random.getFloat());
|
|
Toshihiro Shimizu |
890ddd |
if (values.randomy_ctrl_val)
|
|
Toshihiro Shimizu |
890ddd |
dummy.y = (values.randomy_val.first + (ranges.randomy_range) * randomyreference);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
dummy.y = (values.randomy_val.first + (ranges.randomy_range) * random.getFloat());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (values.rotswingmode_val == ParticlesFx::SWING_SMOOTH) {
|
|
Toshihiro Shimizu |
890ddd |
if (smperioda)
|
|
Toshihiro Shimizu |
890ddd |
dummy.a = smswinga * sin((TConsts::pi * changesigna) / smperioda);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
dummy.a = 0;
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
dummy.a = (values.rotsca_val.first + (ranges.rotsca_range) * random.getFloat());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!(genlifetime - lifetime)) {
|
|
Toshihiro Shimizu |
890ddd |
signx = dummy.x > 0 ? 1 : -1;
|
|
Toshihiro Shimizu |
890ddd |
signy = dummy.y > 0 ? 1 : -1;
|
|
Toshihiro Shimizu |
890ddd |
signa = dummy.a > 0 ? 1 : -1;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
dummy.x = (fabs(dummy.x)) * signx;
|
|
Toshihiro Shimizu |
890ddd |
dummy.y = (fabs(dummy.y)) * signy;
|
|
Toshihiro Shimizu |
890ddd |
dummy.a = (fabs(dummy.a)) * signa;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
changesignx--;
|
|
Toshihiro Shimizu |
890ddd |
changesigny--;
|
|
Toshihiro Shimizu |
890ddd |
changesigna--;
|
|
Toshihiro Shimizu |
890ddd |
if (changesignx <= 0) {
|
|
Toshihiro Shimizu |
890ddd |
// if(random->getFloat()<0.5);
|
|
Toshihiro Shimizu |
890ddd |
signx *= -1;
|
|
Toshihiro Shimizu |
890ddd |
changesignx = abs((int)(values.swing_val.first) + (int)(random.getFloat() * (ranges.swing_range)));
|
|
Toshihiro Shimizu |
890ddd |
if (values.swingmode_val == ParticlesFx::SWING_SMOOTH) {
|
|
Toshihiro Shimizu |
890ddd |
smperiodx = changesignx;
|
|
Toshihiro Shimizu |
890ddd |
if (values.randomx_ctrl_val)
|
|
Toshihiro Shimizu |
890ddd |
smswingx = values.randomx_val.first + randomxreference * (ranges.randomx_range);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
smswingx = values.randomx_val.first + random.getFloat() * (ranges.randomx_range);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (changesigny <= 0) {
|
|
Toshihiro Shimizu |
890ddd |
// if(random->getFloat()<0.5);
|
|
Toshihiro Shimizu |
890ddd |
signy *= -1;
|
|
Toshihiro Shimizu |
890ddd |
changesigny = abs((int)(values.swing_val.first) + (int)(random.getFloat() * (ranges.swing_range)));
|
|
Toshihiro Shimizu |
890ddd |
if (values.swingmode_val == ParticlesFx::SWING_SMOOTH) {
|
|
Toshihiro Shimizu |
890ddd |
smperiody = changesigny;
|
|
Toshihiro Shimizu |
890ddd |
if (values.randomy_ctrl_val)
|
|
Toshihiro Shimizu |
890ddd |
smswingy = values.randomy_val.first + randomyreference * (ranges.randomy_range);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
smswingy = values.randomy_val.first + random.getFloat() * (ranges.randomy_range);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (changesigna <= 0) {
|
|
Toshihiro Shimizu |
890ddd |
signa *= -1;
|
|
Toshihiro Shimizu |
890ddd |
changesigna = abs((int)(values.rotswing_val.first) + (int)(random.getFloat() * (ranges.rotswing_range)));
|
|
Toshihiro Shimizu |
890ddd |
if (values.rotswingmode_val == ParticlesFx::SWING_SMOOTH) {
|
|
Toshihiro Shimizu |
890ddd |
smperioda = changesigna;
|
|
Toshihiro Shimizu |
890ddd |
smswinga = values.rotsca_val.first + random.getFloat() * (ranges.rotsca_range);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*-----------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
void Particle::update_Scale(const particles_values &values,
|
|
Toshihiro Shimizu |
890ddd |
const particles_ranges &ranges, double scalereference,
|
|
Toshihiro Shimizu |
890ddd |
double scalestepreference)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double scalestep;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (values.scale_ctrl_val && values.scale_ctrl_all_val)
|
|
Toshihiro Shimizu |
890ddd |
scale = values.scale_val.first + (ranges.scale_range) * scalereference;
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
if (values.scalestep_ctrl_val)
|
|
Toshihiro Shimizu |
890ddd |
scalestep = values.scalestep_val.first + (ranges.scalestep_range) * scalestepreference;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
scalestep = values.scalestep_val.first + (ranges.scalestep_range) * random.getFloat();
|
|
Toshihiro Shimizu |
890ddd |
if (scalestep)
|
|
Toshihiro Shimizu |
890ddd |
scale += scalestep;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (scale < 0.001)
|
|
Toshihiro Shimizu |
890ddd |
scale = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*-----------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
void Particle::get_image_reference(TTile *ctrl, const particles_values &values,
|
|
Toshihiro Shimizu |
890ddd |
double &imagereference, int type)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRaster32P raster32 = ctrl->getRaster();
|
|
Toshihiro Shimizu |
890ddd |
TPointD tmp(x, y);
|
|
Toshihiro Shimizu |
890ddd |
tmp -= ctrl->m_pos;
|
|
Toshihiro Shimizu |
890ddd |
imagereference = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
raster32->lock();
|
|
Toshihiro Shimizu |
890ddd |
switch (type) {
|
|
Toshihiro Shimizu |
890ddd |
case ParticlesFx::GRAY_REF:
|
|
Toshihiro Shimizu |
890ddd |
if (raster32 && tmp.x >= 0 && tmp.x < raster32->getLx() && tmp.y >= 0 && troundp(tmp.y) < raster32->getLy()) {
|
|
Toshihiro Shimizu |
890ddd |
TPixel32 pix = raster32->pixels(troundp(tmp.y))[(int)tmp.x];
|
|
Toshihiro Shimizu |
890ddd |
imagereference = TPixelGR8::from(pix).value / (double)TPixelGR8::maxChannelValue;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
CASE ParticlesFx::H_REF : if (raster32 && tmp.x >= 0 && tmp.x < raster32->getLx() && tmp.y >= 0 && tround(tmp.y) < raster32->getLy())
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double aux = (double)TPixel32::maxChannelValue;
|
|
Toshihiro Shimizu |
890ddd |
double h, s, v;
|
|
Toshihiro Shimizu |
890ddd |
TPixel32 pix = raster32->pixels(troundp(tmp.y))[(int)tmp.x];
|
|
Toshihiro Shimizu |
890ddd |
OLDRGB2HSV(pix.r / aux, pix.g / aux, pix.b / aux, &h, &s, &v);
|
|
Toshihiro Shimizu |
890ddd |
imagereference = h / 360.0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
raster32->unlock();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*-----------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
void Particle::get_image_gravity(TTile *ctrl1, const particles_values &values,
|
|
Toshihiro Shimizu |
890ddd |
float &gx, float &gy)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRaster32P raster32 = ctrl1->getRaster();
|
|
Toshihiro Shimizu |
890ddd |
TPointD tmp(x, y);
|
|
Toshihiro Shimizu |
890ddd |
tmp -= ctrl1->m_pos;
|
|
Toshihiro Shimizu |
890ddd |
int radius = 4;
|
|
Toshihiro Shimizu |
890ddd |
gx = 0;
|
|
Toshihiro Shimizu |
890ddd |
gy = 0;
|
|
Toshihiro Shimizu |
890ddd |
int i;
|
|
Toshihiro Shimizu |
890ddd |
raster32->lock();
|
|
Toshihiro Shimizu |
890ddd |
//#define OLDSTUFF
|
|
Toshihiro Shimizu |
890ddd |
#ifdef OLDSTUFF
|
|
Toshihiro Shimizu |
890ddd |
if (!values.gravity_radius_val) {
|
|
Toshihiro Shimizu |
890ddd |
radius = 4;
|
|
Toshihiro Shimizu |
890ddd |
if (raster32 && tmp.x >= radius && tmp.x < raster32->getLx() - radius && tmp.y >= radius && tmp.y < raster32->getLy() - radius) {
|
|
Toshihiro Shimizu |
890ddd |
TPixel32 *pix = &(raster32->pixels(troundp(tmp.y))[(int)tmp.x]);
|
|
Toshihiro Shimizu |
890ddd |
double norm = 1 / ((double)TPixelGR8::maxChannelValue);
|
|
Toshihiro Shimizu |
890ddd |
for (i = 1; i < radius; i++) {
|
|
Toshihiro Shimizu |
890ddd |
gx += TPixelGR8::from(*(pix + i)).value;
|
|
Toshihiro Shimizu |
890ddd |
gx -= TPixelGR8::from(*(pix - i)).value;
|
|
Toshihiro Shimizu |
890ddd |
gy += TPixelGR8::from(*(pix + raster32->getWrap() * i)).value;
|
|
Toshihiro Shimizu |
890ddd |
gy -= TPixelGR8::from(*(pix - raster32->getWrap() * i)).value;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
gx = gx * norm;
|
|
Toshihiro Shimizu |
890ddd |
gy = gy * norm;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
radius = 2;
|
|
Toshihiro Shimizu |
890ddd |
if (raster32 && tmp.x >= radius && tmp.x < raster32->getLx() - radius && tmp.y >= radius && tmp.y < raster32->getLy() - radius) {
|
|
Toshihiro Shimizu |
890ddd |
TPixel32 *pix = &(raster32->pixels(troundp(tmp.y))[(int)tmp.x]);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
gx += 2 * TPixelGR8::from(*(pix + 1)).value;
|
|
Toshihiro Shimizu |
890ddd |
gx += TPixelGR8::from(*(pix + 1 + raster32->getWrap() * 1)).value;
|
|
Toshihiro Shimizu |
890ddd |
gx += TPixelGR8::from(*(pix + 1 - raster32->getWrap() * 1)).value;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
gx -= 2 * TPixelGR8::from(*(pix - 1)).value;
|
|
Toshihiro Shimizu |
890ddd |
gx -= TPixelGR8::from(*(pix - 1 + raster32->getWrap() * 1)).value;
|
|
Toshihiro Shimizu |
890ddd |
gx -= TPixelGR8::from(*(pix - 1 - raster32->getWrap() * 1)).value;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
gy += 2 * TPixelGR8::from(*(pix + raster32->getWrap() * 1)).value;
|
|
Toshihiro Shimizu |
890ddd |
gy += TPixelGR8::from(*(pix + raster32->getWrap() * 1 + 1)).value;
|
|
Toshihiro Shimizu |
890ddd |
gy += TPixelGR8::from(*(pix + raster32->getWrap() * 1 - 1)).value;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
gy -= 2 * TPixelGR8::from(*(pix - raster32->getWrap() * 1)).value;
|
|
Toshihiro Shimizu |
890ddd |
gy -= TPixelGR8::from(*(pix - raster32->getWrap() * 1 + 1)).value;
|
|
Toshihiro Shimizu |
890ddd |
gy -= TPixelGR8::from(*(pix - raster32->getWrap() * 1 - 1)).value;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double norm = sqrt(gx * gx + gy * gy);
|
|
Toshihiro Shimizu |
890ddd |
if (norm) {
|
|
Toshihiro Shimizu |
890ddd |
double inorm = 0.1 / norm;
|
|
Toshihiro Shimizu |
890ddd |
gx = gx * inorm;
|
|
Toshihiro Shimizu |
890ddd |
gy = gy * inorm;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#ifdef OLDSTUFF
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
raster32->unlock();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*-----------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
void Particle::get_image_reference(TTile *ctrl1, const particles_values &values,
|
|
Toshihiro Shimizu |
890ddd |
TPixel32 &color)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRaster32P raster32 = ctrl1->getRaster();
|
|
Toshihiro Shimizu |
890ddd |
TPointD tmp(x, y);
|
|
Toshihiro Shimizu |
890ddd |
tmp -= ctrl1->m_pos;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (raster32 && tmp.x >= 0 && tmp.x < raster32->getLx() && tmp.y >= 0 && troundp(tmp.y) < raster32->getLy()) {
|
|
Toshihiro Shimizu |
890ddd |
color = raster32->pixels(troundp(tmp.y))[(int)tmp.x];
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*-- 参照画像のBBoxの外側では、粒子を透明にする --*/
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
color = TPixel32::Transparent;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*-----------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
void Particle::spread_color(TPixel32 &color, double range)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int randcol = (int)((random.getFloat() - 0.5) * range);
|
|
Toshihiro Shimizu |
890ddd |
int r = color.r + randcol;
|
|
Toshihiro Shimizu |
890ddd |
int g = color.g + randcol;
|
|
Toshihiro Shimizu |
890ddd |
int b = color.b + randcol;
|
|
Toshihiro Shimizu |
890ddd |
color.r = (UCHAR)tcrop<tint32>(r, (TINT32)0, (TINT32)255);</tint32>
|
|
Toshihiro Shimizu |
890ddd |
color.g = (UCHAR)tcrop<tint32>(g, (TINT32)0, (TINT32)255);</tint32>
|
|
Toshihiro Shimizu |
890ddd |
color.b = (UCHAR)tcrop<tint32>(b, (TINT32)0, (TINT32)255);</tint32>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*-----------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void Particle::move(map<int, *="" ttile=""> porttiles, const particles_values &values, const particles_ranges &ranges,</int,>
|
|
Toshihiro Shimizu |
890ddd |
float windx,
|
|
Toshihiro Shimizu |
890ddd |
float windy, float xgravity, float ygravity,
|
|
Toshihiro Shimizu |
890ddd |
float dpicorr, int lastframe)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
struct pos_dummy dummy;
|
|
Toshihiro Shimizu |
890ddd |
float frictx, fricty;
|
|
Toshihiro Shimizu |
890ddd |
//int time;
|
|
Toshihiro Shimizu |
890ddd |
map<int, double=""> imagereferences;</int,>
|
|
Toshihiro Shimizu |
890ddd |
dummy.x = dummy.y = dummy.a = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
frictx = fricty = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double frictreference = 1;
|
|
Toshihiro Shimizu |
890ddd |
double scalereference = 0;
|
|
Toshihiro Shimizu |
890ddd |
double scalestepreference = 0;
|
|
Toshihiro Shimizu |
890ddd |
double randomxreference = 1;
|
|
Toshihiro Shimizu |
890ddd |
double randomyreference = 1;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (std::map<int, *="" ttile="">::iterator it = porttiles.begin(); it != porttiles.end(); ++it) {</int,>
|
|
Toshihiro Shimizu |
890ddd |
if (
|
|
Toshihiro Shimizu |
890ddd |
(values.friction_ctrl_val == it->first ||
|
|
Toshihiro Shimizu |
890ddd |
values.scale_ctrl_val == it->first ||
|
|
Toshihiro Shimizu |
890ddd |
values.scalestep_ctrl_val == it->first ||
|
|
Toshihiro Shimizu |
890ddd |
values.randomx_ctrl_val == it->first ||
|
|
Toshihiro Shimizu |
890ddd |
values.randomy_ctrl_val == it->first) &&
|
|
Toshihiro Shimizu |
890ddd |
it->second->getRaster()) {
|
|
Toshihiro Shimizu |
890ddd |
double tmpvalue;
|
|
Toshihiro Shimizu |
890ddd |
get_image_reference(it->second, values, tmpvalue, ParticlesFx::GRAY_REF);
|
|
Toshihiro Shimizu |
890ddd |
imagereferences[it->first] = tmpvalue;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (values.randomx_ctrl_val)
|
|
Toshihiro Shimizu |
890ddd |
randomxreference = imagereferences[values.randomx_ctrl_val];
|
|
Toshihiro Shimizu |
890ddd |
if (values.randomy_ctrl_val)
|
|
Toshihiro Shimizu |
890ddd |
randomyreference = imagereferences[values.randomy_ctrl_val];
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (check_Swing(values))
|
|
Toshihiro Shimizu |
890ddd |
update_Swing(values, ranges, dummy, randomxreference, randomyreference);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (values.friction_ctrl_val)
|
|
Toshihiro Shimizu |
890ddd |
frictreference = imagereferences[values.friction_ctrl_val];
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (values.scale_ctrl_val)
|
|
Toshihiro Shimizu |
890ddd |
scalereference = imagereferences[values.scale_ctrl_val];
|
|
Toshihiro Shimizu |
890ddd |
if (values.scalestep_ctrl_val)
|
|
Toshihiro Shimizu |
890ddd |
scalestepreference = imagereferences[values.scalestep_ctrl_val];
|
|
Toshihiro Shimizu |
890ddd |
lifetime--;
|
|
Toshihiro Shimizu |
890ddd |
oldx = x;
|
|
Toshihiro Shimizu |
890ddd |
oldy = y;
|
|
Toshihiro Shimizu |
890ddd |
//time=genlifetime-lifetime-1;
|
|
Toshihiro Shimizu |
890ddd |
//if(time<0) time=0;
|
|
Toshihiro Shimizu |
890ddd |
if (values.gravity_ctrl_val && (porttiles.find(values.gravity_ctrl_val) != porttiles.end())) {
|
|
Toshihiro Shimizu |
890ddd |
get_image_gravity(porttiles[values.gravity_ctrl_val], values, xgravity, ygravity);
|
|
Toshihiro Shimizu |
890ddd |
xgravity *= values.gravity_val;
|
|
Toshihiro Shimizu |
890ddd |
ygravity *= values.gravity_val;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (values.friction_val * frictreference) {
|
|
Toshihiro Shimizu |
890ddd |
if (vx) {
|
|
Toshihiro Shimizu |
890ddd |
frictx = vx * (1 + values.friction_val * frictreference) + (10 / vx) * values.friction_val * frictreference;
|
|
Toshihiro Shimizu |
890ddd |
if ((frictx / vx) < 0)
|
|
Toshihiro Shimizu |
890ddd |
frictx = 0;
|
|
Toshihiro Shimizu |
890ddd |
vx = frictx;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (!frictx && fabs(values.friction_val * frictreference * 10) > fabs(xgravity)) {
|
|
Toshihiro Shimizu |
890ddd |
xgravity = 0;
|
|
Toshihiro Shimizu |
890ddd |
dummy.x = 0;
|
|
Toshihiro Shimizu |
890ddd |
dummy.a = 0;
|
|
Toshihiro Shimizu |
890ddd |
windx = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (vy) {
|
|
Toshihiro Shimizu |
890ddd |
fricty = vy * (1 + values.friction_val * frictreference) + (10 / vy) * values.friction_val * frictreference;
|
|
Toshihiro Shimizu |
890ddd |
if ((fricty / vy) < 0)
|
|
Toshihiro Shimizu |
890ddd |
fricty = 0;
|
|
Toshihiro Shimizu |
890ddd |
vy = fricty;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (!fricty && fabs(values.friction_val * frictreference * 10) > fabs(ygravity)) {
|
|
Toshihiro Shimizu |
890ddd |
ygravity = 0;
|
|
Toshihiro Shimizu |
890ddd |
dummy.y = 0;
|
|
Toshihiro Shimizu |
890ddd |
dummy.a = 0;
|
|
Toshihiro Shimizu |
890ddd |
windy = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
vx += xgravity * mass;
|
|
Toshihiro Shimizu |
890ddd |
vy += ygravity * mass;
|
|
Toshihiro Shimizu |
890ddd |
if (values.speedscale_val) {
|
|
Toshihiro Shimizu |
890ddd |
float scalecorr = scale / dpicorr;
|
|
Toshihiro Shimizu |
890ddd |
x += (vx + windx + dummy.x) * scalecorr;
|
|
Toshihiro Shimizu |
890ddd |
y += (vy + windy + dummy.y) * scalecorr;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
x += vx + windx + dummy.x;
|
|
Toshihiro Shimizu |
890ddd |
y += vy + windy + dummy.y;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
angle -= values.rotspeed_val + dummy.a;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!(lifetime % values.step_val) || (frame < 0)) {
|
|
Toshihiro Shimizu |
890ddd |
update_Animation(values, 0, lastframe, 0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
update_Scale(values, ranges, scalereference, scalestepreference);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*-----------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
double Particle::set_Opacity(std::map<int, *="" ttile=""> porttiles,</int,>
|
|
Toshihiro Shimizu |
890ddd |
const particles_values &values, float opacity_range, double dist_frame)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double opacity = 1.0, trailcorr;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (values.fadein_val && (genlifetime - lifetime) < values.fadein_val)
|
|
Toshihiro Shimizu |
890ddd |
opacity *= (genlifetime - lifetime - 1) / (values.fadein_val);
|
|
Toshihiro Shimizu |
890ddd |
if (values.fadeout_val && lifetime < values.fadeout_val)
|
|
Toshihiro Shimizu |
890ddd |
opacity *= (lifetime) / values.fadeout_val;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (trail) {
|
|
Toshihiro Shimizu |
890ddd |
trailcorr = values.trailopacity_val.first + (values.trailopacity_val.second - values.trailopacity_val.first) * (1 - (dist_frame) / trail);
|
|
Toshihiro Shimizu |
890ddd |
opacity *= trailcorr;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (values.opacity_ctrl_val && (porttiles.find(values.opacity_ctrl_val) != porttiles.end())) {
|
|
Toshihiro Shimizu |
890ddd |
double opacityreference = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
get_image_reference(porttiles[values.opacity_ctrl_val], values, opacityreference, ParticlesFx::GRAY_REF);
|
|
Toshihiro Shimizu |
890ddd |
opacity = values.opacity_val.first + (opacity_range)*opacityreference * opacity;
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
opacity = values.opacity_val.first + opacity_range * opacity;
|
|
Toshihiro Shimizu |
890ddd |
return opacity;
|
|
Toshihiro Shimizu |
890ddd |
}
|