begin process at 2012 05 30 01:39:47
  Trouver un code source :
 
dans
 
Accueil > Forum > 

Archive C/C++

 > 

Archives

 > 

DirectX

 > 

Probleme d'affichage de plusieurs meshes !!!


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

Probleme d'affichage de plusieurs meshes !!!

mercredi 25 janvier 2006 à 22:19:35 | Probleme d'affichage de plusieurs meshes !!!

DarklordBioopo

bonjour,
J'ai un probleme que je n'arrive pas a resoudre. pourriez vous m'aider svp.

J'arrive a afficher une meshe, maisla seconde ne s'affiche pas.
Mon code est separé en 2 fichiers :
Main.cpp : initialisation de directx
Palet .cpp : classe de mon objet.

Main . cpp :

//-----------------------------------------------------------------------------

// File: Pong.cpp

// Desc: Initialisation de l'application

// Date: 25/01/2006

// Modf: 25/01/2006

//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------

//FICHIER A INCLURE

//-----------------------------------------------------------------------------

#include <Windows.h>

#include <mmsystem.h>

#include <d3dx9.h>

#include <strsafe.h>

#include "Palet.h"

//-----------------------------------------------------------------------------

//INITIALISATION DES VARIABLES GLOBALES

//-----------------------------------------------------------------------------

LPDIRECT3D9 g_pD3D = NULL; // Used to create the D3DDevice

LPDIRECT3DDEVICE9 g_pd3dDevice = NULL; // Our rendering device

CPalet Palet1; // Instance du palet

CPalet Palet2;

//-----------------------------------------------------------------------------

//INITIALISATION DIRECT 3D

//-----------------------------------------------------------------------------

HRESULT InitD3D( HWND hWnd )

{

// Create the D3D object.

if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )

return E_FAIL;

// Set up the structure used to create the D3DDevice. Since we are now

// using more complex geometry, we will create a device with a zbuffer.

D3DPRESENT_PARAMETERS d3dpp;

ZeroMemory( &d3dpp, sizeof(d3dpp) );

d3dpp.Windowed = TRUE;

d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;

d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;

d3dpp.EnableAutoDepthStencil = TRUE;

d3dpp.AutoDepthStencilFormat = D3DFMT_D16;

// Create the D3DDevice

if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,

D3DCREATE_SOFTWARE_VERTEXPROCESSING,

&d3dpp, &g_pd3dDevice ) ) )

{

return E_FAIL;

}

// Turn on the zbuffer

g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );

// Turn on ambient lighting

g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0xffffffff );

return S_OK;

}

//-----------------------------------------------------------------------------

// INITIALISATION DES OBJETS

//-----------------------------------------------------------------------------

HRESULT InitGeometry()

{

Palet1.InitGeometry(g_pd3dDevice);

Palet2.InitGeometry(g_pd3dDevice);

Palet1.InitPosition(g_pd3dDevice,D3DXVECTOR3(0.0f,0.0f,0.0f));

Palet2.InitPosition(g_pd3dDevice,D3DXVECTOR3(0.0f,0.0f,-2.0f));

return S_OK;

}

//-----------------------------------------------------------------------------

// NETTOYAGE DES OBJETS

//-----------------------------------------------------------------------------

VOID Cleanup()

{

Palet1.Cleanup();

Palet2.Cleanup();

}

//-----------------------------------------------------------------------------

// REGLAGE DE LA CAMERA

//-----------------------------------------------------------------------------

VOID SetupMatrices()

{

// Set up our view matrix. A view matrix can be defined given an eye point,

// a point to lookat, and a direction for which way is up. Here, we set the

// eye five units back along the z-axis and up three units, look at the

// origin, and define "up" to be in the y-direction.

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

// For the projection matrix, we set up a perspective transform (which

// transforms geometry from 3D view space to 2D viewport space, with

// a perspective divide making objects smaller in the distance). To build

// a perpsective transform, we need the field of view (1/4 pi is common),

// the aspect ratio, and the near and far clipping planes (which define at

// what distances geometry should be no longer be rendered).

D3DXMATRIXA16 matProj;

D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f );

g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );

}

//-----------------------------------------------------------------------------

// ANIMATION

//-----------------------------------------------------------------------------

VOID FrameMove()

{

// Setup the world, view, and projection matrices

//Palet1.FrameMove(g_pd3dDevice);

//Palet2.FrameMove(g_pd3dDevice);

SetupMatrices();

}

//-----------------------------------------------------------------------------

// AFFICHAGE DE LA SCENE

//-----------------------------------------------------------------------------

VOID Render()

{

// Clear the backbuffer and the zbuffer

g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,

D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );

// Begin the scene

if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )

{

// Meshes are divided into subsets, one for each material. Render them in

// a loop

Palet1.Render(g_pd3dDevice);

Palet2.Render(g_pd3dDevice);

// End the scene

g_pd3dDevice->EndScene();

}

