**This article by Harry** **_** **Spider-Man original, reproduced please indicate the source. Have a question Welcome to contact** **[email protected]**

**Note: The electronic version I gave is more than 700 pages. And the physical book is more than 800 pages, so I mentioned the relevant concepts when. The chapter number is used instead of the page number.**

**The same situation is suitable for the second edition of "Dragon book".**

We officially started this phase of Learning DX 11 programming!

The first three chapters form part one of the book. Called "Mathematical Prerequisites". Learning this part is a prerequisite for moving on. This part of the introduction is preceded by a famous quote, which makes me quite surprised. This reminds me of another book, called the 7th edition of Problem solving with C + +; This book on the introduction of C + + programming is almost always in front of each section (very often very long) a quote, many of which come from literary works, are thought to be very interesting.

It's just a pity. This book seems to be the only occurrence of this time ...

This time the 1th chapter: Vectoralgebra (vector algebra) is described.

The content of this chapter (and the next two chapters) is very easy, especially if you have seen the second edition of "Dragon book", but there are still a lot of noteworthy places.

Because the author himself may be more lazy. Coupled with the fact that a lot of content has not changed substantially (for example, the math part of the story), people who have read the second edition of "Dragon book" will think that very many statements are familiar. It's not really déjà vu, it's very much the exact words. Well, there's no more gossip. Here's the start!

Focus on recall

===============================================================================

This chapter is about vector algebra. Believe that people who have read high school can be very easy to understand (possibly except for the code part later). This chapter also introduces the XNA Math Library, which is different from the second edition of "Dragon book". Of course we can still use the D3DX Math library as in the second edition of "Dragon book", but this XNA Math library is more efficient; Besides, by introducing new things like this, Frank D. Luna gave us a bluntness. Let us know from the beginning that this book and the "Dragon Book" second edition is very different.

For the convenience of this chapter, the learning objectives are listed here:

**1. To Learn how vectors is represented geometricallyand numerically. (Learn how to represent vectors using geometric methods and numerical methods.) )**

**2. To discover the operations defined onvectors and their geometric applications. (Learn to define operations on vectors.) and their geometrical applications. )**

**3. To become familiar with the XNA mathlibrary ' s vector functions and classes. (familiar with XNA Math the library's vector functions and classes. )**

The content of this chapter. Except for the code sections that follow. Most of the "Dragon Book" second edition of the first chapter of knowledge coincident.

And the content is very easy. So I'll just pick a few different places to say.

1.3.1 Orthogonalization (orthogonal)

The Gram-schmidt orthogonal approach is mentioned in this section, which can be found in either a linear algebra (or higher algebra) textbook.

1.4.1 Pseudo 2D cross product (pseudo 2D fork product)

In fact, this concept is not clearly presented here (and is not covered later). It's just that a 2D vector U's pseudo-cross product v is parallel to the vector. In fact, a condition should be added, that is, from U to V is called the positive angle (just how to define a corner of the positive and negative, which is also related to the right and left hand of the coordinate system). Overall. This section is insignificant.

1.4.2 Orthogonalization with Thecross product (orthogonal with cross product)

This section is also the second edition of "Dragon book" does not have. The content here is relatively simple. is parallel to section 1.3.1.

It's just different from the bar. Where the Gram-schmidt orthogonality method is for arbitrarily finite plurality (linearly unrelated. But this book does not tell the concept of linear algebra, and it is not womb can be clear, but I think everyone should have learned this knowledge, should be very easy to understand the vector, and this section is for 3 linearly independent 3D vector and the second kind of orthogonal method proposed.

1.6 Knots XNA mathvectors (XNA math vector)

This is a whole new section.

This section tells us that the D3DX Library of DX 11 no longer has a mathematical library that provides various vector operations. Instead. The DX 11 is provided to us by the XNA Math Library. On the Windows platform, the XNA Math Library uses the SSE2 (streaming SIMD Extension 2) instruction set.

Anyway, SIMD can use an instruction to complete the operation of 4 32-bit floating-point or integer. Therefore, it is very fast to use this library to do the vector operation.

It's just worth noting that. We want to extend the 3D vectors to 4D vectors in order to use such efficient computing techniques. Here is a detailed description of the highlights of the sections in this section:

1.6.1 Vector Types

In this section. The authors summarize the following five points:

**1. for local variables and global variables, use the Xmvector type. **

**2. for a data member of a class, use the XMFLOAT2, XMFLOAT3 and the XMFLOAT4 data members;**

**3. before you perform the calculation, use the Load function ( Loading Functions ) to bring xmfloat* type is converted into Xmvector type;**

**4. with Xmvector calculation of the example;**

**5. Use stored Functions ( Storage Functions ) to bring Xmvector converted into xmfloat* type. **

1.6.2 Loading and Storage Methods

In this section, the author describes the loading and storage functions mentioned above. There is a fxmvector type of participation in it; don't worry about it. The following will be explained.

1.6.3 Parameter Passing

This section describes the two types of parameters, Cxmvector and Fxmvector. And tells us when we define the function. Considerations for the parameter types:

**first three of the function Xmvector type must be Fxmvector , and the back is all Cxmvector . **

1.6.4 Constant Vectors

This section tells us that the Xmvector constants that need to be initialized should be defined as XMVECTORF32 types (for storing floating-point vectors) or XMVECTORU32 types (for storing integer vectors).

1.6.5 Overloaded Operators

This section describes the very many xmvector overloaded operators.

There is nothing to say in this section, but you can remove these overloads by defining Xm_no_operator_overloads. The reason to think of removing these overloads is due to the complexity of the calculations. Canceling overloading can improve performance.

Just in this book we will always use these overloaded operators (that is, we do not perform very complex computations).

1.6.6 Miscellaneous

I don't know how to translate the word. This section tells us about the constants associated with PI, the functions that convert between radians and angles, and two macros that take the maximum minimum value.

1.6.7 Setter Functions

This section describes some of the functions provided by the XNA Math Library to set the value of a xmvector variable and gives a simple console program to demonstrate it.

1.6.8 Vector Functions

This section describes some of the functions for doing various vector operations. and gives a control of it program to test.

It is worth noting here: ** All of these functions, assuming that the return value is not BOOL or VOID . Then it must be xmvector, which contains a point multiplication function that returns a floating-point value. **

1.6.9 floating-point Error

This section describes the more famous question: When calculating with floating-point numbers (or even simply expressing them), errors occur, so when inferences are equal. There is a need to define an allowable error. The author then writes a console program that uses the Xmvector to verify what he says.

In addition The second edition of "Dragon book" in section 1.5 refers to the coordinate transformation, but the first chapter of this book does not mention this topic, but in the 3rd chapter of the narrative.

===============================================================================

Errata

===============================================================================

1, in the 1.6.2 section, the author gives a few functions, some of which are fxmvector type, but this syntax is discussed in the next section.

People who have just started to learn may be confused. The author should mention it here.

===============================================================================

Problem solving:

===============================================================================

**Exercise 1-18:**

These topics are very easy, and students who have learned linear algebra can do it very easily. So I skipped it.

**Exercise 19:**

This topic shows a console program that uses Xmvector and lets us test the function of the Xmvector function used.

Most of them are very easy. I'll just pick a few to talk about!

Xmvectorabs (v)-Returns a vector. Each component of the vector is the absolute value of the corresponding component of V;

Xmvectorcos (v)-Returns a vector in which each component of the vector is the cosine of the corresponding component of V;

Xmvectorlog (v)-Returns a vector that each component of the vector is a 2-based pair of corresponding components of V;

Xmvectorexp (v)-Returns a vector (2^v[0],2^v[1], 2^v[2], 2^v[3]), where 2^x represents the power of 2 x.

Xmvectorpow (U, v)--Returns a vector (U[0]^v[0], u[1]^v[1],u[2]^v[2], u[3]^v[3]), where x^y represents the y power of X;

Xmvectorsqrt (v)-Returns a vector in which each component of the vector is the arithmetic square root of the corresponding component of V;

Xmvectorswizzle (V,a, B, C, D)--Returns a vector (V[a],v[b], v[c], v[d]), and as far as A,b,c,d out 0,1,2,3 this range, what happens, ask the reader to do their own research.

Xmvectormultiply (U,V)-Returns a vector in which each component of the vector is the product of the corresponding component of U and the corresponding component of V;

Xmvectorsaturate (v)-Returns a vector of the values resulting from the saturate operation of each component of V, saturate (x) returns 0 (if x<0), X (if 0<=x<=1), or 1 (x>1).

===============================================================================

OK, this is the time. In the next issue, we will continue to study the contents of chapter 2nd.

Yes, the original book DVD comes with some of the answers to some of the exercises, I put it here, you are welcome to download!

**Part of the exercise answer**

In addition, I put the first three chapters of the color map here, we can look at:

**The first three chapters color map**

Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.

DirectX 11 Game Programming Learning Note 2: Article 1 chapter vector Algebra (vectors algebra)