MCPcopy Create free account
hub / github.com/NVIDIA/cuda-samples / sphereEmitter

Method sphereEmitter

cpp/5_Domain_Specific/smokeParticles/ParticleSystem.cpp:330–369  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

328}
329
330void ParticleSystem::sphereEmitter(uint &index,
331 vec3f pos,
332 vec3f vel,
333 vec3f spread,
334 float r,
335 int n,
336 float lifetime,
337 float lifetimeVariance)
338{
339 float4 *posPtr = m_pos.getHostPtr();
340 float4 *velPtr = m_vel.getHostPtr();
341
342 uint start = index;
343 uint count = 0;
344
345 for (int i = 0; i < n; i++) {
346 vec3f x = randSphere();
347
348 // float dist = length(x);
349 if (index < m_numParticles) {
350 vec3f p = pos + x * r;
351 float age = 0.0;
352
353 float lt = lifetime + frand() * lifetimeVariance;
354
355 vec3f dir = randSphere();
356 dir.y = fabs(dir.y);
357 vec3f v = vel + dir * spread;
358
359 posPtr[index] = make_float4(p.x, p.y, p.z, age);
360 velPtr[index] = make_float4(v.x, v.y, v.z, lt);
361
362 index++;
363 count++;
364 }
365 }
366
367 m_pos.copy(GpuArray<float4>::HOST_TO_DEVICE, start, count);
368 m_vel.copy(GpuArray<float4>::HOST_TO_DEVICE, start, count);
369}
370
371void ParticleSystem::setModelView(float *m)
372{

Callers 1

runEmitterFunction · 0.80

Calls 6

randSphereFunction · 0.85
fabsFunction · 0.85
make_float4Function · 0.85
getHostPtrMethod · 0.80
copyMethod · 0.80
frandFunction · 0.70

Tested by

no test coverage detected