|
Matrices , Vertices.
- SetupMatrices
VOID
SetupMatrices()
{
// 3d- - world matrix,
Y.
D3DXMATRIXA16 matWorld;
//
2*-
// 1000 ms ().
// ,
//
UINT iTime = timeGetTime() % 1000;
FLOAT fAngle = iTime * ( 2.0f * D3DX_PI ) / 1000.0f;
D3DXMatrixRotationY( &matWorld, fAngle );
g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
// view matrix - .
// vEyePt, vLookatPt
//
vUpVec.
//
D3DXVECTOR3 vEyePt( 0.0f, 3.0f,-5.0f );
D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f );
D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );
D3DXMATRIXA16 matView;
//
D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec
);
g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );
// - projection matrix -
// 3D 2D
Viewport,
// ( ).
// , field
of view
//
1/4 pi ,
// - aspect ratio, near
far // ( ,
// ).
D3DXMATRIXA16 matProj;
D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI / 4, 1.0f, 1.0f, 100.0f
);
g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
} |
|
|
Render -
-
//
Begin the scene
if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
{
// ,
BeginScene..EndScene
//
, FrameMove,
// SetupMatrices , .
//
FrameMove wWinMain
SetupMatrices();
// 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();
} |
|
|
-
//FrameMove()
VOID
FrameMove()
{
// Setup the world, view, and projection matrices
SetupMatrices();
}
//Render()
VOID
Render()
{
// Clear the backbuffer to a black color
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB( 0, 0,
0 ), 1.0f, 0 );
// Begin the scene
if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
{
// Setup the world, view, and projection matrices
//SetupMatrices();
//
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();
}
// Present the backbuffer contents to the display
g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
//wWinMain
INT
WINAPI wWinMain( HINSTANCE hInst, HINSTANCE, LPWSTR, INT )
{
// Register the window class
WNDCLASSEX wc =
{
sizeof( WNDCLASSEX ), CS_CLASSDC, MsgProc, 0L, 0L,
GetModuleHandle( NULL ), NULL, NULL, NULL, NULL,
L"D3D Tutorial", NULL
};
RegisterClassEx( &wc );
// Create the application's window
HWND hWnd = CreateWindow( L"D3D Tutorial", L"D3D Tutorial
03: Matrices",
WS_OVERLAPPEDWINDOW, 100, 100, 256, 256,
NULL, NULL, wc.hInstance, NULL );
// Initialize Direct3D
if( SUCCEEDED( InitD3D( hWnd ) ) )
{
// Create the scene geometry
if( SUCCEEDED( InitGeometry() ) )
{
// Show the window
ShowWindow( hWnd, SW_SHOWDEFAULT );
UpdateWindow( hWnd );
// Enter the message loop
MSG msg;
ZeroMemory( &msg, sizeof( msg ) );
while( msg.message != WM_QUIT )
{
if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else {
FrameMove();
Render();
}
}
}
}
UnregisterClass( L"D3D Tutorial", wc.hInstance );
return 0;
} |
|