diff --git a/assets b/assets index 8b6c48b..e2b54e6 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 8b6c48b26b3bbc10f5e66c1f59fec6ca935f641b +Subproject commit e2b54e6212eb1233e6f9935b9e5d7c0295f9ffc6 diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 979376b..1cae957 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -436,6 +436,31 @@ void GameWorld::Initialize() Wheel->ConnectedToHandbrake = true; Wheel->TorqueRatio = 0.125f; CommitEntity(wheel); + + auto entity = CreateEntity(wheel); + auto transformComponent = AddComponent(entity, "Transform"); + /*transformComponent->Position = glm::vec3(0,3,0);*/ + transformComponent->Scale = glm::vec3(3,3,3); + transformComponent->Orientation = glm::angleAxis(glm::pi()/2, glm::vec3(1,0,0)); + auto emitterComponent = AddComponent(entity, "ParticleEmitter"); + emitterComponent->SpawnCount = 2; + emitterComponent->SpawnFrequency = 0.01; + emitterComponent->SpreadAngle = glm::pi()/4; + emitterComponent->UseGoalVelocity = false; + emitterComponent->LifeTime = 2.0; + emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.1)); + auto modelComponent = AddComponent(entity, "Model"); + modelComponent->ModelFile = "Models/Placeholders/PhysicsTest/PointLight.obj"; + CommitEntity(entity); + + auto particleEntity = CreateEntity(entity); + auto TEMP = AddComponent(particleEntity, "Transform"); + TEMP->Scale = glm::vec3(0); + auto spriteComponent = AddComponent(particleEntity, "Sprite"); + spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png"; + emitterComponent->ParticleTemplate = particleEntity; + + CommitEntity(particleEntity); } CommitEntity(tank); @@ -528,6 +553,10 @@ void GameWorld::Initialize() GetSystem("SoundSystem")->PlaySound(emitter); CommitEntity(entity); }*/ + + { + + } } void GameWorld::Update(double dt) @@ -548,7 +577,7 @@ void GameWorld::RegisterSystems() m_SystemFactory.Register("InputSystem", [this]() { return new Systems::InputSystem(this, m_EventBroker); }); m_SystemFactory.Register("DebugSystem", [this]() { return new Systems::DebugSystem(this, m_EventBroker); }); //m_SystemFactory.Register("CollisionSystem", [this]() { return new Systems::CollisionSystem(this); }); - ////m_SystemFactory.Register("ParticleSystem", [this]() { return new Systems::ParticleSystem(this); }); + m_SystemFactory.Register("ParticleSystem", [this]() { return new Systems::ParticleSystem(this, m_EventBroker); }); //m_SystemFactory.Register("PlayerSystem", [this]() { return new Systems::PlayerSystem(this); }); m_SystemFactory.Register("FreeSteeringSystem", [this]() { return new Systems::FreeSteeringSystem(this, m_EventBroker); }); m_SystemFactory.Register("TankSteeringSystem", [this]() { return new Systems::TankSteeringSystem(this, m_EventBroker); }); @@ -564,7 +593,7 @@ void GameWorld::AddSystems() AddSystem("InputSystem"); AddSystem("DebugSystem"); //AddSystem("CollisionSystem"); - ////AddSystem("ParticleSystem"); + AddSystem("ParticleSystem"); //AddSystem("PlayerSystem"); AddSystem("FreeSteeringSystem"); AddSystem("TankSteeringSystem"); diff --git a/src/Renderer.cpp b/src/Renderer.cpp index 99f27a9..2905891 100755 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -274,10 +274,9 @@ void Renderer::DrawScene() glm::mat4 billboardMatrix; std::tie(texture, modelMatrix, billboardMatrix) = tuple; - //MVP = cameraMatrix * glm::inverse(glm::toMat4(m_Camera->Orientation()) * modelMatrix ); - MVP = cameraMatrix * billboardMatrix * modelMatrix; - + MVP = cameraMatrix * modelMatrix * billboardMatrix; + depthMVP = depthCameraMatrix * modelMatrix; glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "DepthMVP"), 1, GL_FALSE, glm::value_ptr(depthMVP)); @@ -410,11 +409,12 @@ void Renderer::AddTextureToDraw(Texture* texture, glm::vec3 position, glm::quat glm::vec3 camToParticle = glm::normalize(m_Camera->Position() - position); glm::vec3 up = glm::vec3(0,1,0); - glm::vec3 rightVec = glm::cross(up, camToParticle); + glm::vec3 rightVec = glm::normalize(glm::cross(up, camToParticle)); + glm::vec3 up2 = glm::normalize(glm::cross(camToParticle, rightVec)); glm::mat4 billboardMatrix; billboardMatrix[0] = glm::vec4(rightVec, 0); - billboardMatrix[1] = glm::vec4(up, 0); + billboardMatrix[1] = glm::vec4(up2, 0); billboardMatrix[2] = glm::vec4(camToParticle, 0); //billboardMatrix[3] = glm::vec4(position, 0); diff --git a/src/Systems/ParticleSystem.cpp b/src/Systems/ParticleSystem.cpp index e77e9c9..0882f9d 100644 --- a/src/Systems/ParticleSystem.cpp +++ b/src/Systems/ParticleSystem.cpp @@ -4,6 +4,11 @@ #include "World.h" +void Systems::ParticleSystem::Initialize() +{ + m_TransformSystem = m_World->GetSystem("TransformSystem"); +} + void Systems::ParticleSystem::Update(double dt) { @@ -19,16 +24,13 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID if(emitterComponent) { emitterComponent->TimeSinceLastSpawn += dt; - auto transformComponent = m_World->GetComponent(entity, "Transform"); + auto emitterTransformComponent = m_World->GetComponent(entity, "Transform"); if(emitterComponent->TimeSinceLastSpawn > emitterComponent->SpawnFrequency) { SpawnParticles(entity); emitterComponent->TimeSinceLastSpawn = 0; } - - - std::list::iterator it; for(it = m_ParticleEmitter[entity].begin(); it != m_ParticleEmitter[entity].end();) { @@ -82,7 +84,7 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID } - transformComponent->Position += transformComponent->Velocity * (float)dt; + transformComponent->Position += transformComponent->Velocity * (float)dt; it++; } @@ -101,6 +103,7 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID) { auto emitterComponent = m_World->GetComponent(emitterID, "ParticleEmitter"); auto emitterTransform = m_World->GetComponent(emitterID, "Transform"); + glm::vec3 emitterPos = m_TransformSystem->AbsolutePosition(emitterID); glm::quat emitterOrientation = emitterTransform->Orientation; float tempSpeed = 4; @@ -111,7 +114,7 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID) auto ent = m_World->CloneEntity(emitterComponent->ParticleTemplate); auto particleTransform = m_World->GetComponent(ent, "Transform"); - particleTransform->Position = emitterTransform->Position; + particleTransform->Position = emitterPos; particleTransform->Orientation = emitterOrientation; //The emitter's orientation as "start value" times the default direction for emitter. Times the speed, and then rotate on x and y axis with the randomized spread angle. diff --git a/src/Systems/ParticleSystem.h b/src/Systems/ParticleSystem.h index d976105..06cbe63 100644 --- a/src/Systems/ParticleSystem.h +++ b/src/Systems/ParticleSystem.h @@ -2,6 +2,7 @@ #define ParticleSystem_h__ #include "System.h" +#include "Systems/TransformSystem.h" #include "Components/Transform.h" #include "Components/ParticleEmitter.h" #include "Components/Particle.h" @@ -25,10 +26,13 @@ namespace Systems class ParticleSystem : public System { public: - ParticleSystem(World* world); + ParticleSystem(World* world, std::shared_ptr<::EventBroker> eventBroker) + : System(world, eventBroker) { } + void RegisterComponents(ComponentFactory* cf) override; void Update(double dt) override; void UpdateEntity(double dt, EntityID entity, EntityID parent) override; + void Initialize() override; private: void SpawnParticles(EntityID emitterID); float RandomizeAngle(float spreadAngle); @@ -39,6 +43,7 @@ private: void Billboard(); std::map> m_ParticleEmitter; std::map m_TimeSinceLastSpawn; + std::shared_ptr m_TransformSystem; }; diff --git a/vs11/Returngeance/Returngeance.vcxproj.filters b/vs11/Returngeance/Returngeance.vcxproj.filters index 4128eef..cd6fb6b 100755 --- a/vs11/Returngeance/Returngeance.vcxproj.filters +++ b/vs11/Returngeance/Returngeance.vcxproj.filters @@ -273,9 +273,6 @@ Particle System\Components - - Physics\Components - GUI