summaryrefslogtreecommitdiff
path: root/src/JSystem/JParticle/JPAParticle.cpp
blob: 195295ad5eccf8ca48ecd8b59ed1be038fe44d17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
//
// Generated By: dol2asm
// Translation Unit: JPAParticle
//

#include "JSystem/JParticle/JPAParticle.h"
#include "JSystem/JParticle/JPABaseShape.h"
#include "JSystem/JParticle/JPAChildShape.h"
#include "JSystem/JParticle/JPAEmitter.h"
#include "JSystem/JParticle/JPAEmitterManager.h"
#include "JSystem/JParticle/JPAExtraShape.h"

/* 8027EFA4-8027EFEC 2798E4 0048+00 0/0 11/11 1/1 .text            __dt__19JPAParticleCallBackFv */
JPAParticleCallBack::~JPAParticleCallBack() {
    /* empty function */
}

/* 8027EFEC-8027F8C8 27992C 08DC+00 0/0 1/1 0/0 .text
 * init_p__15JPABaseParticleFP18JPAEmitterWorkData              */
void JPABaseParticle::init_p(JPAEmitterWorkData* work) {
    JPABaseEmitter* emtr = work->mpEmtr;
    JPAExtraShape* esp = work->mpRes->getEsp();
    JPABaseShape* bsp = work->mpRes->getBsp();
    JPADynamicsBlock* dyn = work->mpRes->getDyn();

    mAge = -1;
    mLifeTime = (1.0f - dyn->getLifetimeRndm() * emtr->get_r_f()) * emtr->mLifeTime;
    mTime = 0.0f;

    initStatus(0);
    MTXMultVecSR(work->mGlobalSR, work->mVolumeCalcData.mVolumePos, mLocalPosition);
    if (emtr->checkFlag(8)) {
        setStatus(0x20);
    }

    mOffsetPosition.set(work->mGlobalPos);
    mPosition.set(mOffsetPosition.x + mLocalPosition.x * work->mPublicScale.x,
                  mOffsetPosition.y + mLocalPosition.y * work->mPublicScale.y,
                  mOffsetPosition.z + mLocalPosition.z * work->mPublicScale.z);

    EGG::Vector3f velOmni; 
    if (emtr->mAwayFromCenterSpeed) {
        velOmni.setLength(work->mVolumeCalcData.mVelOmni, emtr->mAwayFromCenterSpeed);
    } else {
        velOmni.setZero();
    }

    EGG::Vector3f velAxis;
    if (emtr->mAwayFromAxisSpeed) {
        velAxis.setLength(work->mVolumeCalcData.mVelAxis, emtr->mAwayFromAxisSpeed);
    } else {
        velAxis.setZero();
    }

    EGG::Vector3f velDir;
    if (emtr->mDirSpeed) {
        Mtx mtx;
        JPAGetYZRotateMtx(emtr->get_r_zp() * 0x8000 * emtr->mSpread, emtr->get_r_ss(), mtx);
        MTXConcat(work->mDirectionMtx, mtx, mtx);
        velDir.set(emtr->mDirSpeed * mtx[0][2],
                   emtr->mDirSpeed * mtx[1][2],
                   emtr->mDirSpeed * mtx[2][2]);
    } else {
        velDir.setZero();
    }

    EGG::Vector3f velRndm;
    if (emtr->mRndmDirSpeed) {
        velRndm.set(emtr->mRndmDirSpeed * emtr->get_r_zh(),
                    emtr->mRndmDirSpeed * emtr->get_r_zh(),
                    emtr->mRndmDirSpeed * emtr->get_r_zh());
    } else {
        velRndm.setZero();
    }

    f32 ratio = emtr->get_r_zp() * dyn->getInitVelRatio() + 1.0f;
    mVelType1.set(ratio * (velOmni.x + velAxis.x + velDir.x + velRndm.x),
                  ratio * (velOmni.y + velAxis.y + velDir.y + velRndm.y),
                  ratio * (velOmni.z + velAxis.z + velDir.z + velRndm.z));
    
    if (emtr->checkFlag(4)) {
        mVelType1 *= emtr->mLocalScl;
    }
    MTXMultVecSR(work->mGlobalRot, mVelType1, mVelType1);

    mVelType0.setZero();

    mMoment = 1.0f - dyn->getMomentRndm() * emtr->get_r_f();
    mDrag = 1.0f;
    field_0x78 = 0;

    mBaseAxis.set(work->mGlobalRot[0][1], work->mGlobalRot[1][1], work->mGlobalRot[2][1]);

    mPrmClr = emtr->mPrmClr;
    mEnvClr = emtr->mEnvClr;

    mAnmRandom = emtr->get_r_f() * bsp->getLoopOfstValue();

    if (esp != NULL && esp->isEnableScaleAnm()) {
        mParticleScaleX = mParticleScaleY = mScaleOut = emtr->mScaleOut * (emtr->get_r_zp() * esp->getScaleRndm() + 1.0f);
    } else {
        mParticleScaleX = mParticleScaleY = mScaleOut = emtr->mScaleOut;
    }

    mPrmColorAlphaAnm = 0xff;

    if (esp != NULL && esp->isEnableAlphaFlick()) {
        mAlphaWaveRandom = emtr->get_r_zp() * esp->getAlphaFreqRndm() + 1.0f;
    } else {
        mAlphaWaveRandom = 1.0f;
    }

    if (esp != NULL) {
        if (esp->isEnableRotateAnm()) {
            mRotateAngle = esp->getRotateInitAngle() + esp->getRotateRndmAngle() * emtr->get_r_zh();
            mRotateSpeed = esp->getRotateInitSpeed() *
                           (esp->getRotateRndmSpeed() * emtr->get_r_zp() + 1.0f);
            mRotateSpeed = emtr->get_r_zp() < esp->getRotateDirection() ?
                           mRotateSpeed : (s16)-mRotateSpeed;
        } else {
            mRotateAngle = 0;
            mRotateSpeed = 0;
        }
    } else {
        mRotateAngle = 0;
        mRotateSpeed = 0;
    }
}

/* 8027F8C8-8027FFD0 27A208 0708+00 0/0 1/1 0/0 .text
 * init_c__15JPABaseParticleFP18JPAEmitterWorkDataP15JPABaseParticle */
void JPABaseParticle::init_c(JPAEmitterWorkData* work, JPABaseParticle* parent) {
    JPABaseEmitter* emtr = work->mpEmtr;
    JPAChildShape* csp = work->mpRes->getCsp();

    mAge = -1;
    mLifeTime = csp->getLife();
    mTime = 0.0f;
    initStatus(4);
    mLocalPosition.set(parent->mLocalPosition);

    f32 pos_rndm = csp->getPosRndm();
    if (pos_rndm != 0.0f) {
        EGG::Vector3f rnd(emtr->get_r_zh(), emtr->get_r_zh(), emtr->get_r_zh());
        rnd.setLength(pos_rndm * emtr->get_r_f());
        mLocalPosition += rnd;
    }

    if (emtr->checkFlag(0x10)) {
        setStatus(0x20);
    }

    mOffsetPosition.set(parent->mOffsetPosition);

    f32 base_speed = csp->getBaseVel() * (csp->getBaseVelRndm() * emtr->get_r_zp() + 1.0f);
    EGG::Vector3f base_vel(emtr->get_r_zp(), emtr->get_r_zp(), emtr->get_r_zp());
    base_vel.setLength(base_speed);
    mVelType1 = csp->getVelInhRate() * parent->mVelType1 + base_vel;
    mVelType0 = csp->getVelInhRate() * parent->mVelType2;
    
    mMoment = parent->mMoment;
    if (csp->isFieldAffected()) {
        mDrag = parent->mDrag;
    } else {
        setStatus(0x40);
        mDrag = 1.0f;
    }
    field_0x78 = parent->field_0x78;

    mVelType2.set(mVelType0);
    f32 ratio = mMoment * mDrag;
    mVelocity.set(ratio * (mVelType1.x + mVelType2.x),
                  ratio * (mVelType1.y + mVelType2.y),
                  ratio * (mVelType1.z + mVelType2.z));
    
    mBaseAxis.set(parent->mBaseAxis);

    if (csp->isScaleInherited()) {
        mParticleScaleX = mScaleOut = parent->mParticleScaleX * csp->getScaleInhRate();
        mParticleScaleY = mAlphaWaveRandom = parent->mParticleScaleY * csp->getScaleInhRate();
    } else {
        mParticleScaleX = mScaleOut = mParticleScaleY = mAlphaWaveRandom = 1.0f;
    }

    if (csp->isColorInherited()) {
        mPrmClr.r = parent->mPrmClr.r * csp->getColorInhRate();
        mPrmClr.g = parent->mPrmClr.g * csp->getColorInhRate();
        mPrmClr.b = parent->mPrmClr.b * csp->getColorInhRate();
        mEnvClr.r = parent->mEnvClr.r * csp->getColorInhRate();
        mEnvClr.g = parent->mEnvClr.g * csp->getColorInhRate();
        mEnvClr.b = parent->mEnvClr.b * csp->getColorInhRate();
    } else {
        csp->getPrmClr(&mPrmClr);
        csp->getEnvClr(&mEnvClr);
    }

    mPrmColorAlphaAnm = 0xff;
    if (csp->isAlphaInherited()) {
        mPrmClr.a = COLOR_MULTI(parent->mPrmClr.a, parent->mPrmColorAlphaAnm)
                    * csp->getAlphaInhRate();
    } else {
        mPrmClr.a = csp->getPrmAlpha();
    }

    mRotateAngle = parent->mRotateAngle;
    if (csp->isRotateOn()) {
        mRotateSpeed = csp->getRotInitSpeed();
    } else {
        mRotateSpeed = 0;
    }

    mTexAnmIdx = 0;
}

