|
VOID SetupMatrices()
{
// For our world matrix, we will just rotate the object about the y-axis.
D3DXMATRIX matWorld;
D3DXMatrixRotationY( &matWorld, timeGetTime()/150.0f );
g_pd3dDevice->SetTransform( D3DTS_WORLD , &matWorld );
// Set up our view matrix. A view matrix can be defined given an eye point,
// a point to lookat, and a direction for which way is up. Here, we set the
// eye five units back along the z-axis and up three units, look at the
// origin, and define "up" to be in the y-direction.
D3DXMATRIX matView;
D3DXMatrixLookAtLH( &matView, &D3DXVECTOR3( 0.0f, 3.0f, -8.0f ),
&D3DXVECTOR3( 0.0f, 0.0f, 0.0f ),
&D3DXVECTOR3( 0.0f, 1.0f, 0.0f ) );
g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );
// For the projection matrix, we set up a perspective transform (which
// transforms geometry from 3D view space to 2D viewport space, with
// a perspective divide making objects smaller in the distance). To build
// a perpsective transform, we need the field of view (1/4 pi is common),
// the aspect ratio, and the near and far clipping planes (which define at
// what distances geometry should be no longer be rendered).
D3DXMATRIX matProj;
D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f );
g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
}
这是在MS DX8 SDK的Tutorials/Tut03_Matrices里面的一个函数,功能是调整世界坐标、观察坐标和投影坐标,从而让一个三角形绕y轴旋转起
来。考虑其中的世界坐标变换代码:
D3DXMATRIX matWorld;
D3DXMatrixRotationY( &matWorld, timeGetTime()/150.0f );
g_pd3dDevice->SetTransform( D3DTS_WORLD , &matWorld );
每次进入这个函数的时候,matWorld都会被初始化,D3DXMatrixRotationY都会把一个全部是0的矩阵进行变换,而不是针对已经定义好的全局
顶点数组的指针(LPDIRECT3DVERTEXBUFFER8 g_pVB)进行操作,我就奇怪执行g_pd3dDevice->SetTransform( D3DTS_WORLD , &matWorld );怎
么会转动整个世界坐标?没有信息的输入啊!
只有一个解释:在调用SetTransform的时候实际上是将变换矩阵matWorld和现在整个世界坐标进行操作,因此不用显式的给出当前的世界坐标
信息,不过问题在于timeGetTime()的值越来越大,因此将这个空白矩阵matWorld转动的角度也越大,如果按照我的解释的话,当matWorld作用
在世界坐标上,也会使得世界坐标转动越转越快,但实际上是匀速转动的,为什么?
为什么每次D3DXMatrixRotationY操作一个没有任何信息输入的矩阵,却可以使得整个世界转动?
|
|