DI-Guy SDK Documentation  13.5
diguyMathHelper.h
Go to the documentation of this file.
1 /*********************************************************************
2  ** Copyright (c) 1992-2020 MAK Technologies, Inc.
3  ** All rights reserved.
4  *********************************************************************/
5 
6 /*********************************************************************
7  **
8  *t diguyMathHelper
9  **
10  *b Link against: libdiguy
11  */
12 
13 #ifndef __diguyMathHelper_H
14 #define __diguyMathHelper_H
15 
16 #ifdef SWIG
17 %module diguyMathHelper
18 #else
19 #define CPLUSPLUS_ONLY
20 #endif
21 
22 #ifdef CPLUSPLUS_ONLY
23 #include <declspec_diguy.h>
24 #include <diguy_constants.h>
25 #include <diguy_typedefs.h>
26 #include <diguy_vector_classes.h>
27 
28 class bdiScenarioCharacter;
29 class diguyAgentParams;
30 class diguyCharacter;
32 
33 #endif
34 
35 
45 /****************************************************************************/
46 class BDI_DECLSPEC_diguy diguyMathHelper
47 {
48 
49 public:
51  ~diguyMathHelper();
52 
53 /*****************************************************************************/
63  /*l
64  *b Description:
65  **
66  ** Helper function to determine if a ballistic weapon (e.g. artillery) can hit its target,
67  ** given a target point, projectile speed, max and min elevation. If the designated target
68  ** can't be hit (too close or far), this function will offer the closest possible point that
69  ** can be hit.
70  **
71  *b Arguments:
72  **
73  *a delta_x,delta_y,delta_z - position of target relative to start point
74  *a initial_speed - how fast the projectile is going out of the barrel
75  *a max_elevation - the maximum elevation of the weapon above horizontal
76  *a min_elevation - the minimum elevation of the weapon above horizontal
77  *a ret_vel_x,ret_vel_y,ret_vel_z - output parameters; the velocity the projectile must have
78  *a ret_delta_x,ret_delta_y,ret_delta_z - output parameters; the relative pos of point that
79  *a will be hit (if preferred target can't be reached)
80  **
81  *b Returns:
82  **
83  ** 1 on success, 0 on failure
84  ** (float * arguments converted to return values in Lua)
85  */
86  static int get_ballistic_arc_velocity(float delta_x, float delta_y, float delta_z, float initial_speed, float max_elevation, float min_elevation,
87  float *ret_vel_x, float *ret_vel_y, float *ret_vel_z, float *ret_delta_x, float *ret_delta_y, float *ret_delta_z);
88 
89  /*l
90  *b Description:
91  **
92  ** Helper function to solve the quadratic equation (http://en.wikipedia.org/wiki/Quadratic_formula)
93  ** or to report that there is no solution.
94  **
95  *b Arguments:
96  **
97  *a a,b,c - see link above
98  *a ret1,ret2 - output parameters; the solutions, if any exist
99  **
100  *b Returns:
101  **
102  ** 1 if there's a solution; 0 otherwise
103  ** (float * arguments converted to return values in Lua)
104  */
105  static int quadratic_formula(float a, float b, float c, float *ret1, float *ret2);
106 
107  /*l
108  *b Description:
109  **
110  ** Given a vector and a roll value, calculate the Euler angles of yaw and pitch.
111  **
112  *b Arguments:
113  **
114  *a x,y,z - the vector
115  *a roll - roll in degrees, clockwise is positive direction
116  *a yaw, pitch - return parameters, degrees
117  **
118  *b Returns:
119  **
120  ** 1 if results are valid; 0 otherwise
121  ** (float * arguments converted to return values in Lua)
122  */
123  static int calculate_euler_angles_from_vector(float x, float y, float z, float roll, float *yaw, float *pitch);
124 
125  /*l
126  *b Description:
127  **
128  ** Given a vector and a roll value, calculate the Euler angles of yaw and pitch.
129  **
130  *b Arguments:
131  **
132  *a x,y,z - the vector
133  *a roll - roll in degrees, clockwise is positive direction
134  *a yaw, pitch - return parameters, degrees
135  **
136  *b Returns:
137  **
138  ** 1 if results are valid; 0 otherwise
139  ** (float * arguments converted to return values in Lua)
140  */
141  static void calculate_vector_from_euler_angles(float yaw, float pitch, float *x, float *y, float *z);
142 
143  /*l
144  *b Description:
145  **
146  ** A helper function for when there is an object approaching a target, and the goal is for it to slow
147  ** down in a realistic-looking way. If the object is infinitely far away from the target, the returned
148  ** slide-in rate will be infinite (in theory, not practice, obviously). If the object is at the base
149  ** distance, the slide-in rate will be the base rate. If the object is closer than that, the slide-in
150  ** rate will approach zero.
151  **
152  *b Arguments:
153  **
154  *a current_distance - distance to target (can be distance in the conventional sense, or any kind of quantity)
155  *a base_rate - the base rate of travel, per second, in the same units
156  *a base_distance - the exact distance at which the base rate applies
157  *a acceptable_remainder - how much distance can be left for the target to have been "reached"
158  **
159  *b Returns:
160  **
161  ** The new rate to assign to the object
162  **
163  *b Usage Notes:
164  **
165  *- - If current_distance is negative, it will simply be assumed that the object is on the other side of the
166  *- target. Thus, the returned rate will be negative.
167  *- - One can easily apply a cap to the rate returned, so it's not too high
168  *- - To find time to decel from base rate, use t = 2 * base_distance / base_rate
169  *- - If we want to calculate a slide-OUT rate, use distance from starting point, rather than to target
170  *- - This function can even be used to calculate a deceleration value, if the "distances" are deltas between
171  *- two speed values, and the base rate is the base deceleration value
172  */
173  static float calculate_slide_in_rate(float current_distance, float base_rate, float base_distance, float acceptable_remainder = 0.0f);
174 
175  /*l
176  *b Description:
177  **
178  ** Calculates the value of the exponential formula at time t
179  **
180  ** The formula is: y = c * e ^ (k * t)
181  ** Its derivative is: y' = k * c * e ^ (k * t)
182  ** = k * y
183  **
184  *b Calculating k:
185  **
186  ** ln(y) = ln(c) + k * t
187  ** k = (ln(y) - ln(c)) / t
188  ** to grow/decay to y1 in t = 1, c = 1: k = ln(y1)
189  **
190  *b Arguments:
191  **
192  *a c - the starting quantity at time 0
193  *a k - the constant, positive for growth, negative for decay
194  *a t - time
195  **
196  *b Returns:
197  **
198  ** The value of the formula at given time
199  **
200  */
201  static float exponential_formula(float c, float k, float t);
202 
203  /*l
204  *b Description:
205  **
206  ** Calculates the value of k for the exponential growth/decay formula
207  **
208  *b Arguments:
209  **
210  *a multiplier - a value relative to starting value (>1 for growth, <1 for decay)
211  *a t - number of seconds it takes for exponential formula to reach that multiple
212  **
213  *b Returns:
214  **
215  ** Value of k
216  **
217  */
218  static float calculate_exponential_growth_constant(float relative_value, float t);
219 
220  /*l
221  *b Description:
222  **
223  ** Rotate a vector by the given Euler angles
224  **
225  *b Arguments:
226  **
227  *a x, y, z of vector to be rotated
228  *a rx, ry, rz degrees to rotate by
229  *a result x, y, z
230  **
231  *b Returns:
232  **
233  ** (float * arguments converted to return values in Lua)
234  **
235  */
236  static void rotate_vector(float in_x, float in_y, float in_z,
237  float rz, float rx, float ry,
238  float* out_x, float* out_y, float* out_z);
239 
240  /*l
241  *b Description:
242  **
243  ** Rotate a vector by the inverse of the orientation
244  ** defined by three Euler angles
245  **
246  *b Arguments:
247  **
248  *a x, y, z of vector to be rotated
249  *a rx, ry, rz degrees to rotate by
250  *a result x, y, z
251  **
252  *b Returns:
253  **
254  ** (float * arguments converted to return values in Lua)
255  **
256  */
257  static void unrotate_vector(float in_x, float in_y, float in_z,
258  float rz, float rx, float ry,
259  float* out_x, float* out_y, float* out_z);
260 };
261 
262 
263 #endif /* __diguyMathHelper_H */
Contains useful math functions.
Definition: diguyMathHelper.h:44
The class that represents what parameters an agent is currently using to carry out their base behavio...
Definition: diguyAgentParams.h:39
The class that represents a DI-Guy Entity in the world.
Definition: diguyCharacter.h:80
static double t
4 Header files and forward declarations
Definition: simple_playback_ogl.cpp:55
Represents algorithm for steering and maneuvering a character towards a goal point.
Definition: diguyCharacterGuide.h:561