Справочник функций

Ваш аккаунт

Войти через: 
Забыли пароль?
Регистрация
Информацию о новых материалах можно получать и без регистрации:

Почтовая рассылка

Подписчиков: -1
Последний выпуск: 19.06.2015

Трабл с матрицами

13K
26 января 2010 года
karimchik
65 / / 16.06.2008
Народ!У меня большой трабл с матрицами!При их использовании не отображается треугольник((
Код:
#include <stdafx.h>
#include <d3d9.h>
#include <d3dx9.h>
#pragma comment (lib,"d3d9.lib")
#pragma comment (lib,"d3dx9.lib")


LPDIRECT3D9             g_pD3D       = NULL;
LPDIRECT3DDEVICE9       Device = NULL;
LPDIRECT3DVERTEXBUFFER9 buff;

struct Vertex
{

int x,y,z;
DWORD color;

};

void Matrix()
{
    // &#204;&#224;&#242;&#240;&#232;&#246;&#224; &#226;&#232;&#228;&#224;
    D3DXMATRIX MatrixView;
    //&#236;&#224;&#242;&#240;&#232;&#246;&#224; &#239;&#240;&#238;&#229;&#234;&#246;&#232;&#232;
    D3DXMATRIX MatrixProjection;
    D3DXMATRIX MatrixWorld;

    Device->SetTransform(D3DTS_WORLD, &MatrixWorld);

    // &#200;&#231;&#236;&#229;&#237;&#255;&#229;&#236; &#226;&#232;&#228;&#238;&#226;&#243;&#254; &#236;&#224;&#242;&#240;&#232;&#246;&#243;
    D3DXMatrixLookAtLH(&MatrixView,      // &#239;&#238;&#235;&#243;&#247;&#229;&#237;&#237;&#224;&#255; &#226; &#232;&#242;&#238;&#227;&#229; &#226;&#232;&#228;&#238;&#226;&#224;&#255; &#236;&#224;&#242;&#240;&#232;&#246;&#224;
        &D3DXVECTOR3(0.0f, 0.0f, -100.0f),   // &#242;&#238;&#247;&#234;&#224;, &#232;&#231; &#234;&#238;&#242;&#238;&#240;&#238;&#233; &#241;&#236;&#238;&#242;&#240;&#232;&#236;
        &D3DXVECTOR3(0.0f, 0.0f, 0.0f),     // &#234;&#243;&#228;&#224; &#241;&#236;&#238;&#242;&#240;&#232;&#236;
        &D3DXVECTOR3(0.0f, 1.0f, 0.0f));   // &#237;&#224;&#239;&#240;&#224;&#226;&#235;&#229;&#237;&#232;&#229; &#226;&#229;&#240;&#245;&#224;
    // &#211;&#241;&#242;&#224;&#237;&#224;&#226;&#235;&#232;&#226;&#224;&#229;&#236; &#226;&#232;&#228;&#238;&#226;&#243;&#254; &#236;&#224;&#242;&#240;&#232;&#246;&#243;
    Device->SetTransform(D3DTS_VIEW, &MatrixView);
    // &#200;&#231;&#236;&#229;&#237;&#255;&#229;&#236; &#236;&#224;&#242;&#240;&#232;&#246;&#243; &#239;&#240;&#238;&#229;&#234;&#246;&#232;&#232;
    D3DXMatrixPerspectiveFovLH(&MatrixProjection, // &#239;&#238;&#235;&#243;&#247;&#229;&#237;&#237;&#224;&#255; &#232;&#242;&#238;&#227;&#238;&#226;&#224;&#255; &#236;&#224;&#242;&#240;&#232;&#246;&#224; &#239;&#240;&#238;&#229;&#234;&#246;&#232;&#232;
        D3DX_PI/4,                                                      // &#239;&#238;&#235;&#229; &#231;&#240;&#229;&#237;&#232;&#255; &#226; &#237;&#224;&#239;&#240;&#224;&#226;&#235;&#229;&#237;&#232;&#232; &#238;&#241;&#232; Y &#226; &#240;&#224;&#228;&#232;&#224;&#237;&#224;&#245;
        1.54f,                                                               // &#241;&#238;&#238;&#242;&#237;&#238;&#248;&#229;&#237;&#232;&#255; &#241;&#242;&#238;&#240;&#238;&#237; &#253;&#234;&#240;&#224;&#237;&#224; 770/500=1.54
        10.0f,                                                               // &#239;&#229;&#240;&#229;&#228;&#237;&#232;&#233; &#239;&#235;&#224;&#237; &#238;&#242;&#241;&#229;&#247;&#229;&#237;&#232;&#255; &#241;&#246;&#229;&#237;&#251;
        200.0f);                                                           // &#231;&#224;&#228;&#237;&#232;&#233; &#239;&#235;&#224;&#237; &#238;&#242;&#241;&#229;&#247;&#229;&#237;&#232;&#255; &#241;&#246;&#229;&#237;&#251;
    // &#211;&#241;&#242;&#224;&#237;&#224;&#226;&#235;&#232;&#226;&#224;&#229;&#236; &#236;&#224;&#242;&#240;&#232;&#246;&#243; &#239;&#240;&#238;&#229;&#234;&#246;&#232;&#232;
    Device->SetTransform(D3DTS_PROJECTION, &MatrixProjection);

}

Vertex cube[]=
{
    {200,100,0, D3DCOLOR_XRGB(0,0,0)},
    {100,200,0, D3DCOLOR_XRGB(0,0,0)},
    {300,300,0, D3DCOLOR_XRGB(0,0,0)}
};



#define D3D_FVF (D3DFVF_XYZ)


HRESULT InitD3D( HWND hWnd )
{
   
    if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
        return E_FAIL;

    D3DPRESENT_PARAMETERS d3dpp = {(0)};
    d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;

    if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
                                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                      &d3dpp, &Device ) ) )
    {
        return E_FAIL;
    }

    // ???? ?????????? ??????? - ?????????? S_OK

    return S_OK;
}




