Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
// Iwa_Particle for Marnie
Toshihiro Shimizu 890ddd
// based on ParticlesFx by Digital Video
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tfxparam.h"
Toshihiro Shimizu 890ddd
#include "trop.h"
Toshihiro Shimizu 890ddd
#include "iwa_particles.h"
Toshihiro Shimizu 890ddd
#include "iwa_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
Shinya Kitaoka 120a6e
void Iwa_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 Iwa_TiledParticlesFx::ANIM_CYCLE:
Shinya Kitaoka 120a6e
  case Iwa_TiledParticlesFx::ANIM_S_CYCLE:
Shinya Kitaoka 120a6e
    animswing = 0; /*frame <0 perche' c'e' il preroll dialmeno un frame*/
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case Iwa_TiledParticlesFx::ANIM_SR_CYCLE:
Shinya Kitaoka 120a6e
    animswing = random.getFloat() > 0.5 ? 1 : 0;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
Iwa_Particle::Iwa_Particle(
Shinya Kitaoka 120a6e
    int g_lifetime, int seed, std::map<int, *="" ttile=""> porttiles,</int,>
Shinya Kitaoka 120a6e
    const particles_values &values, const particles_ranges &ranges, int howmany,
Shinya Kitaoka 120a6e
    int first, int level, int last, float posx, float posy,
Shinya Kitaoka 120a6e
    bool isUpward,       /*- 初期向き -*/
Shinya Kitaoka 120a6e
    int initSourceFrame) /*- Level内の初期フレーム位置 -*/
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 120a6e
  double random_s_a_range, random_speed;
Shinya Kitaoka 120a6e
  std::map<int, float=""> imagereferences;</int,>
Shinya Kitaoka 120a6e
  random                 = TRandom(seed);
Shinya Kitaoka 120a6e
  float randomxreference = 0.0;
Shinya Kitaoka 120a6e
  float randomyreference = 0.0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*- ここで、出発時の素材フレームが決定するので、ParticleOriginに渡す -*/
Shinya Kitaoka 120a6e
  create_Animation(values, 0, last);
Shinya Kitaoka 120a6e
  frame = initSourceFrame;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  this->level = level;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  x = posx;
Shinya Kitaoka 120a6e
  y = posy;
Shinya Kitaoka 120a6e
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 ||
shun-iwasawa 63f747
         values.scale_ctrl_val == it->first ||
shun-iwasawa 63f747
         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
      float tmpvalue;
Shinya Kitaoka 120a6e
      get_image_reference(it->second, values, tmpvalue,
Shinya Kitaoka 120a6e
                          Iwa_TiledParticlesFx::GRAY_REF);
Shinya Kitaoka 120a6e
      imagereferences[it->first] = tmpvalue;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*- 寿命にControlが刺さっている場合は、その値に合わせて寿命を減ずる -*/
