![]() |
DI-Guy SDK Documentation
13.7
|
Contains useful math functions. More...
#include <diguyMathHelper.h>
Public Member Functions | |
| diguyMathHelper () | |
| ~diguyMathHelper () | |
Static Public Member Functions | |
General Functions | |
Unless otherwise specified, all functions callable from:
| |
| static int | get_ballistic_arc_velocity (float delta_x, float delta_y, float delta_z, float initial_speed, float max_elevation, float min_elevation, float **\returnet_vel_x, float *ret_vel_y, float *ret_vel_z, float *ret_delta_x, float *ret_delta_y, float *ret_delta_z) |
| Helper function to determine if a ballistic weapon (e.g. More... | |
| static int | quadratic_formula (float a, float b, float c, float **\returnet1, float *ret2) |
| Helper function to solve the quadratic equation (http://en.wikipedia.org/wiki/Quadratic_formula) or to report that there is no solution. More... | |
| static int | calculate_euler_angles_from_vector (float x, float y, float z, float roll, float *yaw, float *pitch) |
| Given a vector and a roll value, calculate the Euler angles of yaw and pitch. More... | |
| static void | calculate_vector_from_euler_angles (float yaw, float pitch, float **\note, float *y, float *z) |
| Given a vector and a roll value, calculate the Euler angles of yaw and pitch. More... | |
| static float | calculate_slide_in_rate (float current_distance, float base_rate, float base_distance, float acceptable_remainder=0.0f) |
| A helper function for when there is an object approaching a target, and the goal is for it to slow down in a realistic-looking way. More... | |
| static float | exponential_formula (float c, float k, float t) |
| Calculates the value of the exponential formula at time t. More... | |
| static float | calculate_exponential_growth_constant (float relative_value, float t) |
| Calculates the value of k for the exponential growth/decay formula. More... | |
| static void | rotate_vector (float in_x, float in_y, float in_z, float rz, float rx, float ry, float *out_x, float *out_y, float *out_z) |
| Rotate a vector by the given Euler angles. More... | |
| static void | unrotate_vector (float in_x, float in_y, float in_z, float rz, float rx, float ry, float *out_x, float *out_y, float *out_z) |
| Rotate a vector by the inverse of the orientation defined by three Euler angles. More... | |
Contains useful math functions.
This class is meant to be home to general purpose math formula. Aside from the usefulness of the functions themselves, a secondary goal is to educate the user.
| diguyMathHelper::diguyMathHelper | ( | ) |
| diguyMathHelper::~diguyMathHelper | ( | ) |
|
static |
Helper function to determine if a ballistic weapon (e.g.
artillery) can hit its target, given a target point, projectile speed, max and min elevation. If the designated target can't be hit (too close or far), this function will offer the closest possible point that can be hit.
| delta_x,delta_y,delta_z | position of target relative to start point a initial_speed - how fast the projectile is going out of the barrel |
| max_elevation | the maximum elevation of the weapon above horizontal |
| min_elevation | the minimum elevation of the weapon above horizontal |
| ret_vel_x,ret_vel_y,ret_vel_z | output parameters; the velocity the projectile must have |
| ret_delta_x,ret_delta_y,ret_delta_z | output parameters; the relative pos of point that a will be hit (if preferred target can't be reached) |
Returns:
1 on success, 0 on failure (float * arguments converted to return values in Lua)
|
static |
Helper function to solve the quadratic equation (http://en.wikipedia.org/wiki/Quadratic_formula) or to report that there is no solution.
| a,b,c | see link above |
| ret1,ret2 | output parameters; the solutions, if any exist |
Returns:
1 if there's a solution; 0 otherwise (float * arguments converted to return values in Lua)
|
static |
Given a vector and a roll value, calculate the Euler angles of yaw and pitch.
| x,y,z | the vector |
| roll | roll in degrees, clockwise is positive direction |
| yaw,pitch | return parameters, degrees |
Returns:
1 if results are valid; 0 otherwise (float * arguments converted to return values in Lua)
|
static |
Given a vector and a roll value, calculate the Euler angles of yaw and pitch.
| x,y,z | the vector |
| roll | roll in degrees, clockwise is positive direction |
| yaw,pitch | return parameters, degrees |
Returns:
1 if results are valid; 0 otherwise (float * arguments converted to return values in Lua)
|
static |
A helper function for when there is an object approaching a target, and the goal is for it to slow down in a realistic-looking way.
If the object is infinitely far away from the target, the returned slide-in rate will be infinite (in theory, not practice, obviously). If the object is at the base distance, the slide-in rate will be the base rate. If the object is closer than that, the slide-in rate will approach zero.
| current_distance | distance to target (can be distance in the conventional sense, or any kind of quantity) |
| base_rate | the base rate of travel, per second, in the same units |
| base_distance | the exact distance at which the base rate applies |
| acceptable_remainder | how much distance can be left for the target to have been "reached" |
Returns:
The new rate to assign to the object
Usage Notes:
|
static |
Calculates the value of the exponential formula at time t.
The formula is: y = c * e ^ (k * t) Its derivative is: y' = k * c * e ^ (k * t) = k * y
Calculating k:
ln(y) = ln(c) + k * t k = (ln(y) - ln(c)) / t to grow/decay to y1 in t = 1, c = 1: k = ln(y1)
| c | the starting quantity at time 0 |
| k | the constant, positive for growth, negative for decay |
| t | time |
Returns:
The value of the formula at given time
|
static |
Calculates the value of k for the exponential growth/decay formula.
| multiplier | a value relative to starting value (>1 for growth, <1 for decay) |
| t | number of seconds it takes for exponential formula to reach that multiple |
Returns:
Value of k
|
static |
Rotate a vector by the given Euler angles.
x, y, z of vector to be rotated rx, ry, rz degrees to rotate by result x, y, z
Returns:
(float * arguments converted to return values in Lua)
|
static |
Rotate a vector by the inverse of the orientation defined by three Euler angles.
x, y, z of vector to be rotated rx, ry, rz degrees to rotate by result x, y, z
Returns:
(float * arguments converted to return values in Lua)