1.5 operator
Read this article shows that you have agreed to the statement
HLSL supports a lot of operators similar to C . In addition to rare exceptions, their usage and C are exactly the same. The following table lists HLSL operators:
[]>
<
<=> =! = = =! &&?: = - - = * * = / / =% = - = () '
Although the operator behavior and C are very similar, there are also some differences. First, the demographic% operator works on integer and floating point. In order to use the model operator, the value of the left side and the value of the right must have the same positive and negative (eg, the left and right side must be positive or negative).
Second, pay attention to the HLSL operation is based on each component. This is because the actual vector and matrix are in the language, and these types consist of several components. By applying these operations over the component level, we can complete additions, subtraction, and equal testing of the vector / matrix like the use of numerical types, see example:
Note: The behavior of the operator is just like a numeric value (that is, in a general C method).
Vector u = {1.0F, 0.0F, -3.0F, 1.0F};
Vector v = {-4.0F, 2.0F, 1.0F, 0.0F};
// Adds Corresponding Components
Vector SUM = u v; // sum = (-3.0F, 2.0F, -2.0F, 1.0F)
Increasing a vector is incrementing each of the components:
// before increment: sum = (-3.0F, 2.0F, -2.0F, 1.0F)
SUM ; // after increment: sum = (-2.0F, 3.0F, -1.0F, 2.0F)
Vector multiplied by the vector:
Vector u = {1.0F, 0.0F, -3.0F, 1.0F};
Vector v = {-4.0F, 2.0F, 1.0F, 0.0F};
// Multiply Corresponding Components
Vector SUM = u * v; // product = (-4.0F, 0.0F, -3.0F, 0.0F)
The comparison operation is also performed by the component, and returns a vector or array of each component is the Bool type. The "BOOL" vector as a result contains the result of each component comparison. E.g:
Vector u = {1.0F, 0.0F, -3.0F, 1.0F};
Vector v = {-4.0F, 0.0F, 1.0F, 1.0F};
Vector b = (u == v); // b = (false, true, false, true)
Finally, we have ended as a variable increase in binary operations:
n For binary operations, if the left and right dimensions are different (operators), the dimension is less lifted (forced conversion) to the same dimension with the dimension of the dimension. For example, if the type of X is float, and the type of Y is float3, the variable x in the expression (X Y) is raised to float3, and the value of the calculated expression is also FLOAT3. Improves the use of defined conversions. Note that if the conversion is not defined, it is not defined. For example, we can't convert float2 to float3 because this conversion is not defined. N For binary operations, if the left and right types are different, then the lower type resolution is lifted (forced conversion) to the Higher Type Resolution. For example, if the X type INT, Y type is HALF, the variable X in the expression (x Y) is raised to the HALF, and the value of the calculated expression is also HALF.
[Declaration]: Introduction to 3D Game Programming With DirectX 9.0 "in this article, it is limited to the translator level, and it is inevitable that there is a mistake in the text. Welcome all netizen criticism; this article is only used for learning exchange and reference usage, not to use In any form of commercial use; if you need to reprint the author's own and translator's consent, maintain the integrity of the article, indicate the author, translator and source, for the consequences of violating the above terms, the translator Do not bear any responsibility. My email address is raymond_king123@hotmade.com, welcome 3D graphics and games, and friends with a certain graphical programming experience to communicate.