NAP
Namespaces | Classes | Typedefs | Enumerations | Functions | Variables
nap::math Namespace Reference

Namespaces

 Back
 
 Bounce
 
 Circ
 
 Cubic
 
 Elastic
 
 Expo
 
 Linear
 
 Quad
 
 Quart
 
 Quint
 
 Sine
 

Classes

class  BaseSmoothOperator
 
class  Box
 
struct  FComplex
 
class  FCurve
 
struct  FCurvePoint
 
class  Rect
 
class  SmoothOperator
 

Typedefs

using FloatFComplex = FComplex< float, float >
 
using Vec2FComplex = FComplex< float, glm::vec2 >
 
using Vec3FComplex = FComplex< float, glm::vec3 >
 
using Vec4FComplex = FComplex< float, glm::vec4 >
 
using FloatFCurve = FCurve< float, float >
 
using Vec2FCurve = FCurve< float, glm::vec2 >
 
using Vec3FCurve = FCurve< float, glm::vec3 >
 
using Vec4FCurve = FCurve< float, glm::vec4 >
 
using FloatFCurvePoint = FCurvePoint< float, float >
 
using Vec2FCurvePoint = FCurvePoint< float, glm::vec2 >
 
using Vec3FCurvePoint = FCurvePoint< float, glm::vec3 >
 
using Vec4FCurvePoint = FCurvePoint< float, glm::vec4 >
 
using FloatSmoothOperator = SmoothOperator< float >
 
using DoubleSmoothOperator = SmoothOperator< double >
 
using Vec2SmoothOperator = SmoothOperator< glm::vec2 >
 
using Vec3SmoothOperator = SmoothOperator< glm::vec3 >
 
using Vec4SmoothOperator = SmoothOperator< glm::vec4 >
 

Enumerations

enum  ECurveInterp : int { Bezier = 0, Linear, Stepped }
 
enum  EWaveform : int { SINE = 0, SQUARE, SAW, TRIANGLE }
 

Functions

template<typename T >
void getValueAlongLine (const std::vector< T > &vertexData, float location, bool closed, T &outValue)
 
template<typename T >
int resampleLine (std::vector< T > &vertices, std::vector< T > &buffer, int segments, bool closed)
 
float NAPAPI getDistancesAlongLine (const std::vector< glm::vec3 > &vertexPositions, std::map< float, int > &outDistances, bool loop)
 
float NAPAPI getVertexLerpValue (const std::map< float, int > &distanceMap, float location, int &outMinVertex, int &outMaxVertex)
 
template<typename T >
void getValueAlongLine (const std::map< float, int > &distanceMap, const std::vector< T > &vertexData, float location, T &outValue)
 
void NAPAPI getNormalAlongLine (const std::map< float, int > &distanceMap, const std::vector< glm::vec3 > &vertexNormals, float location, glm::vec3 &outNormal)
 
template<typename T >
float fit (T value, T min, T max, T outMin, T outMax)
 
template<typename T >
lerp (const T &start, const T &end, float percent)
 
template<typename T >
clamp (T value, T min, T max)
 
template<typename T >
min (T left, T right)
 
template<typename T >
max (T left, T right)
 
template<typename T >
floor (T value)
 
template<typename T >
ceil (T value)
 
template<typename T >
power (T value, T exp)
 
template<typename T >
smoothStep (T value, T edge0, T edge1)
 
template<typename T >
abs (T value)
 
template<typename T >
constexpr T epsilon ()
 
template<typename T >
constexpr T max ()
 
template<typename T >
constexpr T min ()
 
template<typename T >
sign (T value)
 
template<typename T >
bell (T time, T strength)
 
template<typename T >
random (T min, T max)
 
void NAPAPI setRandomSeed (int value)
 
float NAPAPI smoothDamp (float currentValue, float targetValue, float &currentVelocity, float deltaTime, float smoothTime, float maxSpeed=math::max< float >())
 
double NAPAPI smoothDamp (double currentValue, double targetValue, double &currentVelocity, float deltaTime, float smoothTime, float maxSpeed=math::max< float >())
 
template<typename T >
void smooth (T &currentValue, const T &targetValue, T &currentVelocity, float deltaTime, float smoothTime, float maxSpeed)
 
