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

Method initGrid

cpp/5_Domain_Specific/smokeParticles/ParticleSystem.cpp:193–220  ·  view source on GitHub ↗

initialize in regular grid

Source from the content-addressed store, hash-verified

191
192// initialize in regular grid
193void ParticleSystem::initGrid(vec3f start,
194 uint3 size,
195 vec3f spacing,
196 float jitter,
197 vec3f vel,
198 uint numParticles,
199 float lifetime)
200{
201 srand(1973);
202
203 float4 *posPtr = m_pos.getHostPtr();
204 float4 *velPtr = m_vel.getHostPtr();
205
206 for (uint z = 0; z < size.z; z++) {
207 for (uint y = 0; y < size.y; y++) {
208 for (uint x = 0; x < size.x; x++) {
209 uint i = (z * size.y * size.x) + (y * size.x) + x;
210
211 if (i < numParticles) {
212 vec3f pos = start + spacing * vec3f((float)x, (float)y, (float)z) + svrand() * jitter;
213
214 posPtr[i] = make_float4(pos.x, pos.y, pos.z, 0.0f);
215 velPtr[i] = make_float4(vel.x, vel.y, vel.z, lifetime);
216 }
217 }
218 }
219 }
220}
221
222// initialize in random positions within cube
223void ParticleSystem::initCubeRandom(vec3f origin, vec3f size, vec3f vel, float lifetime)

Callers

nothing calls this directly

Calls 3

svrandFunction · 0.85
make_float4Function · 0.85
getHostPtrMethod · 0.80

Tested by

no test coverage detected