Math Common Functions
abs(float v)
Returns the absolute value of the argument.Arguments
- float v - Float value.
Return value
Absolute value.abs(double v)
Returns the absolute value of the argument.Arguments
- double v - Value.
Return value
Absolute value.int abs(int v)
Returns the absolute value of the argument.Arguments
- int v - Value.
Return value
Absolute value.long abs(long v)
Returns the absolute value of the argument.Arguments
- long v - Value.
Return value
Absolute value.float bezier(float [] t, float [] v, float time)
Calculates the value of a cubic Bezier function for t = time. A cubic Bezier curve is represented by 4 points. Po is the start point, P1 and P2 are control points 1 and 2 and P3 is the end point. The start and end point denote the beginning and end points of the path and the control points determine how the path moves from the start to the finish. As can be seen from the image, the only variable changing is t which determines how far the path has progressed from P0 to P3. Cubic Bezier curves are used as timing functions particularly for keyframe interpolation.Arguments
- float [] t - Coordinates of the four points of the curve along the horizontal T (times) axis in the range [0.0f, 1.0f].
- float [] v - Coordinates of the four points of the curve along the vertical V (values) axis in the range [0.0f, 1.0f].
- float time - Time in the range [0, 1], for which the value of the Bezier function is to be calculated.
Return value
Value of the Bezier function.double bezier(float [] t, double [] v, float time)
Calculates the value of a cubic Bezier function for t = time. A cubic Bezier curve is represented by 4 points. Po is the start point, P1 and P2 are control points 1 and 2 and P3 is the end point. The start and end point denote the beginning and end points of the path and the control points determine how the path moves from the start to the finish. As can be seen from the image, the only variable changing is t which determines how far the path has progressed from P0 to P3. Cubic Bezier curves are used as timing functions particularly for keyframe interpolation.Arguments
- float [] t - Coordinates of the four points of the curve along the horizontal T (times) axis in the range [0.0f, 1.0f].
- double [] v - Coordinates of the four points of the curve along the vertical V (values) axis in the range [0.0f, 1.0f].
- float time - Time in the range [0, 1], for which the value of the Bezier function is to be calculated.
Return value
Value of the Bezier function.float ceil(float v)
Ceiling function that returns the smallest integer value that is not less than the argument.float a = ceil(3.141593); // a = 4.0
Arguments
- float v - Argument.
Return value
Smallest integer value not less than v.double ceil(double v)
Ceiling function that returns the smallest integer value that is not less than the argument.double a = ceil(3.141593); // a = 4.0
Arguments
- double v - Argument.
Return value
Smallest integer value not less than v.double clamp(double v, double v0, double v1)
Clamps a value within the specified min and max limits.Arguments
- double v - Value to be clamped.
- double v0 - Minimum value.
- double v1 - Maximum value.
Return value
Clamped value.float clamp(float v, float v0, float v1)
Clamps a value within the specified min and max limits.Arguments
- float v - Value to be clamped.
- float v0 - Minimum value.
- float v1 - Maximum value.
Return value
Clamped value.int clamp(int v, int v0, int v1)
Clamps a value within the specified min and max limits.Arguments
- int v - Value to be clamped.
- int v0 - Minimum value.
- int v1 - Maximum value.
Return value
Clamped value.long clamp(long v, long v0, long v1)
Clamps a value within the specified min and max limits.Arguments
- long v - Value to be clamped.
- long v0 - Minimum value.
- long v1 - Maximum value.
Return value
Clamped value.dvec2 clamp(dvec2 v, dvec2 v0, dvec2 v1)
Clamps a value within the specified min and max limits.Arguments
- dvec2 v - Value to be clamped.
- dvec2 v0 - Minimum value.
- dvec2 v1 - Maximum value.
Return value
Clamped value.ivec2 clamp(ivec2 v, ivec2 v0, ivec2 v1)
Clamps a value within the specified min and max limits.Arguments
- ivec2 v - The value.
- ivec2 v0 - Minimum value.
- ivec2 v1 - Maximum value.
Return value
Clamped value.vec2 clamp(vec2 v, vec2 v0, vec2 v1)
Clamps a value within the specified min and max limits.Arguments
- vec2 v - Value to be clamped.
- vec2 v0 - Minimum value.
- vec2 v1 - Maximum value.
Return value
Clamped value.dvec3 clamp(dvec3 v, dvec3 v0, dvec3 v1)
Clamps a value within the specified min and max limits.Arguments
- dvec3 v - Value to be clamped.
- dvec3 v0 - Minimum value.
- dvec3 v1 - Maximum value.
Return value
Clamped value.ivec3 clamp(ivec3 v, ivec3 v0, ivec3 v1)
Clamps a value within the specified min and max limits.Arguments
- ivec3 v - Value to be clamped.
- ivec3 v0 - Minimum value.
- ivec3 v1 - Maximum value.
Return value
Clamped value.vec3 clamp(vec3 v, vec3 v0, vec3 v1)
Clamps a value within the specified min and max limits.Arguments
- vec3 v - Value to be clamped.
- vec3 v0 - Minimum value.
- vec3 v1 - Maximum value.
Return value
Clamped value.bvec4 clamp(bvec4 v, bvec4 v0, bvec4 v1)
Clamps a value within the specified min and max limits.Arguments
- bvec4 v - Value to be clamped.
- bvec4 v0 - Minimum value.
- bvec4 v1 - Maximum value.
Return value
Clamped value.dvec4 clamp(dvec4 v, dvec4 v0, dvec4 v1)
Clamps a value within the specified min and max limits.Arguments
- dvec4 v - Value to be clamped.
- dvec4 v0 - Minimum value.
- dvec4 v1 - Maximum value.
Return value
Clamped value.ivec4 clamp(ivec4 v, ivec4 v0, ivec4 v1)
Clamps a value within the specified min and max limits.Arguments
- ivec4 v - Value to be clamped.
- ivec4 v0 - Minimum value.
- ivec4 v1 - Maximum value.
Return value
Clamped value.vec4 clamp(vec4 v, vec4 v0, vec4 v1)
Clamps a value within the specified min and max limits.Arguments
- vec4 v - Value to be clamped.
- vec4 v0 - Minimum value.
- vec4 v1 - Maximum value.
Return value
Clamped value.compare(float v0, float v1)
Compares two scalars of the float type according to the degree of precision equal to 1.0e-6f.Arguments
- float v0 - First float scalar.
- float v1 - Second float scalar.
Return value
1 if v0 is equal to v1; otherwise, 0.compare(double v0, double v1)
Compares two scalars of the double type according to the degree of precision equal to 1.0e-6f.Arguments
- double v0 - First double scalar.
- double v1 - Second double scalar.
Return value
1 if the v0 is equal to v1; otherwise, 0.compare(float v0, float v1, float epsilon)
Compares two scalars of the float type according to the specified degree of precision.Arguments
- float v0 - First scalar.
- float v1 - Second scalar.
- float epsilon - Epsilon (degree of precision).
Return value
1 if the v0 is equal to v1; otherwise, 0.compare(double v0, double v1, double epsilon)
Compares two scalars of the double type according to the specified degree of precision.Arguments
- double v0 - First scalar.
- double v1 - Second scalar.
- double epsilon - Epsilon (degree of precision).
Return value
1 if the v0 is equal to v1; otherwise, 0.int compare(vec2 v0, vec2 v1)
Compares two vectors according to the degree of precision equal to 1.0e-6f.Arguments
- vec2 v0 - First vector.
- vec2 v1 - Second vector.
Return value
1 if v0 is equal to v1; otherwise, 0.int compare(vec2 v0, vec2 v1, float epsilon)
Compares two vectors according to the specified degree of precision.Arguments
- vec2 v0 - First vector.
- vec2 v1 - Second vector.
- float epsilon - Epsilon (degree of precision).
Return value
1 if v0 is equal to v1; otherwise, 0.int compare(dvec2 v0, dvec2 v1)
Compares two vectors according to the degree of precision equal to 1.0e-6f.Arguments
- dvec2 v0 - First vector.
- dvec2 v1 - Second vector.
Return value
1 if the v0 is equal to v1; otherwise, 0.int compare(dvec2 v0, dvec2 v1, double epsilon)
Compares two vectors according to the specified degree of precision.Arguments
- dvec2 v0 - First vector.
- dvec2 v1 - Second vector.
- double epsilon - Epsilon (degree of precision).
Return value
1 if the v0 is equal to v1; otherwise, 0.int compare(vec3 v0, vec3 v1)
Compares two vectors according to the degree of precision equal to 1.0e-6f.Arguments
- vec3 v0 - First vector.
- vec3 v1 - Second vector.
Return value
1 if the v0 is equal to v1; otherwise, 0.int compare(vec3 v0, vec3 v1, float epsilon)
Compares two vectors according to the specified degree of precision.Arguments
- vec3 v0 - First vector.
- vec3 v1 - Second vector.
- float epsilon - Epsilon (degree of precision).
Return value
1 if the v0 is equal to v1; otherwise, 0.int compare(dvec3 v0, dvec3 v1)
Compares two vectors according to the degree of precision equal to 1.0e-6f.Arguments
- dvec3 v0 - First vector.
- dvec3 v1 - Second vector.
Return value
1 if the v0 is equal to v1; otherwise, 0.int compare(dvec3 v0, dvec3 v1, double epsilon)
Compares two vectors according to the specified degree of precision.Arguments
- dvec3 v0 - First vector.
- dvec3 v1 - Second vector.
- double epsilon - Epsilon (degree of precision).
Return value
1 if the v0 is equal to v1; otherwise, 0.int compare(vec4 v0, vec4 v1)
Compares two vectors according to the degree of precision equal to 1.0e-6f.Arguments
- vec4 v0 - First vector.
- vec4 v1 - Second vector.
Return value
1 if the v0 is equal to v1; otherwise, 0.int compare(vec4 v0, vec4 v1, float epsilon)
Compares two vectors according to the specified degree of precision.Arguments
- vec4 v0 - First vector.
- vec4 v1 - Second vector.
- float epsilon - Epsilon (degree of precision).
Return value
1 if the v0 is equal to v1; otherwise, 0.int compare(dvec4 v0, dvec4 v1)
Compares two vectors according to the degree of precision equal to 1.0e-6f.Arguments
- dvec4 v0 - First vector.
- dvec4 v1 - Second vector.
Return value
1 if the v0 is equal to v1; otherwise, 0.int compare(dvec4 v0, dvec4 v1, double epsilon)
Compares two vectors according to the specified degree of precision.Arguments
- dvec4 v0 - First vector.
- dvec4 v1 - Second vector.
- double epsilon - Epsilon (degree of precision).
Return value
1 if the v0 is equal to v1; otherwise, 0.int compare(quat q0, quat q1)
Compares two quaternions according to the degree of precision equal to 1.0e-6f.Arguments
- quat q0 - First quaternion.
- quat q1 - Second quaternion.
Return value
1 if the q0 is equal to q1; otherwise, 0.int compare(quat q0, quat q1, float epsilon)
Compares two quaternions according to the specified degree of precision.Arguments
- quat q0 - First quaternion.
- quat q1 - Second quaternion.
- float epsilon - Epsilon (degree of precision).
Return value
1 if the q0 is equal to q1; otherwise, 0.int compare(mat3 m0, mat3 m1)
Compares two matrices according to the degree of precision equal to 1.0e-6f.Arguments
- mat3 m0 - First matrix.
- mat3 m1 - Second matrix.
Return value
1 if the m0 is equal to m1; otherwise, 0.int compare(mat3 m0, mat3 m1, float epsilon)
Compares two matrices according to the specified degree of precision.Arguments
- mat3 m0 - First matrix.
- mat3 m1 - Second matrix.
- float epsilon - Epsilon (degree of precision).
Return value
1 if the m0 is equal to m1; otherwise, 0.int compare(mat4 m0, mat4 m1)
Compares two matrices according to the degree of precision equal to 1.0e-6f.Arguments
- mat4 m0 - First matrix.
- mat4 m1 - Second matrix.
Return value
1 if the m0 is equal to m1; otherwise, 0.int compare(mat4 m0, mat4 m1, float epsilon)
Compares two matrices according to the specified degree of precision.Arguments
- mat4 m0 - First matrix.
- mat4 m1 - Second matrix.
- float epsilon - Epsilon (degree of precision).
Return value
1 if the m0 is equal to m1; otherwise, 0.int compare(dmat4 m0, dmat4 m1)
Compares two matrices according to the degree of precision equal to 1.0e-6f.Arguments
- dmat4 m0 - First matrix.
- dmat4 m1 - Second matrix.
Return value
1 if the m0 is equal to m1; otherwise, 0.int compare(dmat4 m0, dmat4 m1, double epsilon)
Compares two matrices according to the specified degree of precision.Arguments
- dmat4 m0 - First matrix.
- dmat4 m1 - Second matrix.
- double epsilon - Epsilon (degree of precision).
Return value
1 if the m0 is equal to m1; otherwise, 0.quat conjugate(quat q)
Returns the conjugate of a given quaternion.Arguments
- quat q - Quaternion.
Return value
Conjugate of a given quaternion.float cross(vec2 v0, vec2 v1)
Cross product of vectors.Arguments
- vec2 v0 - First vector.
- vec2 v1 - Second vector.
Return value
Cross product of the two 2d vectors: v0.x * v1.y - v0.y*v1.x.ivec3 cross(ivec3 v0, ivec3 v1)
Cross product of vectors.Arguments
- ivec3 v0 - First vector.
- ivec3 v1 - Second vector.
Return value
Resulting vector.dvec3 cross(dvec3 v0, dvec3 v1)
Cross product of vectors.Arguments
- dvec3 v0 - First vector.
- dvec3 v1 - Second vector.
Return value
Resulting vector.vec3 cross(vec3 v0, vec3 v1)
Cross product of vectors.Arguments
- vec3 v0 - First vector.
- vec3 v1 - Second vector.
Return value
Resulting vector.void cross(out ivec3 ret, ivec3 v0, ivec3 v1)
Cross product of vectors.Arguments
- out ivec3 ret - Output vector, to which the resulting vector will be put.
- ivec3 v0 - First vector.
- ivec3 v1 - Second vector.
Return value
void cross(out vec3 ret, vec3 v0, vec3 v1)
Cross product of vectors.Arguments
- out vec3 ret - Output vector, to which the resulting vector will be put.
- vec3 v0 - First vector.
- vec3 v1 - Second vector.
Return value
void cross(out vec4 ret, vec3 v0, vec3 v1)
Cross product of vectors.Arguments
- out vec4 ret - Output vector, to which the resulting vector will be put.
- vec3 v0 - First vector.
- vec3 v1 - Second vector.
Return value
void cross(out dvec3 ret, dvec3 v0, dvec3 v1)
Cross product of vectors.Arguments
- out dvec3 ret - Output vector, to which the resulting vector will be put.
- dvec3 v0 - First vector.
- dvec3 v1 - Second vector.
Return value
void cross(out vec4 ret, dvec3 v0, dvec3 v1)
Cross product of vectors.Arguments
- out vec4 ret - Output vector, to which the resulting vector will be put.
- dvec3 v0 - First vector.
- dvec3 v1 - Second vector.
Return value
double dot(dvec2 v0, dvec2 v1)
Dot product of vectors.Arguments
- dvec2 v0 - First vector.
- dvec2 v1 - Second vector.
Return value
Resulting scalar.float dot(vec3 v0, vec4 v1)
Dot product of vectors. In this case, w component of the four-component vector is added to the dot product of first three components of vectors.Arguments
- vec3 v0 - First vector.
- vec4 v1 - Second vector.
Return value
Resulting scalar.float dot(vec4 v0, vec3 v1)
Dot product of vectors. In this case, w component of the four-component vector is added to the dot product of first three components of vectors.Arguments
- vec4 v0 - First vector.
- vec3 v1 - Second vector.
Return value
Resulting scalar.float dot(vec4 v0, vec4 v1)
Dot product of vectors.Arguments
- vec4 v0 - First vector.
- vec4 v1 - Second vector.
Return value
Resulting scalar.float dot(vec3 v0, vec3 v1)
Dot product of vectors.Arguments
- vec3 v0 - First vector.
- vec3 v1 - Second vector.
Return value
Resulting scalar.float dot(vec2 v0, vec2 v1)
Dot product of vectors.Arguments
- vec2 v0 - First vector.
- vec2 v1 - Second vector.
Return value
Resulting scalar.int dot(ivec3 v0, ivec3 v1)
Dot product of vectors.Arguments
- ivec3 v0 - First vector.
- ivec3 v1 - Second vector.
Return value
Resulting scalar.int dot(ivec2 v0, ivec2 v1)
Dot product of vectors.Arguments
- ivec2 v0 - First vector.
- ivec2 v1 - Second vector.
Return value
Resulting scalar.int dot(ivec4 v0, ivec3 v1)
Dot product of vectors. In this case, w component of the four-component vector is added to the dot product of first three components of vectors.Arguments
- ivec4 v0 - First vector.
- ivec3 v1 - Second vector.
Return value
Resulting scalar.int dot(ivec4 v0, ivec4 v1)
Dot product of vectors.Arguments
- ivec4 v0 - First vector.
- ivec4 v1 - Second vector.
Return value
Resulting scalar.double dot(dvec3 v0, dvec3 v1)
Dot product of vectors.Arguments
- dvec3 v0 - First vector.
- dvec3 v1 - Second vector.
Return value
Resulting scalar.double dot(dvec3 v0, dvec4 v1)
Dot product of vectors. In this case, w component of the four-component vector is added to the dot product of first three components of vectors.Arguments
- dvec3 v0 - First vector.
- dvec4 v1 - Second vector.
Return value
Resulting scalar.double dot(dvec4 v0, dvec3 v1)
Dot product of vectors. In this case, w component of the four-component vector is added to the dot product of first three components of vectors.Arguments
- dvec4 v0 - First vector.
- dvec3 v1 - Second vector.
Return value
Resulting scalar.double dot(dvec4 v0, dvec4 v1)
Dot product of vectors.Arguments
- dvec4 v0 - First vector.
- dvec4 v1 - Second vector.
Return value
Resulting scalar.double dot3(dvec3 v0, dvec4 v1)
Dot product of three components of vectors. W components of four-component vectors are ignored.float a = MathLib.dot3(new vec3(1, 2, 3), new vec4(1, 2, 3, 4));
double b = MathLib.dot3(new dvec4(1, 2, 3, 4), new dvec4(1, 2, 3, 4));
/*
result is:
a = 14.000000
b = 14.000000
*/
Arguments
- dvec3 v0 - First vector.
- dvec4 v1 - Second vector.
Return value
Resulting scalar.double dot3(dvec4 v0, dvec3 v1)
Dot product of three components of vectors. W components of four-component vectors are ignored.float a = MathLib.dot3(new vec3(1, 2, 3), new vec4(1, 2, 3, 4));
double b = MathLib.dot3(new dvec4(1, 2, 3, 4), new dvec4(1, 2, 3, 4));
/*
result is:
a = 14.000000
b = 14.000000
*/
Arguments
- dvec4 v0 - First vector.
- dvec3 v1 - Second vector.
Return value
Resulting scalar.double dot3(dvec4 v0, dvec4 v1)
Dot product of three components of vectors. W components of four-component vectors are ignored.float a = MathLib.dot3(new vec3(1, 2, 3), new vec4(1, 2, 3, 4));
double b = MathLib.dot3(new dvec4(1, 2, 3, 4), new dvec4(1, 2, 3, 4));
/*
result is:
a = 14.000000
b = 14.000000
*/
Arguments
- dvec4 v0 - First vector.
- dvec4 v1 - Second vector.
Return value
Resulting scalar.float dot3(vec3 v0, vec4 v1)
Dot product of three components of vectors. W components of four-component vectors are ignored.float a = MathLib.dot3(new vec3(1, 2, 3), new vec4(1, 2, 3, 4));
double b = MathLib.dot3(new dvec4(1, 2, 3, 4), new dvec4(1, 2, 3, 4));
/*
result is:
a = 14.000000
b = 14.000000
*/
Arguments
- vec3 v0 - First vector.
- vec4 v1 - Second vector.
Return value
Resulting scalar.float dot3(vec4 v0, vec3 v1)
Dot product of three components of vectors. W components of four-component vectors are ignored.float a = MathLib.dot3(new vec3(1, 2, 3), new vec4(1, 2, 3, 4));
double b = MathLib.dot3(new dvec4(1, 2, 3, 4), new dvec4(1, 2, 3, 4));
/*
result is:
a = 14.000000
b = 14.000000
*/
Arguments
- vec4 v0 - First vector.
- vec3 v1 - Second vector.
Return value
Resulting scalar.float dot3(vec4 v0, vec4 v1)
Dot product of three components of vectors. W components of four-component vectors are ignored.float a = MathLib.dot3(new vec3(1, 2, 3), new vec4(1, 2, 3, 4));
double b = MathLib.dot3(new dvec4(1, 2, 3, 4), new dvec4(1, 2, 3, 4));
/*
result is:
a = 14.000000
b = 14.000000
*/
Arguments
- vec4 v0 - First vector.
- vec4 v1 - Second vector.
Return value
Resulting scalar.double floor(double v)
Rounds an argument down to the nearest integer.float a = floor(2.3) // a = 2.0
Arguments
- double v - Argument.
Return value
Largest integer value not greater than arg.float floor(float v)
Rounds an argument down to the nearest integer.double a = floor(2.3) // a = 2.0
Arguments
- float v - Argument.
Return value
Largest integer value not greater than arg.float frac(float v)
Returns the fractional part of the argument.float a = frac(3.141593); // a = 0.141593
Arguments
- float v - Argument.
Return value
Fractional part of the argument.double frac(double v)
Returns the fractional part of the argument.double a = frac(3.141593); // a = 0.141593
Arguments
- double v - Argument.
Return value
Fractional part of the argument.float getAngle(quat q0, quat q1)
Returns the angle (in degrees) between the given first and second quaternions. The angle returned is the unsigned acute angle between the two quaternions. This means the smaller of the two possible angles is used.Arguments
- quat q0 - First quaternion (from which the angular difference is measured).
- quat q1 - Second quaternion (to which the angular difference is measured).
Return value
Angle between the given quaternions, in degrees within the range [0.0; 180.0].float getAngle(vec3 v0, vec3 v1)
Returns the angle (in degrees) between the given first and second vectors. The angle returned is the unsigned acute angle between the two vectors. This means the smaller of the two possible angles is used.Arguments
- vec3 v0 - First vector (from which the angular difference is measured).
- vec3 v1 - Second vector (to which the angular difference is measured).
Return value
Angle between the given vectors, in degrees within the range [0.0; 180.0].float getAngle(vec3 v0, vec3 v1, vec3 up)
Returns the signed angle (in degrees) between the given first and second vectors relative to the specified "up" vector.Arguments
- vec3 v0 - First vector (from which the angular difference is measured).
- vec3 v1 - Second vector (to which the angular difference is measured).
- vec3 up - Up vector, around which the other two vectors are rotated.
Return value
Angle between the given vectors, in degrees within the range [-180.0; 180.0].float gradient4(float x, vec4 gradient)
Returns a gradient value for the specified argument using four key components. The gradient value is determined as follows:smoothstep(gradient.x, gradient.y, x) - smoothstep(gradient.z, gradient.w, x);
Arguments
- float x - Argument.
- vec4 gradient - Vector with four key components.
Return value
Gradient value.float length(vec2 v)
Calculates the length of a given vector.Arguments
- vec2 v - Vector.
Return value
Vector length.double length(dvec2 v)
Calculates the length of a given vector.Arguments
- dvec2 v - Vector.
Return value
Vector length.float length(vec3 v)
Calculates the length of a given vector.Arguments
- vec3 v - Vector.
Return value
Vector length.double length(dvec3 v)
Calculates the length of a given vector.Arguments
- dvec3 v - Vector.
Return value
Vector length.float length(vec4 v)
Calculates the length of a given vector.Arguments
- vec4 v - Vector.
Return value
Vector length.double length(dvec4 v)
Calculates the length of a given vector.Arguments
- dvec4 v - Vector.
Return value
Vector length.float length2(vec2 v)
Calculates the squared length of a given vector. This method is much faster than length() - the calculation is basically the same only without the slow Sqrt call. If you are using lengths simply to compare distances, then it is faster to compare squared lengths against the squares of distances as the comparison gives the same result.Arguments
- vec2 v - Vector.
Return value
Squared length of the vector (X2 + Y2 + Z2).double length2(dvec2 v)
Calculates the squared length of a given vector. This method is much faster than length() - the calculation is basically the same only without the slow Sqrt call. If you are using lengths simply to compare distances, then it is faster to compare squared lengths against the squares of distances as the comparison gives the same result.Arguments
- dvec2 v - Vector.
Return value
Squared length of the vector (X2 + Y2 + Z2).int length2(ivec2 v)
Calculates the squared length of a given vector. If you are using lengths simply to compare distances, then it is faster to compare squared lengths against the squares of distances as the comparison gives the same result.Arguments
- ivec2 v - Vector.
Return value
Squared length of the vector (X2 + Y2 + Z2).float length2(vec3 v)
Calculates the squared length of a given vector. This method is much faster than length() - the calculation is basically the same only without the slow Sqrt call. If you are using lengths simply to compare distances, then it is faster to compare squared lengths against the squares of distances as the comparison gives the same result.Arguments
- vec3 v - Vector.
Return value
Squared length of the vector (X2 + Y2 + Z2).double length2(dvec3 v)
Calculates the squared length of a given vector. This method is much faster than length() - the calculation is basically the same only without the slow Sqrt call. If you are using lengths simply to compare distances, then it is faster to compare squared lengths against the squares of distances as the comparison gives the same result.Arguments
- dvec3 v - Vector.
Return value
Squared length of the vector (X2 + Y2 + Z2).int length2(ivec3 v)
Calculates the squared length of a given vector. If you are using lengths simply to compare distances, then it is faster to compare squared lengths against the squares of distances as the comparison gives the same result.Arguments
- ivec3 v - Vector.
Return value
Squared length of the vector (X2 + Y2 + Z2).float length2(vec4 v)
Calculates the squared length of a given vector. This method is much faster than length() - the calculation is basically the same only without the slow Sqrt call. If you are using lengths simply to compare distances, then it is faster to compare squared lengths against the squares of distances as the comparison gives the same result.Arguments
- vec4 v - Vector.
Return value
Squared length of the vector (X2 + Y2 + Z2).double length2(dvec4 v)
Calculates the squared length of a given vector. This method is much faster than length() - the calculation is basically the same only without the slow Sqrt call. If you are using lengths simply to compare distances, then it is faster to compare squared lengths against the squares of distances as the comparison gives the same result.Arguments
- dvec4 v - Vector.
Return value
Squared length of the vector (X2 + Y2 + Z2).int length2(ivec4 v)
Calculates the squared length of a given vector. If you are using lengths simply to compare distances, then it is faster to compare squared lengths against the squares of distances as the comparison gives the same result.Arguments
- ivec4 v - Vector.
Return value
Squared length of the vector (X2 + Y2 + Z2).float lerp(float v0, float v1, float k)
Returns the interpolated value according to the following formula: v0 + (v1 - v0) * k.Arguments
- float v0 - First float value.
- float v1 - Second float value.
- float k - Interpolation coefficient.
Return value
Interpolated value.double lerp(double v0, double v1, double k)
Returns the interpolated value according to the following formula: v0 + (v1 - v0) * k.Arguments
- double v0 - First double value.
- double v1 - Second double value.
- double k - Interpolation coefficient.
Return value
Interpolated value.int lerp(int v0, int v1, int k)
Returns the interpolated value according to the following formula: v0 + (v1 - v0) * k.Arguments
- int v0 - First int value.
- int v1 - Second int value.
- int k - Interpolation coefficient.
Return value
Interpolated value.vec2 lerp(vec2 v0, vec2 v1, float k)
Returns the interpolated vector according to the following formula: v0 + (v1 - v0) * k.Arguments
- vec2 v0 - First vector.
- vec2 v1 - Second vector.
- float k - Interpolation coefficient.
Return value
Interpolated vector.vec3 lerp(vec3 v0, vec3 v1, float k)
Returns the interpolated vector according to the following formula: v0 + (v1 - v0) * k.Arguments
- vec3 v0 - First vector.
- vec3 v1 - Second vector.
- float k - Interpolation coefficient.
Return value
Interpolated vector.vec4 lerp(vec4 v0, vec4 v1, float k)
Returns the interpolated vector according to the following formula: v0 + (v1 - v0) * k.Arguments
- vec4 v0 - First vector.
- vec4 v1 - Second vector.
- float k - Interpolation coefficient.
Return value
Interpolated vector.dvec2 lerp(dvec2 v0, dvec2 v1, double k)
Returns the interpolated vector according to the following formula: v0 + (v1 - v0) * k.Arguments
- dvec2 v0 - First vector.
- dvec2 v1 - Second vector.
- double k - Interpolation coefficient.
Return value
Interpolated vector.dvec3 lerp(dvec3 v0, dvec3 v1, double k)
Returns the interpolated vector according to the following formula: v0 + (v1 - v0) * k.Arguments
- dvec3 v0 - First vector.
- dvec3 v1 - Second vector.
- double k - Interpolation coefficient.
Return value
Interpolated vector.dvec4 lerp(dvec4 v0, dvec4 v1, double k)
Returns the interpolated vector according to the following formula: v0 + (v1 - v0) * k.Arguments
- dvec4 v0 - First vector.
- dvec4 v1 - Second vector.
- double k - Interpolation coefficient.
Return value
Interpolated vector.ivec2 lerp(ivec2 v0, ivec2 v1, int k)
Returns the interpolated vector according to the following formula: v0 + (v1 - v0) * k.Arguments
- ivec2 v0 - First vector.
- ivec2 v1 - Second vector.
- int k - Interpolation coefficient.
Return value
Interpolated vector.ivec3 lerp(ivec3 v0, ivec3 v1, int k)
Returns the interpolated vector according to the following formula: v0 + (v1 - v0) * k.Arguments
- ivec3 v0 - First vector.
- ivec3 v1 - Second vector.
- int k - Interpolation coefficient.
Return value
Interpolated vector.ivec4 lerp(ivec4 v0, ivec4 v1, int k)
Returns the interpolated vector according to the following formula: v0 + (v1 - v0) * k.Arguments
- ivec4 v0 - First vector.
- ivec4 v1 - Second vector.
- int k - Interpolation coefficient.
Return value
Interpolated vector.max(float v0, float v1)
Returns the maximum value.Arguments
- float v0 - First value.
- float v1 - Second value.
Return value
Maximum value.max(double v0, double v1)
Returns the maximum value.Arguments
- double v0 - First value.
- double v1 - Second value.
Return value
Maximum value.max(int v0, int v1)
Returns the maximum value.Arguments
- int v0 - First value.
- int v1 - Second value.
Return value
Maximum value.long max(long v0, long v1)
Returns the maximum value.Arguments
- long v0 - First value.
- long v1 - Second value.
Return value
Maximum value.vec2 max(vec2 v0, vec2 v1)
Returns the maximum value.Arguments
- vec2 v0 - First value.
- vec2 v1 - Second value.
Return value
Maximum value.vec3 max(vec3 v0, vec3 v1)
Returns the maximum value.Arguments
- vec3 v0 - First value.
- vec3 v1 - Second value.
Return value
Maximum value.vec4 max(vec4 v0, vec4 v1)
Returns the maximum value.Arguments
- vec4 v0 - First value.
- vec4 v1 - Second value.
Return value
Maximum value.dvec2 max(dvec2 v0, dvec2 v1)
Returns the maximum value.Arguments
- dvec2 v0 - First value.
- dvec2 v1 - Second value.
Return value
Maximum value.dvec3 max(dvec3 v0, dvec3 v1)
Returns the maximum value.Arguments
- dvec3 v0 - First value.
- dvec3 v1 - Second value.
Return value
Maximum value.dvec4 max(dvec4 v0, dvec4 v1)
Returns the maximum value.Arguments
- dvec4 v0 - First value.
- dvec4 v1 - Second value.
Return value
Maximum value.ivec2 max(ivec2 v0, ivec2 v1)
Returns the maximum value.Arguments
- ivec2 v0 - First value.
- ivec2 v1 - Second value.
Return value
Maximum value.ivec3 max(ivec3 v0, ivec3 v1)
Returns the maximum value.Arguments
- ivec3 v0 - First value.
- ivec3 v1 - Second value.
Return value
Maximum value.ivec4 max(ivec4 v0, ivec4 v1)
Returns the maximum value.Arguments
- ivec4 v0 - First value.
- ivec4 v1 - Second value.
Return value
Maximum value.bvec4 max(bvec4 v0, bvec4 v1)
Returns the maximum value.Arguments
- bvec4 v0 - First value.
- bvec4 v1 - Second value.
Return value
Maximum value.float min(float v0, float v1)
Returns the minimum value.Arguments
- float v0 - First value.
- float v1 - Second value.
Return value
Minimum value.double min(double v0, double v1)
Returns the minimum value.Arguments
- double v0 - First value.
- double v1 - Second value.
Return value
Minimum value.int min(int v0, int v1)
Returns the minimum value.Arguments
- int v0 - First value.
- int v1 - Second value.
Return value
Minimum value.long min(long v0, long v1)
Returns the minimum value.Arguments
- long v0 - First value.
- long v1 - Second value.
Return value
Minimum value.vec2 min(vec2 v0, vec2 v1)
Returns the minimum value.Arguments
- vec2 v0 - First value.
- vec2 v1 - Second value.
Return value
Minimum value.vec3 min(vec3 v0, vec3 v1)
Returns the minimum value.Arguments
- vec3 v0 - First value.
- vec3 v1 - Second value.
Return value
Minimum value.vec4 min(vec4 v0, vec4 v1)
Returns the minimum value.Arguments
- vec4 v0 - First value.
- vec4 v1 - Second value.
Return value
Minimum value.dvec2 min(dvec2 v0, dvec2 v1)
Returns the minimum value.Arguments
- dvec2 v0 - First value.
- dvec2 v1 - Second value.
Return value
Minimum value.dvec3 min(dvec3 v0, dvec3 v1)
Returns the minimum value.Arguments
- dvec3 v0 - First value.
- dvec3 v1 - Second value.
Return value
Minimum value.dvec4 min(dvec4 v0, dvec4 v1)
Returns the minimum value.Arguments
- dvec4 v0 - First value.
- dvec4 v1 - Second value.
Return value
Minimum value.ivec2 min(ivec2 v0, ivec2 v1)
Returns the minimum value.Arguments
- ivec2 v0 - First value.
- ivec2 v1 - Second value.
Return value
Minimum value.ivec3 min(ivec3 v0, ivec3 v1)
Returns the minimum value.Arguments
- ivec3 v0 - First value.
- ivec3 v1 - Second value.
Return value
Minimum value.ivec4 min(ivec4 v0, ivec4 v1)
Returns the minimum value.Arguments
- ivec4 v0 - First value.
- ivec4 v1 - Second value.
Return value
Minimum value.bvec4 min(bvec4 v0, bvec4 v1)
Returns the minimum value.Arguments
- bvec4 v0 - First value.
- bvec4 v1 - Second value.
Return value
Minimum value.int npot(int arg)
Rounds up to the nearest power of two value.Arguments
- int arg - Argument.
Return value
The nearest upper power of 2 number.float rcp(float v)
Returns the reciprocal of the specified argument.Arguments
- float v - Argument.
Return value
Reciprocal of the argument.double rcp(double v)
Returns the reciprocal of the specified argument.Arguments
- double v - Argument.
Return value
Reciprocal of the argument.double round(double v)
Rounds an argument to the nearest integer value.In halfway cases, when an argument has a fractional part of exactly 0.5, the function rounds away from zero to the integer with larger magnitude.
- 3.5 -> 4
- - 3.5 -> - 4
double a = round(2.3) // a = 2.0
double b = round(5.5) // b = 6.0
double c = round(-5.5) // c = -6.0
Arguments
- double v - Argument.
Return value
Nearest integer value to the argument.float round(float v)
Rounds an argument to the nearest integer value.In halfway cases, when an argument has a fractional part of exactly 0.5, the function rounds away from zero to the integer with larger magnitude.
- 3.5 -> 4
- - 3.5 -> - 4
float a = round(2.3) // a = 2.0
float b = round(5.5) // b = 6.0
float c = round(-5.5) // c = -6.0
Arguments
- float v - Argument.
Return value
Nearest integer value to the argument.float saturate(float v)
Clamps the value within the range of 0.0 to 1.0.Arguments
- float v - Argument.
Return value
Argument value clamped within the range of 0.0 to 1.0.double saturate(double v)
Clamps the value within the range of 0.0 to 1.0.Arguments
- double v - Argument.
Return value
Argument value clamped within the range of 0.0 to 1.0.dvec2 saturate(dvec2 v)
Clamps the values of vector components within the range of 0.0 to 1.0.Arguments
- dvec2 v
vec2 saturate(vec2 v)
Clamps the values of vector components within the range of 0.0 to 1.0.Arguments
- vec2 v - Vector.
Return value
Vector with components clamped within the range of 0.0 to 1.0.dvec3 saturate(dvec3 v)
Clamps the values of vector components within the range of 0.0 to 1.0.Arguments
- dvec3 v - Vector.
Return value
Vector with components clamped within the range of 0.0 to 1.0.vec3 saturate(vec3 v)
Clamps the values of vector components within the range of 0.0 to 1.0.Arguments
- vec3 v - Vector.
Return value
Vector with components clamped within the range of 0.0 to 1.0.dvec4 saturate(dvec4 v)
Clamps the values of vector components within the range of 0.0 to 1.0.Arguments
- dvec4 v - Vector.
Return value
Vector with components clamped within the range of 0.0 to 1.0.vec4 saturate(vec4 v)
Clamps the values of vector components within the range of 0.0 to 1.0.Arguments
- vec4 v - Vector.
Return value
Vector with components clamped within the range of 0.0 to 1.0.float sign(float v)
Returns the sign of the argument.Arguments
- float v - Argument.
Return value
Sign of the argument. 1.0 if v >= 0.0 ; -1.0 if v < 0.0.double sign(double v)
Returns the sign of the argument.Arguments
- double v - Argument.
Return value
Sign of the argument. 1.0 if v >= 0.0 ; -1.0 if v < 0.0.int udiv(int x, int y)
Performs integer division with rounding up.Arguments
- int x - First argument.
- int y - Second argument.
Return value
The rounded up quotient of two arguments that satisfies the following condition: y * z >= x.quat slerp(quat q0, quat q1, float k)
Spherical interpolation between two given quaternions.Arguments
- quat q0 - The value of the first quaternion.
- quat q1 - The value of the second quaternion.
- float k - The current position (from 0 to 1).
Return value
Resulting quaternion.Last update: 2018-08-10
Help improve this article
Was this article helpful?
(or select a word/phrase and press Ctrl+Enter)