| 157 | } |
| 158 | |
| 159 | void collisions(vector<af::array> &pos, vector<af::array> &vels, bool is3D) { |
| 160 | // clamp particles inside screen border |
| 161 | af::array invalid_x = -2 * (pos[0] > width - 1 || pos[0] < 0) + 1; |
| 162 | af::array invalid_y = -2 * (pos[1] > height - 1 || pos[1] < 0) + 1; |
| 163 | // af::array invalid_x = (pos[0] < width-1 || pos[0] > 0); |
| 164 | // af::array invalid_y = (pos[1] < height-1 || pos[1] > 0); |
| 165 | vels[0] = invalid_x * vels[0]; |
| 166 | vels[1] = invalid_y * vels[1]; |
| 167 | |
| 168 | af::array projected_px = min(width - 1, max(0, pos[0])); |
| 169 | af::array projected_py = min(height - 1, max(0, pos[1])); |
| 170 | pos[0] = projected_px; |
| 171 | pos[1] = projected_py; |
| 172 | |
| 173 | if (is3D) { |
| 174 | af::array invalid_z = -2 * (pos[2] > depth - 1 || pos[2] < 0) + 1; |
| 175 | vels[2] = invalid_z * vels[2]; |
| 176 | af::array projected_pz = min(depth - 1, max(0, pos[2])); |
| 177 | pos[2] = projected_pz; |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | int main(int, char **) { |
| 182 | try { |