MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / collisions

Function collisions

examples/graphics/gravity_sim.cpp:159–179  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

157}
158
159void 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
181int main(int, char **) {
182 try {

Callers 1

mainFunction · 0.85

Calls 2

minFunction · 0.50
maxFunction · 0.50

Tested by

no test coverage detected