glm::mat4 NAPAPI composeMatrix (const glm::vec3 &translate, const glm::quat &rotate, const glm::vec3 &scale)
 
glm::quat NAPAPI eulerToQuat (const glm::vec3 &eulerAngle)
 
glm::quat NAPAPI eulerToQuat (float roll, float pitch, float yaw)
 
glm::vec3 NAPAPI radians (const glm::vec3 &eulerDegrees)
 
glm::vec3 NAPAPI radians (float roll, float pitch, float yaw)
 
float NAPAPI radians (float degrees)
 
float NAPAPI degrees (float radians)
 
glm::vec3 NAPAPI extractPosition (const glm::mat4x4 &matrix)
 
glm::vec3 NAPAPI objectToWorld (const glm::vec3 &point, const glm::mat4x4 &objectToWorldMatrix)
 
glm::vec3 NAPAPI worldToObject (const glm::vec3 &point, const glm::mat4x4 &objectToWorldMatrix)
 
std::string NAPAPI generateUUID ()
 
template<>
NAPAPI float lerp< float > (const float &start, const float &end, float percent)
 
template<>
NAPAPI double lerp< double > (const double &start, const double &end, float percent)
 
template<>
NAPAPI glm::vec2 lerp< glm::vec2 > (const glm::vec2 &start, const glm::vec2 &end, float percent)
 
template<>
NAPAPI glm::vec3 lerp< glm::vec3 > (const glm::vec3 &start, const glm::vec3 &end, float percent)
 
template<>
NAPAPI glm::vec4 lerp< glm::vec4 > (const glm::vec4 &start, const glm::vec4 &end, float percent)
 
template<>
NAPAPI float power< float > (float value, float exp)
 
template<>
NAPAPI double power< double > (double value, double exp)
 
template<>
NAPAPI int power< int > (int value, int exp)
 
template<>
NAPAPI void smooth (float &currentValue, const float &targetValue, float &currentVelocity, float deltaTime, float smoothTime, float maxSpeed)
 
template<>
NAPAPI void smooth (double &currentValue, const double &targetValue, double &currentVelocity, float deltaTime, float smoothTime, float maxSpeed)
 
template<>
NAPAPI void smooth (glm::vec2 &currentValue, const glm::vec2 &targetValue, glm::vec2 &currentVelocity, float deltaTime, float smoothTime, float maxSpeed)
 
template<>
NAPAPI void smooth (glm::vec3 &currentValue, const glm::vec3 &targetValue, glm::vec3 &currentVelocity, float deltaTime, float smoothTime, float maxSpeed)
 
template<>
NAPAPI void smooth (glm::vec4 &currentValue, const glm::vec4 &targetValue, glm::vec4 &currentVelocity, float deltaTime, float smoothTime, float maxSpeed)
 
template<>
NAPAPI uint random (uint min, uint max)
 
template<>
NAPAPI int random (int min, int max)
 
template<>
NAPAPI float random (float min, float max)
 
template<>
NAPAPI glm::vec3 random (glm::vec3 min, glm::vec3 max)
 
template<>
NAPAPI glm::vec4 random (glm::vec4 min, glm::vec4 max)
 
template<>
NAPAPI glm::vec2 random (glm::vec2 min, glm::vec2 max)
 
template<>
NAPAPI glm::ivec2 random (glm::ivec2 min, glm::ivec2 max)
 
template<>
NAPAPI glm::ivec3 random (glm::ivec3 min, glm::ivec3 max)
 
template<>
NAPAPI glm::ivec4 random (glm::ivec4 min, glm::ivec4 max)
 
template<>
NAPAPI glm::mat4 random (glm::mat4 min, glm::mat4 max)
 
template<>
NAPAPI float abs (float value)
 
template<>
NAPAPI int abs (int value)
 
template<typename T >
darken (T target, T blend)
 
template<typename T >
multiply (T target, T blend)
 
template<typename T >
colorBurn (T target, T blend)
 
template<typename T >
linearBurn (T target, T blend)
 
template<typename T >
lighten (T target, T blend)
 
template<typename T >
screen (T target, T blend)
 
template<typename T >
colorDodge (T target, T blend)
 
