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

Method addSphere

cpp/5_Domain_Specific/smokeParticles/ParticleSystem.cpp:236–265  ·  view source on GitHub ↗

add sphere on regular grid

Source from the content-addressed store, hash-verified

234
235// add sphere on regular grid
236void ParticleSystem::addSphere(uint &index, vec3f pos, vec3f vel, int r, float spacing, float jitter, float lifetime)
237{
238 float4 *posPtr = m_pos.getHostPtr();
239 float4 *velPtr = m_vel.getHostPtr();
240
241 uint start = index;
242 uint count = 0;
243
244 for (int z = -r; z <= r; z++) {
245 for (int y = -r; y <= r; y++) {
246 for (int x = -r; x <= r; x++) {
247 vec3f delta = vec3f((float)x, (float)y, (float)z) * spacing;
248 float dist = length(delta);
249
250 if ((dist <= spacing * r) && (index < m_numParticles)) {
251 // vec3f p = pos + delta + svrand()*jitter;
252
253 posPtr[index] = make_float4(pos.x, pos.y, pos.z, 0.0f);
254 velPtr[index] = make_float4(vel.x, vel.y, vel.z, lifetime);
255
256 index++;
257 count++;
258 }
259 }
260 }
261 }
262
263 m_pos.copy(GpuArray<float4>::HOST_TO_DEVICE, start, count);
264 m_vel.copy(GpuArray<float4>::HOST_TO_DEVICE, start, count);
265}
266
267void ParticleSystem::reset(ParticleConfig config)
268{

Callers

nothing calls this directly

Calls 4

make_float4Function · 0.85
getHostPtrMethod · 0.80
copyMethod · 0.80
lengthFunction · 0.70

Tested by

no test coverage detected