Commit 351aa5e6 authored by AL's avatar AL

smooth 3DEffectsPhysics dissappearance

parent c5337820
......@@ -130,14 +130,14 @@ int CombatManager::ProcessInput(Keyboard::Event in_event) //why does it return
// EH::AddEffect3D(EH::Effect::PlayerSandThrowDamage);
//}
//
//if (in_event.GetCode() == 'K') //for testing
//{
// EH::AddEffect3D(EH::Effect::PlayerSandThrow);
//}
//if (in_event.GetCode() == 'L') //for testing
//{
// EH::AddEffect3D(EH::Effect::PlayerSandStorm);
//}
if (in_event.GetCode() == 'K') //for testing
{
EH::AddEffect3D(EH::Effect::PlayerSandThrow);
}
if (in_event.GetCode() == 'L') //for testing
{
EH::AddEffect3D(EH::Effect::PlayerSandStorm);
}
if (in_event.GetCode() == 'T') //for testing
{
CM::PendScenario(CM::Scenario::GhoulRage);
......
......@@ -491,7 +491,8 @@ std::optional<Effect3DData> Effect3DSequence::Update(float dt)
Effect3DPhysics::Effect3DPhysics(ParticleBurstData burstData, ParticleSpreadData partSpread, std::wstring model, DXGraphics& gfx) :
lifeTime(burstData.lifeTime),
particleModel(model, gfx),
friction(burstData.friction)
friction(burstData.friction),
gfx(gfx)
{
particleModel.GetTechniquesReference()[0].GetSteps()[0].SetTargetPass(1u);
particleModel.GetTechniquesReference()[1].GetSteps()[0].SetTargetPass(1u);
......@@ -513,32 +514,57 @@ Effect3DPhysics::Effect3DPhysics(ParticleBurstData burstData, ParticleSpreadData
partVel.emplace_back(velocity.x,velocity.y,velocity.z);
}
particleModel.BindPositionData(&partPos);
auto& s = particleModel.GetTechniquesReference()[0].GetSteps()[0]; //making model use pixel shader with configurable opacity
s.DeleteBindableByUID(L"class Bind::PixelShader#PhongPSNormMask.cso");
s.AddBindable(Bind::PixelShader::Resolve(gfx, L"PhongPSOpac.cso"));
cbuf = std::make_shared<Bind::PixelConstantBuffer<OpacCBuff>>(gfx, 4); //opacity buffer
s.AddBindable(cbuf);
cbData.val = 1.0f;
}
void Effect3DPhysics::SubmitAndUpdateParticles(FrameCommander& fc, float dt)
{
curTime += dt;
if (curTime <= lifeTime)
if (!isDying)
{
for (size_t i = 0; i < partPos.size(); i++)
if (curTime <= lifeTime)
{
partPos[i].pos.x += (partVel[i].pos.x * dt);
partPos[i].pos.y += (partVel[i].pos.y * dt);
partPos[i].pos.z += (partVel[i].pos.z * dt);
for (size_t i = 0; i < partPos.size(); i++)
{
partPos[i].pos.x += (partVel[i].pos.x * dt);
partPos[i].pos.y += (partVel[i].pos.y * dt);
partPos[i].pos.z += (partVel[i].pos.z * dt);
partVel[i].pos.x *= friction;
partVel[i].pos.y *= friction;
partVel[i].pos.z *= friction;
partVel[i].pos.x *= friction;
partVel[i].pos.y *= friction;
partVel[i].pos.z *= friction;
}
}
else
{
isDying = true;
curTime = 0.0f;
}
}
else
{
isDead = true;
partPos.clear();
partVel.clear();
if (curTime <= deathTime)
{
cbData.val = (1.0f - curTime / deathTime);
}
else
{
isDead = true;
partPos.clear();
partVel.clear();
}
}
if (partPos.size())
{
cbuf->Update(gfx, cbData);
particleModel.SmartSubmit(fc, Techniques::Standart);
}
}
......
......@@ -128,14 +128,26 @@ public:
Effect3DPhysics(Effect3DPhysics&&) = default;
Effect3DPhysics& operator=(Effect3DPhysics&&) = default;
void SubmitAndUpdateParticles(FrameCommander& fc, float dt); //make friend of handler
bool isDying = false;
bool isDead = false;
private:
struct OpacCBuff
{
float val;
float pad1;
float pad2;
float pad3;
};
std::vector<PositionData> partPos;
std::vector<PositionData> partVel; //here PositionData.pos represents velocities and .rot - acceleration
PlaneTexNorm particleModel;
std::shared_ptr <Bind::PixelConstantBuffer<OpacCBuff>> cbuf = nullptr;
OpacCBuff cbData;
float curTime = 0.0f;
const float friction = 1.0f; //actually the opposite of friction
const float friction = 0.97f; //actually the opposite of friction
const float lifeTime;
static constexpr float deathTime = 1.0f;
DXGraphics& gfx;
};
template<typename T, typename Base>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment