コード例 #1
0
ファイル: torpedo.c プロジェクト: vivek-vilvaraj/my_game
void fire_torpedo(void)
{
	int i;
	static int tracer_count = MAX_TORPS;

	/*
	 * check for a free torpedo slot.
	 * use the first free slot found, or
	 * return if none are found.
	 */

	for (i = 0; i < MAX_TORPS; ++i)
		if (!torp[i].in_flight_flag)
			break;

	if (i == MAX_TORPS) /* no free slot */
		return;

	/* when tracer_count = 0, do a tracer shot */
	if (optmap.draw_tracer_flag)
		--tracer_count;

	/* set up the torpedo's fight parameters */

	torp[i].in_flight_flag = 1;   /* let her fly... */
	torp[i].ttl            = TORP_TTL * tps + ticks; /* fly for "this long" */
	play_sound(SOUND_TORP_FIRED, 0); /* play the torp fired sound */

	if (tracer_count == 0) {
		torp[i].is_tracer = 1;
		tracer_count = MAX_TORPS;
		tracer_light_flag = 1; /* turn on tracer light */
	} else {
		torp[i].is_tracer = 0;
	}

	/* set the initial position of the torpedo just in front of the player */
	vec_addmul(&torp[i].pos, &pos, 2, &zaxis);
	vec_addmul(&torp[i].pos_delta, &velocity, TORP_DELTA, &zaxis);
	torp[i].bb_zrot = 0 ;

	/* set up the torpedo trails */
	torp[i].trail_num = get_free_torpedo_trail();
	if (torp[i].trail_num != NO_TRAIL) {
		TorpedoTrail *t = &torp_trail[torp[i].trail_num];
		t->is_running_flag = 1;
		t->is_ending_flag  = 0;
		t->trail_start     = 0;
		t->trail_end       = 0;
		t->pos[0]          = torp[i].pos;
	}

	/* found a free torp slot, so we're going to have a torp in flight */
	torps_in_flight_flag = 1;
	return;
}
コード例 #2
0
ファイル: glw_math_common.c プロジェクト: carlinx/showtime
/**
 * m   Model matrix
 * x   Return x in model space
 * y   Return y in model space
 * p   Mouse pointer at camera z plane
 * dir Mouse pointer direction vector
 */
int
glw_widget_unproject(Mtx m, float *xp, float *yp, 
		     const float *p, const float *dir)
{
  Vector u, v, n, w0, T0, T1, T2, out, I;
  float b, inv[16];

  glw_mtx_mul_vec(T0, m, -1, -1, 0);
  glw_mtx_mul_vec(T1, m,  1, -1, 0);
  glw_mtx_mul_vec(T2, m,  1,  1, 0);

  vec_sub(u, T1, T0);
  vec_sub(v, T2, T0);
  vec_cross(n, u, v);
  
  vec_sub(w0, p, T0);
  b = vec_dot(n, dir);
  if(fabs(b) < 0.000001)
    return 0;

  vec_addmul(I, p, dir, -vec_dot(n, w0) / b);

  if(!glw_mtx_invert(inv, m))
    return 0;
  glw_mtx_mul_vec(out, inv, I[0], I[1], I[2]);

  *xp = out[0];
  *yp = out[1];
  return 1;
}
コード例 #3
0
ファイル: torpedo.c プロジェクト: vivek-vilvaraj/my_game
void process_torpedo_motion(int value)
{
	int num_in_flight = 0, i;
	TorpedoTrail *t;

	if (!torps_in_flight_flag)
		return;

	for (i = 0; i < MAX_TORPS; ++i) {
		if (!torp[i].in_flight_flag)
			continue;

		++num_in_flight;
		vec_addmul(&torp[i].pos, &torp[i].pos, dt, &torp[i].pos_delta);
		torp[i].bb_zrot += TORP_BB_ZROT;

		if (ticks >= torp[i].ttl) {
			torp[i].in_flight_flag = 0;
			if (torp[i].is_tracer)
				tracer_light_flag = 0; // turn off tracer light
		}

		if (torp[i].trail_num == NO_TRAIL)
			continue;

		t = &torp_trail[torp[i].trail_num];
		if (!torp[i].in_flight_flag) {
			t->is_running_flag = 0;
			t->is_ending_flag  = 1;
		}

		// Increment the trail array's index and wrap start & end indicators
		++t->trail_start;
		if (t->trail_start == TORP_TRAIL_LEN) {
			t->trail_start = 0;
			t->trail_end   = 1;
		}

		if (t->trail_start == t->trail_end) {
			++t->trail_end;
			t->trail_end %= TORP_TRAIL_LEN;
		}

		// add a new point to the trail
		t->pos[t->trail_start] = torp[i].pos;
	}

	if (num_in_flight <= 0)
		torps_in_flight_flag = 0;

	/* Why sort the torpedos: Well, when you alpha blend things, for the alpha
	blending to work you must draw everything behind the blended polygon before
	you draw the polygon. If you don't, the blending will be wrong. So the two
	steps below sort the torpedos by distance from the eye, so that distant
	torpedos are drawn before close torpedos, so that the blending works
	correctly. */
	memcpy(sorted_torp, torp, sizeof(torp));
	qsort(sorted_torp, MAX_TORPS, sizeof(Torpedo), compare_torps);
	return;
}