2016-02-07 00:19:59 +00:00
|
|
|
#include "CVectorElement.hpp"
|
|
|
|
#include "CParticleGlobals.hpp"
|
|
|
|
#include "CRandom16.hpp"
|
2016-02-25 06:23:35 +00:00
|
|
|
#include "CElementGen.hpp"
|
2016-03-04 23:04:53 +00:00
|
|
|
#include "zeus/Math.hpp"
|
2016-04-03 05:25:34 +00:00
|
|
|
#include "CGenDescription.hpp"
|
2016-02-07 00:19:59 +00:00
|
|
|
|
2016-02-28 06:55:05 +00:00
|
|
|
/* Documentation at: http://www.metroid2002.com/retromodding/wiki/Particle_Script#Vector_Elements */
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
namespace urde
|
2016-02-07 00:19:59 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
CVEKeyframeEmitter::CVEKeyframeEmitter(CInputStream& in)
|
|
|
|
{
|
|
|
|
x4_percent = in.readUint32Big();
|
|
|
|
x8_unk1 = in.readUint32Big();
|
|
|
|
xc_loop = in.readBool();
|
|
|
|
xd_unk2 = in.readBool();
|
|
|
|
x10_loopEnd = in.readUint32Big();
|
|
|
|
x14_loopStart = in.readUint32Big();
|
|
|
|
|
|
|
|
u32 count = in.readUint32Big();
|
|
|
|
x18_keys.reserve(count);
|
|
|
|
for (u32 i=0 ; i<count ; ++i)
|
2016-02-07 23:59:05 +00:00
|
|
|
x18_keys.push_back(in.readVec3fBig());
|
2016-02-07 00:19:59 +00:00
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
bool CVEKeyframeEmitter::GetValue(int frame, zeus::CVector3f& valOut) const
|
2016-02-07 00:19:59 +00:00
|
|
|
{
|
|
|
|
if (!x4_percent)
|
|
|
|
{
|
2016-02-09 22:52:33 +00:00
|
|
|
int emitterTime = CParticleGlobals::g_EmitterTime;
|
2016-02-07 00:19:59 +00:00
|
|
|
int calcKey = emitterTime;
|
|
|
|
if (xc_loop)
|
|
|
|
{
|
|
|
|
if (emitterTime >= x10_loopEnd)
|
|
|
|
{
|
|
|
|
int v1 = emitterTime - x14_loopStart;
|
|
|
|
int v2 = x10_loopEnd - x14_loopStart;
|
|
|
|
calcKey = v1 % v2;
|
|
|
|
calcKey += x14_loopStart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int v1 = x10_loopEnd - 1;
|
|
|
|
if (v1 < emitterTime)
|
|
|
|
calcKey = v1;
|
|
|
|
}
|
|
|
|
valOut = x18_keys[calcKey];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-02-09 22:52:33 +00:00
|
|
|
int ltPerc = CParticleGlobals::g_ParticleLifetimePercentage;
|
|
|
|
float ltPercRem = CParticleGlobals::g_ParticleLifetimePercentageRemainder;
|
2016-02-07 00:19:59 +00:00
|
|
|
if (ltPerc == 100)
|
|
|
|
valOut = x18_keys[100];
|
|
|
|
else
|
|
|
|
valOut = ltPercRem * x18_keys[ltPerc+1] + (1.0f - ltPercRem) * x18_keys[ltPerc];
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CVECone::CVECone(CVectorElement* a, CRealElement* b)
|
2016-02-07 07:25:34 +00:00
|
|
|
: x4_direction(a), x8_magnitude(b)
|
2016-02-07 00:19:59 +00:00
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
zeus::CVector3f av;
|
2016-02-07 07:25:34 +00:00
|
|
|
x4_direction->GetValue(0, av);
|
2016-02-07 23:59:05 +00:00
|
|
|
av.normalize();
|
|
|
|
if (av[0] > 0.8)
|
2016-03-04 23:04:53 +00:00
|
|
|
xc_xVec = av.cross(zeus::CVector3f(0.f, 1.f, 0.f));
|
2016-02-07 00:19:59 +00:00
|
|
|
else
|
2016-03-04 23:04:53 +00:00
|
|
|
xc_xVec = av.cross(zeus::CVector3f(1.f, 0.f, 0.f));
|
2016-02-07 23:59:05 +00:00
|
|
|
x18_yVec = av.cross(xc_xVec);
|
2016-02-07 00:19:59 +00:00
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
bool CVECone::GetValue(int frame, zeus::CVector3f& valOut) const
|
2016-02-07 00:19:59 +00:00
|
|
|
{
|
|
|
|
float b;
|
2016-02-07 07:25:34 +00:00
|
|
|
x8_magnitude->GetValue(frame, b);
|
2016-03-04 23:04:53 +00:00
|
|
|
zeus::CVector3f dir;
|
2016-02-07 07:25:34 +00:00
|
|
|
x4_direction->GetValue(frame, dir);
|
2016-02-07 00:19:59 +00:00
|
|
|
float b2 = std::min(1.f, b);
|
2016-02-07 07:25:34 +00:00
|
|
|
|
|
|
|
float randX, randY;
|
|
|
|
do
|
2016-02-07 00:19:59 +00:00
|
|
|
{
|
2016-02-07 07:25:34 +00:00
|
|
|
float rand1 = CRandom16::GetRandomNumber()->Float() - 0.5f;
|
|
|
|
randX = 2.f * b2 * rand1;
|
|
|
|
float rand2 = CRandom16::GetRandomNumber()->Float() - 0.5f;
|
|
|
|
randY = 2.f * b2 * rand2;
|
|
|
|
} while (randX * randX + randY * randY > 1.f);
|
|
|
|
|
|
|
|
valOut = xc_xVec * randX + x18_yVec * randY + dir;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
bool CVETimeChain::GetValue(int frame, zeus::CVector3f& valOut) const
|
2016-02-07 07:25:34 +00:00
|
|
|
{
|
|
|
|
int v;
|
|
|
|
xc_swFrame->GetValue(frame, v);
|
|
|
|
if (frame >= v)
|
|
|
|
return x8_b->GetValue(frame, valOut);
|
|
|
|
else
|
|
|
|
return x4_a->GetValue(frame, valOut);
|
|
|
|
}
|
2016-02-07 00:19:59 +00:00
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
bool CVEAngleCone::GetValue(int frame, zeus::CVector3f& valOut) const
|
2016-02-07 07:25:34 +00:00
|
|
|
{
|
|
|
|
float xc, yc, xr, yr;
|
|
|
|
x4_angleXConstant->GetValue(frame, xc);
|
|
|
|
x8_angleYConstant->GetValue(frame, yc);
|
|
|
|
xc_angleXRange->GetValue(frame, xr);
|
|
|
|
x10_angleYRange->GetValue(frame, yr);
|
2016-02-07 00:19:59 +00:00
|
|
|
|
2016-02-07 07:25:34 +00:00
|
|
|
float xtmp = CRandom16::GetRandomNumber()->Float() * xr;
|
2016-03-04 23:04:53 +00:00
|
|
|
float xang = zeus::degToRad(0.5f * xr - xtmp + xc);
|
2016-02-07 00:19:59 +00:00
|
|
|
|
2016-02-07 07:25:34 +00:00
|
|
|
float ytmp = CRandom16::GetRandomNumber()->Float() * yr;
|
2016-03-04 23:04:53 +00:00
|
|
|
float yang = zeus::degToRad(0.5f * yr - ytmp + yc);
|
2016-02-07 07:25:34 +00:00
|
|
|
|
|
|
|
float mag;
|
|
|
|
x14_magnitude->GetValue(frame, mag);
|
|
|
|
|
|
|
|
/* This takes a +Z vector and rotates it around X and Y axis (like a rotation matrix would) */
|
2016-03-04 23:04:53 +00:00
|
|
|
valOut = zeus::CVector3f(std::cos(xang) * -std::sin(yang), std::sin(xang), std::cos(xang) * std::cos(yang)) * zeus::CVector3f(mag);
|
2016-02-07 07:25:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
bool CVEAdd::GetValue(int frame, zeus::CVector3f& valOut) const
|
2016-02-07 07:25:34 +00:00
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
zeus::CVector3f a, b;
|
2016-02-07 07:25:34 +00:00
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
x8_b->GetValue(frame, b);
|
|
|
|
valOut = a + b;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-07 23:59:05 +00:00
|
|
|
CVECircleCluster::CVECircleCluster(CVectorElement* a, CVectorElement* b, CIntElement* c, CRealElement* d)
|
|
|
|
: x4_a(a), x24_magnitude(d)
|
|
|
|
{
|
|
|
|
int cv;
|
|
|
|
c->GetValue(0, cv);
|
2016-03-04 23:04:53 +00:00
|
|
|
x20_deltaAngle = zeus::degToRad(360.f / float(cv));
|
2016-02-07 23:59:05 +00:00
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
zeus::CVector3f bv;
|
2016-02-07 23:59:05 +00:00
|
|
|
b->GetValue(0, bv);
|
|
|
|
bv.normalize();
|
2016-03-04 23:04:53 +00:00
|
|
|
if (bv[0] > 0.8f)
|
|
|
|
x8_xVec = bv.cross(zeus::CVector3f(0.f, 1.f, 0.f));
|
2016-02-07 23:59:05 +00:00
|
|
|
else
|
2016-03-04 23:04:53 +00:00
|
|
|
x8_xVec = bv.cross(zeus::CVector3f(1.f, 0.f, 0.f));
|
2016-02-07 23:59:05 +00:00
|
|
|
x14_yVec = bv.cross(x8_xVec);
|
|
|
|
|
|
|
|
delete b;
|
|
|
|
delete c;
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
bool CVECircleCluster::GetValue(int frame, zeus::CVector3f& valOut) const
|
2016-02-07 07:25:34 +00:00
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
zeus::CVector3f av;
|
2016-02-07 23:59:05 +00:00
|
|
|
x4_a->GetValue(frame, av);
|
|
|
|
|
|
|
|
float curAngle = frame * x20_deltaAngle;
|
2016-03-04 23:04:53 +00:00
|
|
|
zeus::CVector3f x = x8_xVec * std::cos(curAngle);
|
|
|
|
zeus::CVector3f y = x14_yVec * std::sin(curAngle);
|
|
|
|
zeus::CVector3f tv = x + y + av;
|
2016-02-07 23:59:05 +00:00
|
|
|
|
|
|
|
float dv;
|
|
|
|
x24_magnitude->GetValue(frame, dv);
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
zeus::CVector3f magVec(dv * tv.magnitude());
|
|
|
|
zeus::CVector3f rv = magVec * zeus::CVector3f(CRandom16::GetRandomNumber()->Float(),
|
2016-02-07 23:59:05 +00:00
|
|
|
CRandom16::GetRandomNumber()->Float(),
|
|
|
|
CRandom16::GetRandomNumber()->Float());
|
|
|
|
|
|
|
|
valOut = tv + rv;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
bool CVEConstant::GetValue(int frame, zeus::CVector3f& valOut) const
|
2016-02-07 23:59:05 +00:00
|
|
|
{
|
|
|
|
float a, b, c;
|
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
x8_b->GetValue(frame, b);
|
|
|
|
xc_c->GetValue(frame, c);
|
2016-03-04 23:04:53 +00:00
|
|
|
valOut = zeus::CVector3f(a, b, c);
|
2016-02-07 23:59:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
bool CVEFastConstant::GetValue(int frame, zeus::CVector3f& valOut) const
|
2016-02-07 23:59:05 +00:00
|
|
|
{
|
|
|
|
valOut = x4_val;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CVECircle::CVECircle(CVectorElement* a, CVectorElement* b, CRealElement* c, CRealElement* d, CRealElement* e)
|
2016-02-28 06:55:05 +00:00
|
|
|
: x4_direction(a), x20_angleConstant(c), x24_angleLinear(d), x28_radius(e)
|
2016-02-07 23:59:05 +00:00
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
zeus::CVector3f bv;
|
2016-02-07 23:59:05 +00:00
|
|
|
b->GetValue(0, bv);
|
|
|
|
bv.normalize();
|
2016-03-04 23:04:53 +00:00
|
|
|
if (bv[0] > 0.8f)
|
|
|
|
x8_xVec = bv.cross(zeus::CVector3f(0.f, 1.f, 0.f));
|
2016-02-07 23:59:05 +00:00
|
|
|
else
|
2016-03-04 23:04:53 +00:00
|
|
|
x8_xVec = bv.cross(zeus::CVector3f(1.f, 0.f, 0.f));
|
2016-02-07 23:59:05 +00:00
|
|
|
x14_yVec = bv.cross(x8_xVec);
|
|
|
|
delete b;
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
bool CVECircle::GetValue(int frame, zeus::CVector3f& valOut) const
|
2016-02-07 23:59:05 +00:00
|
|
|
{
|
|
|
|
float c, d, e;
|
|
|
|
x20_angleConstant->GetValue(frame, c);
|
|
|
|
x24_angleLinear->GetValue(frame, d);
|
2016-02-28 06:55:05 +00:00
|
|
|
x28_radius->GetValue(frame, e);
|
2016-02-07 23:59:05 +00:00
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
float curAngle = zeus::degToRad(d * frame + c);
|
2016-02-07 23:59:05 +00:00
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
zeus::CVector3f av;
|
2016-02-07 23:59:05 +00:00
|
|
|
x4_direction->GetValue(frame, av);
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
zeus::CVector3f x = x8_xVec * e * std::cos(curAngle);
|
|
|
|
zeus::CVector3f y = x14_yVec * e * std::sin(curAngle);
|
2016-02-07 07:25:34 +00:00
|
|
|
|
2016-02-07 23:59:05 +00:00
|
|
|
valOut = x + y + av;
|
2016-02-07 07:25:34 +00:00
|
|
|
return false;
|
2016-02-07 00:19:59 +00:00
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
bool CVEMultiply::GetValue(int frame, zeus::CVector3f& valOut) const
|
2016-02-07 00:19:59 +00:00
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
zeus::CVector3f a, b;
|
2016-02-07 00:19:59 +00:00
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
x8_b->GetValue(frame, b);
|
|
|
|
valOut = a * b;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
bool CVERealToVector::GetValue(int frame, zeus::CVector3f& valOut) const
|
2016-02-07 00:19:59 +00:00
|
|
|
{
|
|
|
|
float a;
|
|
|
|
x4_a->GetValue(frame, a);
|
2016-03-04 23:04:53 +00:00
|
|
|
valOut = zeus::CVector3f(a);
|
2016-02-07 00:19:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
bool CVEPulse::GetValue(int frame, zeus::CVector3f& valOut) const
|
2016-02-07 00:19:59 +00:00
|
|
|
{
|
|
|
|
int a, b;
|
|
|
|
x4_aDuration->GetValue(frame, a);
|
|
|
|
x8_bDuration->GetValue(frame, b);
|
|
|
|
int cv = std::max(1, a + b + 1);
|
|
|
|
|
|
|
|
if (b >= 1)
|
|
|
|
{
|
|
|
|
int cv2 = frame % cv;
|
|
|
|
if (cv2 >= a)
|
|
|
|
x10_bVal->GetValue(frame, valOut);
|
|
|
|
else
|
|
|
|
xc_aVal->GetValue(frame, valOut);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
xc_aVal->GetValue(frame, valOut);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
bool CVEParticleVelocity::GetValue(int /*frame*/, zeus::CVector3f& valOut) const
|
2016-02-07 00:19:59 +00:00
|
|
|
{
|
2016-02-25 06:23:35 +00:00
|
|
|
valOut = CElementGen::g_currentParticle->x1c_vel;
|
2016-02-07 00:19:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-19 02:04:12 +00:00
|
|
|
bool CVEParticleColor::GetValue(int /*frame*/, zeus::CVector3f& valOut) const
|
2016-02-07 00:19:59 +00:00
|
|
|
{
|
2016-02-25 06:23:35 +00:00
|
|
|
valOut = CElementGen::g_currentParticle->x10_prevPos;
|
2016-02-07 00:19:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-19 02:04:12 +00:00
|
|
|
bool CVEParticleLocation::GetValue(int /*frame*/, zeus::CVector3f& valOut) const
|
2016-02-07 00:19:59 +00:00
|
|
|
{
|
2016-02-25 06:23:35 +00:00
|
|
|
valOut = CElementGen::g_currentParticle->x4_pos;
|
2016-02-07 00:19:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-19 02:04:12 +00:00
|
|
|
bool CVEParticleSystemOrientationFront::GetValue(int /*frame*/, zeus::CVector3f& valOut) const
|
2016-02-07 00:19:59 +00:00
|
|
|
{
|
2016-04-25 05:46:28 +00:00
|
|
|
zeus::CMatrix4f trans = CParticleGlobals::g_currentParticleSystem->x4_system->GetOrientation().toMatrix4f().transposed();
|
|
|
|
valOut.assign(trans.vec[0].y, trans.vec[1].z, trans.vec[3].x);
|
2016-02-07 00:19:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-19 02:04:12 +00:00
|
|
|
bool CVEParticleSystemOrientationUp::GetValue(int /*frame*/, zeus::CVector3f& valOut) const
|
2016-02-12 06:06:17 +00:00
|
|
|
{
|
2016-04-25 05:46:28 +00:00
|
|
|
zeus::CMatrix4f trans = CParticleGlobals::g_currentParticleSystem->x4_system->GetOrientation().toMatrix4f().transposed();
|
|
|
|
valOut.assign(trans.vec[0].z, trans.vec[2].x, trans.vec[3].y);
|
2016-02-12 06:06:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-19 02:04:12 +00:00
|
|
|
bool CVEParticleSystemOrientationRight::GetValue(int /*frame*/, zeus::CVector3f& valOut) const
|
2016-02-12 06:06:17 +00:00
|
|
|
{
|
2016-04-25 05:46:28 +00:00
|
|
|
zeus::CMatrix4f trans = CParticleGlobals::g_currentParticleSystem->x4_system->GetOrientation().toMatrix4f().transposed();
|
|
|
|
valOut.assign(trans.vec[0].x, trans.vec[1].y, trans.vec[2].z);
|
2016-02-12 06:06:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-19 02:04:12 +00:00
|
|
|
bool CVEParticleSystemTranslation::GetValue(int /*frame*/, zeus::CVector3f& valOut) const
|
2016-02-07 00:19:59 +00:00
|
|
|
{
|
2016-02-14 07:38:01 +00:00
|
|
|
valOut = CParticleGlobals::g_currentParticleSystem->x4_system->GetTranslation();
|
2016-02-07 00:19:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
bool CVESubtract::GetValue(int frame, zeus::CVector3f& valOut) const
|
2016-02-12 06:06:17 +00:00
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
zeus::CVector3f a, b;
|
2016-02-12 06:06:17 +00:00
|
|
|
x4_a->GetValue(frame, a);
|
|
|
|
x8_b->GetValue(frame, b);
|
|
|
|
valOut = a - b;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
bool CVEColorToVector::GetValue(int frame, zeus::CVector3f &valOut) const
|
2016-02-17 08:07:32 +00:00
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
zeus::CColor val = {0.0f, 0.0f, 0.0f, 1.0f};
|
2016-02-17 08:17:12 +00:00
|
|
|
x4_a->GetValue(frame, val);
|
2016-03-04 23:04:53 +00:00
|
|
|
valOut = zeus::CVector3f{val.r, val.g, val.b};
|
2016-02-17 08:07:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-07 00:19:59 +00:00
|
|
|
}
|