Shinya Kitaoka 120a6e
  if (values.lifetime_ctrl_val) {
Shinya Kitaoka 120a6e
    float 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
  genlifetime = lifetime;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*- 粒子の初期速度を得る -*/
Shinya Kitaoka 120a6e
  if (values.speed_ctrl_val &&
Shinya Kitaoka 120a6e
      (porttiles.find(values.speed_ctrl_val) != porttiles.end())) {
Shinya Kitaoka 120a6e
    float 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
  /*- 粒子の初期移動方向を得る -*/
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
      float 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が無ければランダム -*/
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
  /*- 移動方向から速度のX,Y成分を得る -*/
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
Shinya Kitaoka 120a6e
  trail =
Shinya Kitaoka 120a6e
      (int)(values.trail_val.first + (ranges.trail_range) * random.getFloat());
Shinya Kitaoka 120a6e
  oldx = 0;
Shinya Kitaoka 120a6e
  oldy = 0;
Shinya Kitaoka 120a6e
  /*- 質量を指定(動きにくさ) -*/
Shinya Kitaoka 120a6e
  mass = values.mass_val.first + (ranges.mass_range) * random.getFloat();
Shinya Kitaoka 120a6e
  /*- サイズを得る -*/
Shinya Kitaoka 120a6e
  if (values.scale_ctrl_val &&
Shinya Kitaoka 120a6e
      (porttiles.find(values.scale_ctrl_val) != porttiles.end())) {
Shinya Kitaoka 120a6e
    float scalereference = 0.0f;
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
    /*- ONのとき、かつ、ScaleにControlが無い場合、
Shinya Kitaoka 120a6e
            粒子サイズが小さいほど(遠くにあるので)多く分布するようになる。 -*/
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
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
    float anglereference = 0.0f;
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
  // 140212 初期粒子向き
Shinya Kitaoka 120a6e
  if (!isUpward) angle += 180.0f;
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
  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.001f) scale = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*- ひらひらした動き -*/
Shinya Kitaoka 120a6e
  if (values.flap_ctrl_val &&
Shinya Kitaoka 120a6e
      (porttiles.find(values.flap_ctrl_val) != porttiles.end())) {
Shinya Kitaoka 120a6e
    //*- 参照画像のGradientを得る関数を利用して角度を得る -*/
Shinya Kitaoka 120a6e
    float dir_x, dir_y;
Shinya Kitaoka 120a6e
    float norm;
Shinya Kitaoka 120a6e
    norm = get_image_gravity(porttiles[values.flap_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
      flap_theta = 0.0f;
Shinya Kitaoka 120a6e
      flap_phi   = 0.0f;
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      flap_theta = atan2f(dir_y, dir_x) * 180.0f / 3.14159f;
Shinya Kitaoka 120a6e
      flap_phi   = values.iw_flap_velocity_val * norm / mass;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    flap_theta = 0.0f;
Shinya Kitaoka 120a6e
    flap_phi   = 0.0f;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  initial_x     = x;
Shinya Kitaoka 120a6e
  initial_y     = y;
Shinya Kitaoka 120a6e
  initial_angle = angle;
Shinya Kitaoka 120a6e
  initial_scale = scale;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  curlx = 0.0f;
Shinya Kitaoka 120a6e
  curly = 0.0f;
Shinya Kitaoka 120a6e
  curlz = random.getFloat();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int Iwa_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 Iwa_Particle::create_Swing(const particles_values &values,
Shinya Kitaoka 120a6e
                                const particles_ranges &ranges,
Shinya Kitaoka 120a6e
                                double randomxreference,
Shinya Kitaoka 120a6e
                                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 == Iwa_TiledParticlesFx::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 == Iwa_TiledParticlesFx::SWING_SMOOTH) {
shun-iwasawa 63f747
    smswinga  = abs((int)(values.rotsca_val.first +
Shinya Kitaoka 120a6e
                         random.getFloat() * (ranges.rotsca_range)));
Shinya Kitaoka 120a6e
    smperioda = changesigna;
Shinya Kitaoka 120a6e
  }
otakuto e1f79e
  signx = random.getBool() ? 1 : -1;
otakuto e1f79e
  signy = random.getBool() ? 1 : -1;
otakuto e1f79e
  signa = random.getBool() ? 1 : -1;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*-----------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void Iwa_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
  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
shun-iwasawa 63f747
      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
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
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
Toshihiro Shimizu 890ddd
/*- modify_colors_and_opacityから呼ばれる。
Shinya Kitaoka 120a6e
        lifetimeが粒子の現在の年齢。 gencol/fincol/foutcolから色を決める -*/
Shinya Kitaoka 120a6e
void Iwa_Particle::modify_colors(TPixel32 &color, double &intensity) {
Shinya Kitaoka 120a6e
  float percent = 0;
Shinya Kitaoka 120a6e
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     = 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
Toshihiro Shimizu 890ddd
/*- do_render から呼ばれる。各粒子の描画の直前に色を決めるところ -*/
Toshihiro Shimizu 890ddd
void Iwa_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
  }
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 Iwa_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 Iwa_TiledParticlesFx::ANIM_RANDOM:
Shinya Kitaoka 120a6e
    frame = (int)(first + random.getFloat() * (last - first));
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case Iwa_TiledParticlesFx::ANIM_R_CYCLE:
Shinya Kitaoka 120a6e
  case Iwa_TiledParticlesFx::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
  case Iwa_TiledParticlesFx::ANIM_S_CYCLE:
Shinya Kitaoka 120a6e
  case Iwa_TiledParticlesFx::ANIM_SR_CYCLE:
Shinya Kitaoka 120a6e
    if (!keep || frame != keep - 1) {
Shinya Kitaoka 120a6e
      if (!animswing && frame < last - 1) {
shun-iwasawa 63f747
        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 Iwa_Particle::update_Swing(const particles_values &values,
Shinya Kitaoka 120a6e
                                const particles_ranges &ranges,
Shinya Kitaoka 120a6e
                                struct pos_dummy &dummy,
Shinya Kitaoka 120a6e
                                double randomxreference,
Shinya Kitaoka 120a6e
                                double randomyreference) {
Shinya Kitaoka 120a6e
  if (values.swingmode_val == Iwa_TiledParticlesFx::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 == Iwa_TiledParticlesFx::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 == Iwa_TiledParticlesFx::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 == Iwa_TiledParticlesFx::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 == Iwa_TiledParticlesFx::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 Iwa_Particle::update_Scale(const particles_values &values,
Shinya Kitaoka 120a6e
                                const particles_ranges &ranges,
Shinya Kitaoka 120a6e
                                double scalereference,
Shinya Kitaoka 120a6e
                                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
/*-----------------------------------------------------------------*/
Shinya Kitaoka 120a6e
void Iwa_Particle::get_image_reference(TTile *ctrl,
Shinya Kitaoka 120a6e
                                       const particles_values &values,
Shinya Kitaoka 120a6e
                                       float &imagereference, int type) {
Shinya Kitaoka 120a6e
  TRaster32P raster32 = ctrl->getRaster();
Shinya Kitaoka 120a6e
  TRaster64P raster64 = 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
Shinya Kitaoka 120a6e
  if (raster32)
Shinya Kitaoka 120a6e
    raster32->lock();
Shinya Kitaoka 120a6e
  else if (raster64)
Shinya Kitaoka 120a6e
    raster64->lock();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  switch (type) {
Shinya Kitaoka 120a6e
  case Iwa_TiledParticlesFx::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 / (float)TPixelGR8::maxChannelValue;
Shinya Kitaoka 120a6e
    } else if (raster64 && tmp.x >= 0 && tmp.x < raster64->getLx() &&
Shinya Kitaoka 120a6e
               tmp.y >= 0 && troundp(tmp.y) < raster64->getLy()) {
Shinya Kitaoka 120a6e
      TPixel64 pix = raster64->pixels(troundp(tmp.y))[(int)tmp.x];
Shinya Kitaoka 120a6e
      imagereference =
Shinya Kitaoka 120a6e
          TPixelGR16::from(pix).value / (float)TPixelGR16::maxChannelValue;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case Iwa_TiledParticlesFx::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
      float aux = (float)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 = (float)h / 360.0f;
Shinya Kitaoka 120a6e
    } else if (raster64 && tmp.x >= 0 && tmp.x < raster64->getLx() &&
Shinya Kitaoka 120a6e
               tmp.y >= 0 && tround(tmp.y) < raster64->getLy()) {
Shinya Kitaoka 120a6e
      float aux = (float)TPixel64::maxChannelValue;
Shinya Kitaoka 120a6e
      double h, s, v;
Shinya Kitaoka 120a6e
      TPixel64 pix = raster64->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 = (float)h / 360.0f;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (raster32)
Shinya Kitaoka 120a6e
    raster32->unlock();
Shinya Kitaoka 120a6e
  else if (raster64)
Shinya Kitaoka 120a6e
    raster64->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*-----------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
/*- ベクタ長を返す -*/
Shinya Kitaoka 120a6e
float Iwa_Particle::get_image_gravity(TTile *ctrl1,
Shinya Kitaoka 120a6e
                                      const particles_values &values, float &gx,
Shinya Kitaoka 120a6e
                                      float &gy) {
Shinya Kitaoka 120a6e
  TRaster32P raster32 = ctrl1->getRaster();
Shinya Kitaoka 120a6e
  TRaster64P raster64 = ctrl1->getRaster();
Shinya Kitaoka 120a6e
  TPointD tmp(x, y);
Shinya Kitaoka 120a6e
  tmp -= ctrl1->m_pos;
Shinya Kitaoka 120a6e
  int radius = 2;
Shinya Kitaoka 120a6e
  gx         = 0;
Shinya Kitaoka 120a6e
  gy         = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  float norm = 1.0f;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (raster32) {
Shinya Kitaoka 120a6e
    raster32->lock();
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
      norm = sqrtf(gx * gx + gy * gy);
Shinya Kitaoka 120a6e
      if (norm) {
Shinya Kitaoka 120a6e
        float inorm = 0.1f / norm;
Shinya Kitaoka 120a6e
        gx          = gx * inorm;
Shinya Kitaoka 120a6e
        gy          = gy * inorm;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    raster32->unlock();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    norm /= (float)(TPixelGR8::maxChannelValue);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  } else if (raster64) {
Shinya Kitaoka 120a6e
    raster64->lock();
Shinya Kitaoka 120a6e
    if (raster64 && tmp.x >= radius && tmp.x < raster64->getLx() - radius &&
Shinya Kitaoka 120a6e
        tmp.y >= radius && tmp.y < raster64->getLy() - radius) {
Shinya Kitaoka 120a6e
      TPixel64 *pix = &(raster64->pixels(troundp(tmp.y))[(int)tmp.x]);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      gx += 2 * TPixelGR16::from(*(pix + 1)).value;
Shinya Kitaoka 120a6e
      gx += TPixelGR16::from(*(pix + 1 + raster64->getWrap() * 1)).value;
Shinya Kitaoka 120a6e
      gx += TPixelGR16::from(*(pix + 1 - raster64->getWrap() * 1)).value;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      gx -= 2 * TPixelGR16::from(*(pix - 1)).value;
Shinya Kitaoka 120a6e
      gx -= TPixelGR16::from(*(pix - 1 + raster64->getWrap() * 1)).value;
Shinya Kitaoka 120a6e
      gx -= TPixelGR16::from(*(pix - 1 - raster64->getWrap() * 1)).value;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      gy += 2 * TPixelGR16::from(*(pix + raster64->getWrap() * 1)).value;
Shinya Kitaoka 120a6e
      gy += TPixelGR16::from(*(pix + raster64->getWrap() * 1 + 1)).value;
Shinya Kitaoka 120a6e
      gy += TPixelGR16::from(*(pix + raster64->getWrap() * 1 - 1)).value;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      gy -= 2 * TPixelGR16::from(*(pix - raster64->getWrap() * 1)).value;
Shinya Kitaoka 120a6e
      gy -= TPixelGR16::from(*(pix - raster64->getWrap() * 1 + 1)).value;
Shinya Kitaoka 120a6e
      gy -= TPixelGR16::from(*(pix - raster64->getWrap() * 1 - 1)).value;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      norm = sqrtf(gx * gx + gy * gy);
Shinya Kitaoka 120a6e
      if (norm) {
Shinya Kitaoka 120a6e
        float inorm = 0.1 / norm;
Shinya Kitaoka 120a6e
        gx          = gx * inorm;
Shinya Kitaoka 120a6e
        gy          = gy * inorm;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    raster64->unlock();
Shinya Kitaoka 120a6e
    norm /= (float)(TPixelGR16::maxChannelValue);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return norm;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*-----------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool Iwa_Particle::get_image_curl(TTile *ctrl1, const particles_values &values,
Shinya Kitaoka 120a6e
                                  float &cx, float &cy) {
Shinya Kitaoka 120a6e
  TRaster32P raster32 = ctrl1->getRaster();
Shinya Kitaoka 120a6e
  TRaster64P raster64 = 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
  cx         = 0;
Shinya Kitaoka 120a6e
  cy         = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool ret;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (raster32) {
Shinya Kitaoka 120a6e
    raster32->lock();
Shinya Kitaoka 120a6e
    if (raster32 && tmp.x >= radius + 1 &&
Shinya Kitaoka 120a6e
        tmp.x < raster32->getLx() - radius - 1 && tmp.y >= radius + 1 &&
Shinya Kitaoka 120a6e
        tmp.y < raster32->getLy() - radius - 1) {
Shinya Kitaoka 120a6e
      TPixel32 *pix = &(raster32->pixels(troundp(tmp.y))[(int)tmp.x]);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      cx = -TPixelGR8::from(*(pix + radius * raster32->getWrap())).value +
Shinya Kitaoka 120a6e
           TPixelGR8::from(*(pix - radius * raster32->getWrap())).value;
Shinya Kitaoka 120a6e
      cy = TPixelGR8::from(*(pix + radius)).value -
Shinya Kitaoka 120a6e
           TPixelGR8::from(*(pix - radius)).value;
Shinya Kitaoka 120a6e
      ret = true;
Shinya Kitaoka 120a6e
    } else
Shinya Kitaoka 120a6e
      ret = false;
Shinya Kitaoka 120a6e
    raster32->unlock();
Shinya Kitaoka 120a6e
  } else if (raster64) {
Shinya Kitaoka 120a6e
    raster64->lock();
Shinya Kitaoka 120a6e
    if (raster64 && tmp.x >= radius + 1 &&
Shinya Kitaoka 120a6e
        tmp.x < raster64->getLx() - radius - 1 && tmp.y >= radius + 1 &&
Shinya Kitaoka 120a6e
        tmp.y < raster64->getLy() - radius - 1) {
Shinya Kitaoka 120a6e
      TPixel64 *pix = &(raster64->pixels(troundp(tmp.y))[(int)tmp.x]);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      cx = -TPixelGR16::from(*(pix + radius * raster64->getWrap())).value +
Shinya Kitaoka 120a6e
           TPixelGR16::from(*(pix - radius * raster64->getWrap())).value;
Shinya Kitaoka 120a6e
      cy = TPixelGR16::from(*(pix + radius)).value -
Shinya Kitaoka 120a6e
           TPixelGR16::from(*(pix - radius)).value;
Shinya Kitaoka 120a6e
      cx /= 256.0f;
Shinya Kitaoka 120a6e
      cy /= 256.0f;
Shinya Kitaoka 120a6e
      ret = true;
Shinya Kitaoka 120a6e
    } else
Shinya Kitaoka 120a6e
      ret = false;
Shinya Kitaoka 120a6e
    raster64->unlock();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return ret;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*-----------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void Iwa_Particle::get_image_reference(TTile *ctrl1,
Shinya Kitaoka 120a6e
                                       const particles_values &values,
Shinya Kitaoka 120a6e
                                       TPixel32 &color) {
Shinya Kitaoka 120a6e
  TRaster32P raster32 = ctrl1->getRaster();
Shinya Kitaoka 120a6e
  TRaster64P raster64 = ctrl1->getRaster();
Shinya Kitaoka 120a6e
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
  } else if (raster64 && tmp.x >= 0 && tmp.x < raster64->getLx() &&
Shinya Kitaoka 120a6e
             tmp.y >= 0 && troundp(tmp.y) < raster64->getLy()) {
Shinya Kitaoka 120a6e
    TPixel64 pix64 = raster64->pixels(troundp(tmp.y))[(int)tmp.x];
Shinya Kitaoka 120a6e
    color = TPixel32((int)pix64.r / 256, (int)pix64.g / 256, (int)pix64.b / 256,
Shinya Kitaoka 120a6e
                     (int)pix64.m / 256);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  /*- 参照画像のBBoxの外側で、粒子の色を透明にする -*/
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    color = TPixel32::Transparent;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*-----------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void Iwa_Particle::get_base_image_texture(TTile *ctrl1,
Shinya Kitaoka 120a6e
                                          const particles_values &values,
Shinya Kitaoka 120a6e
                                          TRasterP texRaster,
Shinya Kitaoka 120a6e
                                          const TRectD &texBBox,
Shinya Kitaoka 120a6e
                                          const TRenderSettings &ri) {
Shinya Kitaoka 120a6e
  /*- ベースの絵を粒子の初期位置にあわせ移動させる -*/
Shinya Kitaoka 120a6e
  TPointD pos(initial_x, initial_y);
Shinya Kitaoka 120a6e
  pos = ri.m_affine * pos;
Shinya Kitaoka 120a6e
  TRotation rotM(-initial_angle);
Shinya Kitaoka 120a6e
  TScale scaleM(1.0);
Shinya Kitaoka 120a6e
  TAffine M = TTranslation(-texBBox.getP00()) * scaleM * rotM *
Shinya Kitaoka 120a6e
              TTranslation(-pos + ctrl1->m_pos);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRaster32P baseRas32 = ctrl1->getRaster();
Shinya Kitaoka 120a6e
  TRaster64P baseRas64 = ctrl1->getRaster();
Shinya Kitaoka 120a6e
  if (baseRas32) {
Shinya Kitaoka 120a6e
    baseRas32->lock();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    /*- 粒子と同サイズのラスタを用意 -*/
Shinya Kitaoka 120a6e
    TRaster32P kirinukiBaseRas(texRaster->getSize());
Shinya Kitaoka 120a6e
    kirinukiBaseRas->lock();
Shinya Kitaoka 120a6e
    TRaster32P texRas32 = texRaster;
Shinya Kitaoka 120a6e
    texRas32->lock();
Shinya Kitaoka 120a6e
    /*- そこにquickput -*/
Shinya Kitaoka 120a6e
    TRop::quickPut(kirinukiBaseRas, baseRas32, M);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    /*- 粒子のRGBをベース絵で置換していく -*/
Shinya Kitaoka 120a6e
    for (int j = 0; j < texRaster->getLy(); j++) {
Shinya Kitaoka 120a6e
      TPixel32 *pix     = texRas32->pixels(j);
Shinya Kitaoka 120a6e
      TPixel32 *endPix  = pix + texRas32->getLx();
Shinya Kitaoka 120a6e
      TPixel32 *basePix = kirinukiBaseRas->pixels(j);
Shinya Kitaoka 120a6e
      while (pix < endPix) {
Shinya Kitaoka 120a6e
        double factor = pix->m / 255.0;
Shinya Kitaoka 120a6e
        pix->r        = (UCHAR)(factor * basePix->r);
Shinya Kitaoka 120a6e
        pix->g        = (UCHAR)(factor * basePix->g);
Shinya Kitaoka 120a6e
        pix->b        = (UCHAR)(factor * basePix->b);
Shinya Kitaoka 120a6e
        pix->m        = (UCHAR)(factor * basePix->m);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        ++pix;
Shinya Kitaoka 120a6e
        ++basePix;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    kirinukiBaseRas->unlock();
Shinya Kitaoka 120a6e
    baseRas32->unlock();
Shinya Kitaoka 120a6e
    texRas32->unlock();
Shinya Kitaoka 120a6e
  } else if (baseRas64) {
Shinya Kitaoka 120a6e
    baseRas64->lock();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    /*- 粒子と同サイズのラスタを用意 -*/
Shinya Kitaoka 120a6e
    TRaster64P kirinukiBaseRas(texRaster->getSize());
Shinya Kitaoka 120a6e
    kirinukiBaseRas->lock();
Shinya Kitaoka 120a6e
    TRaster64P texRas64 = texRaster;
Shinya Kitaoka 120a6e
    texRas64->lock();
Shinya Kitaoka 120a6e
    /*- そこにquickput -*/
Shinya Kitaoka 120a6e
    TRop::quickPut(kirinukiBaseRas, baseRas64, M);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    /*- 粒子のRGBをベース絵で置換していく -*/
Shinya Kitaoka 120a6e
    for (int j = 0; j < texRaster->getLy(); j++) {
Shinya Kitaoka 120a6e
      TPixel64 *pix     = texRas64->pixels(j);
Shinya Kitaoka 120a6e
      TPixel64 *endPix  = pix + texRas64->getLx();
Shinya Kitaoka 120a6e
      TPixel64 *basePix = kirinukiBaseRas->pixels(j);
Shinya Kitaoka 120a6e
      while (pix < endPix) {
Shinya Kitaoka 120a6e
        double factor = (double)pix->m / (double)TPixel64::maxChannelValue;
Shinya Kitaoka 120a6e
        pix->r        = (TPixel64::Channel)(factor * basePix->r);
Shinya Kitaoka 120a6e
        pix->g        = (TPixel64::Channel)(factor * basePix->g);
Shinya Kitaoka 120a6e
        pix->b        = (TPixel64::Channel)(factor * basePix->b);
Shinya Kitaoka 120a6e
        pix->m        = (TPixel64::Channel)(factor * basePix->m);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        ++pix;
Shinya Kitaoka 120a6e
        ++basePix;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    kirinukiBaseRas->unlock();
Shinya Kitaoka 120a6e
    baseRas64->unlock();
Shinya Kitaoka 120a6e
    texRas64->unlock();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*-----------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void Iwa_Particle::get_base_image_color(TTile *ctrl1,
Shinya Kitaoka 120a6e
                                        const particles_values &values,
Shinya Kitaoka 120a6e
                                        TRasterP texRaster,
Shinya Kitaoka 120a6e
                                        const TRectD &texBBox,
Shinya Kitaoka 120a6e
                                        const TRenderSettings &ri) {
Shinya Kitaoka 120a6e
  /*- まず、色を拾う -*/
Shinya Kitaoka 120a6e
  TPixel32 color;
Shinya Kitaoka 120a6e
  TRaster32P baseRas32 = ctrl1->getRaster();
Shinya Kitaoka 120a6e
  TRaster64P baseRas64 = ctrl1->getRaster();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TPointD tmp(initial_x, initial_y);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  tmp = ri.m_affine * tmp;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  tmp -= ctrl1->m_pos;
Shinya Kitaoka 120a6e
  if (baseRas32 && tmp.x >= 0 && tmp.x < baseRas32->getLx() && tmp.y >= 0 &&
Shinya Kitaoka 120a6e
      troundp(tmp.y) < baseRas32->getLy()) {
Shinya Kitaoka 120a6e
    color = baseRas32->pixels(troundp(tmp.y))[(int)tmp.x];
Shinya Kitaoka 120a6e
  } else if (baseRas64 && tmp.x >= 0 && tmp.x < baseRas64->getLx() &&
Shinya Kitaoka 120a6e
             tmp.y >= 0 && troundp(tmp.y) < baseRas64->getLy()) {
Shinya Kitaoka 120a6e
    TPixel64 pix64 = baseRas64->pixels(troundp(tmp.y))[(int)tmp.x];
Shinya Kitaoka 120a6e
    color = TPixel32((int)pix64.r / 256, (int)pix64.g / 256, (int)pix64.b / 256,
Shinya Kitaoka 120a6e
                     (int)pix64.m / 256);
Shinya Kitaoka 120a6e
  } else
Shinya Kitaoka 120a6e
    color = TPixel32::Transparent;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRaster32P texRas32 = texRaster;
Shinya Kitaoka 120a6e
  TRaster64P texRas64 = texRaster;
Shinya Kitaoka 120a6e
  if (texRas32) {
Shinya Kitaoka 120a6e
    texRas32->lock();
Shinya Kitaoka 120a6e
    for (int j = 0; j < texRas32->getLy(); j++) {
Shinya Kitaoka 120a6e
      TPixel32 *pix    = texRas32->pixels(j);
Shinya Kitaoka 120a6e
      TPixel32 *endPix = pix + texRas32->getLx();
Shinya Kitaoka 120a6e
      while (pix < endPix) {
Shinya Kitaoka 120a6e
        double factor = pix->m / (double)TPixel32::maxChannelValue;
Shinya Kitaoka 120a6e
        pix->r        = (UCHAR)(factor * color.r);
Shinya Kitaoka 120a6e
        pix->g        = (UCHAR)(factor * color.g);
Shinya Kitaoka 120a6e
        pix->b        = (UCHAR)(factor * color.b);
Shinya Kitaoka 120a6e
        pix->m        = (UCHAR)(factor * color.m);
Shinya Kitaoka 120a6e
        ++pix;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    texRas32->unlock();
Shinya Kitaoka 120a6e
  } else if (texRas64) {
Shinya Kitaoka 120a6e
    texRas64->lock();
Shinya Kitaoka 120a6e
    TPixel64 color64(color.r * 256, color.g * 256, color.b * 256,
Shinya Kitaoka 120a6e
                     color.m * 256);
Shinya Kitaoka 120a6e
    for (int j = 0; j < texRas64->getLy(); j++) {
Shinya Kitaoka 120a6e
      TPixel64 *pix    = texRas64->pixels(j);
Shinya Kitaoka 120a6e
      TPixel64 *endPix = pix + texRas64->getLx();
Shinya Kitaoka 120a6e
      while (pix < endPix) {
Shinya Kitaoka 120a6e
        double factor = pix->m / (double)TPixel64::maxChannelValue;
Shinya Kitaoka 120a6e
        pix->r        = (USHORT)(factor * color64.r);
Shinya Kitaoka 120a6e
        pix->g        = (USHORT)(factor * color64.g);
Shinya Kitaoka 120a6e
        pix->b        = (USHORT)(factor * color64.b);
Shinya Kitaoka 120a6e
        pix->m        = (USHORT)(factor * color64.m);
Shinya Kitaoka 120a6e
        ++pix;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    texRas64->unlock();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*-----------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
/*- 照明モードのとき、その明るさを色に格納 -*/
Toshihiro Shimizu 890ddd
void Iwa_Particle::set_illuminated_colors(float illuminant,
Shinya Kitaoka 120a6e
                                          TRasterP texRaster) {
Shinya Kitaoka 120a6e
  TRaster32P texRas32 = texRaster;
Shinya Kitaoka 120a6e
  TRaster64P texRas64 = texRaster;
Shinya Kitaoka 120a6e
  if (texRas32) {
Shinya Kitaoka 120a6e
    texRas32->lock();
Shinya Kitaoka 120a6e
    TPixel32::Channel val =
Shinya Kitaoka 120a6e
        (TPixel32::Channel)(illuminant * TPixel32::maxChannelValue);
Shinya Kitaoka 120a6e
    for (int j = 0; j < texRas32->getLy(); j++) {
Shinya Kitaoka 120a6e
      TPixel32 *pix    = texRas32->pixels(j);
Shinya Kitaoka 120a6e
      TPixel32 *endPix = pix + texRas32->getLx();
Shinya Kitaoka 120a6e
      while (pix < endPix) {
Shinya Kitaoka 120a6e
        double factor = pix->m / (double)TPixel32::maxChannelValue;
Shinya Kitaoka 120a6e
        pix->r        = (UCHAR)(factor * val);
Shinya Kitaoka 120a6e
        pix->g        = (UCHAR)(factor * val);
Shinya Kitaoka 120a6e
        pix->b        = (UCHAR)(factor * val);
Shinya Kitaoka 120a6e
        ++pix;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    texRas32->unlock();
Shinya Kitaoka 120a6e
  } else if (texRas64) {
Shinya Kitaoka 120a6e
    texRas64->lock();
Shinya Kitaoka 120a6e
    TPixel64::Channel val =
Shinya Kitaoka 120a6e
        (TPixel64::Channel)(illuminant * TPixel64::maxChannelValue);
Shinya Kitaoka 120a6e
    for (int j = 0; j < texRas64->getLy(); j++) {
Shinya Kitaoka 120a6e
      TPixel64 *pix    = texRas64->pixels(j);
Shinya Kitaoka 120a6e
      TPixel64 *endPix = pix + texRas64->getLx();
Shinya Kitaoka 120a6e
      while (pix < endPix) {
Shinya Kitaoka 120a6e
        double factor = pix->m / (double)TPixel64::maxChannelValue;
Shinya Kitaoka 120a6e
        pix->r        = (USHORT)(factor * val);
Shinya Kitaoka 120a6e
        pix->g        = (USHORT)(factor * val);
Shinya Kitaoka 120a6e
        pix->b        = (USHORT)(factor * val);
Shinya Kitaoka 120a6e
        ++pix;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    texRas64->unlock();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*-----------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Iwa_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
/*-----------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*-----------------------------------------------
Toshihiro Shimizu 890ddd
 Iwa_Particles_Engine::roll_particles から呼ばれる
Toshihiro Shimizu 890ddd
 粒子の移動
Toshihiro Shimizu 890ddd
-----------------------------------------------*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
void Iwa_Particle::move(std::map<int, *="" ttile=""> porttiles,</int,>
Shinya Kitaoka 120a6e
                        const particles_values &values,
Shinya Kitaoka 120a6e
                        const particles_ranges &ranges, float windx,
Shinya Kitaoka 120a6e
                        float windy, float xgravity, float ygravity,
Shinya Kitaoka 120a6e
                        float dpicorr, int lastframe) {
Shinya Kitaoka 120a6e
  struct pos_dummy dummy;
Shinya Kitaoka 120a6e
  std::map<int, float=""> imagereferences;</int,>
Shinya Kitaoka 120a6e
  dummy.x = dummy.y = dummy.a = 0.0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  float frictreference     = 1;
Shinya Kitaoka 120a6e
  float scalereference     = 0;
Shinya Kitaoka 120a6e
  float scalestepreference = 0;
Shinya Kitaoka 120a6e
  float randomxreference   = 1;
Shinya Kitaoka 120a6e
  float randomyreference   = 1;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*-
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.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
      float tmpvalue;
Shinya Kitaoka 120a6e
      get_image_reference(it->second, values, tmpvalue,
Shinya Kitaoka 120a6e
                          Iwa_TiledParticlesFx::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
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
shun-iwasawa 63f747
  if (double friction = values.friction_val * frictreference) {
shun-iwasawa 63f747
    if (vx || vy) {
shun-iwasawa 63f747
      double v           = std::sqrt(vx * vx + vy * vy);
shun-iwasawa 63f747
      double frictined_v = v * (1 + friction) + (10 / v) * friction;
shun-iwasawa 63f747
      if (frictined_v < 0) frictined_v = 0;
Shinya Kitaoka 120a6e
shun-iwasawa 63f747
      double f_ratio = frictined_v / v;
shun-iwasawa 63f747
      if (vx) vx *= f_ratio;
shun-iwasawa 63f747
      if (vy) vy *= f_ratio;
shun-iwasawa 63f747
    }
shun-iwasawa 63f747
    if (!vx && fabs(friction * 10) > fabs(xgravity)) {
shun-iwasawa 63f747
      xgravity = 0;
shun-iwasawa 63f747
      dummy.x  = 0;
shun-iwasawa 63f747
      dummy.a  = 0;
shun-iwasawa 63f747
      windx    = 0;
Shinya Kitaoka 120a6e
    }
shun-iwasawa 63f747
    if (!vy && fabs(friction * 10) > fabs(xgravity)) {
shun-iwasawa 63f747
      xgravity = 0;
shun-iwasawa 63f747
      dummy.x  = 0;
shun-iwasawa 63f747
      dummy.a  = 0;
shun-iwasawa 63f747
      windx    = 0;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*- 重力を徐々に付けていく処理を入れる -*/
Shinya Kitaoka 120a6e
  if (genlifetime - lifetime < values.iw_gravityBufferFrame_val) {
Shinya Kitaoka 120a6e
    float ratio = (float)(genlifetime - lifetime) /
Shinya Kitaoka 120a6e
                  (float)values.iw_gravityBufferFrame_val;
Shinya Kitaoka 120a6e
    xgravity *= ratio;
Shinya Kitaoka 120a6e
    ygravity *= ratio;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*- 重力の寄与 -*/
Shinya Kitaoka 120a6e
  vx += xgravity * mass;
Shinya Kitaoka 120a6e
  vy += ygravity * mass;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*- カールノイズ的動き 奥行き持たせる -*/
Shinya Kitaoka 120a6e
  if (values.curl_ctrl_1_val &&
Shinya Kitaoka 120a6e
      (porttiles.find(values.curl_ctrl_1_val) != porttiles.end())) {
Shinya Kitaoka 120a6e
    float tmpCurlx, tmpCurly;
Shinya Kitaoka 120a6e
    if (get_image_curl(porttiles[values.curl_ctrl_1_val], values, tmpCurlx,
Shinya Kitaoka 120a6e
                       tmpCurly)) {
Shinya Kitaoka 120a6e
      if (values.curl_ctrl_2_val &&
Shinya Kitaoka 120a6e
          (porttiles.find(values.curl_ctrl_2_val) != porttiles.end())) {
Shinya Kitaoka 120a6e
        float tmpCurlx2, tmpCurly2;
Shinya Kitaoka 120a6e
        if (get_image_curl(porttiles[values.curl_ctrl_2_val], values, tmpCurlx2,
Shinya Kitaoka 120a6e
                           tmpCurly2)) {
Shinya Kitaoka 120a6e
          float length1 = sqrtf(tmpCurlx * tmpCurlx + tmpCurly * tmpCurly);
Shinya Kitaoka 120a6e
          float length2 = sqrtf(tmpCurlx2 * tmpCurlx2 + tmpCurly2 * tmpCurly2);
Shinya Kitaoka 120a6e
          float length  = length1 * curlz + length2 * (1.0f - curlz);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
          tmpCurlx     = tmpCurlx * curlz + tmpCurlx2 * (1.0f - curlz);
Shinya Kitaoka 120a6e
          tmpCurly     = tmpCurly * curlz + tmpCurly2 * (1.0f - curlz);
Shinya Kitaoka 120a6e
          float tmpLen = tmpCurlx * tmpCurlx + tmpCurly * tmpCurly;
Shinya Kitaoka 120a6e
          if (tmpLen > 0.0f) {
Shinya Kitaoka 120a6e
            tmpLen = sqrtf(tmpLen);
Shinya Kitaoka 120a6e
            tmpCurlx *= length / tmpLen;
Shinya Kitaoka 120a6e
            tmpCurly *= length / tmpLen;
Shinya Kitaoka 120a6e
          }
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      tmpCurlx *= values.curl_val * mass;
Shinya Kitaoka 120a6e
      tmpCurly *= values.curl_val * mass;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      /*- ローパスフィルタをかます -*/
Shinya Kitaoka 120a6e
      curlx = 0.5f * curlx + 0.5f * tmpCurlx;
Shinya Kitaoka 120a6e
      curly = 0.5f * curly + 0.5f * tmpCurly;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      vx = vx * 0.5 + curlx;
Shinya Kitaoka 120a6e
      vy = vy * 0.5 + curly;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*- 現在位置に速度を足す -*/
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
  /*- 粒子の向きを計算 -*/
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);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*-  ひらひら -*/
Shinya Kitaoka 120a6e
  if (values.flap_ctrl_val &&
Shinya Kitaoka 120a6e
      (porttiles.find(values.flap_ctrl_val) != porttiles.end())) {
Shinya Kitaoka 120a6e
    /*- 参照画像のGradientを得る関数を利用して角度を得る -*/
Shinya Kitaoka 120a6e
    float dir_x, dir_y;
Shinya Kitaoka 120a6e
    double norm;
Shinya Kitaoka 120a6e
    norm = get_image_gravity(porttiles[values.flap_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
    } else {
Shinya Kitaoka 120a6e
      float newTheta = atan2f(dir_y, dir_x) * 180.0f / 3.14159f;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      /*- Thetaを補間する。右回り/左回りで近いほうを選ぶ -*/
Shinya Kitaoka 120a6e
      if (newTheta > flap_theta && newTheta - flap_theta > 180.0f)
Shinya Kitaoka 120a6e
        newTheta -= 360.0f;
Shinya Kitaoka 120a6e
      else if (newTheta < flap_theta && flap_theta - newTheta > 180.0f)
Shinya Kitaoka 120a6e
        newTheta += 360.0f;
Shinya Kitaoka 120a6e
      flap_theta = flap_theta * (1.0f - values.iw_flap_dir_sensitivity_val) +
Shinya Kitaoka 120a6e
                   newTheta * values.iw_flap_dir_sensitivity_val;
Shinya Kitaoka 120a6e
      if (flap_theta < 0.0f)
Shinya Kitaoka 120a6e
        flap_theta += 360.0f;
Shinya Kitaoka 120a6e
      else if (flap_theta > 360.0f)
Shinya Kitaoka 120a6e
        flap_theta -= 360.0f;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      flap_phi += values.iw_flap_velocity_val * norm / mass;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      while (flap_phi > 360.0f) flap_phi -= 360.0f;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*-----------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
double Iwa_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
    float opacityreference = 0.0f;
Shinya Kitaoka 120a6e
    get_image_reference(porttiles[values.opacity_ctrl_val], values,
Shinya Kitaoka 120a6e
                        opacityreference, Iwa_TiledParticlesFx::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
}