template<typename T >
linearDodge (T target, T blend)
 
template<typename T >
overlay (T target, T blend)
 
template<typename T >
softLight (T target, T blend)
 
template<typename T >
hardLight (T target, T blend)
 
template<typename T >
vividLight (T target, T blend)
 
template<typename T >
linearLight (T target, T blend)
 
template<typename T >
pinLight (T target, T blend)
 
template<typename T >
difference (T target, T blend)
 
template<typename T >
exclusion (T target, T blend)
 
float NAPAPI waveform (EWaveform type, float time, float frequency)
 

Variables

constexpr double E = 2.71828182845904523536
 
constexpr double LOG2E = 1.44269504088896340736
 
constexpr double LOG10E = 0.434294481903251827651
 
constexpr double LN2 = 0.693147180559945309417
 
constexpr double LN10 = 2.30258509299404568402
 
constexpr double PI = 3.14159265358979323846
 
constexpr double PIX2 = 6.28318530717958647692
 
constexpr double PI_2 = 1.57079632679489661923
 
constexpr double PI_4 = 0.785398163397448309616
 
constexpr double M1_PI = 0.318309886183790671538
 
constexpr double M2_PI = 0.636619772367581343076
 
constexpr double M2_SQRTPI = 1.12837916709551257390
 
constexpr double SQRT2 = 1.41421356237309504880
 
constexpr double SQRT1_2 = 0.707106781186547524401
 
constexpr glm::vec3 X_AXIS = { 1.0f, 0.0f, 0.0f }
 
constexpr glm::vec3 Y_AXIS = { 0.0f, 1.0f, 0.0f }
 
constexpr glm::vec3 Z_AXIS = { 0.0f, 0.0f, 1.0f }
 
constexpr glm::vec3 FORWARD = { 0.0f, 0.0f, -1.0f }
 

Typedef Documentation

◆ DoubleSmoothOperator

◆ FloatFComplex

using FloatFComplex = FComplex<float, float>

◆ FloatFCurve

using FloatFCurve = FCurve<float, float>

◆ FloatFCurvePoint

using FloatFCurvePoint = FCurvePoint<float, float>

◆ FloatSmoothOperator

◆ Vec2FComplex

using Vec2FComplex = FComplex<float, glm::vec2>

◆ Vec2FCurve

using Vec2FCurve = FCurve<float, glm::vec2>

◆ Vec2FCurvePoint

using Vec2FCurvePoint = FCurvePoint<float, glm::vec2>

◆ Vec2SmoothOperator

using Vec2SmoothOperator = SmoothOperator<glm::vec2>

◆ Vec3FComplex

using Vec3FComplex = FComplex<float, glm::vec3>

◆ Vec3FCurve

using Vec3FCurve = FCurve<float, glm::vec3>

◆ Vec3FCurvePoint

using Vec3FCurvePoint = FCurvePoint<float, glm::vec3>

◆ Vec3SmoothOperator

using Vec3SmoothOperator = SmoothOperator<glm::vec3>

◆ Vec4FComplex

using Vec4FComplex = FComplex<float, glm::vec4>

◆ Vec4FCurve

using Vec4FCurve = FCurve<float, glm::vec4>

◆ Vec4FCurvePoint

using Vec4FCurvePoint = FCurvePoint<float, glm::vec4>

◆ Vec4SmoothOperator

using Vec4SmoothOperator = SmoothOperator<glm::vec4>

Enumeration Type Documentation

◆ ECurveInterp

enum ECurveInterp : int
strong

Possible interpolations per curve segment

Enumerator
Bezier 

Bezier style interpolation.

Linear 

Linear style interpolation.

Stepped 

