World Transformation |
This discussion of the world transformation introduces basic concepts and provides details on how to set up a world transformation matrix in a Microsoft Direct3D application.
A world transformation changes coordinates from model space, where vertices are defined relative to a model's local origin, to world space, where vertices are defined relative to an origin common to all of the objects in a scene. In essence, the world transformation places a model into the world; hence its name. The following diagram illustrates the relationship between the world coordinate system and a model's local coordinate system.
The world transformation can include any combination of translations, rotations, and scalings. For a discussion of the mathematics of transformations, see 3-D Transformations.
As with any other transformation, you create the world transformation by concatenating a series of transformation matrices into a single matrix that contains the sum total of their effects. In the simplest case, when a model is at the world origin and its local coordinate axes are oriented the same as world space, the world matrix is the identity matrix. More commonly, the world matrix is a combination of a translation into world space and possibly one or more rotations to turn the model as needed.
The following C# code example, from a fictitious 3-D model class written in C#, creates a world matrix that includes three rotations to orient a model and a translation to relocate it relative to its position in world space.
[C#]
public class ModelClass { private float xPos=0; private float yPos=0; private float zPos=0; private float Pitch=0; private float Yaw=0; private float Roll=0; //...Other model properties and methods public Matrix MakeWorldMatrix(Matrix worldMatrix) { worldMatrix.Translate(xPos,yPos,zPos); Matrix matRot = Matrix.Identity; matRot.RotateYawPitchRoll(Yaw,Pitch,Roll); worldMatrix = Matrix.Multiply(matRot, worldMatrix); return worldMatrix; } }
After you prepare the world transformation matrix, call the SetTransform method to set it, specifying the TransformType.World value for the first parameter. Alternately, you can pass the world transformation matrix to the Device.Transform.World property.
Send comments about this topic to Microsoft. © Microsoft Corporation. All rights reserved.
Feedback? Please provide us with your comments on this topic.
For more help, visit the DirectX Developer Center