|
我在一本书上看到世界矩阵第一行是模型自身向右的向量,第二行是向上的,第三行是向前的,第四行是位置。
而且书上写了这样一个函数来控制模型
VOID SetWorldMatrix()
{
static long curTime=0;
static float elapsetime=0;
elapsetime = (timeGetTime()-curTime)/1000.0f;
curTime = timeGetTime();
//创建并设置世界矩阵
float fRoll, fPitch, fYaw;
fRoll = fPitch = fYaw = 0.0f;
if (m_bKey['D']) fRoll -= 3*elapsetime;
if (m_bKey['A']) fRoll += 3*elapsetime;
if (m_bKey['S']) fPitch -= 3*elapsetime;
if (m_bKey['W']) fPitch += 3*elapsetime;
if (m_bKey['Q']) fYaw -= 3*elapsetime;
if (m_bKey['E']) fYaw += 3*elapsetime;
//更新网格模型姿态
static D3DXVECTOR3 vRight, vUp, vLook, vPos;
vRight.x = g_matWorld._11;
vRight.y = g_matWorld._12;
vRight.z = g_matWorld._13;
vUp.x = g_matWorld._21;
vUp.y = g_matWorld._22;
vUp.z = g_matWorld._23;
vLook.x = g_matWorld._31;
vLook.y = g_matWorld._32;
vLook.z = g_matWorld._33;
vPos.x = g_matWorld._41;
vPos.y = g_matWorld._42;
vPos.z = g_matWorld._43;
D3DXVec3Normalize(&vLook, &vLook);
D3DXVec3Cross(&vRight, &vUp, &vLook);
D3DXVec3Normalize(&vRight, &vRight);
D3DXVec3Cross(&vUp, &vLook, &vRight);
D3DXVec3Normalize(&vUp, &vUp);
static D3DXMATRIX matPitch, matYaw, matRoll;
D3DXMatrixRotationAxis(&matYaw, &vUp, fYaw);
D3DXVec3TransformCoord(&vLook, &vLook, &matYaw);
D3DXVec3TransformCoord(&vRight, &vRight, &matYaw);
D3DXMatrixRotationAxis(&matRoll, &vLook, fRoll);
D3DXVec3TransformCoord(&vRight, &vRight, &matRoll);
D3DXVec3TransformCoord(&vUp, &vUp, &matRoll);
D3DXMatrixRotationAxis(&matPitch, &vRight, fPitch);
D3DXVec3TransformCoord(&vLook, &vLook, &matPitch);
D3DXVec3TransformCoord(&vUp, &vUp, &matPitch);
g_matWorld._11 = vRight.x;
g_matWorld._12 = vRight.y;
g_matWorld._13 = vRight.z;
g_matWorld._21 = vUp.x ;
g_matWorld._22 = vUp.y ;
g_matWorld._23 = vUp.z;
g_matWorld._31 = vLook.x;
g_matWorld._32 = vLook.y;
g_matWorld._33 = vLook.z;
//向前移动
if (m_bKey['F'])
{
g_matWorld._41 += 30*elapsetime * vLook.x;
g_matWorld._42 += 30*elapsetime * vLook.y;
g_matWorld._43 += 30*elapsetime * vLook.z;
}
//向后移动
if (m_bKey['V'])
{
g_matWorld._41 -= 30*elapsetime * vLook.x;
g_matWorld._42 -= 30*elapsetime * vLook.y;
g_matWorld._43 -= 30*elapsetime * vLook.z;
}
g_pd3dDevice->SetTransform( D3DTS_WORLD, &g_matWorld );
}
我想知道这个函数里世界是转动的模型自身还是整个世界。
还有如何控制单个模型的大小位置而不影响场景中的其他模型呢?
谢谢了 |
|