游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2468|回复: 0

DXUT框架中类CDXUTDirectionWidget

[复制链接]

2

主题

5

帖子

5

积分

新手上路

Rank: 1

积分
5
发表于 2012-2-23 11:34:00 | 显示全部楼层 |阅读模式
有谁能够解释一下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
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-6-9 18:26

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表