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