// Present the backbuffer contents to the display

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

}

//-----------------------------------------------------------------------------

// Name: MsgProc()

// Desc: The window's message handler

//-----------------------------------------------------------------------------

LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )

{

switch( msg )

{

case WM_DESTROY:

Cleanup();

PostQuitMessage( 0 );

return 0;

}

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

}

//-----------------------------------------------------------------------------

// Name: WinMain()

// Desc: The application's entry point

//-----------------------------------------------------------------------------

INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )

{

// Register the window class

WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,

GetModuleHandle(NULL), NULL, NULL, NULL, NULL,

"PONG 3D", NULL };

RegisterClassEx( &wc );

// Create the application's window

HWND hWnd = CreateWindow( "PONG 3D", "PONG 3D",

WS_OVERLAPPEDWINDOW, 100, 10, 790, 590,

GetDesktopWindow(), 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( "PONG 3D", wc.hInstance );

return 0;

}

Palet . cpp :

//-----------------------------------------------------------------------------

// File: Palet.h

// Desc: Implementation de la classe CPalet

// Date: 25/01/2006

// Modf: 25/01/2006

//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------

//FICHIER A INCLURE

//-----------------------------------------------------------------------------

#include <Windows.h>

#include <mmsystem.h>

#include <d3dx9.h>

#include <strsafe.h>

#include "Palet.h"

//-----------------------------------------------------------------------------

//CONSTRUCTEUR / DESTRUCTEUR

//-----------------------------------------------------------------------------

CPalet::CPalet(void)

{

m_dwNumMaterials = 0L;

m_pMesh = NULL; // Our mesh object in sysmem

m_pMeshMaterials = NULL; // Materials for our mesh

m_pMeshTextures = NULL; // Textures for our mesh

m_dwNumMaterials = NULL; // Number of mesh materials

//m_pD3DXMtrlBuffer = NULL;

D3DXMatrixIdentity(&m_matPalet);

D3DXMatrixIdentity(&m_matTemp);

}

CPalet::~CPalet(void)

{

}

//-----------------------------------------------------------------------------

// INITIALISATION DES OBJETS - CHARGEMENT DES MESHES

//-----------------------------------------------------------------------------

HRESULT CPalet::InitGeometry(LPDIRECT3DDEVICE9 pd3dDevice)

{

m_pd3dDevice = pd3dDevice;

m_dwNumMaterials = 0L;

LPD3DXBUFFER m_pD3DXMtrlBuffer;

// Load the mesh from the specified file

if( FAILED( D3DXLoadMeshFromX( "palet.x", D3DXMESH_SYSTEMMEM,

m_pd3dDevice, NULL,

&m_pD3DXMtrlBuffer, NULL, &m_dwNumMaterials,

&m_pMesh ) ) )

{

MessageBox(NULL, "Could not find palet.x", "Meshes.exe", MB_OK);

return E_FAIL;

}

// We need to extract the material properties and texture names from the

// pD3DXMtrlBuffer

D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)m_pD3DXMtrlBuffer->GetBufferPointer();

m_pMeshMaterials = new D3DMATERIAL9[m_dwNumMaterials];

m_pMeshTextures = new LPDIRECT3DTEXTURE9[m_dwNumMaterials];

for( DWORD i=0; i<m_dwNumMaterials; i++ )

{

// Copy the material

m_pMeshMaterials[i] = d3dxMaterials[i].MatD3D;

// Set the ambient color for the material (D3DX does not do this)

m_pMeshMaterials[i].Ambient = m_pMeshMaterials[i].Diffuse;

m_pMeshTextures[i] = NULL;

if( d3dxMaterials[i].pTextureFilename != NULL &&

lstrlen(d3dxMaterials[i].pTextureFilename) > 0 )

{

// Create the texture

if( FAILED( D3DXCreateTextureFromFile( m_pd3dDevice,

d3dxMaterials[i].pTextureFilename,

&m_pMeshTextures[i] ) ) )

{

MessageBox(NULL, "Could not find texture map", "Meshes.exe", MB_OK);

}

}

}

// Done with the material buffer

m_pD3DXMtrlBuffer->Release();

return S_OK;

}

//-----------------------------------------------------------------------------

// AFFICHAGE DE LA SCENE - AFFICHAGE DES MESHES

//-----------------------------------------------------------------------------

void CPalet::Render(LPDIRECT3DDEVICE9 pd3dDevice)

{

m_pd3dDevice = pd3dDevice;

for( DWORD i=0; i<m_dwNumMaterials; i++ )

{

// Set the material and texture for this subset

m_pd3dDevice->SetMaterial( &m_pMeshMaterials[i] );

m_pd3dDevice->SetTexture( 0, m_pMeshTextures[i] );

m_pMesh->DrawSubset( i );

}

}

//-----------------------------------------------------------------------------

// NETTOYAGE DES OBJETS

//-----------------------------------------------------------------------------

void CPalet::Cleanup(void)

{

if( m_pMeshMaterials != NULL )

delete[] m_pMeshMaterials;

if( m_pMeshTextures )

{

for( DWORD i = 0; i < m_dwNumMaterials; i++ )

{

if( m_pMeshTextures[i] )

m_pMeshTextures[i]->Release();

}

delete[] m_pMeshTextures;

}

if( m_pMesh != NULL )

m_pMesh->Release();

}

//-----------------------------------------------------------------------------

// INITIALISATION DES OBJETS - POSITION DE DEPART

//-----------------------------------------------------------------------------

void CPalet::InitPosition(LPDIRECT3DDEVICE9 pd3dDevice,D3DXVECTOR3 position)

{

//Position de depart

m_pd3dDevice = pd3dDevice;

D3DXMatrixIdentity(&m_matPalet);

D3DXMatrixTranslation(&m_matPalet, position.x, position.y, position.z);

m_pd3dDevice->SetTransform(D3DTS_WORLD,&m_matPalet);

}

//-----------------------------------------------------------------------------

// ANIMATION DES OBJETS

//-----------------------------------------------------------------------------

void CPalet::FrameMove(LPDIRECT3DDEVICE9 pd3dDevice)

{

//D3DXMatrixIdentity(&m_matPalet);

//m_pd3dDevice->SetTransform(D3DTS_WORLD,&m_matPalet);

}

merci de votre aide

mercredi 25 janvier 2006 à 23:37:12 | Re : Probleme d'affichage de plusieurs meshes !!!

Galmiza

Essaie avec:
Palet2.InitPosition(g_pd3dDevice,D3DXVECTOR3(0.0f,0.0f,2.0f));

Si le problème est résolu, c'est que ton deuxième objet est clippé par le plan proche. Remplace la ligne correspondante par:
D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 0.1f, 100.0f );
jeudi 26 janvier 2006 à 18:08:57 | Re : Probleme d'affichage de plusieurs meshes !!!

DarklordBioopo

Merci mais cela ne fonctionne pas, en fait, il initialise le premier objet avec les parametres de position du second et ne créé pas le second meshes
.
jeudi 26 janvier 2006 à 18:09:27 | Re : Probleme d'affichage de plusieurs meshes !!!

DarklordBioopo

Merci mais cela ne fonctionne pas, en fait, il initialise le premier objet avec les parametres de position du second et ne créé pas le second meshes
.


Cette discussion est classée dans : void, hwnd, 0f, pd3ddevice, cpalet


Répondre à ce message

Sujets en rapport avec ce message

Faire des vertex (ou mesh) avec des animations différentes [ par Thecheeselover ] Bonjour, J'ai remarqué que dans un tutoriel, on ne pouvait que faire des animations que sur un même groupe de verticles (mesh). Or, j'aimerais pouvoi LRESULT CALLBACK dans une class [ par TeniX ] Salut, Je crée une class PRINCIPAL qui memorise la class WNDCLASSEX class PRINCIPAL { public: HINSTANCE hinstance; HWND hwndp pikcing opengl [ par znb ] J 'ai fait un code et ça marche très bien; il détecte les couleurs des objets. Mais je veux que, pour une valeur particulière de la couleur, dessiner D3DXMatrixTranslation [ par niketou ] Salut a tous.Voila je fais un moteur 3d en dx9.Voici un bout de code,en fait je devrai voir un objet 3d mais je ne vois rien.L'objet et sa texture se directx texture [ par niketou ] Salut a tous.Voila j'ai mon triangle texturé mais je voudrai que la texture ce repete plusieur fois au lieu d'un simple plaquage.Si quelqu'un sait com wxGLCanvas --> dessiner un point !!!!!! [ par satellite34 ] salut,ca va peut etre paraitre ridicule mais ca fait maintenant 3 longues heures que j'essaie de dessiner un point aux coordonnées (x, y) avec openGL, DirectX 9: Probleme pour effectuer deux transformations en même temps (rotation et ranslation) [ par Overwrite ] Je veux effectuer une translation et une rotation en même temps sur un triangle tt bete mais ca fonctionne pas. DirectX n'execute que la rotation : / aide moi acompiler ce graph stp [ par temoin ] Bonjour mon erreur est ceci je tout suivi a la lettre je mais les link et je installer le sdk de microsoft qui fait le 200 meg et auusi je mais les li PB POUR LA GESTION MULTIFENETRES [ par algeros ] Voici un code ://////////////////////////////////////////////////////////////////                                                          //   Name: probleme fenêtre sous windows [ par vixare ] Bonjour  à tous je debute en C++ sous windows et je voulais créer une fenêtre(fond bleu ) découpé en 9 rectangles à la  bordure jaune.La fenêtre s'aff


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,593 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales