Preface
I used to use VC for computer graphics. About a year ago, the company received a project using C # + direcx and began to learn mangaged DirectX since then, I will make a summary of the development process and share it with my colleagues for reference, learning, and making progress together. The previous section describes some basic content, some algorithms used in the development process are being sorted out. 1: During the sorting process, some of the content is the information obtained from the Internet, and some are the translation of foreign articles. The so-called "a huge copy of an article in the world will not be copied .", If your personal interests are violated, contact me. 2: The previous development environment was vs. net2003 1.1 + directx9.0. Now the development environment is vs2005, and some development environments cannot be remembered. However, it should not be affected. 3: some of the content is done by GDI +, and all the examples are saved with source code. However, due to network conditions, some of them are not uploaded and can be contacted if necessary. 4: learning is not easy, personal level is limited, hope the prawns criticize and correct; 5: Contact: Mail: tongabcd@yeah.net QQ: 50759188 (when I add managed DirectX)
Chapter 1 vectorIn this section, we will introduce some basic mathematical knowledge, including vector, matrix, and transformation, as well as some knowledge about spatial points, lines, surfaces, and bodies, if you already have two courses, linear algebra and space analytic ry, it will be easy to read. If you have never touched them before, it doesn't matter, however, it may be a little difficult. Here we will introduce them in combination with the related mathematical models in the d3dx class and related function integration programs. In this section, we will mainly introduce four aspects: (1) vector concept and three-dimensional concept; (2) matrix concept and its application in directx10; (3) how to generate line and plane in directx10; (4) 3D mathematical formulas and related classes. For example, the dot product of a vector and the cross product of a vector;
1: VectorIn the Cartesian coordinate system of a three-dimensional Euclidean space, a vector is represented by a directed line segment. We know that two points in the space determine a straight line segment. If the direction of these two points is included, it becomes a directed line segment, that is, a vector. We can see that the two attributes of a vector are its length and the direction indicated by the vertex. In this way, we can use vectors to simulate physical models with both sizes and directions. For example, particle systems often appear in 3D games, and vectors can be used to simulate the velocity and acceleration of particles; for example, a linear light not only has the position of the light, but also the direction of the light. The camera also has the position and angle of view. Therefore, vectors provide convenience for expressing the direction in 3D space. All vectors are displayed. (figure 1) vectors have the size and direction, but are not related to the position, the two vectors with the same length and direction but different starting points are equal. Now, in the figure above, the vectors u and v are equal.
2: Coordinate SystemIn 3D space, when the X axis and Y axis are fixed, the Z axis can be inward or outward, which is called the left-hand coordinate system and the right-hand coordinate system;
3: vector RepresentationBecause the vector has nothing to do with the position, the starting point of the vector and the starting point of the coordinate system can be overlapped by translation. Therefore, the standard position of a vector can be described with only one point. For example, a vector V (1, 2, 3) indicates that the starting point is (0, 0, 0 ), A directed line segment whose end point is V (, 3). Generally, a letter is used to represent a vector, Which is case-insensitive. In addition, sometimes, only X is required, Y coordinates instead of zcoordinates. For example, for a two-dimensional game, the Z value is sometimes redundant, but sometimes for a point, in addition to using X, Y, and Z to represent its position, a numerical value is also required to represent its color, transformation, and other information. Therefore, DirectX contains two-dimensional, three-dimensional, and four-dimensional vectors. For example, the 2, 3, and 4-dimensional vectors are: U = (UX, uy), n = (NX, NY, NZ), c = (CX, Cy, CZ, CW ).
4: unit vectorA vector with only one unit length is called a unit vector. If they happen to be in the coordinate axis, they are called the UNIT base vector. They are called the I, j, and K vectors, respectively along the X axis, Y axis, and Z axis of the coordinate system, and the unit length is 1: I = (1, 0, 0), j = (0, 1, 0), and K = (0, 0, 1 ). In DirectX, a two-dimensional, three-dimensional, and four-dimensional Vector class is defined in the Microsoft. DirectX namespace, which are vector2, vector3, and vector4 respectively.
5: ExampleThe following code defines a two-dimensional vector and draws a straight line. Only relevant code is written here. For the complete code, see the source file; private void render () {vector2 [] VECs = new vector2 [2]; VECs [0] = new vector2 (300,300); device. clear (clearflags. target, system. drawing. color. white, 1.0f, 0); device. beginscene (); Using (line L = new line (device) {L. draw (VECs, color. red);} device. endscene (); device. present: