metaforce/Runtime/Particle/CModVectorElement.cpp

265 lines
6.7 KiB
C++
Raw Normal View History

2016-02-07 23:59:05 +00:00
#include "CModVectorElement.hpp"
#include "CParticleGlobals.hpp"
#include "CRandom16.hpp"
#include <math.h>
2016-02-13 09:02:47 +00:00
namespace pshag
2016-02-07 23:59:05 +00:00
{
bool CMVEImplosion::GetValue(int frame, Zeus::CVector3f& pVel, Zeus::CVector3f& pPos) const
{
Zeus::CVector3f av;
x4_implPoint->GetValue(frame, av);
Zeus::CVector3f dv = av - pPos;
float dvm = dv.magnitude();
float c;
xc_maxMag->GetValue(frame, c);
if (dvm > c)
return false;
float d;
x10_minMag->GetValue(frame, d);
if (x14_enableMinMag && dvm < d)
return false;
if (0.f == dvm)
return false;
float b;
x8_magScale->GetValue(frame, b);
pVel += Zeus::CVector3f(b / dvm) * dv;
return false;
}
bool CMVEExponentialImplosion::GetValue(int frame, Zeus::CVector3f& pVel, Zeus::CVector3f& pPos) const
{
Zeus::CVector3f av;
x4_implPoint->GetValue(frame, av);
Zeus::CVector3f dv = av - pPos;
float dvm = dv.magnitude();
float c;
xc_maxMag->GetValue(frame, c);
if (dvm > c)
return false;
float d;
x10_minMag->GetValue(frame, d);
if (x14_enableMinMag && dvm < d)
return false;
if (0.f == dvm)
return false;
float b;
x8_magScale->GetValue(frame, b);
pVel += Zeus::CVector3f(b) * dv;
return false;
}
bool CMVELinearImplosion::GetValue(int frame, Zeus::CVector3f& pVel, Zeus::CVector3f& pPos) const
{
Zeus::CVector3f av;
x4_implPoint->GetValue(frame, av);
Zeus::CVector3f dv = av - pPos;
float dvm = dv.magnitude();
float c;
xc_maxMag->GetValue(frame, c);
if (dvm > c)
return false;
float d;
x10_minMag->GetValue(frame, d);
if (x14_enableMinMag && dvm < d)
return false;
if (0.f == dvm)
return false;
float b;
x8_magScale->GetValue(frame, b);
pVel = Zeus::CVector3f(b / dvm) * dv;
return false;
}
bool CMVETimeChain::GetValue(int frame, Zeus::CVector3f& pVel, Zeus::CVector3f& pPos) const
{
int v;
xc_swFrame->GetValue(frame, v);
if (frame >= v)
return x8_b->GetValue(frame, pVel, pPos);
else
return x4_a->GetValue(frame, pVel, pPos);
}
2016-02-13 06:25:29 +00:00
CMVEBounce::CMVEBounce(CVectorElement *a, CVectorElement *b, CRealElement *c, CRealElement *d, bool f)
: x4_a(a), x8_b(b), xc_c(c), x10_d(d), x14_e(false), x15_f(f), x24_j(0.0)
{
if (x4_a && x8_b && x4_a->IsFastConstant() && x8_b->IsFastConstant())
{
x14_e = true;
x8_b->GetValue(0, x18_g);
if (x18_g.magSquared() > 0.0)
x18_g.normalize();
Zeus::CVector3f a;
x4_a->GetValue(0, a);
x24_j = x18_g.dot(a);
}
}
2016-02-13 20:02:50 +00:00
bool CMVEBounce::GetValue(int frame, Zeus::CVector3f& pVel, Zeus::CVector3f& pPos) const
2016-02-13 06:25:29 +00:00
{
if (!x14_e)
{
x8_b->GetValue(frame, ((Zeus::CVector3f&)x18_g));
((Zeus::CVector3f&)x18_g).normalize();
Zeus::CVector3f a;
x4_a->GetValue(frame, a);
(float&)(x24_j) = x18_g.dot(a);
}
float dot = x18_g.dot(pPos);
if ((dot - x24_j) <= 0.0f)
{
2016-02-14 06:23:03 +00:00
if (x15_f)
2016-02-13 06:25:29 +00:00
return true;
}
else
return false;
if (pVel.magSquared() > 0.0f)
return false;
Zeus::CVector3f delta = pPos - pVel;
2016-02-14 07:38:01 +00:00
pPos += Zeus::CVector3f{(-((((delta.z * ((delta.x * (delta.y * x18_g.y))
+ ((pVel.x * (x18_g.y * pVel.y)) + x18_g.x))) + x18_g.z) - x24_j)) /
((pVel.z * ((pVel.x * (x18_g.y * pVel.y)) + x18_g.x)) + x18_g.z)) - (
(x18_g.z * ((x18_g.x * (x18_g.y * pVel.y)) + pVel.x)) + pVel.z)} * pVel;
2016-02-13 06:25:29 +00:00
2016-02-14 06:23:03 +00:00
float d = 0.0f;
x10_d->GetValue(frame, d);
pVel -= d * pVel;
float c = 0.0f;
xc_c->GetValue(frame, c);
pVel -= Zeus::CVector3f{(1.0f + c) * ((x18_g.z * (x18_g.x * (x18_g.y * pVel.y)) + pVel.x) + pVel.x)} * x18_g;
2016-02-13 06:25:29 +00:00
return false;
}
bool CMVEConstant::GetValue(int frame, Zeus::CVector3f& pVel, Zeus::CVector3f& /*pPos*/) const
2016-02-14 00:14:23 +00:00
{
x4_x->GetValue(frame, pVel.x);
x8_y->GetValue(frame, pVel.y);
xc_z->GetValue(frame, pVel.z);
return false;
}
bool CMVEFastConstant::GetValue(int /*frame*/, Zeus::CVector3f& pVel, Zeus::CVector3f& /*pPos*/) const
{
pVel = x4_val;
return false;
}
bool CMVEGravity::GetValue(int frame, Zeus::CVector3f& pVel, Zeus::CVector3f& /*pPos*/) const
{
Zeus::CVector3f grav;
x4_a->GetValue(frame, grav);
pVel += grav;
return false;
}
bool CMVEExplode::GetValue(int frame, Zeus::CVector3f& pVel, Zeus::CVector3f& /*pPos*/) const
{
if (frame == 0)
{
float b;
x8_b->GetValue(frame, b);
pVel *= b;
}
else
{
CRandom16* rand = CRandom16::GetRandomNumber();
Zeus::CVector3f vec;
do
{
vec = {rand->Float() - 0.5f, rand->Float() - 0.5f, rand->Float() - 0.5f};
}
while (vec.magSquared() > 1.0);
vec.normalize();
float a;
x4_a->GetValue(frame, a);
pVel = vec * a;
}
return false;
}
2016-02-13 20:02:50 +00:00
bool CMVESetPosition::GetValue(int frame, Zeus::CVector3f& /*pVel*/, Zeus::CVector3f& pPos) const
{
x4_a->GetValue(frame, pPos);
return false;
}
2016-02-14 00:14:23 +00:00
bool CMVEPulse::GetValue(int frame, Zeus::CVector3f& pVel, Zeus::CVector3f& pPos) const
{
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, pVel, pPos);
else
xc_aVal->GetValue(frame, pVel, pPos);
}
else
xc_aVal->GetValue(frame, pVel, pPos);
return false;
}
bool CMVEWind::GetValue(int frame, Zeus::CVector3f& pVel, Zeus::CVector3f& /*pPos*/) const
{
Zeus::CVector3f direction;
x4_direction->GetValue(frame, direction);
float speed;
x8_speed->GetValue(frame, speed);
pVel += (direction - pVel) * speed;
return false;
}
bool CMVESwirl::GetValue(int frame, Zeus::CVector3f& pVel, Zeus::CVector3f& pPos) const
{
Zeus::CVector3f a, b;
x4_a->GetValue(frame, a);
x8_b->GetValue(frame, b);
const Zeus::CVector3f diff = a - pPos;
float x = (diff.x - (((diff.z * ((diff.x * (diff.y * b.y)) + b.x)) + b.z) * b.x));
float y = (diff.y - (((diff.z * ((diff.x * (diff.y * b.y)) + b.x)) + b.z) * b.y));
float z = (diff.z - (((diff.z * ((diff.x * (diff.y * b.y)) + b.x)) + b.z) * b.z));
float c = 0.0f, d = 0.0f;
xc_c->GetValue(frame, c);
x10_d->GetValue(frame, d);
const float f9 = (b.z * ((b.x * (b.y * pVel.y)) + pVel.x)) + pVel.x;
pVel.x = (c * ((f9 * b.x) + (d * ((b.y * (y * b.z)) - z)))) + ((1.0 - c) * pVel.x);
pVel.y = (c * ((f9 * b.y) + (d * ((b.z * x) - (z * b.x))))) + ((1.0 - c) * pVel.y);
pVel.z = (c * ((f9 * b.z) + (d * ((b.x * (x * b.y)) - y)))) + ((1.0 - c) * pVel.x);
return false;
}
2016-02-07 23:59:05 +00:00
}