DI-Guy SDK Documentation  13.8
diguyMathHelper Class Reference

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:

  • C++
  • Script
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...
 

Detailed Description

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.

Constructor & Destructor Documentation

diguyMathHelper::diguyMathHelper ( )
diguyMathHelper::~diguyMathHelper ( )

Member Function Documentation

static int diguyMathHelper::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 
)
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.

Parameters
delta_x,delta_y,delta_zposition of target relative to start point
initial_speedhow fast the projectile is going out of the barrel
max_elevationthe maximum elevation of the weapon above horizontal
min_elevationthe minimum elevation of the weapon above horizontal
ret_vel_x,ret_vel_y,ret_vel_zoutput parameters; the velocity the projectile must have
ret_delta_x,ret_delta_y,ret_delta_zoutput parameters; the relative pos of point that 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 int diguyMathHelper::quadratic_formula ( float  a,
float  b,
float  c,
float **\  returnet1,
float *  ret2 
)
static

Helper function to solve the quadratic equation (http://en.wikipedia.org/wiki/Quadratic_formula) or to report that there is no solution.

Parameters
a,b,csee link above
ret1,ret2output parameters; the solutions, if any exist

Returns:

1 if there's a solution; 0 otherwise (float * arguments converted to return values in Lua)

static int diguyMathHelper::calculate_euler_angles_from_vector ( float  x,
float  y,
float  z,
float  roll,
float *  yaw,
float *  pitch 
)
static

Given a vector and a roll value, calculate the Euler angles of yaw and pitch.

Parameters
x,y,zthe vector
rollroll in degrees, clockwise is positive direction
yaw,pitchreturn parameters, degrees

Returns:

1 if results are valid; 0 otherwise (float * arguments converted to return values in Lua)

static void diguyMathHelper::calculate_vector_from_euler_angles ( float  yaw,
float  pitch,
float **\  note,
float *  y,
float *  z 
)
static

Given a vector and a roll value, calculate the Euler angles of yaw and pitch.

Parameters
x,y,zthe vector
rollroll in degrees, clockwise is positive direction
yaw,pitchreturn parameters, degrees

Returns:

1 if results are valid; 0 otherwise (float * arguments converted to return values in Lua)

static float diguyMathHelper::calculate_slide_in_rate ( float  current_distance,
float  base_rate,
float  base_distance,
float  acceptable_remainder = 0.0f 
)
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.

Parameters
current_distancedistance to target (can be distance in the conventional sense, or any kind of quantity)
base_ratethe base rate of travel, per second, in the same units
base_distancethe exact distance at which the base rate applies
acceptable_remainderhow much distance can be left for the target to have been "reached"

Returns:

The new rate to assign to the object

Usage Notes:

  • If current_distance is negative, it will simply be assumed that the object is on the other side of the target. Thus, the returned rate will be negative.
  • One can easily apply a cap to the rate returned, so it's not too high
  • To find time to decel from base rate, use t = 2 * base_distance / base_rate
  • If we want to calculate a slide-OUT rate, use distance from starting point, rather than to target
  • This function can even be used to calculate a deceleration value, if the "distances" are deltas between two speed values, and the base rate is the base deceleration value
static float diguyMathHelper::exponential_formula ( float  c,
float  k,
float  t 
)
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)

Parameters
cthe starting quantity at time 0
kthe constant, positive for growth, negative for decay
ttime

Returns:

The value of the formula at given time

static float diguyMathHelper::calculate_exponential_growth_constant ( float  relative_value,
float  t 
)
static

Calculates the value of k for the exponential growth/decay formula.

Parameters
multipliera value relative to starting value (>1 for growth, <1 for decay)
tnumber of seconds it takes for exponential formula to reach that multiple

Returns:

Value of k

static void diguyMathHelper::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 
)
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 void diguyMathHelper::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 
)
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)


The documentation for this class was generated from the following file: