source: golgotha/src/golg/objs/fire_angle.cc

Last change on this file was 80, checked in by Sam Hocevar, 11 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 1.4 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#include "objs/fire_angle.hh"
10#include "math/pi.hh"
11#include <math.h>
12
13i4_bool g1_calc_fire_angle(i4_float x_y_dist,
14                           i4_float z1,
15                           i4_float z2,
16                           i4_float g,
17                           i4_float vo,
18                           i4_float &theta)
19
20  if (z1!=z2)
21  {
22    i4_float z_dist=z2-z1;
23    i4_float b=x_y_dist * sqrt(1 - (4 * z_dist * g)/(2 * vo*vo));
24    i4_float c=(2 * z_dist);
25
26    // ignore the +b solution because it occurs in negative time
27
28    i4_float cos_theta2=(x_y_dist - b)/c;
29    if (cos_theta2>=-1 && cos_theta2<=1)     
30    {
31      theta=acos(cos_theta2);
32      return i4_T;
33    }
34    return i4_F;
35  }
36  else
37  {
38    i4_float cos_theta=g * x_y_dist / (2 * vo*vo);
39
40    if (cos_theta>=-1 && cos_theta<=1)
41    {
42      theta=acos(cos_theta);
43      if (theta>=i4_pi()/4)
44        theta=i4_pi()/2-theta;
45
46
47      return i4_T;
48    }
49    return i4_F;
50  }
51}
Note: See TracBrowser for help on using the repository browser.