MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / MakeParticle

Method MakeParticle

Source/Graphics/particles.cpp:1325–1375  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1323}
1324
1325unsigned ParticleSystem::MakeParticle(SceneGraph* scenegraph, const std::string& path, const vec3& pos, const vec3& vel, const vec3& tint) {
1326 // ParticleTypeRef particle_type_ref = particle_types->ReturnRef(path);
1327 ParticleTypeRef particle_type_ref = Engine::Instance()->GetAssetManager()->LoadSync<ParticleType>(path);
1328 Particle* particle = new Particle();
1329 if (particle_type_ref->ae_ref.valid()) {
1330 particle->ae_reader.AttachTo(particle_type_ref->ae_ref);
1331 }
1332 particle->size = RangedRandomFloat(particle_type_ref->size_range[0], particle_type_ref->size_range[1]) * 0.5f;
1333 for (int i = 0; i < 4; ++i) {
1334 particle->color[i] = RangedRandomFloat(particle_type_ref->color_range[0][i], particle_type_ref->color_range[1][i]);
1335 }
1336 particle->position = pos;
1337 particle->velocity = vel;
1338 for (int i = 0; i < 3; ++i) {
1339 particle->color[i] *= tint[i];
1340 }
1341 particle->particle_type = particle_type_ref;
1342 particle->collided = false;
1343 particle->alive_time = 0.0f;
1344 particle->initial_size = particle->size;
1345 particle->initial_opacity = particle->color[3];
1346 if (particle_type_ref->opacity_ramp_time > 0.0f) {
1347 particle->color[3] = 0.0f;
1348 }
1349 if (!particle_type_ref->no_rotation) {
1350 particle->rotate_speed = RangedRandomFloat(particle_type_ref->rotation_range[0], particle_type_ref->rotation_range[1]);
1351 particle->rotation = (float)abs(rand() % 720) - 360;
1352 } else {
1353 particle->rotate_speed = 0.0f;
1354 particle->rotation = 0.0f;
1355 }
1356 particle->old_position = particle->position;
1357 particle->old_color = particle->color;
1358 particle->old_size = particle->size;
1359 particle->old_rotation = particle->rotation;
1360 particle->has_last_connected = false;
1361 int id = CreateID();
1362 particle->id = id;
1363
1364 particles.push_back(particle);
1365 particle_map[particle->id] = particle;
1366 // Only allow one theora-reading particle at any given time
1367 if (particle->ae_reader.valid()) {
1368 for (int i = (int)particles.size() - 2; i >= 0; --i) {
1369 if (particles[i]->ae_reader.valid()) {
1370 deleteParticle(i);
1371 }
1372 }
1373 }
1374 return id;
1375}
1376
1377// Dispose of particle system
1378void ParticleSystem::Dispose() {

Callers 10

UpdateMethod · 0.80
CollidedMethod · 0.80
MPCutPlaneMethod · 0.80
CutPlaneMethod · 0.80
StabMethod · 0.80
asMaterialParticleFunction · 0.80
CreateLeafMethod · 0.80
ASMakeParticleFunction · 0.80
ASMakeParticleColorFunction · 0.80

Calls 7

RangedRandomFloatFunction · 0.85
GetAssetManagerMethod · 0.80
absFunction · 0.50
validMethod · 0.45
AttachToMethod · 0.45
push_backMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected