void physics_new_ball(void) { ball.x = arena.x / 2; ball.y = arena.y / 2; ball_velocity.x = random_velocity(); ball_velocity.y = random_velocity(); ball_spin = ((double)random() / ((double)RAND_MAX * 100)) + 0.005; }
// constructor sets up new sphere // NOTE : while condition was removed // TODO : maybe include it again Sphere::Sphere(double rad) { // RADIUS MUST BE BEFORE RANDOM POINTS radius = rad; // gets 4 random points for the bezier curve p1 = random_ranged_point(radius); p2 = new_curve_point(p1); p3 = new_curve_point(p2); p4 = new_curve_point(p3); // position starts at p1 pos = p1; // 3D previous_pos.x = 0.0; previous_pos.y = 5.0; previous_pos.z = 0.0; // = {0.0, 5.0, 0.0}; // gets a random direction, this might be a wasted step direction = random_direction(radius); active = 0; velocity = random_velocity(); // start on a curved path path = 1; color = random_color(); curve_length = get_curve_length(); start_time = (double) clock(); curve_time = curve_length / velocity; ghost = 0; }
/* * struct sphere generate_sphere(); * * return a ball */ struct sphere generate_sphere() { struct sphere ball; do{ // RADIUS MUST BE BEFORE RANDOM POINTS ball.radius = random_radius(); // gets 4 random points for the bezier curve ball.p1 = random_ranged_point(ball.radius); ball.p2 = new_curve_point(ball.p1); ball.p3 = new_curve_point(ball.p2); ball.p4 = new_curve_point(ball.p3); // position starts at p1 ball.pos = ball.p1; ball.previous_pos = {0.0, 0.0}; //printf("generation: %f %f || %f %f\n", ball.previous_pos.x, ball.previous_pos.y, ball.pos.x, ball.pos.y); // gets a random direction, this might be a wasted step ball.direction = random_direction(ball.radius); ball.active = 0; ball.velocity = random_velocity(); // start on a curved path ball.path = 1; // dead variable is set to 0, used to prevent collisions //ball.dead = 0; ball.color = random_color(); ball.curve_length = curve_length( &ball ); ball.start_time = (double) clock(); ball.curve_time = ball.curve_length / ball.velocity; ball.ghost = 0; }while(collision_detection(ball) == 1 ); return ball; }
/* * struct sphere generate_sphere(); * * return a ball */ struct sphere generate_sphere(int rad) { struct sphere ball; do{ // RADIUS MUST BE BEFORE RANDOM POINTS ball.radius = (rad) ? next_ball_radius : random_radius(); // gets 4 random points for the bezier curve ball.p1 = random_ranged_point(ball.radius); ball.p2 = new_curve_point(ball.p1); ball.p3 = new_curve_point(ball.p2); ball.p4 = new_curve_point(ball.p3); // position starts at p1 ball.pos = ball.p1; // 3D ball.previous_pos = {0.0, 5.0, 0.0}; // gets a random direction, this might be a wasted step ball.direction = random_direction(ball.radius); ball.active = 0; ball.velocity = random_velocity(); // start on a curved path ball.path = 1; ball.color = random_color(); ball.curve_length = curve_length( &ball ); ball.start_time = (double) clock(); ball.curve_time = ball.curve_length / ball.velocity; ball.ghost = 0; // 3D }while(collision_detection(ball) == 1 || ball.p1.x == 0.0 || ball.p1.y == 0.0 || ball.p1.z == 0.0); return ball; }