Cg语言中,对两个向量进行 "*"的乘法运算时,既不是点积(内积),也不是叉积(外积),只是两向量各分量分别相乘而已。
以下内容只是引述出处,太长可以不看。
参考网页 <https://en.wikibooks.org/wiki/Cg_Programming/Vector_and_Matrix_Operations>
float3 a =float3(1.0, 2.0, 3.0);
float3 b =float3(0.1, 0.2, 0.3);
float3 c = a + b; //= float3(1.1, 2.2, 3.3)
float3 d = a * b; //= float3(0.1, 0.4, 0.9)
Note in particularthat a * b represents a component-wise product of two vectors, which is not often seen in linear algebra. For matrices, these operators also workcomponent-wise. Again, a component-wise product of two matrices is not often seen in linear algebra.
特别注意,a * b表示两个向量的各分量的乘积,这在线性代数中并不常见。对于矩阵,这些运算符也是分别作用于各分量的。同样,两个矩阵的各分量的乘积,在线性代数中也是不常见到。
For the usualmatrix-vector product or matrix-matrix product, see the built-in mul functionbelow. For the dot product and cross product between vectors, see the built-infunctions dot and cross below.
对于通常的矩阵向量乘积或矩阵-矩阵乘积,请参见下面的内置mul函数。对于向量的点积和向量积,可以看到内建的函数点和下面的点。
The *-operator canalso be used to multiply a floating-point value (i.e. a scalar) to allcomponents of a vector or matrix (from left or right):
运算符也可用于将浮点值(即标量)乘于向量或矩阵的所有分量(从左或右):
float3 a =float3(1.0, 2.0, 3.0);
float2x2 m =float2x2(1.0, 0.0, 0.0, 1.0);
float s = 10.0;
float3 b = s * a; //float3(10.0, 20.0, 30.0)
float3 c = a * s; //float3(10.0, 20.0, 30.0)
float2x2 m2 = s * m;// = float2x2(10.0, 0.0, 0.0, 10.0)
float2x2 m3 = m * s;// = float2x2(10.0, 0.0, 0.0, 10.0)