/* 8027FFD0-80280260 27A910 0290+00 0/0 1/1 0/0 .text
 * calc_p__15JPABaseParticleFP18JPAEmitterWorkData              */
bool JPABaseParticle::calc_p(JPAEmitterWorkData* work) {
    if (++mAge >= mLifeTime) {
        return true;
    }
    mTime = (f32)mAge / (f32)mLifeTime;

    if (checkStatus(0x20)) {
        mOffsetPosition.set(work->mGlobalPos);
    }

    mVelType2.setZero();
    if (!checkStatus(0x40)) {
        work->mpRes->calcField(work, this);
    }
    mVelType2 += mVelType0;
    mVelType1 *= work->mpEmtr->mAirResist;
    f32 ratio = mMoment * mDrag;
    mVelocity.set(ratio * (mVelType1.x + mVelType2.x),
                  ratio * (mVelType1.y + mVelType2.y),
                  ratio * (mVelType1.z + mVelType2.z));
    
    if (work->mpEmtr->mpPtclCallBack != NULL) {
        work->mpEmtr->mpPtclCallBack->execute(work->mpEmtr, this);
    }

    if (checkStatus(2)) {
        return true;
    }

    work->mpRes->calc_p(work, this);
    mRotateAngle += mRotateSpeed;

    if (work->mpRes->getCsp() != NULL && canCreateChild(work)) {
        for (int i = work->mpRes->getCsp()->getRate(); i > 0; i--) {
            work->mpEmtr->createChild(this);
        }
    }

    mLocalPosition += mVelocity;
    mPosition.set(mOffsetPosition.x + mLocalPosition.x * work->mPublicScale.x,
                  mOffsetPosition.y + mLocalPosition.y * work->mPublicScale.y,
                  mOffsetPosition.z + mLocalPosition.z * work->mPublicScale.z);

    return false;
}

/* 80280260-802804C8 27ABA0 0268+00 0/0 1/1 0/0 .text
 * calc_c__15JPABaseParticleFP18JPAEmitterWorkData              */
bool JPABaseParticle::calc_c(JPAEmitterWorkData* work) {
    if (++mAge >= mLifeTime) {
        return true;
    }
    mTime = (f32)mAge / (f32)mLifeTime;

    if (mAge != 0) {
        if (checkStatus(0x20)) {
            mOffsetPosition.set(work->mGlobalPos);
        }

        mVelType1.y -= work->mpRes->getCsp()->getGravity();
        mVelType2.setZero();
        if (!checkStatus(0x40)) {
            work->mpRes->calcField(work, this);
        }
        mVelType2 += mVelType0;
        mVelType1 *= work->mpEmtr->mAirResist;
        f32 ratio = mMoment * mDrag;
        mVelocity.set(ratio * (mVelType1.x + mVelType2.x),
                    ratio * (mVelType1.y + mVelType2.y),
                    ratio * (mVelType1.z + mVelType2.z));
    }
    
    if (work->mpEmtr->mpPtclCallBack != NULL) {
        work->mpEmtr->mpPtclCallBack->execute(work->mpEmtr, this);
    }

    if (checkStatus(2)) {
        return true;
    }

    work->mpRes->calc_c(work, this);
    mRotateAngle += mRotateSpeed;
    mLocalPosition += mVelocity;
    mPosition.set(mOffsetPosition.x + mLocalPosition.x * work->mPublicScale.x,
                  mOffsetPosition.y + mLocalPosition.y * work->mPublicScale.y,
                  mOffsetPosition.z + mLocalPosition.z * work->mPublicScale.z);

    return false;
}

/* 802804C8-80280548 27AE08 0080+00 1/1 0/0 0/0 .text
 * canCreateChild__15JPABaseParticleFP18JPAEmitterWorkData      */
bool JPABaseParticle::canCreateChild(JPAEmitterWorkData* work) {
    JPAChildShape* csp = work->mpRes->getCsp();
    bool ret = false;
    int time = mAge - (int)((mLifeTime - 1) * csp->getTiming());
    if (time >= 0 && time % (csp->getStep() + 1) == 0) {
        ret = true;
    }
    return ret;
}

/* 80280548-80280568 27AE88 0020+00 0/0 3/3 0/0 .text
 * getWidth__15JPABaseParticleCFPC14JPABaseEmitter              */
f32 JPABaseParticle::getWidth(JPABaseEmitter const* emtr) const {
    f32 scale = 2.0f * mParticleScaleX;
    return scale * emtr->mpEmtrMgr->pWd->mGlobalPtclScl.x;
}

/* 80280568-80280588 27AEA8 0020+00 0/0 3/3 0/0 .text
 * getHeight__15JPABaseParticleCFPC14JPABaseEmitter             */
f32 JPABaseParticle::getHeight(JPABaseEmitter const* emtr) const {
    f32 scale = 2.0f * mParticleScaleY;
    return scale * emtr->mpEmtrMgr->pWd->mGlobalPtclScl.y;
}