add sphere on regular grid
| 234 | |
| 235 | // add sphere on regular grid |
| 236 | void 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 | |
| 267 | void ParticleSystem::reset(ParticleConfig config) |
| 268 | { |
nothing calls this directly
no test coverage detected