Platform SDK: DirectX |
The following transformation translates the point (x, y, z) to a new point (x', y', z').
You can create a translation matrix by hand in C++. The following example shows the source code for a function that creates a matrix to translate vertices.
D3DMATRIX Translate(const float dx, const float dy, const float dz) { D3DMATRIX ret = D3DUtil_SetIdentityMatrix(); // declared in d3dutil.h ret(3, 0) = dx; ret(3, 1) = dy; ret(3, 2) = dz; return ret; } // End of Translate
In Visual Basic, you can create a translation matrix by hand, or you can use the TranslateMatrix helper subroutine in the Math.bas file that is included with this SDK. The following example shows the source code for the TranslateMatrix subroutine.
Sub TranslateMatrix(m As D3DMATRIX, v As D3DVECTOR) Call dx.IdentityMatrix(m) ' Method of the DirectX7 object m.rc41 = v.x m.rc42 = v.y m.rc43 = v.z End Sub