Stepped interpolated (hold previous value until next curve point.

◆ EWaveform

enum EWaveform : int
strong

Various available waveforms

Enumerator
SINE 

Sine.

SQUARE 

Square.

SAW 

Saw.

TRIANGLE 

Triangle.

Function Documentation

◆ abs() [1/3]

NAPAPI float nap::math::abs ( float  value)

◆ abs() [2/3]

NAPAPI int nap::math::abs ( int  value)

◆ abs() [3/3]

T nap::math::abs ( value)
Returns
absolute value.

◆ bell()

T bell ( time,
strength 
)
Returns
a bell shaped curve based on value T (0-1)
Parameters
timesample value, from 0-1.
strengthexponent of the bell curve

◆ ceil()

T ceil ( value)

Rounds value upward, returning the smallest integral value that is not less than x. For example: 2.3 -> 3.0, -2.3 -> 2.0

Parameters
valuevalue to ceil
Returns
The smallest integral value that is not less than x (as a floating-point value).

◆ clamp()

T clamp ( value,
min,
max 
)

Clamp a value between min and max. The value will never exceed max parameter or fall below min.

Parameters
valuevalue to clamp.
minlower limit of value.
maxupper limit of value.
Returns
value clamped to min and max.

◆ colorBurn()

T colorBurn ( target,
blend 
)

Color Burn

Non-Commutative

Parameters
targetBase value
blendValue to combine with
Returns
The result

◆ colorDodge()

T colorDodge ( target,
blend 
)

Color Dodge

Non-Commutative

Parameters
targetBase value
blendValue to combine with
Returns
The result

◆ composeMatrix()

glm::mat4 NAPAPI nap::math::composeMatrix ( const glm::vec3 &  translate,
const glm::quat &  rotate,
const glm::vec3 &  scale 
)

Composes a 4x4 matrix based on individual transformation, rotation and scale values

Parameters
translatea vector describing the objects position
rotatequaternion describing the objects rotation
scalea vector describing the objects scale
Returns
the composed 4x4 matrix

◆ darken()

T darken ( target,
blend 
)

Darken

Commutative

Parameters
targetBase value
blendValue to combine with
Returns
The result

◆ degrees()

float NAPAPI nap::math::degrees ( float  radians)

Converts radians to degrees.

Parameters
radiansangle in radians
Returns
angle in degrees

◆ difference()

T difference ( target,
blend 
)

Difference

Commutative

Parameters
targetBase value
blendValue to combine with
Returns
The result

◆ epsilon()

constexpr T epsilon ( )
constexpr

Returns the machine epsilon, that is, the difference between 1.0 and the next value representable by the floating-point type T. Only works for non-integral types.

Returns
epsilon of type T.

◆ eulerToQuat() [1/2]

glm::quat NAPAPI nap::math::eulerToQuat ( const glm::vec3 &  eulerAngle)

Converts euler angles in to a quaternion The euler angle axis are interpreted as: roll(x), pitch(y), yaw(z),

Parameters
eulerAnglethe individual euler angles in radians
Returns
the composed quaternion

◆ eulerToQuat() [2/2]

glm::quat NAPAPI nap::math::eulerToQuat ( float  roll,
float  pitch,
float  yaw 
)

Converts euler angles in to a quaternion The euler angle axis are interpreted as: roll(x), pitch(y), yaw(z),

Parameters
rollthe x axis rotation value in radians
pitchthe y axis rotation value in radians
yawthe z axis rotation value in radians
Returns
the composed quaternion

◆ exclusion()

T exclusion ( target,
blend 
)

Exclusion

Commutative

Parameters
targetBase value
blendValue to combine with
Returns
The result

◆ extractPosition()

glm::vec3 NAPAPI nap::math::extractPosition ( const glm::mat4x4 &  matrix)

Extracts the position component from a 4x4 matrix. This call assumes the matrix is column major, the outermost array dimension is a column.

Parameters
matrixcolumn major matrix
Returns
the position component from a 4x4 matrix

◆ fit()

float fit ( value,
min,
max,
outMin,
outMax 
)

Maps a value from min/max to outMin/outMax. For example: fit<float>(10.0f, 0.0f, 20.0f, 100.0f, 200.0f) -> returns 150.0f. Input is clamped, ensuring output is always in outMin and outMax range.

Parameters
valuethe value to map
minthe min input value
maxthe max input value
outMinmin output value
outMaxmax output value
Returns
mapped value

◆ floor()

T floor ( value)

Rounds value downward, returning the largest integral value that is not greater than value. For example: 2.3 -> 2.0, -3.8 -> -4.0

Parameters
valuevalue to floor.
Returns
floored value of T

◆ generateUUID()

std::string NAPAPI nap::math::generateUUID ( )

Generate a UUID4, random every time, based on host device and random distribution

◆ getDistancesAlongLine()

float NAPAPI nap::math::getDistancesAlongLine ( const std::vector< glm::vec3 > &  vertexPositions,
std::map< float, int > &  outDistances,
bool  loop 
)

Utility function to retrieve distances along a line This function will calculate the distance of a vertex along the line based on the total length of that line The distance map allows you to easily retrieve the closest vertex associated with a certain distance

Parameters
vertexPositionsthe vertex position data
outDistancesa map that has a distance entry for every vertex of the line
loopif the last vertex should be connected to the first vertex, creating a loop
Returns
the total length of the line

◆ getNormalAlongLine()

void NAPAPI nap::math::getNormalAlongLine ( const std::map< float, int > &  distanceMap,
const std::vector< glm::vec3 > &  vertexNormals,
float  location,
glm::vec3 &  outNormal 
)

Utility function that returns the interpolated normal value along a line This function accurately blends a normal based on the position of a vertex on the line Note that normals with a length of 0 will result in an invalid normal as we can't rotate along a normal with no value

Parameters
distanceMapthe per vertex line distance map that can be acquired using the getDistancesAlongLine function
vertexNormalsthe normal data associated with a line
locationparametric normalized location along the spline, this value needs to be within the 0-1 range
outNormalthe interpolated normal

◆ getValueAlongLine() [1/2]

void getValueAlongLine ( const std::map< float, int > &  distanceMap,
const std::vector< T > &  vertexData,
float  location,
T &  outValue 
)

Utility function that returns an interpolated attribute value along a line This function is more accurate but requires an extra step to perform the interpolation

Parameters
distanceMapthe per vertex line distance map that can be acquired using the getDistancesAlongLine() function
vertexDatathe polyline attribute to sample
locationparametric normalized location along the spline, this value needs to be within the 0-1 range
outValuethe interpolated attribute value

◆ getValueAlongLine() [2/2]

void getValueAlongLine ( const std::vector< T > &  vertexData,
float  location,
bool  closed,
T &  outValue 
)

Returns an interpolated value along the line based on the given location Note that this function works best with equally distributed vertices, ie: segments of equal length. For more accurate results use the getDistancesAlongLine() function, based on actual distance.

Parameters
vertexDatathe polyline attribute to sample, ie position, normal etc.
locationparametric normalized (0-1) location along the spline
closedif the line is closed or not
outValuethe interpolated attribute value

◆ getVertexLerpValue()

float NAPAPI nap::math::getVertexLerpValue ( const std::map< float, int > &  distanceMap,
float  location,
int &  outMinVertex,
int &  outMaxVertex 
)

Utility function that returns a normalized blend value between two line vertices based on a position along the line

Parameters
distanceMapthe per vertex line distance map that can be acquired using the getDistancesAlongLine() function
locationparametric normalized location along the spline, this value needs to be within the 0-1 range
outMinVertexthe lower bound vertex id
outMaxVertexthe upper bound vertex id
Returns
the blend value between the lower and upper vertex

◆ hardLight()

T hardLight ( target,
blend 
)

Hard Light

Non-Commutative

Parameters
targetBase value
blendValue to combine with
Returns
The result

◆ lerp()

T nap::math::lerp ( const T &  start,
const T &  end,
float  percent 
)

Blends a value between start and end value based on percentage (0-1).

Parameters
startbegin value
endend value
percentthe amount to blend between start and end, in between 0 and 1.
Returns
interpolated value.

◆ lerp< double >()

NAPAPI double nap::math::lerp< double > ( const double &  start,
const double &  end,
float  percent 
)

◆ lerp< float >()

NAPAPI float nap::math::lerp< float > ( const float &  start,
const float &  end,
float  percent 
)

◆ lerp< glm::vec2 >()

NAPAPI glm::vec2 nap::math::lerp< glm::vec2 > ( const glm::vec2 &  start,
const glm::vec2 &  end,
float  percent 
)

◆ lerp< glm::vec3 >()

NAPAPI glm::vec3 nap::math::lerp< glm::vec3 > ( const glm::vec3 &  start,
const glm::vec3 &  end,
float  percent 
)

◆ lerp< glm::vec4 >()

NAPAPI glm::vec4 nap::math::lerp< glm::vec4 > ( const glm::vec4 &  start,
const glm::vec4 &  end,
float  percent 
)

◆ lighten()

T lighten ( target,
blend 
)

Lighten

Commutative

Parameters
targetBase value
blendValue to combine with
Returns
The result

◆ linearBurn()

T linearBurn ( target,
blend 
)

Linear Burn

Commutative

Parameters
targetBase value
blendValue to combine with
Returns
The result

◆ linearDodge()

T linearDodge ( target,
blend 
)

Linear Dodge

Commutative

Parameters
targetBase value
blendValue to combine with
Returns
The result

◆ linearLight()

T linearLight ( target,
blend 
)

Linear Light

Non-Commutative

Parameters
targetBase value
blendValue to combine with
Returns
The result

◆ max() [1/2]

constexpr T max ( )
constexpr
Returns
the maximum possible value of type T

◆ max() [2/2]

T max ( left,
right 
)

Returns the highest of 2 values.

Parameters
leftfirst value.
rightsecond value.
Returns
the highest value.

◆ min() [1/2]

constexpr T min ( )
constexpr
Returns
the lowest finite value of type T

◆ min() [2/2]

T min ( left,
right 
)

Returns the lowest of 2 values.

Parameters
leftfirst value.
rightsecond value.
Returns
the lowest value.

◆ multiply()

T multiply ( target,
blend 
)

Multiply

Commutative

Parameters
targetBase value
blendValue to combine with
Returns
The result

◆ objectToWorld()

glm::vec3 NAPAPI nap::math::objectToWorld ( const glm::vec3 &  point,
const glm::mat4x4 &  objectToWorldMatrix 
)

Converts a point in object space to world space using the given object to world matrix.

Parameters
pointthe point in object space
objectToWorldMatrixlocal to world space transformation matrix
Returns
point in world space

◆ overlay()

T overlay ( target,
blend 
)

Overlay

Non-Commutative

Parameters
targetBase value
blendValue to combine with
Returns
The result

◆ pinLight()

T pinLight ( target,
blend 
)

Pin Light

Non-Commutative

Parameters
targetBase value
blendValue to combine with
Returns
The result

◆ power()

T nap::math::power ( value,
exp 
)
Parameters
valueparameter to raise.
exppower exponent.
Returns
Return base raised to the power exponent.

◆ power< double >()

NAPAPI double nap::math::power< double > ( double  value,
double  exp 
)

◆ power< float >()

NAPAPI float nap::math::power< float > ( float  value,
float  exp 
)

◆ power< int >()

NAPAPI int nap::math::power< int > ( int  value,
int  exp 
)

◆ radians() [1/3]

glm::vec3 NAPAPI nap::math::radians ( const glm::vec3 &  eulerDegrees)

Converts an euler rotation in degrees to radians

Parameters
eulerDegreesthe euler rotation roll(x), pitch(y), yaw(z) in degrees
Returns
the euler rotation in radians

◆ radians() [2/3]

float NAPAPI nap::math::radians ( float  degrees)

Converts degrees to radians.

Parameters
degreesangle in degrees
Returns
angle as radians

◆ radians() [3/3]

glm::vec3 NAPAPI nap::math::radians ( float  roll,
float  pitch,
float  yaw 
)

Converts an euler rotation in degrees to radians The arguments are interpreted as floats

Parameters
rollthe x axis rotation in degrees
pitchthe y axis rotation in degrees
yawthe z axis rotation in degrees
Returns
the euler rotation in radians

◆ random() [1/11]

NAPAPI float nap::math::random ( float  min,
float  max 
)

◆ random() [2/11]

NAPAPI glm::ivec2 nap::math::random ( glm::ivec2  min,
glm::ivec2  max 
)

◆ random() [3/11]

NAPAPI glm::ivec3 nap::math::random ( glm::ivec3  min,
glm::ivec3  max 
)

◆ random() [4/11]

NAPAPI glm::ivec4 nap::math::random ( glm::ivec4  min,
glm::ivec4  max 
)

◆ random() [5/11]

NAPAPI glm::mat4 nap::math::random ( glm::mat4  min,
glm::mat4  max 
)

◆ random() [6/11]

NAPAPI glm::vec2 nap::math::random ( glm::vec2  min,
glm::vec2  max 
)

◆ random() [7/11]

NAPAPI glm::vec3 nap::math::random ( glm::vec3  min,
glm::vec3  max 
)

◆ random() [8/11]

NAPAPI glm::vec4 nap::math::random ( glm::vec4  min,
glm::vec4  max 
)

◆ random() [9/11]

NAPAPI int nap::math::random ( int  min,
int  max 
)

◆ random() [10/11]

T nap::math::random ( min,
max 
)

Returns a random number of type T in the range of the given min / max value. Note that the random number is based on the seed set by setRandomSeed.

Returns
a random number in range min / max.
Parameters
minmin random number
maxmax random number
Returns
the generated random number.

◆ random() [11/11]

NAPAPI uint nap::math::random ( uint  min,
uint  max 
)

◆ resampleLine()

int resampleLine ( std::vector< T > &  vertices,
std::vector< T > &  buffer,
int  segments,
bool  closed 
)

Utility function to up-sample a polyline to the given number of segments This function distributes the vertices equally among every segment, something that is not desirable with more uneven, complex lines A weighted distribution method is preferred but for now this will do.

Parameters
verticesthe original mesh vertices
bufferthe buffer that will hold the re-sampled vertices
segmentsthe amount of segments the poly line should have, a segment is the line between two vertices
closedif the line is closed or not, if a line is not closed it will contain one extra point to maintain the last vertex
Returns
the total number of generated vertices

◆ screen()

T screen ( target,
blend 
)

Screen

Commutative

Parameters
targetBase value
blendValue to combine with
Returns
The result

◆ setRandomSeed()

void NAPAPI nap::math::setRandomSeed ( int  value)

Sets the seed for all subsequent random calls.

Parameters
valuethe new seed value

◆ sign()

T sign ( value)
Parameters
valuerequested sign value
Returns
the sign of the given value, 1 for values > 0, -1 for values < 0, 0 for values of exactly 0.

◆ smooth() [1/6]

NAPAPI void nap::math::smooth ( double &  currentValue,
const double &  targetValue,
double &  currentVelocity,
float  deltaTime,
float  smoothTime,
float  maxSpeed 
)

◆ smooth() [2/6]

NAPAPI void nap::math::smooth ( float &  currentValue,
const float &  targetValue,
float &  currentVelocity,
float  deltaTime,
float  smoothTime,
float  maxSpeed 
)

◆ smooth() [3/6]

NAPAPI void nap::math::smooth ( glm::vec2 &  currentValue,
const glm::vec2 &  targetValue,
glm::vec2 &  currentVelocity,
float  deltaTime,
float  smoothTime,
float  maxSpeed 
)

◆ smooth() [4/6]

NAPAPI void nap::math::smooth ( glm::vec3 &  currentValue,
const glm::vec3 &  targetValue,
glm::vec3 &  currentVelocity,
float  deltaTime,
float  smoothTime,
float  maxSpeed 
)

◆ smooth() [5/6]

NAPAPI void nap::math::smooth ( glm::vec4 &  currentValue,
const glm::vec4 &  targetValue,
glm::vec4 &  currentVelocity,
float  deltaTime,
float  smoothTime,
float  maxSpeed 
)

◆ smooth() [6/6]

void nap::math::smooth ( T &  currentValue,
const T &  targetValue,
T &  currentVelocity,
float  deltaTime,
float  smoothTime,
float  maxSpeed 
)

Smoothly interpolates a value of type T over time to a target using a dampening model. This is a specialization of the default smoothDamp() function.

Parameters
currentValuethe current blend value, will be updated after calling
targetValuethe value to blend to
currentVelocitythe current velocity used to blend to target
deltaTimetime in seconds between cooks
smoothTimeapproximately the time it will take to reach the target. A smaller value will reach the target faster.
maxSpeedallows you to clamp the maximum speed
Returns
the blended current value

◆ smoothDamp() [1/2]

double NAPAPI nap::math::smoothDamp ( double  currentValue,
double  targetValue,
double &  currentVelocity,
float  deltaTime,
float  smoothTime,
float  maxSpeed = math::max< float >() 
)

Interpolates a double value over time to a target using a dampening model.

Parameters
currentValuethe current blend value, often the return value
targetValuethe value to blend to
currentVelocitythe current velocity used to blend to target
deltaTimetime in seconds between cooks
smoothTimeapproximately the time it will take to reach the target. A smaller value will reach the target faster.
maxSpeedallows you to clamp the maximum speed
Returns
the blended current value

◆ smoothDamp() [2/2]

float NAPAPI nap::math::smoothDamp ( float  currentValue,
float  targetValue,
float &  currentVelocity,
float  deltaTime,
float  smoothTime,
float  maxSpeed = math::max< float >() 
)

Interpolates a float value over time to a target using a dampening model

Parameters
currentValuethe current blend value, often the return value
targetValuethe value to blend to
currentVelocitythe current velocity used to blend to target
deltaTimetime in seconds between cooks
smoothTimeapproximately the time it will take to reach the target. A smaller value will reach the target faster.
maxSpeedallows you to clamp the maximum speed
Returns
the blended current value

◆ smoothStep()

T smoothStep ( value,
edge0,
edge1 
)

Smoothly interpolates, using a Hermite polynomial, between 0 and 1

Parameters
valuevalue to interpolate
edge0returns 0 if input is less than this value
edge1returns 1 if input is higher than this value

◆ softLight()

T softLight ( target,
blend 
)

Soft Light

Non-Commutative

Parameters
targetBase value
blendValue to combine with
Returns
The result

◆ vividLight()

T vividLight ( target,
blend 
)

Vivid Light

Non-Commutative

Parameters
targetBase value
blendValue to combine with
Returns
The result

◆ waveform()

float NAPAPI nap::math::waveform ( EWaveform  type,
float  time,
float  frequency 
)
Returns
a normalized value (0-1) associated with a specific type of waveform
Parameters
typethe waveform type to query
timepoint in time to sample the waveform
frequencythe waveform frequency
Returns
a normalized (0-1) waveform value

◆ worldToObject()

glm::vec3 NAPAPI nap::math::worldToObject ( const glm::vec3 &  point,
const glm::mat4x4 &  objectToWorldMatrix 
)

Converts a point in world space to a point in object space using the given object to world matrix Note that this call internally uses matrix inversion, a rather costly operation

Parameters
pointin world space
objectToWorldMatrixthe object to world transformation matrix
Returns
point in object space

Variable Documentation

◆ E

constexpr double E = 2.71828182845904523536
constexpr

◆ FORWARD

constexpr glm::vec3 FORWARD = { 0.0f, 0.0f, -1.0f }
constexpr

◆ LN10

constexpr double LN10 = 2.30258509299404568402
constexpr

◆ LN2

constexpr double LN2 = 0.693147180559945309417
constexpr

◆ LOG10E

constexpr double LOG10E = 0.434294481903251827651
constexpr

◆ LOG2E

constexpr double LOG2E = 1.44269504088896340736
constexpr

◆ M1_PI

constexpr double M1_PI = 0.318309886183790671538
constexpr

◆ M2_PI

constexpr double M2_PI = 0.636619772367581343076
constexpr

◆ M2_SQRTPI

constexpr double M2_SQRTPI = 1.12837916709551257390
constexpr

◆ PI

constexpr double PI = 3.14159265358979323846
constexpr

◆ PI_2

constexpr double PI_2 = 1.57079632679489661923
constexpr

◆ PI_4

constexpr double PI_4 = 0.785398163397448309616
constexpr

◆ PIX2

constexpr double PIX2 = 6.28318530717958647692
constexpr

◆ SQRT1_2

constexpr double SQRT1_2 = 0.707106781186547524401
constexpr

◆ SQRT2

constexpr double SQRT2 = 1.41421356237309504880
constexpr

◆ X_AXIS

constexpr glm::vec3 X_AXIS = { 1.0f, 0.0f, 0.0f }
constexpr

◆ Y_AXIS

constexpr glm::vec3 Y_AXIS = { 0.0f, 1.0f, 0.0f }
constexpr

◆ Z_AXIS

constexpr glm::vec3 Z_AXIS = { 0.0f, 0.0f, 1.0f }
constexpr