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

Function main

examples/graphics/gravity_sim.cpp:181–255  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

179}
180
181int main(int, char **) {
182 try {
183 af::info();
184
185 af::Window myWindow(width, height,
186 "Gravity Simulation using ArrayFire");
187 myWindow.setColorMap(AF_COLORMAP_HEAT);
188
189 int frame_count = 0;
190
191 // Initialize the kernel array just once
192 const af::array draw_kernel = gaussianKernel(7, 7);
193
194 const int dims = (is3D) ? 3 : 2;
195
196 vector<af::array> pos(dims);
197 vector<af::array> vels(dims);
198 vector<af::array> forces(dims);
199 af::array mass;
200
201 // Generate a random starting state
202 initial_conditions_galaxy(mass, pos, vels, forces);
203
204 af::array image = af::constant(0, width, height);
205 af::array ids(total_particles, u32);
206
207 af::timer timer = af::timer::start();
208 while (!myWindow.close()) {
209 float dt = af::timer::stop(timer);
210 timer = af::timer::start();
211
212 af::array mid = mass(span) > (min_mass + mass_range / 3);
213 ids = (is3D) ? ids_from_3D(pos, 0, 0 + frame_count / 150.f, 0, mid)
214 : ids_from_pos(pos);
215 // ids = (is3D)? ids_from_3D(pos, 0, 0, 0, mid) : ids_from_pos(pos);
216 // //uncomment for no 3d rotation
217 image(ids) += 4.f;
218
219 mid = mass(span) > (min_mass + 2 * mass_range / 3);
220 ids = (is3D) ? ids_from_3D(pos, 0, 0 + frame_count / 150.f, 0, mid)
221 : ids_from_pos(pos);
222 // ids = (is3D)? ids_from_3D(pos, 0, 0, 0, mid) : ids_from_pos(pos);
223 // //uncomment for no 3d rotation
224 image(ids) += 4.f;
225
226 ids = (is3D) ? ids_from_3D(pos, 0, 0 + frame_count / 150.f, 0)
227 : ids_from_pos(pos);
228 // ids = (is3D)? ids_from_3D(pos, 0, 0, 0) : ids_from_pos(pos);
229 // //uncomment for no 3d rotation
230 image(ids) += 4.f;
231
232 image = convolve(image, draw_kernel);
233 myWindow.image(image);
234 image = af::constant(0, image.dims());
235
236 frame_count++;
237
238 // Generate a random starting state

Callers

nothing calls this directly

Calls 13

infoFunction · 0.85
constantFunction · 0.85
ids_from_3DFunction · 0.85
ids_from_posFunction · 0.85
simulateFunction · 0.85
collisionsFunction · 0.85
setColorMapMethod · 0.80
closeMethod · 0.80
imageMethod · 0.80
gaussianKernelFunction · 0.50
convolveFunction · 0.50

Tested by

no test coverage detected