void Physics::step( real_t dt ) { // step the world forward by dt. Need to detect collisions, apply // forces, and integrate positions and orientations. for(size_t i=0; i<num_spheres(); i++){ //Update Spheres boundbox Vector3 upper = spheres[i]->position + Vector3(spheres[i]->radius, spheres[i]->radius, spheres[i]->radius); Vector3 lower = spheres[i]->position - Vector3(spheres[i]->radius, spheres[i]->radius, spheres[i]->radius); spheres[i]->bound = BoundBox(lower, upper); for(size_t j=0; j<num_spheres(); j++){ if(i!=j){ collides(*spheres[i], *spheres[j], collision_damping); } } for(size_t j=0; j<num_planes(); j++){ collides(*spheres[i], *planes[j], collision_damping); } for(size_t j=0; j<num_triangles(); j++){ collides(*spheres[i], *triangles[j], collision_damping); } for(size_t j=0; j<num_models(); j++){ collides(*spheres[i], *models[j], collision_damping); } //RK4 Position & Orientation rk4_update(*spheres[i], dt); spheres[i]->clear_force(); } }
void Physics::detect_collisions() { for (size_t i = 0; i < num_spheres(); i++) { for (size_t j = 0; j < num_spheres(); j++) { if (i != j) { collides(*(spheres[i]), *(spheres[j]), collision_damping); } } for (size_t j = 0; j < num_planes(); j++) { collides(*(spheres[i]), *(planes[j]), collision_damping); } for (size_t j = 0; j < num_triangles(); j++) { collides(*(spheres[i]), *(triangles[j]), collision_damping); } } }
void Physics::step( real_t dt ) { // Check collision between every sphere and other objects. for (size_t i = 0; i < num_spheres(); i++) { for (size_t j = 0; j < num_planes(); j++) collides(*spheres[i], *planes[j], collision_damping); for (size_t j = 0; j < num_triangles(); j++) collides(*spheres[i], *triangles[j], collision_damping); for (size_t j = i + 1; j < num_spheres(); j++) { collides(*spheres[i], *spheres[j], collision_damping); } } std::vector<State> states(num_spheres()); for (size_t i = 0; i < num_spheres(); i++) { states[i].position = spheres[i]->position; states[i].velocity = spheres[i]->velocity; states[i].angular_velocity = spheres[i]->angular_velocity; // Step dt using rk4 integral. rk4_integrate(states[i], spheres[i], dt); } // Update every sphere's state after rk4 integral. for (size_t i = 0; i < num_spheres(); i++) { spheres[i]->position = states[i].position; spheres[i]->velocity = states[i].velocity; spheres[i]->angular_velocity = states[i].angular_velocity; spheres[i]->update_orientation(states[i].angular_position); spheres[i]->sphere->orientation = spheres[i]->orientation; spheres[i]->sphere->position = states[i].position; // Update the offset vector of this sphere in every spring it is attached to. for (size_t j = 0; j < spheres[i]->spring_ptrs.size(); j++) { spheres[i]->spring_ptrs[j]->update_offset(spheres[i], states[i].angular_position); } } }