Emitter childed to a wheel. BUG FIXED: Billboarding calculation.

This commit is contained in:
Stiffly
2014-05-12 22:21:27 +02:00
parent 5d48ea7e2a
commit 19a2879104
6 changed files with 52 additions and 18 deletions
+1 -1
Submodule assets updated: 8b6c48b26b...e2b54e6212
+31 -2
View File
@@ -436,6 +436,31 @@ void GameWorld::Initialize()
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
CommitEntity(wheel);
auto entity = CreateEntity(wheel);
auto transformComponent = AddComponent<Components::Transform>(entity, "Transform");
/*transformComponent->Position = glm::vec3(0,3,0);*/
transformComponent->Scale = glm::vec3(3,3,3);
transformComponent->Orientation = glm::angleAxis(glm::pi<float>()/2, glm::vec3(1,0,0));
auto emitterComponent = AddComponent<Components::ParticleEmitter>(entity, "ParticleEmitter");
emitterComponent->SpawnCount = 2;
emitterComponent->SpawnFrequency = 0.01;
emitterComponent->SpreadAngle = glm::pi<float>()/4;
emitterComponent->UseGoalVelocity = false;
emitterComponent->LifeTime = 2.0;
emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.1));
auto modelComponent = AddComponent<Components::Model>(entity, "Model");
modelComponent->ModelFile = "Models/Placeholders/PhysicsTest/PointLight.obj";
CommitEntity(entity);
auto particleEntity = CreateEntity(entity);
auto TEMP = AddComponent<Components::Transform>(particleEntity, "Transform");
TEMP->Scale = glm::vec3(0);
auto spriteComponent = AddComponent<Components::Sprite>(particleEntity, "Sprite");
spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png";
emitterComponent->ParticleTemplate = particleEntity;
CommitEntity(particleEntity);
}
CommitEntity(tank);
@@ -528,6 +553,10 @@ void GameWorld::Initialize()
GetSystem<Systems::SoundSystem>("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");
+5 -5
View File
@@ -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);
+9 -6
View File
@@ -4,6 +4,11 @@
#include "World.h"
void Systems::ParticleSystem::Initialize()
{
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>("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<Components::Transform>(entity, "Transform");
auto emitterTransformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
if(emitterComponent->TimeSinceLastSpawn > emitterComponent->SpawnFrequency)
{
SpawnParticles(entity);
emitterComponent->TimeSinceLastSpawn = 0;
}
std::list<ParticleData>::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<Components::ParticleEmitter>(emitterID, "ParticleEmitter");
auto emitterTransform = m_World->GetComponent<Components::Transform>(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<Components::Transform>(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.
+6 -1
View File
@@ -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<EntityID, std::list<ParticleData>> m_ParticleEmitter;
std::map<EntityID, double> m_TimeSinceLastSpawn;
std::shared_ptr<Systems::TransformSystem> m_TransformSystem;
};
@@ -273,9 +273,6 @@
<ClInclude Include="..\..\src\Components\Particle.h">
<Filter>Particle System\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\Sphere.h">
<Filter>Physics\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\GUI\Frame.h">
<Filter>GUI</Filter>
</ClInclude>