Ca tourne pas :S

Résolu
JoebarGlut Messages postés 111 Date d'inscription mercredi 13 août 2003 Statut Membre Dernière intervention 17 octobre 2007 - 16 déc. 2004 à 07:28
zoom1984 Messages postés 17 Date d'inscription mercredi 13 octobre 2004 Statut Membre Dernière intervention 26 février 2005 - 22 févr. 2005 à 05:24
Salut,
Je suis passé d'OpenGL à DirectX9 depuis peu et j'ai donc commencé par me faire tous les tutos fournis avec le SDK.
Hélas je ne suis pas arrivé tres loin, j'en suis aux matrices sous DirectGraphics.
Je precise que je suis parti tu tuto 1 que j'ai modifié en m'aidant des tutos 2 et 3 et j'ai apportés mes petites modifs du style faire un carré au lieu d'un triangle, affichage en fullscreen ect...
J'ai donc mon carré qui s'affiche normalement et je souhaite lui faire une rotation.
Je rajoute donc ce code avant de dessiner entre beginscene et endscene :

D3DXMATRIXA16 matWorld;
UINT iTime = timeGetTime() % 1000;
FLOAT fAngle = iTime * (2.0f * D3DX_PI) / 1000.0f;
D3DXMatrixRotationY( &matWorld, fAngle );
g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );

Mais rien ne se passe : mon carré est affiché mais ne tourne pas, quelqu'un aurais-il une idée ? :)

2 réponses

zoom1984 Messages postés 17 Date d'inscription mercredi 13 octobre 2004 Statut Membre Dernière intervention 26 février 2005
22 févr. 2005 à 05:24
D3DFVF_XYZRHW indique des vertices déjà transormées/projettées.



Donc, non, ça ne risque pas de tourner.



Utilise plutôt
D3DFVF_XYZ.
3
JoebarGlut Messages postés 111 Date d'inscription mercredi 13 août 2003 Statut Membre Dernière intervention 17 octobre 2007
16 déc. 2004 à 11:21
Op je me permet de mettre le code entier car je trouve pas mon erreur et comme l'exemple du tuto3 fonctionne et pas ma modif du tuto1 c'est qu'il y a un truc que j'ai pas compris et ça m'embete de passer l'étape suivante sur un echec :S

#include <Windows.h>
#include <mmsystem.h>
#include <d3dx9.h>
LPDIRECT3D9 g_pD3D NULL; LPDIRECT3DDEVICE9 g_pd3dDevice NULL;
//LPDIRECT3DSURFACE9 lpBackBuffer_Surface=NULL;
LPDIRECT3DVERTEXBUFFER9 g_pVB = NULL;

struct CUSTOMVERTEX
{
FLOAT x, y, z, rhw;
DWORD color;
};

#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE)

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

D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = FALSE;
d3dpp.BackBufferWidth = 1024 ;
d3dpp.BackBufferHeight = 768 ;
d3dpp.BackBufferCount = 1;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
D3DFORMAT formatDePixel = D3DFMT_A8R8G8B8;
d3dpp.BackBufferFormat = formatDePixel;

//d3dpp.hDeviceWindow = hWnd ;
d3dpp.FullScreen_RefreshRateInHz = 60 ;
//d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE ;

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

ShowCursor(FALSE);
g_pd3dDevice->ShowCursor(FALSE);

/* g_pd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, true);
g_pd3dDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_NOTEQUAL);
g_pd3dDevice->SetRenderState(D3DRS_ALPHAREF, 0x00);
g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
g_pd3dDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
g_pd3dDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);
g_pd3dDevice->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_MODULATE);
g_pd3dDevice->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
g_pd3dDevice->SetTextureStageState(0,D3DTSS_ALPHAARG2,D3DTA_DIFFUSE);*/

//g_pd3dDevice->SetTextureStageState(0,D3DTSS_MAGFILTER,D3DTEXF_LINEAR);
// g_pd3dDevice->SetTextureStageState(0,D3DTSS_MINFILTER,D3DTEXF_LINEAR);
//désactivation de la lumière (sinon les sprites seront noirs)
g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE);

//on obtient un pointeur sur la surface du BackBuffer
// g_pd3dDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO,&lpBackBuffer_Surface);

return S_OK;
}

HRESULT InitVB()
{
CUSTOMVERTEX vertices[] =
{
{ 500.0f, 500.0f, 0.5f, 1.0f, 0xffff0000, },
{ 600.0f, 500.0f, 0.5f, 1.0f, 0xffff00ff, },
{ 500.0f, 600.0f, 0.5f, 1.0f, 0xff00ffff, },
{ 600.0f, 600.0f, 0.5f, 1.0f, 0xff00ff00, },
// x, y, z, rhw, color
};

if( FAILED( g_pd3dDevice->CreateVertexBuffer( 4*sizeof(CUSTOMVERTEX),
0, D3DFVF_CUSTOMVERTEX,
D3DPOOL_DEFAULT, &g_pVB, NULL ) ) )
{
return E_FAIL;
}

VOID* pVertices;
if( FAILED( g_pVB->Lock( 0, sizeof(vertices), (void**)&pVertices, 0 ) ) )
return E_FAIL;
memcpy( pVertices, vertices, sizeof(vertices) );
g_pVB->Unlock();

return S_OK;
}

VOID SetupMatrices()
{
D3DXMATRIXA16 matWorld;
UINT iTime = timeGetTime() % 1000;
FLOAT fAngle = iTime * (2.0f * D3DX_PI) / 1000.0f;
D3DXMatrixRotationY( &matWorld, fAngle );
g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );

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 );

D3DXMATRIXA16 matProj;
D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f );
g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
}

VOID Cleanup()
{
if( g_pd3dDevice != NULL)
g_pd3dDevice->Release();

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

VOID Render()
{
if( NULL == g_pd3dDevice )
return;

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

if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
{
SetupMatrices();

g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) );
g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP , 0, 2 );

g_pd3dDevice->EndScene();
}

g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}

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

case WM_PAINT:
Render();
ValidateRect( hWnd, NULL );
return 0;
}

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

INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
{
WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
"D3D Tutorial", NULL };
RegisterClassEx( &wc );

HWND hWnd = CreateWindow( "D3D Tutorial", "D3D Tutorial 01: CreateDevice",
WS_EX_TOPMOST , 100, 100, 1024, 768,
GetDesktopWindow(), NULL, wc.hInstance, NULL );

if( SUCCEEDED( InitD3D( hWnd ) ) )
{
if( SUCCEEDED( InitVB() ) )
{
ShowWindow( hWnd, SW_SHOWDEFAULT );
UpdateWindow( hWnd );

MSG msg;
ZeroMemory( &msg, sizeof(msg) );

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

}
}

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

merci ;)
0
Rejoignez-nous