strafelib
Functions | Variables
strafelib.hpp File Reference
#include <cmath>
Include dependency graph for strafelib.hpp:

Go to the source code of this file.

Functions

template<int N>
double dot_product (const double *__restrict a, const double *__restrict b)
 
double fric_speed (double speed, double E, double tau_k)
 
void fric_vel (double *__restrict vel, double speed, double E, double tau_k)
 
double fric_speedsq (double speedsq, double E, double tau_k)
 
double fme_speed (double speed, double costheta, double L, double ke_tau_M_A)
 
void fme_vel_theta (double *__restrict vel, double speed, double costheta, double sintheta, double L, double ke_tau_M_A)
 
void fme_maxaccel_cossin_theta (double speed, double L, double ke_tau_M_A, double *__restrict costheta, double *__restrict sintheta)
 
double fme_maxaccel_speed (double speed, double L, double ke_tau_M_A)
 
double fme_maxaccel_speed_C (double speedsq, double L, double ke_tau_M_A)
 
double fme_minaccel_speed (double speed, double L, double ke_tau_M_A)
 
template<int N>
void collision_vel (double *__restrict v, const double *__restrict n, double b)
 
template<int N>
void snark_hunt_vel (double *__restrict v, const double *__restrict dir)
 
double tau_g_to_p (double tau_g)
 
void water_vel (double *__restrict v, double speed, const double *__restrict a, double geomfric, double M, double ke_tau_M_A)
 

Variables

constexpr const double JUMP_SPEED = 268.3281572999748
 The initial jumping speed, before gravity is applied.
 

Function Documentation

◆ collision_vel()

template<int N>
void collision_vel ( double *__restrict  v,
const double *__restrict  n,
double  b 
)

Compute the velocity after colliding with a hyperplane.

The caller is responsible of ensuring n is a unit vector.

◆ dot_product()

template<int N>
double dot_product ( const double *__restrict  a,
const double *__restrict  b 
)
inline

Compute the dot product of two vectors.

◆ fme_maxaccel_cossin_theta()

void fme_maxaccel_cossin_theta ( double  speed,
double  L,
double  ke_tau_M_A,
double *__restrict  costheta,
double *__restrict  sintheta 
)

Compute the \(\cos\theta\) for maximum acceleration.

There is no point accepting a squared speed, because the very common zeta strafing case requires computing a square root anyway.

◆ fme_maxaccel_speed()

double fme_maxaccel_speed ( double  speed,
double  L,
double  ke_tau_M_A 
)

Compute the speed after applying the FME at maximum acceleration.

This function is easier to use than fme_maxaccel_speed_C(), but much less performant for the common cases of zeta and 90 degrees strafing, due to the need to compute a square root.

◆ fme_maxaccel_speed_C()

double fme_maxaccel_speed_C ( double  speedsq,
double  L,
double  ke_tau_M_A 
)

Compute a constant for adding to the squared speed at maximum acceleration.

The new squared speed after applying the FME can always be written in the form of

\[ \lVert\mathbf{v}'\rVert^2 = \lVert\mathbf{v}\rVert^2 + C(\lVert\mathbf{v}\rVert^2) \]

where \(C\) is a function of the current squared speed in general. Though in the zeta and the 90 degrees cases, \(C\) is independent of the current squared speed.

This function provides a significant performance boost over fme_maxaccel_speed() by avoiding the need to compute the relatively expensive square root for the most common cases of zeta and 90 degrees, at the expense of needing a square root when computing the much less common linear and backward-linear cases. Since \(C\) is independent of the current speed in the zeta and 90 degrees cases, the value only needs to be computed once in those cases, assuming the caller is certain that the strafing type will never change. Subsequently, each iteration of the FME amounts only to a single addition of \(C\) to the current squared speed.

It is the responsibility of the user to use this function correctly. If you are unsure how to use this function, opt for the more straightforward fme_maxaccel_speed() instead.

◆ fme_minaccel_speed()

double fme_minaccel_speed ( double  speed,
double  L,
double  ke_tau_M_A 
)

Compute the speed after applying the FME at minimum acceleration.

◆ fme_speed()

double fme_speed ( double  speed,
double  costheta,
double  L,
double  ke_tau_M_A 
)

Compute the speed after applying the FME.

This function runs at constant time.

◆ fme_vel_theta()

void fme_vel_theta ( double *__restrict  vel,
double  speed,
double  costheta,
double  sintheta,
double  L,
double  ke_tau_M_A 
)

Compute the velocity after applying the FME.

The caller is responsible of ensuring costheta and sintheta are consistent. speed must also match the 2D magnitude of vel. vel must have at least two elements.

The apparent redundancy of providing both vel and speed is to improve the efficiency. Under most situations, the user of this function needs to compute a square root to obtain the speed (the norm of velocity). This speed is needed by a function that computes \(\cos\theta\) and this function. To avoid computing the square root twice, we leave the responsibility to the caller.

◆ fric_speed()

double fric_speed ( double  speed,
double  E,
double  tau_k 
)

Compute the speed after applying ground friction.

This function runs at constant time. The caller is responsible of computing tau_k correctly by considering the values of the entity friction and the edgefriction.

If you are working on squared speeds for performance reasons, use fric_speedsq() instead to avoid computing square roots for speed when the geometric friction is in effect.

◆ fric_speedsq()

double fric_speedsq ( double  speedsq,
double  E,
double  tau_k 
)

Compute the squared speed after applying ground friction.

This function behaves similar to fric_speed(), except it operates on the squared speed, making it more convenient to use if you are working on squared speeds for performance reasons (e.g. by relying on fme_maxaccel_speed_C()). Compared to fric_speed(), this function appears to be less performant when viewed in isolation. However, if you are working on squared speeds, this function avoids computing the square root for the most common case of geometric friction. Computing the arithmetic friction requires a square root.

◆ fric_vel()

void fric_vel ( double *__restrict  vel,
double  speed,
double  E,
double  tau_k 
)

Compute the velocity after applying ground friction.

vel must have at least two elements.

The caller is responsible of ensuring speed matches the 2D norm of vel. By giving you the responsibility of computing the speed, this function avoids computing any square roots.

◆ snark_hunt_vel()

template<int N>
void snark_hunt_vel ( double *__restrict  v,
const double *__restrict  dir 
)

Compute the hunting velocity of a snark.

dir must be a unit vector.

◆ tau_g_to_p()

double tau_g_to_p ( double  tau_g)
inline

Compute the player frame time given the game frame time.

◆ water_vel()

void water_vel ( double *__restrict  v,
double  speed,
const double *__restrict  a,
double  geomfric,
double  M,
double  ke_tau_M_A 
)

Compute the player velocity after one frame of water movement.

All vectors are in 3D.