void bullet_init(struct bullet *b, volatile struct phys_obj *p, double speed)
{
	zero_bullet_init(b);
	b->pos = p->pos;
	b->pos.y += vector_y(0.1, p->rotation);
	b->pos.x -= vector_x(0.1, p->rotation);
	b->vel = p->vel;
	b->vel.x -= vector_x(speed, p->rotation);
	b->vel.y += vector_y(speed, p->rotation);
}
Beispiel #2
0
///
/// @par Detailed description
/// ...
/// @param [in, out] (param1) ...
/// @return ...
/// @note ...
void
sasio::Files::
read_dcd_step(FILE *dcd_infile, int &frame, int &natoms, int &reverseEndian)
{

    int charmm = 0 ;
    int num_fixed = 0 ;
    int result ;

    std::vector<float> vector_x(natoms) ;
    std::vector<float> vector_y(natoms) ;
    std::vector<float> vector_z(natoms) ;

    result = read_dcdstep(dcd_infile,natoms,&vector_x[0],&vector_y[0],&vector_z[0],num_fixed,frame,reverseEndian,charmm) ;

    if(_x().cols() < frame)
    {
        std::cout << "resizing array: cols() =  " << _x().cols() << " frame = " << frame  << std::endl ;
        resize_array() ;
    }

    for(int i = 0 ; i < _natoms() ; ++i)
    {
        _x()(i,frame) = vector_x[i] ;
        _y()(i,frame) = vector_y[i] ;
        _z()(i,frame) = vector_z[i] ;
    }

    _number_of_frames()++ ;

    return ;
}
static void movement_calc(void *o)
{
	struct missile *m = o;
	float target_dist = FLT_MAX;
	if (m->target != NULL) {
		target_dist = vector_magnitude(m->pos, m->target->pos);
		target_dist -= m->hb[0].rad;
		target_dist -= m->target->hb[0].rad;
	}
	if (	(m->life_time != 0 && 
		get_tick_count() - m->init_time > m->life_time) ||
		(m->frag && target_dist < 0.05*world_scale)
		) {
		if (m->frag) {
			missile_frag(m);
		}
		if (m->target != NULL) {
			remove_reset_ptr((void*)m->target, &m->target);
		}
		m->is_alive = false;
		explode(m);
		return;
	}
	if (m->target == NULL) {
		remove_reset_ptr((void*)m->target, &m->target);
		if (!m->dumb) {
			m->target = acquire_target(m->firer);
			if (m->target != NULL) {
				puts("required target");
			}
		}
		return;
	}
	if (	!m->target->is_alive ||
		!timed_out_r(&m->last_ctrl_tick, CTRL_RATE)) {
		return;
	}
	float dx = -m->target->pos.x + m->pos.x;
	float dy = +m->target->pos.y - m->pos.y;
	float old_rot = m->rotation;
	m->rotation = rad_to_degd(atan2(dx, dy));
	const float MAX_ROT = 10;
	if (old_rot > m->rotation) {
		if (old_rot - m->rotation > MAX_ROT ||
			fmod(360 + old_rot - m->rotation, 360) > MAX_ROT) {
			m->rotation = old_rot - MAX_ROT;
		}
	} else {
		if (m->rotation - old_rot  > MAX_ROT ||
			fmod(360 + m->rotation - old_rot, 360) > MAX_ROT) {
			m->rotation = old_rot + MAX_ROT;
		}
	}
	float mag = xy_magnitude(m->vel.x, m->vel.y);
	m->vel.x = vector_x(mag, 180 + m->rotation);
	m->vel.y = vector_y(mag, m->rotation);
	m->accel = 0;
}
void missile_init(struct missile *m, struct phys_obj *p, double speed,
		  float accel, float rad, unsigned long long life_time,
		  int fragments, bool fins, bool frag, bool dumb,
		  enum explosion_type e)
{
	zero_missile_init(m, fins, frag, dumb, accel, rad);
	m->pos = p->pos;
	m->pos.y += vector_y(0.2*world_scale, p->rotation);
	m->pos.x -= vector_x(0.2*world_scale, p->rotation);
	m->vel = p->vel;
	m->vel.x -= vector_x(speed, p->rotation);
	m->vel.y += vector_y(speed, p->rotation);
	m->rotation = p->rotation;
	m->target = dumb ? NULL : acquire_target(p);
	if (m->target != NULL) {
		add_reset_ptr((void*)m->target, &m->target);
	}
	m->init_time = get_tick_count();
	m->last_ctrl_tick = get_tick_count();
	m->life_time = life_time;
	m->fragments = fragments;
	m->firer = p;
	m->explosion_type = e;
}
void missile_frag(struct missile *m)
{
	const float theta = 360.0/m->fragments;
	const float delta = 0.015 * m->fragments / 4.0 * world_scale;
	for (int i = 0; i < m->fragments; i++) {
		struct bullet *b = malloc(sizeof(*b));
		m->vel = (struct xy_d){0.0, 0.0};
		bullet_init(b, (void*)m, 0.0);
		b->pos.x += vector_x(delta, theta * i);
		b->pos.y += vector_y(delta, theta * i);
		float x_angl = i*theta + theta*drand()/2;
		float y_angl = i*theta + theta*drand()/2;
		b->vel.x = vector_x(FRAGMENT_SPEED*world_scale, x_angl);
		b->vel.y = vector_y(FRAGMENT_SPEED*world_scale, y_angl);
		b->type = OBJ_GENERIC;
		spawn_phys_obj((void*)b);
		draw_buffer_push((void*)b);
	}
}

void explode(struct missile *m)
{
	void *v;
	if (m->explosion_type == BOOM) {
		struct boom *b = malloc(sizeof(*b));
		v = b;
		boom_init(b, m->pos, m->rad, m->rad, 500);
	} else {
		struct mc_explosion *b = malloc(sizeof(*b));
		v = b;
		mc_explosion_init(b, m->pos, 0.0, m->rad, 800);
	}
	spawn_phys_obj(v);
	draw_buffer_push(v);
	particle_spawn_cloud(m->pos, 50 + m->rad * 10, 500, 10.0);
}
Beispiel #6
0
string_t
string_from_vector(char* buffer, size_t capacity, const vector_t v) {
	return string_format(buffer, capacity, STRING_CONST("(%.6" PRIreal ", %.6" PRIreal ", %.6" PRIreal ", %.6" PRIreal ")"),
		(real)vector_x(v), (real)vector_y(v), (real)vector_z(v), (real)vector_w(v));
}