temporary particles for demo. trails for bricks, and on brick hit.
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 120 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 4.0 KiB |
@@ -41,6 +41,8 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "Physics/ECreateParticleSequence.h"
|
||||||
|
|
||||||
namespace dd
|
namespace dd
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ namespace Components
|
|||||||
|
|
||||||
struct ParticleEmitter : public Component
|
struct ParticleEmitter : public Component
|
||||||
{
|
{
|
||||||
|
EntityID Parent = 0;
|
||||||
int NumberOfTicks = 10.f;
|
int NumberOfTicks = 10.f;
|
||||||
float InitialSpeed = 1.f;
|
float InitialSpeed = 1.f;
|
||||||
double SpawnRate = 1;
|
double SpawnRate = 1;
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ struct CreateParticleSequence : public Event
|
|||||||
float EmittingAngle = 0.f;
|
float EmittingAngle = 0.f;
|
||||||
float MaxCount = 0;
|
float MaxCount = 0;
|
||||||
glm::vec4 Color = glm::vec4(0);
|
glm::vec4 Color = glm::vec4(0);
|
||||||
|
EntityID parent = 0;
|
||||||
|
|
||||||
//Particle
|
//Particle
|
||||||
std::string SpriteFile = "";
|
std::string SpriteFile = "";
|
||||||
|
|||||||
@@ -440,7 +440,7 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
|
|||||||
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
|
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(viewMatrix));
|
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(viewMatrix));
|
||||||
glUniform4fv(glGetUniformLocation(shaderProgramHandle, "Color"), 1, glm::value_ptr(modelJob->Color));
|
glUniform4fv(glGetUniformLocation(shaderProgramHandle, "Color"), 1, glm::value_ptr(spriteJob->Color));
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, spriteJob->DiffuseTexture);
|
glBindTexture(GL_TEXTURE_2D, spriteJob->DiffuseTexture);
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ uniform vec3 LightPosition;
|
|||||||
uniform float LightRadius;
|
uniform float LightRadius;
|
||||||
uniform vec3 LightSpecular;
|
uniform vec3 LightSpecular;
|
||||||
uniform vec3 LightDiffuse;
|
uniform vec3 LightDiffuse;
|
||||||
|
uniform vec4 Color;
|
||||||
|
|
||||||
in VertexData
|
in VertexData
|
||||||
{
|
{
|
||||||
@@ -86,5 +87,5 @@ void main()
|
|||||||
vec4 La = vec4(0.3, 0.3, 0.3, 1.0);
|
vec4 La = vec4(0.3, 0.3, 0.3, 1.0);
|
||||||
vec4 light = phong(Input.Position, normalize(normal), specularTexel.rgb, specularTexel.a);
|
vec4 light = phong(Input.Position, normalize(normal), specularTexel.rgb, specularTexel.a);
|
||||||
//frag_Diffuse = light;
|
//frag_Diffuse = light;
|
||||||
frag_Diffuse = diffuseTexel;
|
frag_Diffuse = diffuseTexel * Color;
|
||||||
}
|
}
|
||||||
@@ -189,20 +189,20 @@ void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBe
|
|||||||
m_World->RemoveComponent<Components::Template>(brick);
|
m_World->RemoveComponent<Components::Template>(brick);
|
||||||
auto transform = m_World->GetComponent<Components::Transform>(brick);
|
auto transform = m_World->GetComponent<Components::Transform>(brick);
|
||||||
auto cBrick = m_World->GetComponent<Components::Brick>(brick);
|
auto cBrick = m_World->GetComponent<Components::Brick>(brick);
|
||||||
|
|
||||||
if (typeInt == StandardBrick) {
|
if (typeInt == StandardBrick) {
|
||||||
} else if (typeInt == MultiBallBrick) {
|
} else if (typeInt == MultiBallBrick) {
|
||||||
cBrick->Type = MultiBallBrick;
|
cBrick->Type = MultiBallBrick;
|
||||||
auto model = m_World->GetComponent<Components::Model>(brick);
|
auto model = m_World->GetComponent<Components::Model>(brick);
|
||||||
model->ModelFile = "Models/Brick/IceBrick.obj";
|
model->ModelFile = "Models/Brick/IceBrick.obj";
|
||||||
|
|
||||||
} else if (typeInt == LifebuoyBrick) {
|
} else if (typeInt == LifebuoyBrick) {
|
||||||
cBrick->Type = LifebuoyBrick;
|
cBrick->Type = LifebuoyBrick;
|
||||||
auto model = m_World->GetComponent<Components::Model>(brick);
|
auto model = m_World->GetComponent<Components::Model>(brick);
|
||||||
model->Color = glm::vec4(1.f, 0.f, 0.f, .0f);
|
model->Color = glm::vec4(1.f, 0.f, 0.f, 1.f);
|
||||||
} else if (typeInt == StickyBrick) {
|
} else if (typeInt == StickyBrick) {
|
||||||
cBrick->Type = StickyBrick;
|
cBrick->Type = StickyBrick;
|
||||||
auto model = m_World->GetComponent<Components::Model>(brick);
|
auto model = m_World->GetComponent<Components::Model>(brick);
|
||||||
model->Color = glm::vec4(0.f, 0.f, 1.f, .0f);
|
model->Color = glm::vec4(0.f, 0.f, 1.f, 1.f);
|
||||||
}
|
}
|
||||||
float x = line * spacesBetweenBricks.x;
|
float x = line * spacesBetweenBricks.x;
|
||||||
float y = row * spacesBetweenBricks.y;
|
float y = row * spacesBetweenBricks.y;
|
||||||
@@ -273,6 +273,7 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
|
|||||||
|
|
||||||
auto transformComponentBrick = m_World->GetComponent<Components::Transform>(entityBrick);
|
auto transformComponentBrick = m_World->GetComponent<Components::Transform>(entityBrick);
|
||||||
auto transformComponentBall = m_World->GetComponent<Components::Transform>(entityBall);
|
auto transformComponentBall = m_World->GetComponent<Components::Transform>(entityBall);
|
||||||
|
auto brickModel = m_World->GetComponent<Components::Model>(entityBrick);
|
||||||
|
|
||||||
Events::SetImpulse e;
|
Events::SetImpulse e;
|
||||||
e.Entity = entityBrick;
|
e.Entity = entityBrick;
|
||||||
@@ -291,6 +292,21 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
|
|||||||
es.Score = brick->Score * ball->Combo;
|
es.Score = brick->Score * ball->Combo;
|
||||||
EventBroker->Publish(es);
|
EventBroker->Publish(es);
|
||||||
|
|
||||||
|
Events::CreateParticleSequence ep;
|
||||||
|
ep.parent = entityBrick;
|
||||||
|
ep.EmitterLifeTime = 1.f;
|
||||||
|
ep.ParticleLifeTime = 1.5f;
|
||||||
|
ep.ParticlesPerTick = 1;
|
||||||
|
ep.SpawnRate = 0.2;
|
||||||
|
ep.EmittingAngle = glm::half_pi<float>();
|
||||||
|
ep.Spread = 1.5f;
|
||||||
|
ep.Position = transformComponentBrick->Position;
|
||||||
|
ep.Radius = 0.05;
|
||||||
|
ep.SpriteFile = "Textures/Particles/FadeBall.png";
|
||||||
|
ep.Color = brickModel->Color + glm::vec4(1);
|
||||||
|
ep.Speed = 50;
|
||||||
|
EventBroker->Publish(ep);
|
||||||
|
|
||||||
//std::cout << "Combo: " << ball->Combo << std::endl;
|
//std::cout << "Combo: " << ball->Combo << std::endl;
|
||||||
//std::cout << NumberOfBricks() << std::endl;
|
//std::cout << NumberOfBricks() << std::endl;
|
||||||
//std::cout << "Brick Score: " << brick->Score << std::endl;
|
//std::cout << "Brick Score: " << brick->Score << std::endl;
|
||||||
|
|||||||
@@ -265,12 +265,9 @@ void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, Entity
|
|||||||
auto particle = m_World->GetComponent<Components::Particle>(entity);
|
auto particle = m_World->GetComponent<Components::Particle>(entity);
|
||||||
auto pTemplate = m_World->GetComponent<Components::Template>(entity);
|
auto pTemplate = m_World->GetComponent<Components::Template>(entity);
|
||||||
|
|
||||||
if (particle && pTemplate)
|
|
||||||
LOG_ERROR("Particel + template finns");
|
|
||||||
|
|
||||||
if (particle && !pTemplate) {
|
if (particle && !pTemplate) {
|
||||||
//LOG_ERROR("Particel - template finns");
|
|
||||||
|
|
||||||
particle->LifeTime -= dt;
|
particle->LifeTime -= dt;
|
||||||
if (particle->LifeTime <= 0) {
|
if (particle->LifeTime <= 0) {
|
||||||
for (int i = 0; i < m_EntitiesToParticleHandle.size(); i++) {
|
for (int i = 0; i < m_EntitiesToParticleHandle.size(); i++) {
|
||||||
@@ -285,11 +282,24 @@ void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, Entity
|
|||||||
if (iter2 != m_ParticleHandleToEntities[i].end()) {
|
if (iter2 != m_ParticleHandleToEntities[i].end()) {
|
||||||
m_ParticleHandleToEntities[i].erase(iter2);
|
m_ParticleHandleToEntities[i].erase(iter2);
|
||||||
}
|
}
|
||||||
LOG_INFO("Deleteing particle!!.");
|
|
||||||
m_World->RemoveEntity(entity);
|
m_World->RemoveEntity(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
auto sprite = m_World->GetComponent<Components::Sprite>(entity);
|
||||||
|
sprite->Color.w = particle->LifeTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto emitter = m_World->GetComponent<Components::ParticleEmitter>(entity);
|
||||||
|
if (emitter) {
|
||||||
|
EntityID emitterParent = emitter->Parent;
|
||||||
|
if (emitterParent != 0) {
|
||||||
|
auto emitterTransform = m_World->GetComponent<Components::Transform>(entity);
|
||||||
|
auto parentTransform = m_World->GetComponent<Components::Transform>(emitterParent);
|
||||||
|
if (emitterTransform && parentTransform) {
|
||||||
|
emitterTransform->Position = parentTransform->Position;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dd::Systems::PhysicsSystem::OnPause(const dd::Events::Pause &event)
|
bool dd::Systems::PhysicsSystem::OnPause(const dd::Events::Pause &event)
|
||||||
@@ -344,6 +354,7 @@ void dd::Systems::PhysicsSystem::OnEntityRemoved(EntityID entity)
|
|||||||
m_BodiesToEntities.erase(it->second);
|
m_BodiesToEntities.erase(it->second);
|
||||||
m_EntitiesToBodies.erase(entity);
|
m_EntitiesToBodies.erase(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -480,8 +491,8 @@ void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
|||||||
LOG_INFO("ParticleTemplate Component is nil.");
|
LOG_INFO("ParticleTemplate Component is nil.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto TempTransform = m_World->GetComponent<Components::Transform>(e);
|
auto emitterTransform = m_World->GetComponent<Components::Transform>(e);
|
||||||
TempTransform->Orientation = glm::rotate(glm::quat(), 3.f, glm::vec3(0.f, 0.f, -1.f));
|
emitterTransform->Orientation = glm::rotate(glm::quat(), 3.f, glm::vec3(0.f, 0.f, -1.f));
|
||||||
|
|
||||||
emitter->TimeSinceLastSpawn += dt;
|
emitter->TimeSinceLastSpawn += dt;
|
||||||
emitter->LifeTime -= dt;
|
emitter->LifeTime -= dt;
|
||||||
@@ -506,20 +517,22 @@ void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
|||||||
|
|
||||||
std::uniform_real_distribution<float> dis(eAngle - halfSpread, eAngle + halfSpread);
|
std::uniform_real_distribution<float> dis(eAngle - halfSpread, eAngle + halfSpread);
|
||||||
float pAngle = dis(gen);
|
float pAngle = dis(gen);
|
||||||
|
std::uniform_real_distribution<float> dis2(0.3, 1.5);
|
||||||
|
float speedMultiplier = dis2(gen);
|
||||||
glm::vec2 unitVec = glm::normalize(glm::vec2(glm::cos(pAngle), glm::sin(pAngle)));
|
glm::vec2 unitVec = glm::normalize(glm::vec2(glm::cos(pAngle), glm::sin(pAngle)));
|
||||||
glm::vec2 vel = unitVec * emitter->Speed * (float)dt;
|
glm::vec2 vel = unitVec * emitter->Speed * (float)dt * speedMultiplier * 0.5f;
|
||||||
particleDef.velocity = b2Vec2(vel.x, vel.y);
|
particleDef.velocity = b2Vec2(vel.x, vel.y);
|
||||||
particleDef.position = b2Vec2(templateTransform->Position.x, templateTransform->Position.y);
|
particleDef.position = b2Vec2(emitterTransform->Position.x, emitterTransform->Position.y);
|
||||||
|
|
||||||
|
|
||||||
auto particle = m_World->CloneEntity(pt, 0);
|
auto particle = m_World->CloneEntity(pt, 0);
|
||||||
m_World->RemoveComponent<Components::Template>(particle);
|
m_World->RemoveComponent<Components::Template>(particle);
|
||||||
auto transform2 = m_World->GetComponent<Components::Transform>(particle);
|
auto transform2 = m_World->GetComponent<Components::Transform>(particle);
|
||||||
|
|
||||||
std::uniform_real_distribution<float> dist(0, 1);
|
std::uniform_real_distribution<float> dist(0, 1);
|
||||||
float zDistribution = dist(gen);
|
float zDistribution = dist(gen);
|
||||||
transform2->Position = glm::vec3(transform2->Position.x, transform2->Position.y, -9.5f + zDistribution);
|
transform2->Position = glm::vec3(emitterTransform->Position.x, emitterTransform->Position.y, -9.5f + zDistribution);
|
||||||
transform2->Scale = glm::vec3(particleTemplate->Radius * 2.f, particleTemplate->Radius * 2.f, 1);
|
transform2->Scale = glm::vec3(particleTemplate->Radius * 2.f / speedMultiplier, particleTemplate->Radius * 2.f / speedMultiplier, 1);
|
||||||
|
|
||||||
|
|
||||||
auto b2Particle = ps->CreateParticle(particleDef);
|
auto b2Particle = ps->CreateParticle(particleDef);
|
||||||
@@ -580,10 +593,15 @@ void dd::Systems::PhysicsSystem::UpdateParticleEmitters(double dt)
|
|||||||
bool dd::Systems::PhysicsSystem::CreateParticleSequence(const Events::CreateParticleSequence &event)
|
bool dd::Systems::PhysicsSystem::CreateParticleSequence(const Events::CreateParticleSequence &event)
|
||||||
{
|
{
|
||||||
//Creating Emitter
|
//Creating Emitter
|
||||||
auto emitter = m_World->CreateEntity();
|
EntityID emitter = m_World->CreateEntity();
|
||||||
|
|
||||||
auto emitterTransform = m_World->AddComponent<Components::Transform>(emitter);
|
auto emitterTransform = m_World->AddComponent<Components::Transform>(emitter);
|
||||||
auto particleEmitter= m_World->AddComponent<Components::ParticleEmitter>(emitter);
|
auto particleEmitter= m_World->AddComponent<Components::ParticleEmitter>(emitter);
|
||||||
|
|
||||||
|
if (event.parent != 0) {
|
||||||
|
particleEmitter->Parent = event.parent;
|
||||||
|
}
|
||||||
|
|
||||||
emitterTransform->Position = event.Position;
|
emitterTransform->Position = event.Position;
|
||||||
particleEmitter->GravityScale = event.GravityScale;
|
particleEmitter->GravityScale = event.GravityScale;
|
||||||
particleEmitter->SpawnRate = event.SpawnRate;
|
particleEmitter->SpawnRate = event.SpawnRate;
|
||||||
@@ -685,18 +703,18 @@ bool dd::Systems::PhysicsSystem::OnContact(const dd::Events::Contact &event)
|
|||||||
model = m_World->GetComponent<Components::Model>(event.Entity1);
|
model = m_World->GetComponent<Components::Model>(event.Entity1);
|
||||||
}
|
}
|
||||||
Events::CreateParticleSequence e;
|
Events::CreateParticleSequence e;
|
||||||
e.EmitterLifeTime = 2;
|
e.EmitterLifeTime = 4;
|
||||||
//- glm::atan(event.Normal.x, event.Normal.y
|
//- glm::atan(event.Normal.x, event.Normal.y
|
||||||
e.EmittingAngle = glm::half_pi<float>();
|
e.EmittingAngle = glm::half_pi<float>();
|
||||||
e.Spread = 0;
|
e.Spread = 0.5f;
|
||||||
e.NumberOfTicks = 1;
|
e.NumberOfTicks = 1;
|
||||||
e.ParticleLifeTime = 1.f;
|
e.ParticleLifeTime = 1.f;
|
||||||
e.ParticlesPerTick = 1;
|
e.ParticlesPerTick = 15;
|
||||||
e.Position = glm::vec3(event.IntersectionPoint.x, event.IntersectionPoint.y, -10);
|
e.Position = glm::vec3(event.IntersectionPoint.x, event.IntersectionPoint.y, -10);
|
||||||
e.Radius = 0.1f;
|
e.Radius = 0.2f;
|
||||||
e.SpriteFile = "Textures/Bricks/3.png";
|
e.SpriteFile = "Textures/Particles/Cloud_Particle.png";
|
||||||
e.Color = model->Color;
|
e.Color = model->Color + glm::vec4(1);
|
||||||
e.Speed = 100.f;
|
e.Speed = 100;
|
||||||
EventBroker->Publish(e);
|
EventBroker->Publish(e);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user