|
|
|
|
@ -318,10 +318,10 @@ ParticleDemo("Space battle", sharedData)
|
|
|
|
|
m_spaceshipTemplate = m_shared.world3D->CreateEntity();
|
|
|
|
|
m_spaceshipTemplate->Enable(false);
|
|
|
|
|
|
|
|
|
|
m_spaceshipTemplate->AddComponent<Ndk::NodeComponent>();
|
|
|
|
|
m_spaceshipTemplate->AddComponent<Ndk::VelocityComponent>();
|
|
|
|
|
m_spaceshipTemplate->AddComponent<SpaceshipComponent>();
|
|
|
|
|
auto& gfxComponent = m_spaceshipTemplate->AddComponent<Ndk::GraphicsComponent>();
|
|
|
|
|
auto& nodeComponent = m_spaceshipTemplate->AddComponent<Ndk::NodeComponent>();
|
|
|
|
|
auto& velocityComponent = m_spaceshipTemplate->AddComponent<Ndk::VelocityComponent>();
|
|
|
|
|
auto& spaceshipComponent = m_spaceshipTemplate->AddComponent<SpaceshipComponent>();
|
|
|
|
|
gfxComponent.Attach(&m_spaceshipModel);
|
|
|
|
|
|
|
|
|
|
m_ambientMusic.OpenFromFile("resources/ambience.ogg");
|
|
|
|
|
@ -386,9 +386,7 @@ void SpacebattleExample::Enter(Ndk::StateMachine& fsm)
|
|
|
|
|
m_torpedoGroup->AddController(Nz::ParticleFunctionController::New([this] (Nz::ParticleGroup& group, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime)
|
|
|
|
|
{
|
|
|
|
|
auto positionPtr = mapper.GetComponentPtr<Nz::Vector3f>(Nz::ParticleComponent_Position);
|
|
|
|
|
auto rotationPtr = mapper.GetComponentPtr<float>(Nz::ParticleComponent_Rotation);
|
|
|
|
|
auto sizePtr = mapper.GetComponentPtr<Nz::Vector2f>(Nz::ParticleComponent_Size);
|
|
|
|
|
auto velocityPtr = mapper.GetComponentPtr<Nz::Vector3f>(Nz::ParticleComponent_Velocity);
|
|
|
|
|
|
|
|
|
|
auto& spaceshipSystem = m_shared.world3D->GetSystem<SpaceshipSystem>();
|
|
|
|
|
|
|
|
|
|
@ -422,7 +420,7 @@ void SpacebattleExample::Enter(Ndk::StateMachine& fsm)
|
|
|
|
|
emitter.SetEmissionCount(2);
|
|
|
|
|
emitter.SetEmissionRate(200.f);
|
|
|
|
|
|
|
|
|
|
emitter.SetSetupFunc([this] (const Ndk::EntityHandle& entity, Nz::ParticleMapper& mapper, unsigned int count)
|
|
|
|
|
emitter.SetSetupFunc([this] (const Ndk::EntityHandle& emitter, Nz::ParticleMapper& particleMapper, unsigned int count)
|
|
|
|
|
{
|
|
|
|
|
auto& gen = m_shared.randomGen;
|
|
|
|
|
|
|
|
|
|
@ -434,29 +432,29 @@ void SpacebattleExample::Enter(Ndk::StateMachine& fsm)
|
|
|
|
|
std::uniform_real_distribution<float> sizeDis(1.0f, 4.f);
|
|
|
|
|
std::uniform_real_distribution<float> velDis(-maxFireVel, maxFireVel);
|
|
|
|
|
|
|
|
|
|
Nz::Vector3f pos = entity->GetComponent<Ndk::NodeComponent>().GetPosition();
|
|
|
|
|
Nz::Vector3f pos = emitter->GetComponent<Ndk::NodeComponent>().GetPosition();
|
|
|
|
|
|
|
|
|
|
Nz::ParticleStruct_Billboard* billboards = static_cast<Nz::ParticleStruct_Billboard*>(mapper.GetPointer());
|
|
|
|
|
Nz::ParticleStruct_Billboard* billboards = static_cast<Nz::ParticleStruct_Billboard*>(particleMapper.GetPointer());
|
|
|
|
|
Nz::ParticleStruct_Billboard* smokeParticles = static_cast<Nz::ParticleStruct_Billboard*>(m_smokeGroup->CreateParticles(count));
|
|
|
|
|
for (unsigned int i = 0; i < count; ++i)
|
|
|
|
|
for (unsigned int j = 0; j < count; ++j)
|
|
|
|
|
{
|
|
|
|
|
billboards[i].color = Nz::Color::White;
|
|
|
|
|
billboards[i].life = 1.f + lifeDis(gen);
|
|
|
|
|
billboards[i].position = pos + Nz::Vector3f(posDis(gen), posDis(gen), posDis(gen));
|
|
|
|
|
billboards[i].rotation = rotDis(gen);
|
|
|
|
|
billboards[i].size = {1.28f, 1.28f};
|
|
|
|
|
billboards[i].size *= sizeDis(gen);
|
|
|
|
|
billboards[i].velocity.Set(normalDis(gen), normalDis(gen), normalDis(gen));
|
|
|
|
|
billboards[i].velocity.Normalize();
|
|
|
|
|
billboards[i].velocity *= velDis(gen);
|
|
|
|
|
billboards[j].color = Nz::Color::White;
|
|
|
|
|
billboards[j].life = 1.f + lifeDis(gen);
|
|
|
|
|
billboards[j].position = pos + Nz::Vector3f(posDis(gen), posDis(gen), posDis(gen));
|
|
|
|
|
billboards[j].rotation = rotDis(gen);
|
|
|
|
|
billboards[j].size = {1.28f, 1.28f};
|
|
|
|
|
billboards[j].size *= sizeDis(gen);
|
|
|
|
|
billboards[j].velocity.Set(normalDis(gen), normalDis(gen), normalDis(gen));
|
|
|
|
|
billboards[j].velocity.Normalize();
|
|
|
|
|
billboards[j].velocity *= velDis(gen);
|
|
|
|
|
|
|
|
|
|
smokeParticles[i].color = Nz::Color(128, 128, 128, 0);
|
|
|
|
|
smokeParticles[i].life = maxSmokeLife;
|
|
|
|
|
smokeParticles[i].position = billboards[i].position;
|
|
|
|
|
smokeParticles[i].rotation = billboards[i].rotation;
|
|
|
|
|
smokeParticles[i].size = {2.56f, 2.56f};
|
|
|
|
|
smokeParticles[i].size *= sizeDis(gen);
|
|
|
|
|
smokeParticles[i].velocity = billboards[i].velocity / 2.f;
|
|
|
|
|
smokeParticles[j].color = Nz::Color(128, 128, 128, 0);
|
|
|
|
|
smokeParticles[j].life = maxSmokeLife;
|
|
|
|
|
smokeParticles[j].position = billboards[j].position;
|
|
|
|
|
smokeParticles[j].rotation = billboards[j].rotation;
|
|
|
|
|
smokeParticles[j].size = {2.56f, 2.56f};
|
|
|
|
|
smokeParticles[j].size *= sizeDis(gen);
|
|
|
|
|
smokeParticles[j].velocity = billboards[j].velocity / 2.f;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
m_fireGroup->AddEmitter(entity);
|
|
|
|
|
@ -467,12 +465,11 @@ void SpacebattleExample::Enter(Ndk::StateMachine& fsm)
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
m_torpedoGroup->SetRenderer(Nz::ParticleFunctionRenderer::New([sparkleMat1 = Nz::MaterialLibrary::Get("TorpedoFlare1")] (const Nz::ParticleGroup& group, const Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, Nz::AbstractRenderQueue* renderQueue)
|
|
|
|
|
m_torpedoGroup->SetRenderer(Nz::ParticleFunctionRenderer::New([sparkleMat1 = Nz::MaterialLibrary::Get("TorpedoFlare1")] (const Nz::ParticleGroup& /*group*/, const Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, Nz::AbstractRenderQueue* renderQueue)
|
|
|
|
|
{
|
|
|
|
|
auto positionPtr = mapper.GetComponentPtr<const Nz::Vector3f>(Nz::ParticleComponent_Position);
|
|
|
|
|
auto rotationPtr = mapper.GetComponentPtr<const float>(Nz::ParticleComponent_Rotation);
|
|
|
|
|
auto sizePtr = mapper.GetComponentPtr<const Nz::Vector2f>(Nz::ParticleComponent_Size);
|
|
|
|
|
auto velocityPtr = mapper.GetComponentPtr<const Nz::Vector3f>(Nz::ParticleComponent_Velocity);
|
|
|
|
|
|
|
|
|
|
renderQueue->AddBillboards(0, sparkleMat1, endId - startId + 1, positionPtr, sizePtr, rotationPtr);
|
|
|
|
|
for (unsigned int i = startId; i <= endId; ++i)
|
|
|
|
|
@ -581,7 +578,7 @@ void SpacebattleExample::Enter(Ndk::StateMachine& fsm)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
m_fireGroup->AddController(movementController);
|
|
|
|
|
m_fireGroup->AddController(Nz::ParticleFunctionController::New([] (Nz::ParticleGroup& group, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime)
|
|
|
|
|
m_fireGroup->AddController(Nz::ParticleFunctionController::New([] (Nz::ParticleGroup& /*group*/, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime)
|
|
|
|
|
{
|
|
|
|
|
auto colorPtr = mapper.GetComponentPtr<Nz::Color>(Nz::ParticleComponent_Color);
|
|
|
|
|
auto lifePtr = mapper.GetComponentPtr<float>(Nz::ParticleComponent_Life);
|
|
|
|
|
@ -592,7 +589,7 @@ void SpacebattleExample::Enter(Ndk::StateMachine& fsm)
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
m_smokeGroup->AddController(movementController);
|
|
|
|
|
m_smokeGroup->AddController(Nz::ParticleFunctionController::New([] (Nz::ParticleGroup& group, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime)
|
|
|
|
|
m_smokeGroup->AddController(Nz::ParticleFunctionController::New([] (Nz::ParticleGroup& /*group*/, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime)
|
|
|
|
|
{
|
|
|
|
|
auto colorPtr = mapper.GetComponentPtr<Nz::Color>(Nz::ParticleComponent_Color);
|
|
|
|
|
auto lifePtr = mapper.GetComponentPtr<float>(Nz::ParticleComponent_Life);
|
|
|
|
|
@ -618,7 +615,7 @@ void SpacebattleExample::Enter(Ndk::StateMachine& fsm)
|
|
|
|
|
smokeMat->SetDiffuseColor(Nz::Color(128, 128, 128));
|
|
|
|
|
smokeMat->SetDiffuseMap("resources/smoke.png");
|
|
|
|
|
|
|
|
|
|
m_fireGroup->SetRenderer(Nz::ParticleFunctionRenderer::New([fireMat] (const Nz::ParticleGroup& group, const Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, Nz::AbstractRenderQueue* renderQueue)
|
|
|
|
|
m_fireGroup->SetRenderer(Nz::ParticleFunctionRenderer::New([fireMat] (const Nz::ParticleGroup& /*group*/, const Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, Nz::AbstractRenderQueue* renderQueue)
|
|
|
|
|
{
|
|
|
|
|
auto colorPtr = mapper.GetComponentPtr<const Nz::Color>(Nz::ParticleComponent_Color);
|
|
|
|
|
auto posPtr = mapper.GetComponentPtr<const Nz::Vector3f>(Nz::ParticleComponent_Position);
|
|
|
|
|
@ -628,7 +625,7 @@ void SpacebattleExample::Enter(Ndk::StateMachine& fsm)
|
|
|
|
|
renderQueue->AddBillboards(0, fireMat, endId - startId + 1, posPtr, sizePtr, rotPtr, colorPtr);
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
m_smokeGroup->SetRenderer(Nz::ParticleFunctionRenderer::New([smokeMat] (const Nz::ParticleGroup& group, const Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, Nz::AbstractRenderQueue* renderQueue)
|
|
|
|
|
m_smokeGroup->SetRenderer(Nz::ParticleFunctionRenderer::New([smokeMat] (const Nz::ParticleGroup& /*group*/, const Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, Nz::AbstractRenderQueue* renderQueue)
|
|
|
|
|
{
|
|
|
|
|
auto colorPtr = mapper.GetComponentPtr<const Nz::Color>(Nz::ParticleComponent_Color);
|
|
|
|
|
auto posPtr = mapper.GetComponentPtr<const Nz::Vector3f>(Nz::ParticleComponent_Position);
|
|
|
|
|
@ -816,7 +813,7 @@ void SpacebattleExample::CreateTurret()
|
|
|
|
|
cannonGfx.Attach(&m_turret.cannonModel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SpacebattleExample::OnMouseMoved(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseMoveEvent& event)
|
|
|
|
|
void SpacebattleExample::OnMouseMoved(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::MouseMoveEvent& event)
|
|
|
|
|
{
|
|
|
|
|
const float speed = 0.1f;
|
|
|
|
|
|
|
|
|
|
|