游戏开发论坛

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

DXUT中关于摄像机的问题

[复制链接]

4

主题

10

帖子

14

积分

新手上路

Rank: 1

积分
14
发表于 2011-8-7 17:48:00 | 显示全部楼层 |阅读模式
我把directX的第三课(Matrices )的绘图代码移植到到DXUT框架下,发现不能正常的绘制出三角形。我已经搞了一个下午了,还是不知道原因。下面是一部分代码。DXUT的框架就是教程里面的SimpleSample

DXUT中的绘图代码,中间有一段是我加的绘图代码,其他都是框架自动生成的,我可以保证摄像机的位置和绘制的三角形的位置都没有问题。
void CALLBACK OnD3D9FrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
    HRESULT hr;
    D3DXMATRIXA16 mWorld;
    D3DXMATRIXA16 mView;
    D3DXMATRIXA16 mProj;
    D3DXMATRIXA16 mWorldViewProjection;

    // If the settings dialog is being shown, then render it instead of rendering the app's scene
    if( g_SettingsDlg.IsActive() )
    {
        g_SettingsDlg.OnRender( fElapsedTime );
        return;
    }

    // Clear the render target and the zbuffer
    V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB( 0, 45, 50, 170 ), 1.0f, 0 ) );

    //My Render Codes
    g_pd3dDevice->SetTransform( D3DTS_PROJECTION, g_Camera.GetProjMatrix());
    g_pd3dDevice->SetTransform( D3DTS_VIEW,       g_Camera.GetViewMatrix());
    g_pd3dDevice->SetTransform( D3DTS_WORLD,      g_Camera.GetWorldMatrix());       
    if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
    {
                // Render the vertex buffer contents
                g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof( CUSTOMVERTEX ) );
                g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
                g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 1 );

                // End the scene
                g_pd3dDevice->EndScene();
    }
    //End My Render Code
    if( SUCCEEDED( pd3dDevice->BeginScene() ) )
    {
        // Get the projection & view matrix from the camera class
        mWorld = *g_Camera.GetWorldMatrix();
        mProj = *g_Camera.GetProjMatrix();
        mView = *g_Camera.GetViewMatrix();

        mWorldViewProjection = mWorld * mView * mProj;

        // Update the effect's variables.  Instead of using strings, it would
        // be more efficient to cache a handle to the parameter by calling
        // ID3DXEffect::GetParameterByName
        V( g_pEffect9->SetMatrix( g_hmWorldViewProjection, &mWorldViewProjection ) );
        V( g_pEffect9->SetMatrix( g_hmWorld, &mWorld ) );
        V( g_pEffect9->SetFloat( g_hfTime, ( float )fTime ) );

        DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" ); // These events are to help PIX identify what the code is doing
        RenderText();
        V( g_HUD.OnRender( fElapsedTime ) );
        V( g_SampleUI.OnRender( fElapsedTime ) );
        DXUT_EndPerfEvent();

        V( pd3dDevice->EndScene() );
    }
}
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2025-8-5 20:56

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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