![]() |
|||||
|
|
IT'S ALL ABOUT VECTORS
In this tutorial we assume you have read
this document. ![]() In your .dll code, a vector is declared (created, allocated) with D3DXVECTOR3 myvector; where 'myvector' is a custom name you choose. In your code, you will use 'myvector' as a single variable, but keep in mind that it is made of three components really. Each component is a value. For example, you can set the three values with myvector.x = 0.0f; myvector.y = 1.0f; myvector.z = 0.0f; or with myvector = D3DXVECTOR3(0.0f,1.0f,0.0f); The three values define the arrow. In the code above, 'myvector' is set to an one-meter-long arrow that points upward. Given the three values, you can visualize the corresponding arrow as follows: The x,y,z values can be negative. If so, you will translate the arrow tip leftward, downward and backward respectively. 2. The origin of a vector is always understood. For example, if the vector is used to express an absolute space location, its origin is understood to match the world center. Imagine the world center exactly between your eyes. The horizontal (ground) plane passes through your eyes and through the world center. The vector D3DXVECTOR3(-7.0f,2.5f,0.0f); is a point located 7 meters on your left, 2.5 meters above the ground plane. If a vector is used to express a force applied to a body, its origin is understood to match the point where the force is applied to (usually defined by a second vector). Its orientation defines the direction of the force, and its length defines the intensity of the force. If a vector is used to express a torque applied to a body, its origin is, for simplicity, assumed to match the center of mass of the body. A torque is a force that tends to rotate a body about a certain axis. So the vector direction is the axis of rotation, and vector length is the intensity of the torque. 3. Vectors are passed to 3Impact functions as variables. For instance iBodyLocationSet(body,&myvector); Note that the vector variable name is always preceded by the & character, when vectors are passed to functions as parameters. The function above places the specified body to the specified absolute space location. Of course the absolute location (second parameter) is passed as a vector. You can visualize it as an arrow from the world center to the desired location. Some functions return vectors. For example iBodyLocation(body,&myvector); will set the three values of 'myvector' so that it expresses the absolute location of the specified body. 4. Vectors can be transformed and added up. 3Impact provides a number of functions that allow you to manage vectors. Names of vector-manipulation functions start with 'iVector...'. You can also compute vectors with common C language expressions. For example myvector = v1 + v2; where v1 and v2 are vector variables, is a valid expression. The resulting 'myvector' variable is filled with the sum of v1 and v2. REMEMBER: when you deal with vector variables, do your best to visualize them as 3d ARROWS. Mastering vectors alone means mastering half the power of 3Impact game engine! |
||||
![]() |
|||||