矩陣類型

矩陣是一種特殊資料類型,其中包含介於一到十六個元件之間。 矩陣的每個元件都必須是相同的類型。

TypeComponents 名稱

單元

項目 描述
TypeComponents
包含三個部分的單一名稱。 第一個部分是其中一個 純量 類型。 第二個部分是資料列數目。 第三個部分是資料行數目。 資料列和資料行數目是介於 1 到 4 之間的正整數。
名字
可唯一識別變數名稱的 ASCII 字串。

範例

以下是一些範例:

int1x1    iMatrix;   // integer matrix with 1 row,  1 column
int4x1    iMatrix;   // integer matrix with 4 rows, 1 column
int1x4    iMatrix;   // integer matrix with 1 row, 4 columns
double3x3 dMatrix;   // double matrix with 3 rows, 3 columns

float2x2 fMatrix = { 0.0f, 0.1, // row 1
                     2.1f, 2.2f // row 2
                   };   

您也可以使用此語法來宣告矩陣:

matrix <Type, Number> VariableName

矩陣類型會使用角括弧來指定類型、資料列數目和欄數。 這個範例會建立一個浮點矩陣,其中包含兩個數據列和兩個數據行。 您可以使用任何純量資料類型。

範例如下:

matrix <float, 2, 2> fMatrix = { 0.0f, 0.1, // row 1
                                 2.1f, 2.2f // row 2
                               };

另請參閱

(DirectX HLSL)