//////////////////////////////////////////////////////////// // Check for collisions with rocks //////////////////////////////////////////////////////////// void CheckCollisions(R3Scene *scene) { const double MOVEMENT_WEIGHT = 0.02; // check each bobsled - //TODO CHANGE THIS WHEN WE HAVE MULTIPLE BOBSLEDS for (unsigned int i = 0; i < 1; i++) { R3Bobsled *bobsled = scene->bobsleds[i]; bobsled->x_vibration = 0.0; R3Box &bbox = bobsled->sleds[0]->mesh->bbox; // printf("bobsled: %f %f %f %f %f %f\n", bbox.XMin(), bbox.XMax(), bbox.YMin(), bbox.YMax(), bbox.ZMin(), bbox.ZMax()); // check each obstacle for a collision for (unsigned int j = 0; j < scene->obstacles.size(); j++) { R3Obstacle *obstacle = scene->obstacles[j]; R3Box intersection = bbox; R3Box *obstacle_box = ObstacleBBox(obstacle); intersection.Intersect(*obstacle_box); if (intersection.XMin() < intersection.XMax() && intersection.YMin() < intersection.YMax() && intersection.ZMin() < intersection.ZMax()) { double current_z = bobsled->velocity.Z(); // slow down if (obstacle->hit_count == 0 && abs(current_z) > 40) bobsled->velocity.SetZ(current_z * 0.6); // add left-to-right vibration if this is a rock if (obstacle->type == OBSTACLE_ROCK) { if (obstacle->hit_count - 2 * ((int) obstacle->hit_count / 2) == 0) bobsled->x_vibration = MOVEMENT_WEIGHT * (1 + Rand()); else bobsled->x_vibration = - MOVEMENT_WEIGHT * (1 + Rand()); } obstacle->hit_count++; } delete obstacle_box; } } }