//-----------------------------------------------------------------------------
// ???: Cleanup()
// ????????: ??????????? ??? ????? ???????????????? ???????
//-----------------------------------------------------------------------------
VOID Cleanup()
{
    if( Device != NULL)
        Device->Release();

    if( g_pD3D != NULL)
        g_pD3D->Release();
}




//-----------------------------------------------------------------------------
// ???: Render()
// ????????: ????????? ?????
//-----------------------------------------------------------------------------
VOID Render()
{

    Device->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );

    Device->CreateVertexBuffer(sizeof(Vertex)*3,0,D3D_FVF,D3DPOOL_SYSTEMMEM,&buff,NULL);
   
    VOID * pv=NULL;

    buff->Lock(0,sizeof(cube),(void**)&pv,0);

    memcpy(pv,cube,sizeof(cube));

    buff->Unlock();

    Matrix();
   
    Device->BeginScene();
   
    Device->SetStreamSource(0,buff,0,sizeof(Vertex));

    Device->SetFVF(D3D_FVF);

    Device->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);

    Device->EndScene();
 
    Device->Present( NULL, NULL, NULL, NULL );
}




//-----------------------------------------------------------------------------
// ???: MsgProc()
// ????????: ????????? ?????????
//-----------------------------------------------------------------------------
LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
    switch( msg )
    {
        case WM_DESTROY:
            Cleanup();
            PostQuitMessage( 0 );
            return 0;

        case WM_QUIT:
            Cleanup();
            PostQuitMessage(0);
            return 0;
           
    }

    return DefWindowProc( hWnd, msg, wParam, lParam );
}




//-----------------------------------------------------------------------------
// ???: WinMain()
// ????????: ????? ????? ??????????
//-----------------------------------------------------------------------------
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
{
    // ???????????? ????? ????
    WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
                      GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
                      "Win main", NULL };
    RegisterClassEx( &wc );

    // ???????? ???? ?????????
    HWND hWnd = CreateWindow( "Win main", "DirectX 9.0 C",
                              WS_OVERLAPPEDWINDOW, 0, 0, 1024, 768,
                              GetDesktopWindow(), NULL, wc.hInstance, NULL );

    // ????????????? Direct3D
    if( SUCCEEDED( InitD3D( hWnd ) ) )
    {
        // ?????????? ????
        ShowWindow( hWnd, SW_SHOWDEFAULT );
        UpdateWindow( hWnd );

        // ???? ????? ?????????
        MSG msg;
        while( msg.message!=WM_QUIT )
        {
            if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
            {
            TranslateMessage( &msg );
            DispatchMessage( &msg );
            }
            else
            {
                Render();
            };

        }
    }

    UnregisterClass( "D3D Tutorial", wc.hInstance );
    return 0;
}

Help please!!!
Реклама на сайте | Обмен ссылками | Ссылки | Экспорт (RSS) | Контакты
Добавить статью | Добавить исходник | Добавить хостинг-провайдера | Добавить сайт в каталог