1,在世界坐标系中有一个正方体,立方体的世界转换矩阵是 WorldMatrix,如果 WorldMatrix 是单位矩阵的话,则该立方体中心位于世界坐标系原点。
2,在设置观察矩阵的时候,可确定世界坐标系与屏幕的关系。
// Initialize the view matrix
D3DXVECTOR3 Eye( 0.0f, 0.0f, -8.0f );
D3DXVECTOR3 At( 0.0f, 0.0f, 0.0f );
D3DXVECTOR3 Up( 0.0f, 1.0f, 0.0f );
D3DXMatrixLookAtLH( &g_View, &Eye, &At, &Up );
g_View是输出的观察矩阵,向量Eye,At 是世界坐标系中的点,Eye 是照相机的位置, At 是观察点,就是眼睛看的位置,无论怎么设置这个点,这个点始终在屏幕中心。根据这个条件,则可知道世界坐标系在屏幕的位置。
比如 At(0,0,0),则世界坐标系的原点就这屏幕中心;At(3,0,0),则世界坐标系的原点在屏幕中往左(X轴)偏移3。
3,物体在世界坐标系中的位置
WorldMatrix 变换
1 0 0 0
0 1 0 0
0 0 1 0
a b c 1
(a,b,c)是该立方体在世界坐标系中的位置。
相关函数:
Builds a matrix using the specified offsets.
D3DXMATRIX * D3DXMatrixTranslation(
D3DXMATRIX * pOut,
FLOAT x,
FLOAT y,
FLOAT z
);
Parameters
pOut
[in, out] Pointer to the D3DXMATRIX structure that is the result of the operation.
x
[in] X-coordinate offset.
y
[in] Y-coordinate offse