void bhtree_insert(Particle p, BHTree* bht){ double m = bht->body.mass; // if there are no particles if (m == 0.){ //printf("No particles in bht!\n"); // put this particle in bht->body = p; } // if it's an internal node else if (bht->is_leaf == false){ //printf("It's an internal node!\n"); // update the COM and total mass bht->body = particle_add(p, bht->body); // put the particle into the correct quadrant bhtree_put_into_correct_quad(p, bht); } // if it's an external node else if (bht->is_leaf == true){ //printf("It's a leaf!\n"); // if it's a leaf, then bht->body represents // a single particle. We'll initialize the // quadrants and then insert both into the // correct one(s). // initialize the four quadrants //BHTree* SW = malloc( sizeof( BHTree ) ); //bht->SW = SW; //BHTree SW = bhtree_new( quad_SW( bht->quad ) ); //bht->SW = &SW; //BHTree NW = bhtree_new( quad_NW( bht->quad ) ); bht->SW = bhtree_new( quad_SW( bht->quad ) ); bht->NW = bhtree_new( quad_NW( bht->quad ) ); bht->NE = bhtree_new( quad_NE( bht->quad ) ); bht->SE = bhtree_new( quad_SE( bht->quad ) ); //bht->NW = &NW; //BHTree NE = bhtree_new( quad_NE( bht->quad ) ); //bht->NE = ≠ //BHTree SE = bhtree_new( quad_SE( bht->quad ) ); //bht->SE = &SE; // put the two particles into the correct node(s) bhtree_put_into_correct_quad(p, bht); bhtree_put_into_correct_quad(bht->body, bht); // update the COM and mass info bht->body = particle_add(p, bht->body); bht->is_leaf = false; } }
void mouse_callback(GLFWwindow* window, int button, int action, int mods) { const int vk = 70; // Velocity to mouse vector coefficient double x, y; glfwGetCursorPos(window, &x, &y); if (action == GLFW_PRESS) { mouse.is_dragging = true; mouse.xp = x; mouse.yp = y; } else { mouse.is_dragging = false; particle_add((mouse.xp+x)/2, (mouse.yp+y)/2, (mouse.xp - x) / vk, (mouse.yp - y) / vk); } }
void update(void) { static int time = 0; if(SDL_GetTicks() - time > 16){ flicker = !flicker; time = SDL_GetTicks(); float pos[2] = {0.0f, 1.0f}; float vel[2] = {0.0f, 0.0f}; float ang = angle + (1.0f - 2.0f*(float)rand() / (float) RAND_MAX) * log(scale[player->state]) * - 5; float rad = 175.0f + 250 * exp(scale[player->state] / scale[elephant]); pos[0] = cos(3.0f*PI/2.0f-ang) * rad; pos[1] = sin(3.0f*PI/2.0f-ang) * rad; particle_add(pos, vel); } if(!title){ actor_update(player); particle_update(); } }