Main Index : Reference :
Here are some convenient math functions that are included in the SDK.
| Constant | Explanation |
PI |
p |
PI2 |
2p |
PI05 |
p/2 |
SQRT2 |
21/2 |
ONESQRT2 |
2-1/2 |
[float] Degree([float] radians);
[float] Radians([float] degree);
[vector] MinimizeAngle([vector] a1, [vector] a2);
[vector] VectorToHPB([vector] v);
[vector] HSVToRGB([vector] hsv);
[vector] RGBToHSV([vector] rgb);
[vector] PointLineDistance([vector] p0, [vector] v0, [vector] q);
[float] Modulo([float] a, [float] b);
[float] Step([float] a, [float] x);
[float] Pulse([float] a, [float] b, [float] x);
[float] Clamp([float] a, [float] b, [float] x);
[float] BoxStep([float] a, [float] b, [float] x);
[float] SmoothStep([float] a, [float] b, [float] x);
[float] GammaCorrect([float] gamma, [float] x);
[float] Bias([float] bias, [float] x);
[float] Gain([float] g, [float] x);
[float,vector] Mix([float,vector] a, [float,vector] b, [float,vector] x);
[float] Degree([float] radians);
Returns the angle radians converted to degrees.
[float] Radians([float] degree);
Returns the angle degree converted to radians.
[vector] MinimizeAngle([vector] a1, [vector] a2);
The change of the HPB angles from a1 to a2 might include loops with angles greater than 180°. This function returns a new value of a2 that represents the same rotation, but won't create loops when one rotates from a1 to a2.
[vector] VectorToHPB([vector] v);
Returns HPB angles from the vector v.
[vector] HSVToRGB([vector] hsv);
Converts hsv into the RGB color space and returns the converted value.
[vector] RGBToHSV([vector] rgb);
Converts rgb into the HSV color space and returns the converted value.
[vector] PointLineDistance([vector] p0, [vector] v0, [vector] q);
Returns the shortest vector between the point q and the line defined by the starting point p0 and the direction v0. The returned vector points from the nearest point on the line to q. Therefore the length of the returned vector gives the shortest distance between the line and q.
[float] Modulo([float] a, [float] b);
Returns a modulo b.
[float] Step([float] a, [float] x);
Returns 1.0 if x is greater than or equal to a, else 0.0.
[float] Pulse([float] a, [float] b, [float] x);
Returns 1.0 if x is between or equal to either of a and b, else 0.0.
[float] Clamp([float] a, [float] b, [float] x);
Returns a if x is less than a and b if x is greater than b, else returns x.
[float] BoxStep([float] a, [float] b, [float] x);
Returns 0.0 if x is less than a and 1.0 if x is greater than b, else returns x mapped on the range [a,b] (a number between 0.0 and 1.0).
[float] SmoothStep([float] a, [float] b, [float] x);
Returns 0.0 if x is less than a and 1.0 if x is greater than b, else returns x mapped on the range [a,b] (a number between 0.0 and 1.0). The mapping is smoothed using an ease-in/ease-out curve.
[float] GammaCorrect([float] gamma, [float] x);
Returns the gamma corrected value of x, calculated with the formula x1/gamma.
[float] Bias([float] bias, [float] x);
Returns the bias as the defined in the book "Texturing and Modeling" by Ebert. The internal code is:
Bias(b, x)
{
return Pow(x, -Ln(b) / 0.693147180559945);
}
[float] Gain([float] g, [float] x);
Returns the gain as the defined in the book "Texturing and Modeling" by Ebert. The internal code is:
Gain(g, x)
{
if (x<0.5)
return Bias(1.0 - g, 2.0 * x) * 0.5;
else
return 1.0 - Bias(1.0 - g, 2.0 - 2.0 * x) * 0.5;
}
[float,vector] Mix([float,vector] a, [float,vector] b, [float,vector] x);
Returns a mixed value of a and b using the parameter x, as calculated by a+(b-a)*x.