Game Development Reference
In-Depth Information
When copying vectors, we do not have to copy every component over.
For example, we can copy over only the x- and y-components, as this
code snippet illustrates:
vector u = {1.0f, 2.0f, 3.0f, 4.0f};
vector v = {0.0f, 0.0f, 5.0f, 6.0f};
v.xy = u; // v = {1.0f, 2.0f, 5.0f, 6.0f}
16.3.3
Matrix Types
HLSL has the following built-in matrix types:
matrix
—A 4
4 matrix, where each entry is of type
float
matrix<T, m, n>
—An
m
n
matrix, where each entry is of sca-
lar type
T
. The matrix dimensions
m
and
n
must be between 1 and
4. Here is an example of an 2
2 integer matrix:
matrix<int, 2, 2> m2x2;
Alternatively, we can define an
m
n
matrix, where
m
and
n
are
between 1 and 4, using the following syntax:
floatmxn matmxn;
Examples:
float2x2 mat2x2;
float3x3 mat3x3;
float4x4 mat4x4;
float2x4 mat2x4;
Note:
The types need not be only
float
—we can use other types.
For instance we can use integers and write:
int2x2 i2x2;
int2x2 i3x3;
int2x2 i2x4;
We can access an entry in a matrix using a double array subscript syn-
tax. For example, to set the
ij
th
entry of a matrix
M
, we would write:
M[i][j] = value;
In addition, we can refer to the entries of a matrix
M
as we would access
the members of a structure. The following entry names are defined:
One-based:
M._11 = M._12 = M._13 = M._14 = 0.0f;
M._21 = M._22 = M._23 = M._24 = 0.0f;
M._31 = M._32 = M._33 = M._34 = 0.0f;
M._41 = M._42 = M._43 = M._44 = 0.0f;
Search WWH ::
Custom Search