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

Method initGrid

cpp/2_Concepts_and_Techniques/particles/particleSystem.cpp:404–429  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

402inline float frand() { return rand() / (float)RAND_MAX; }
403
404void ParticleSystem::initGrid(uint *size, float spacing, float jitter, uint numParticles)
405{
406 srand(1973);
407
408 for (uint z = 0; z < size[2]; z++) {
409 for (uint y = 0; y < size[1]; y++) {
410 for (uint x = 0; x < size[0]; x++) {
411 uint i = (z * size[1] * size[0]) + (y * size[0]) + x;
412
413 if (i < numParticles) {
414 m_hPos[i * 4] = (spacing * x) + m_params.particleRadius - 1.0f + (frand() * 2.0f - 1.0f) * jitter;
415 m_hPos[i * 4 + 1] =
416 (spacing * y) + m_params.particleRadius - 1.0f + (frand() * 2.0f - 1.0f) * jitter;
417 m_hPos[i * 4 + 2] =
418 (spacing * z) + m_params.particleRadius - 1.0f + (frand() * 2.0f - 1.0f) * jitter;
419 m_hPos[i * 4 + 3] = 1.0f;
420
421 m_hVel[i * 4] = 0.0f;
422 m_hVel[i * 4 + 1] = 0.0f;
423 m_hVel[i * 4 + 2] = 0.0f;
424 m_hVel[i * 4 + 3] = 0.0f;
425 }
426 }
427 }
428 }
429}
430
431void ParticleSystem::reset(ParticleConfig config)
432{

Callers

nothing calls this directly

Calls 1

frandFunction · 0.70

Tested by

no test coverage detected