Game Development Reference
In-Depth Information
Function
Description
max(x, y)
Returns x if x
!
y , else returns y .
min(x, y)
Returns x if x , x
y else returns y .
mul(M, N)
Returns the matrix product MN . Note that the
matrix product MN must be defined. If M is a
vector, it is treated as a row vector so that the
vector-matrix product is defined. Likewise, if N is
a vector it is treated as a column vector so that
the matrix-vector product is defined.
normalize(v)
Returns v / v .
pow(b, n)
Returns b n .
radians(x)
Converts x from degrees to radians.
reflect(v, n)
Computes the reflection vector given the incident
vector v and the surface normal n .
refract(v, n, eta)
Computes the refraction vector given the incident
vector v , the surface normal n , and the ratio of
the two indices of refraction of the two materials
eta . Look up Snell's law in a physics topic or on
the Internet fo r information on refraction.
rsqrt(x)
Returns 1/
x .
saturate(x)
Returns clamp(x, 0.0, 1.0).
sin(x)
Returns the sine of x , where x is in radians.
sincos(in x, out s, out c)
Returns the sine and cosine of x , where x is in
radians.
sqrt(x)
Returns
x .
tan(x)
Returns the tangent of x , where x is in radians.
transpose(M)
Returns the transpose M T .
Most of the functions are overloaded to work with all the built-in types
for which the function makes sense. For instance, abs makes sense for
all scalar types and so is overloaded for all of them. As another exam-
ple, the cross product cross only makes sense for 3D vectors, so it is
only overloaded for 3D vectors of any type (e.g., 3D vectors of int s,
float s, double s etc.). On the other hand, linear interpolation, lerp ,
makes sense for scalars, and 2D, 3D, and 4D vectors and therefore is
overloaded for all types.
Note: If you pass in a non-scalar type into a “scalar” function, that
is, a function that traditionally operates on scalars (e.g., cos(x) ), the
function will act per component. For example, if you write:
float3 v = float3(0.0f, 0.0f, 0.0f);
v = cos(v);
Search WWH ::




Custom Search