niketou
Messages postés295Date d'inscriptiondimanche 4 mai 2003StatutMembreDernière intervention 6 décembre 2010
-
5 juin 2005 à 16:03
mezaya
Messages postés202Date d'inscriptiondimanche 18 mai 2003StatutMembreDerniè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.
// 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();
mezaya
Messages postés202Date d'inscriptiondimanche 18 mai 2003StatutMembreDerniè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 :
mezaya
Messages postés202Date d'inscriptiondimanche 18 mai 2003StatutMembreDerniè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)