|
有谁能够解释一下CDXUTDirectionWidget中函数OnRender9()?
HRESULT CDXUTDirectionWidget::OnRender9( D3DXCOLOR color, const D3DXMATRIX* pmView,
const D3DXMATRIX* pmProj, const D3DXVECTOR3* pEyePt )
{
m_mView = *pmView;
// Render the light spheres so the user can visually see the light dir
UINT iPass, cPasses;
D3DXMATRIX mRotate;
D3DXMATRIX mScale;
D3DXMATRIX mTrans;
D3DXMATRIXA16 mWorldViewProj;
HRESULT hr;
V( s_pD3D9Effect->SetTechnique( s_hRenderWith1LightNoTexture ) );
V( s_pD3D9Effect->SetVector( s_hMaterialDiffuseColor, ( D3DXVECTOR4* )&color ) );
D3DXVECTOR3 vEyePt;
D3DXVec3Normalize( &vEyePt, pEyePt );
V( s_pD3D9Effect->SetValue( s_hLightDir, &vEyePt, sizeof( D3DXVECTOR3 ) ) );
// Rotate arrow model to point towards origin
D3DXMATRIX mRotateA, mRotateB;
D3DXVECTOR3 vAt = D3DXVECTOR3( 0, 0, 0 );
D3DXVECTOR3 vUp = D3DXVECTOR3( 0, 1, 0 );
D3DXMatrixRotationX( &mRotateB, D3DX_PI );
D3DXMatrixLookAtLH( &mRotateA, &m_vCurrentDir, &vAt, &vUp );
D3DXMatrixInverse( &mRotateA, NULL, &mRotateA );//这里为什么要求mRotateA 的逆矩阵啊?????
mRotate = mRotateB * mRotateA;//
D3DXVECTOR3 vL = m_vCurrentDir * m_fRadius * 1.0f;
D3DXMatrixTranslation( &mTrans, vL.x, vL.y, vL.z );
D3DXMatrixScaling( &mScale, m_fRadius * 0.2f, m_fRadius * 0.2f, m_fRadius * 0.2f );
D3DXMATRIX mWorld = mRotate * mScale * mTrans;//这里为什么用mRotate 相乘啊??????
mWorldViewProj = mWorld * ( m_mView )*( *pmProj );
V( s_pD3D9Effect->SetMatrix( s_hWorldViewProjection, &mWorldViewProj ) );
V( s_pD3D9Effect->SetMatrix( s_hWorld, &mWorld ) );
for( int iSubset = 0; iSubset < 2; iSubset++ )
{
V( s_pD3D9Effect->Begin( &cPasses, 0 ) );
for( iPass = 0; iPass < cPasses; iPass++ )
{
V( s_pD3D9Effect->BeginPass( iPass ) );
V( s_pD3D9Mesh->DrawSubset( iSubset ) );
V( s_pD3D9Effect->EndPass() );
}
V( s_pD3D9Effect->End() );
}
return S_OK;
}abc |
|