-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParticleSystem.cpp
More file actions
64 lines (49 loc) · 1.75 KB
/
Copy pathParticleSystem.cpp
File metadata and controls
64 lines (49 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "ParticleSystem.h"
ParticleSystem::ParticleSystem(Transform* transform, GameObject* parent, int maxParticles) : mTransform(transform), mParent(parent), mMaxParticles(maxParticles)
{
}
ParticleSystem::ParticleSystem(Transform* transform, int maxParticles) : mTransform(transform), mMaxParticles(maxParticles)
{
mParent = nullptr;
}
ParticleSystem::~ParticleSystem()
{
}
void ParticleSystem::Draw(ID3D11DeviceContext* pImmediateContext, ConstantBuffer cb, ID3D11Buffer* constantBuffer)
{
ConstantBuffer cBuffer = cb;
for(auto &particle : mParticles)
{
// Copy material to shader
cBuffer.surface.AmbientMtrl = particle->GetAppearance()->GetMaterial().ambient;
cBuffer.surface.DiffuseMtrl = particle->GetAppearance()->GetMaterial().diffuse;
cBuffer.surface.SpecularMtrl = particle->GetAppearance()->GetMaterial().specular;
// Set world matrix
cBuffer.World = XMMatrixTranspose(particle->GetWorldMatrix());
//no texture
cBuffer.HasTexture = 0.0f;
pImmediateContext->UpdateSubresource(constantBuffer, 0, nullptr, &cBuffer, 0, 0);
particle->Draw(pImmediateContext);
}
}
void ParticleSystem::Update(float t)
{
for (auto &particle : mParticles)
{
particle->Update(t);
}
}
void ParticleSystem::CreateParticles(int num, Geometry geometry, Material material, Vector3D rotation, Vector3D scale, Vector3D color, float mass, float lifeSpan)
{
for (int i = 0; i < num; i++)
{
if (mParticles.size() >= mMaxParticles)
{
return;
}
Transform* transform = new Transform(Vector3D(0.0f, 0.0f, 0.0f), rotation, scale);
PhysicsModel* pPhysics = new PhysicsModel(transform);
pPhysics->SetMass(mass);
mParticles.push_back(new Particle("Particle", new Appearance(geometry, material), transform, this->mTransform, pPhysics, color, lifeSpan));
}
}