Jump to content
  • Advertisement
Sign in to follow this  
ayros

can 't see and transform my vertex

This topic is 4656 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi I m a begginner in directX dev. I try to move a triangle but I have 2 bug : I can't see my vertex without use the D3DFVF_XYZRHW flag in my vertex structure. D3DFVF_XYZ don't work. When i use D3DFVF_XYZRHW flag, I can see the object but I can't move them :,( I try different way but I'm lost now :) someone got an idea ? Here is my code : //vertex strutre *************************************************************** #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ | D3DFVF_DIFFUSE) //x, y, z and color struct D3DVERTEX { float fX, fY, fZ; DWORD dwColor; }; ********************************************************************* //*********************************************************************** void DirectX::InitScene(){ void * buffer; //buffer de copy //initialise la lumiére d3dDevice->SetRenderState(D3DRS_AMBIENT,RGB(255,255,255)); //maximum ambient light d3dDevice->SetRenderState(D3DRS_LIGHTING,false); //lighting disabled d3dDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE); //don't cull backside d3dDevice->SetRenderState(D3DRS_ZENABLE,D3DZB_TRUE); //enable depth buffering //Définit le type de vertex utilisé d3dDevice->SetFVF(D3DFVF_CUSTOMVERTEX); //indique le type de vertex //cré un triangle en vertex D3DVERTEX triangle[] = { { 150.0f, 50.0f, 12.0f, 0xffff0000, }, // x, y, z, rhw, color { 250.0f, 250.0f, 12.0f, 0xff00ff00, }, { 50.0f, 250.0f, 12.0f, 0xff00ffff, }/*, { 150.0f, 50.0f, 1.0f, 0xffff0000, }, // x, y, z, rhw, color { 250.0f, 50.0f, 1.0f, 0xff00ff00, }, { 250.0f, 50.0f, 250.0f, 0xff00ffff, }, { 150.0f, 50.0f, 1.0f, 0xffff0000, }, // x, y, z, rhw, color { 50.0f, 250.0f, 1.0f, 0xff00ffff, }, { 50.0f, 250.0f, 250.0f, 0xff00ffff, } */ }; D3DVERTEX carre[] = { { 250.0f, 50.0f, 12.0f, 0xffff0000, }, // x, y, z, rhw, color { 350.0f, 50.0f, 12.0f, 0xff00ff00, }, { 250.0f, 150.0f, 12.0f, 0xff00ffff, }, { 350.0f, 150.0f, 12.0f, 0xff00ffff, } }; // cré le vertexBuffer d3dDevice->CreateVertexBuffer(sizeof(triangle),D3DUSAGE_WRITEONLY,D3DFVF_CUSTOMVERTEX,D3DPOOL_DEFAULT,&vertexBuffer1,NULL); //rempli le vertexBuffer vertexBuffer1->Lock(0,sizeof(triangle),(void **) &buffer,D3DLOCK_DISCARD); //lock buffer memcpy( buffer, triangle, sizeof(triangle) ); vertexBuffer1->Unlock(); //unlock buffer buffer=NULL; // cré le vertexBuffer d3dDevice->CreateVertexBuffer(sizeof(carre),D3DUSAGE_WRITEONLY,D3DFVF_CUSTOMVERTEX,D3DPOOL_DEFAULT,&vertexBuffer2,NULL); //rempli le vertexBuffer vertexBuffer2->Lock(0,sizeof(carre),(void **) &buffer,D3DLOCK_DISCARD); //lock buffer memcpy( buffer, carre, sizeof(carre) ); vertexBuffer2->Unlock(); //unlock buffer // matrice identité pour la world transformation D3DXMatrixIdentity(&world); // on s'éloigne un peu du centre D3DXMatrixTranslation(&view, 0.0f, 0.0f, 10.0f); // matrice de projection D3DXMatrixPerspectiveFovLH(&projection, D3DX_PI/4, 1024/768, 1.0f, 100.0f); // application des matrices d3dDevice->SetTransform(D3DTS_WORLD, &world); d3dDevice->SetTransform(D3DTS_VIEW, &view); d3dDevice->SetTransform(D3DTS_PROJECTION, &projection); } //************************************************************************ //render********************************************************************* void DirectX::render(){ static float compteur = 0; D3DXMATRIX temp; // on mesure combien de temps s'est écoulé depuis la // derniere frame puis on la multiple par une valeur arbitraire // qui représente la vitesse de déplacement. derniereFrame = (float) (GetTickCount() - courant) / 1000.0f; courant = GetTickCount(); compteur += derniereFrame * 50.0f; D3DXMatrixRotationY(&world, D3DXToRadian(compteur)); D3DXMatrixRotationX(&temp, D3DXToRadian(compteur)); world*=temp; // application de la matrice d3dDevice->SetTransform(D3DTS_WORLD, &world); if(check3DCard()) { d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0,0), 1.0f, 0); d3dDevice->BeginScene(); //debut du rendu d3dDevice->SetStreamSource(0,vertexBuffer1,0,sizeof(D3DVERTEX)); d3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST , 0, 1); //dessine les points d3dDevice->SetStreamSource(0,vertexBuffer2,0,sizeof(D3DVERTEX)); d3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2); d3dDevice->EndScene(); //fin du rendu d3dDevice->Present(NULL,NULL,NULL,NULL); //affiche la scène }

Share this post


Link to post
Share on other sites
Advertisement
Without fully checking.

You can't set a transformation matrix as a view matrix. You can set that as a world matrix.
d3dDevice->SetTransform(D3DTS_VIEW, &view); expects a view matrix. Check D3DXMatrixLookAtLH.

Also don't forget sizes and directions. You might not see your triangle becasue the camera is not looking at it or it is huge.

Please edit first post so it will display code properly, read posting FAQ for this.

Cheers

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!