void create_hitscan_effect(struct Vec3 pos, struct Vec3 fwd) { HitscanEffect* he = hitscan_effect_list->create(); if (he == NULL) return; pos = translate_position(pos); he->set_state(pos, fwd); }
// 下一手棋 void play() { int ret; int ply, turn, time_limit; int chsbrd[BOARD_SIZE]; int score; int r, move_type; int MaxDepth; clock_t t; printf("inputting board\n"); ret = load_game("board.txt", piece_num, chsbrd, &turn, &time_limit); transform_board(board, chsbrd); dark_num = get_dark_num(board); red_num = get_piece_num(RED, piece_num); black_num = get_piece_num(BLACK, piece_num); best_src = 0; best_dest = 0; if(dark_num == PIECE_NUM) move_type = REVEAL_PIECE; else move_type = MOVE_PIECE; if(move_type == MOVE_PIECE){ printf("searching\n"); clock_limit = clock() + time_limit * CLK_TCK; if(time_limit < 20) max_depth = 6; else max_depth = (int) (log(time_limit / 20) / log(3)) * 2 + 6; score = search(board, piece_num, dark_num, red_num, black_num, turn, 1, max_depth, clock_limit); } move_type = (best_dest == -1) ? 1 : 0; if(best_src == 0){ move_type = REVEAL_PIECE; printf("revealing\n"); reveal(board); } best_src = translate_position(board, best_src); best_dest = translate_position(board, best_dest); printf("outputing\n\n"); output_move("move.txt", move_type, best_src, best_dest, score); }
bool hitscan_sprite_mobs(const Vec3& position, const Vec3& direction, float range, SpriteMobID& id, float& distance, Vec3& collision_point) { SpriteMobID nearest_mob = NULL_SPRITE_MOB; float nearest_distance = 100000.0f; Vec3 nearest_collision_point = vec3_init(0); const float range_sq = range * range; const Vec3 up = vec3_init(0, 0, 1); for (size_t i=0, j=0; i<sprite_mob_list->max && j<sprite_mob_list->count; i++) { // TODO // do a line-plane intersection test against the mob, if its in frustum SpriteMob* m = sprite_mob_list->objects[i]; if (m == NULL) continue; j++; Vec3 p = m->get_center(); p = quadrant_translate_position(position, p); if (vec3_distance_squared(position, p) > range_sq) continue; float rad_sq = 10000.0f; Vec3 line_point = vec3_init(0); if (!sphere_line_distance(position, direction, p, line_point, rad_sq)) continue; Vec3 forward = vec3_sub(position, p); forward.z = 0.0f; if (unlikely(vec3_length_squared(forward) == 0)) continue; forward = vec3_normalize(forward); const Vec3 right = vec3_normalize(vec3_cross(forward, up)); float d = 1000000.0f; float width = get_mob_width(m->type) * 0.5f; float height = get_mob_height(m->type) * 0.5f; if (!line_plane_intersection(position, direction, p, width, height, forward, right, up, d)) continue; if (d >= nearest_distance) continue; nearest_distance = d; nearest_mob = m->id; nearest_collision_point = line_point; } id = nearest_mob; distance = nearest_distance; collision_point = translate_position(nearest_collision_point); return (nearest_mob != NULL_SPRITE_MOB); }
void mining_laser_beam(struct Vec3 position, struct Vec3 orientation, float length) { if (Options::animation_level <= 0) return; const float speed = 6.0f; int n = Options::animation_level * 2; const float spread = 0.05f; Vec3 step = vec3_scalar_mult(orientation, spread); for (int i=0; i<n; i++) { Animations::create_mining_laser_particle(translate_position(position), orientation, speed, length); // move the particle a little bit ahead of the last // to get an even distribution position = vec3_add(position, step); } }
void VoxelModel::set_skeleton_root(const Vec3& position, float theta) { //set offset and rotation IF_ASSERT(!this->skeleton_inited) return; Vec3 angles = vec3_init(theta, 0.0f, 0.0f); vox_skeleton_world_matrix[0] = affine_euler_rotation_and_translation(position, angles); vox_skeleton_world_matrix[0].c = translate_position(vox_skeleton_world_matrix[0].c); } void VoxelModel::set_skeleton_root(float *data) { IF_ASSERT(!this->skeleton_inited) return; vox_skeleton_world_matrix[0] = affine_euler_rotation_and_translation( vec3_init(data[0], data[1], data[2]), vec3_init(data[3], data[4], data[5])); vox_skeleton_world_matrix[0].c = translate_position(vox_skeleton_world_matrix[0].c); } int VoxelModel::get_parent_node_index(int part) { IF_ASSERT(part < 0 || part >= this->n_parts) return -1; VoxPart* vp = vox_dat->vox_part[part]; if (vp == NULL) return -1; return vp->skeleton_parent_matrix; } void VoxelModel::set_node_rotation_by_part(int part, float theta, float phi, float rho) { IF_ASSERT(!this->skeleton_inited) return; int node = this->get_parent_node_index(part); if (node == -1) return;
void RailTrailEffect::tick() { if (Options::animation_level <= 0) return; static const float span = 0.5f; // space between particle layers static const float spin_span = PI / 8; const float dist = vec3_distance(this->end, this->start); const float step = span / (dist); Vec3 fwd = vec3_sub(this->end, this->start); //this->start = vec3_add(this->start, vec3_scalar_mult(vec3_normalize(this->start), 0.005f)); // RIGHT SETTINGS WOULD LOOK GOOD ON MOB IMPACTS ---> voxel_explode(this->end, /*min*/ 4, /*max*/ 14, /*size*/ 0.2f, /*force*/ 0.1f, COLOR_GREEN); float theta, phi; vec3_to_angles(fwd, &theta, &phi); float curr_spin = 0.0f; //float curr_spin = (PI/16) * this->ttl; for (float fl=0.0f; fl<=1.0f; fl+=step) { Vec3 curr = vec3_interpolate(this->start, this->end, fl); //float r = 0.17f; // quadratic radius float r = 0.08f; // quadratic radius Vec3 spiral = vec3_init( r * cosf(curr_spin), 0, r * sinf(curr_spin) ); Vec3 spiral2 = vec3_init( r * cosf(curr_spin + PI), 0, r * sinf(curr_spin + PI) ); spiral = vec3_euler_rotation(spiral, theta-0.5f, 0, phi-0.5f); spiral2 = vec3_euler_rotation(spiral2, theta-0.5f, 0, phi-0.5f); spiral = vec3_add(curr, spiral); spiral2 = vec3_add(curr, spiral2); spiral = translate_position(spiral); spiral2 = translate_position(spiral2); //float anim_scale = float(Options::animation_level)/3.0f; //n = anim_scale*float(n); Particle::Shrapnel *s; s = Particle::create_shrapnel(spiral, /*vel*/ vec3_init(0,0,0)); if (s == NULL) return; //s->ttl = randrange(8, 15); //s->scale = 0.1f; //s->texture_index = 54; s->ttl = randrange(2, 4); //s->ttl = 2; s->scale = 0.06f; s->texture_index = 22; s = Particle::create_shrapnel(spiral2, /*vel*/ vec3_init(0,0,0)); if (s == NULL) return; //s->ttl = randrange(8, 15); //s->scale = 0.1f; s->texture_index = 54; s->ttl = randrange(2, 4); //s->ttl = 2; s->scale = 0.06f; s->texture_index = 22; //draw_quad(curr, span, theta, phi); curr_spin += spin_span; if (curr_spin >= PI*2) curr_spin = 0.0f; } }