void render_spin_test() { Matrix *faces = mat_construct(0, 4); double col[4] = {0, 0, 0, 1}; double eye[3] = {0, 0, 100}; screen = malloc(4 * sizeof(double)); screen[0] = -10; screen[1] = -10; screen[2] = 10; screen[3] = 10; if (init_live_render(600, 600)) printf("live rendering setup failed... Exiting now.\n"); clock_t t; double rad = rand_radian(); unsigned long i; double white[3] = {1, 1, 1}; Matrix *color = mat_construct(0, 3); do { for (i=0; i < 3000; i++) { rand_point(col); mat_add_column(faces, col); mat_add_column(color, white); } t = clock(); apply_transform(rotate_y_mat(rad), &faces); rendercyclops(faces, eye, color); t = clock() - t; printf("%d faces spun in %f seconds\n", faces->cols/3, ((float)t)/CLOCKS_PER_SEC); } while (((float)t)/CLOCKS_PER_SEC < 1); renderppm("test.ppm"); mat_destruct(faces); }
void spin_test() { Matrix *faces = mat_construct(0, 4); double col[4] = {0, 0, 0, 1}; clock_t t; double rad = rand_radian(); unsigned long i; do { for (i=0; i < 3000; i++) { rand_point(col); mat_add_column(faces, col); } t = clock(); apply_transform(rotate_z_mat(rad), &faces); t = clock() - t; printf("%d faces spun in %f seconds\n", faces->cols/3,((float)t)/CLOCKS_PER_SEC); } while (((float)t)/CLOCKS_PER_SEC < 1); mat_destruct(faces); }
void start_location::place_player( player &u ) const { // Need the "real" map with it's inside/outside cache and the like. map &m = g->m; // Start us off somewhere in the center of the map u.setx( SEEX * int( MAPSIZE / 2 ) + 5 ); u.sety( SEEY * int( MAPSIZE / 2 ) + 6 ); u.setz( g->get_levz() ); m.build_map_cache( m.get_abs_sub().z ); const bool must_be_inside = flags().count( "ALLOW_OUTSIDE" ) == 0; ///\EFFECT_STR allows player to start behind less-bashable furniture and terrain const int bash = u.get_str(); // TODO: Allow using items here // Remember biggest found location // Sometimes it may be impossible to automatically found an ideal location // but the player may be more creative than this algorithm and do away with just "good" int best_rate = 0; // In which attempt did this area get checked? // We can overwrite earlier attempts, but not start in them int checked[SEEX * MAPSIZE][SEEY * MAPSIZE]; std::fill_n( &checked[0][0], SEEX * MAPSIZE * SEEY * MAPSIZE, 0 ); bool found_good_spot = false; // Try some random points at start int tries = 0; const auto check_spot = [&]( const tripoint & pt ) { tries++; const int rate = rate_location( m, pt, must_be_inside, bash, tries, checked ); if( best_rate < rate ) { best_rate = rate; u.setpos( pt ); if( rate == INT_MAX ) { found_good_spot = true; } } }; while( !found_good_spot && tries < 100 ) { tripoint rand_point( ( SEEX * int( MAPSIZE / 2 ) ) + rng( 0, SEEX * 2 ), ( SEEY * int( MAPSIZE / 2 ) ) + rng( 0, SEEY * 2 ), u.posz() ); check_spot( rand_point ); } // If we haven't got a good location by now, screw it and brute force it // This only happens in exotic locations (deep of a science lab), but it does happen if( !found_good_spot ) { tripoint tmp = u.pos(); int &x = tmp.x; int &y = tmp.y; for( x = 0; x < SEEX * MAPSIZE; x++ ) { for( y = 0; y < SEEY * MAPSIZE; y++ ) { check_spot( tmp ); } } } if( !found_good_spot ) { debugmsg( "Could not find a good starting place for character" ); } }
void PolycrystalVoronoiVoidIC::computeCircleCenters() { _centers.resize(_numbub); // This Code will place void center points on grain boundaries for (unsigned int vp = 0; vp < _numbub; ++vp) { bool try_again; unsigned int num_tries = 0; do { try_again = false; num_tries++; if (num_tries > _max_num_tries) mooseError("Too many tries of assigning void centers in " "PolycrystalVoronoiVoidIC"); Point rand_point; for (unsigned int i = 0; i < LIBMESH_DIM; ++i) rand_point(i) = _bottom_left(i) + _range(i) * _random.rand(_tid); // Allow the vectors to be sorted based on their distance from the // rand_point std::vector<PolycrystalVoronoiVoidIC::DistancePoint> diff(_grain_num); for (unsigned int gr = 0; gr < _grain_num; ++gr) { diff[gr].d = _mesh.minPeriodicDistance(_var.number(), rand_point, _centerpoints[gr]); diff[gr].gr = gr; } std::sort(diff.begin(), diff.end(), _customLess); Point closest_point = _centerpoints[diff[0].gr]; Point next_closest_point = _centerpoints[diff[1].gr]; // Find Slope of Line in the plane orthogonal to the diff_centerpoint // vector Point diff_centerpoints = _mesh.minPeriodicVector(_var.number(), closest_point, next_closest_point); Point diff_rand_center = _mesh.minPeriodicVector(_var.number(), closest_point, rand_point); Point normal_vector = diff_centerpoints.cross(diff_rand_center); Point slope = normal_vector.cross(diff_centerpoints); // Midpoint position vector between two center points Point midpoint = closest_point + (0.5 * diff_centerpoints); // Solve for the scalar multiplier solution on the line Real lambda = 0; Point mid_rand_vector = _mesh.minPeriodicVector(_var.number(), midpoint, rand_point); Real slope_dot = slope * slope; mooseAssert(slope_dot > 0, "The dot product of slope with itself is zero"); for (unsigned int i = 0; i < LIBMESH_DIM; ++i) lambda += (mid_rand_vector(i) * slope(i)) / slope_dot; // Assigning points to vector _centers[vp] = slope * lambda + midpoint; // Checking to see if points are in the domain ONLY WORKS FOR PERIODIC for (unsigned int i = 0; i < LIBMESH_DIM; i++) if ((_centers[vp](i) > _top_right(i)) || (_centers[vp](i) < _bottom_left(i))) try_again = true; for (unsigned int i = 0; i < vp; ++i) { Real dist = _mesh.minPeriodicDistance(_var.number(), _centers[vp], _centers[i]); if (dist < _bubspac) try_again = true; } // Two algorithms are available for screening bubbles falling in grain // interior. They produce // nearly identical results. // Here only one is listed. The other one is available upon request. // Use circle center for checking whether voids are at GBs if (try_again == false) { Real min_rij_1, min_rij_2, rij, rij_diff_tol; min_rij_1 = _range.norm(); min_rij_2 = _range.norm(); rij_diff_tol = 0.1 * _radius; for (unsigned int gr = 0; gr < _grain_num; ++gr) { rij = _mesh.minPeriodicDistance(_var.number(), _centers[vp], _centerpoints[gr]); if (rij < min_rij_1) { min_rij_2 = min_rij_1; min_rij_1 = rij; } else if (rij < min_rij_2) min_rij_2 = rij; } if (std::abs(min_rij_1 - min_rij_2) > rij_diff_tol) try_again = true; } } while (try_again == true); } }
void Game_Snake::addtreat(void) { T.p=rand_point(&cells); T.points=rand_score(); T.type=rand_treat(); }