Directx9 meshes

Résolu
niketou Messages postés 295 Date d'inscription dimanche 4 mai 2003 Statut Membre Dernière intervention 6 décembre 2010 - 5 juin 2005 à 16:03
mezaya Messages postés 202 Date d'inscription dimanche 18 mai 2003 Statut Membre Dernière intervention 6 mars 2010 - 5 juin 2005 à 17:50
Salut a tous.
Voila le tuto du sdk :
cela affiche un tigre avec texture,mais comment faire pour choisir la position dans un espace 3d?
Merci.

HRESULT InitGeometry()
{
LPD3DXBUFFER pD3DXMtrlBuffer;


// Load the mesh from the specified file
if( FAILED( D3DXLoadMeshFromX( "Tiger.x", D3DXMESH_SYSTEMMEM,
g_pd3dDevice, NULL,
&pD3DXMtrlBuffer, NULL, &g_dwNumMaterials,
&g_pMesh ) ) )
{
// If model is not in current folder, try parent folder
if( FAILED( D3DXLoadMeshFromX( "..\\Tiger.x", D3DXMESH_SYSTEMMEM,
g_pd3dDevice, NULL,
&pD3DXMtrlBuffer, NULL, &g_dwNumMaterials,
&g_pMesh ) ) )
{
MessageBox(NULL, "Could not find tiger.x", "Meshes.exe", MB_OK);
return E_FAIL;
}
}


// We need to extract the material properties and texture names from the
// pD3DXMtrlBuffer
D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();
g_pMeshMaterials = new D3DMATERIAL9[g_dwNumMaterials];
g_pMeshTextures = new LPDIRECT3DTEXTURE9[g_dwNumMaterials];


for( DWORD i=0; i<g_dwNumMaterials; i++ )
{
// Copy the material
g_pMeshMaterials[i] = d3dxMaterials[i].MatD3D;


// Set the ambient color for the material (D3DX does not do this)
g_pMeshMaterials[i].Ambient = g_pMeshMaterials[i].Diffuse;


g_pMeshTextures[i] = NULL;
if( d3dxMaterials[i].pTextureFilename != NULL &&
lstrlen(d3dxMaterials[i].pTextureFilename) > 0 )
{
// Create the texture
if( FAILED( D3DXCreateTextureFromFile( g_pd3dDevice,
d3dxMaterials[i].pTextureFilename,
&g_pMeshTextures[i] ) ) )
{
// If texture is not in current folder, try parent folder
const TCHAR* strPrefix = TEXT("..\");
const int lenPrefix = lstrlen( strPrefix );
TCHAR strTexture[MAX_PATH];
lstrcpyn( strTexture, strPrefix, MAX_PATH );
lstrcpyn( strTexture + lenPrefix, d3dxMaterials[i].pTextureFilename, MAX_PATH - lenPrefix );
// If texture is not in current folder, try parent folder
if( FAILED( D3DXCreateTextureFromFile( g_pd3dDevice,
strTexture,
&g_pMeshTextures[i] ) ) )
{
MessageBox(NULL, "Could not find texture map", "Meshes.exe", MB_OK);
}
}
}
}


// Done with the material buffer
pD3DXMtrlBuffer->Release();


return S_OK;
}

3 réponses

mezaya Messages postés 202 Date d'inscription dimanche 18 mai 2003 Statut Membre Dernière intervention 6 mars 2010
5 juin 2005 à 17:50
j'ai pas de code mais par exemple si tu veut mettre donc tigre sur la
position (0,0,10) donc 10 en Z. tu initialise la camera comme
d'habitude et tu ajoute une translation de 10 en Z :



D3DXMATRIX matProj,matView,matWorld;



// initialise projection

D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/3.0f, 640.f/480.f, 0.1f, 100.0f );

pDevice->SetTransform( D3DTS_PROJECTION, &matProj );



// initialise camera

D3DXVECTOR3 Veye(0.f,0.f,-3.0f), Vat(0.0f,0.0f,0.0f), Vup(0.0f,1.0f,0.0f);

D3DXMatrixLookAtLH( &matView, &Veye, &Vat, &Vup );

pDevice->SetTransform( D3DTS_VIEW, &matView );



// initialise position objet

<NAME>D3DXMatrixTranslation</NAME>( &matWorld , 0 , 0 , 10 );

pDevice -> SetTransform( D3DTS_WORLD , &matWorld );

<link href="../../../../../css/ie4.css" type="text/css" rel="stylesheet"><!-- @ --><link href="../../../../../css/inetsdk.css" type="text/css" rel="stylesheet"><!-- @ --><style type="text/css">
PRE.clsCode { font-size:110%; }
PRE.clsSyntax { font-size:100%; }
TD DIV.clsBeta { display:none;}

A:link { color:#0000ff; text-decoration:underline;}
A:visited { color:#0000ff; text-decoration:underline;}
A:hover { color:#3366ff; text-decoration:underline;}
MSHelp\:link {
color:#0000ff;
text-decoration:underline;
cursor:hand;
hoverColor:#3366ff;
filterString: ;}
</style><link href="ms-help://Hx/HxRuntime/HxLink.css" type="text/css" rel="stylesheet"><XML id="_topicdata" pagetype="function" proj="dx9cpp" name="D3DXMatrixTranslation" pubpath="/directx/graphics/reference/d3dx/functions/math/d3dxmatrixtranslation.htm"><!-- topic data --><root></root></XML><xml xmlns:mshelp="http://msdn.microsoft.com/mshelp"></xml>

Voili,Voilou
3
mezaya Messages postés 202 Date d'inscription dimanche 18 mai 2003 Statut Membre Dernière intervention 6 mars 2010
5 juin 2005 à 16:54
la position se gere avec la matrice de transformation : il suffit
d'appliquer des translation rotation... pour faire bouger l'objet car
ton tigre est surement centrée en (0,0,0)



D3DXMATRIX Matrice;

pDevice -> SetTransform( D3DTS_WORLD , &Matrice );

Voili,Voilou
0
niketou Messages postés 295 Date d'inscription dimanche 4 mai 2003 Statut Membre Dernière intervention 6 décembre 2010
5 juin 2005 à 17:26
Excuse tu ne peux pas me file le code stp,j'y arrive pas :(
0
Rejoignez-nous