Advertisement

Please Help.......

Started by January 09, 2001 10:57 PM
1 comment, last by atreyu 24 years ago
I just started learning D3D and I need a little help getting my head on straight. This DIRECT3DVERTEXBUFFER8 is giving me troubles. I have two choices: 1) Create one vertex buffer that will store all objects. 2) Create a separate vertex buffer for each object. -I know how to do choice 1, though I don''t want to because It looks really messy and i''d have to store the indices for the beginning and end of each object. -The second choice goes a hell of a lot better with OOP, and seems like it would be much cleaner to implement As you might guess, I don''t know how to implement the second choice. I can''t find a way to select different vertex buffers to apply transformations to. The Direct3D Device applies the transformations and does the rendering for one big vertex buffer without any problems. How in the world do you handle multiple vertex buffers with it though? Here''s an example-->
  
//Create first vbuffer

D3DDevice->CreateVertexBuffer(NumVertices* sizeof(CUSTOMVERTEX), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &VertexBuffer);

//Create second vbuffer

D3DDevice->CreateVertexBuffer(NumVertices* sizeof(CUSTOMVERTEX), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &ExtraVertexBuffer);

...


// **** The following transforms "VertexBuffer" ****

//Setup matrices for transform

D3DXMatrixRotationX(&matX, rx);
D3DXMatrixRotationY(&matY, ry);
D3DXMatrixRotationZ(&matZ, rz);

rx=ry=rz=0;

//Transform the entire vbuffer (I think i''m doing this right)

D3DDevice->MultiplyTransform(D3DTS_WORLD, &matY);
D3DDevice->MultiplyTransform(D3DTS_WORLD, &matX);
D3DDevice->MultiplyTransform(D3DTS_WORLD, &matZ);

// **** Now I need to transform "ExtraVertexBuffer" ****

//I have no clue how to select it with the D3DDevice though

//Please Help:)

  
Any ideas on how to accomplish this would help a lot. If I''m going about this incorrectly please fire away. P.S.(How would stuff like this be done by professionals?...am I even close ) Thanks, --atreyu
It is a case of setting the stream source. Every time you want to apply a different transformation to a different buffer you have to set the stream source appropriatly....

D3DDevice->SetStreamSource(0, VertexBuffer1, sizeof(CUSTOMVERTEX));
D3DDevice->SetTransformation(D3DTS_WORLD, &matWorld);
//Drawprimitives in this vertex buffer

D3DDevice->SetStreamSource(0, VertexBuffer2, sizeof(CUSTOMVERTEX));
D3DDevice->SetTransformation(D3DTS_WORLD, &matWorld);
//Drawprimitives in this vertex buffer

And do this until all the vertex buffers you need drawn are rendered.

-Omalacon
Advertisement
Thanks Omalacon That got me a lot closer. It works for the rendering stage (ie DrawPrimitive etc). The transformation stage is still being wierd. It rotates both vbuffers no matter what I try with "D3DDevice->SetStreamSource(0, VertexBuffer, sizeof(CUSTOMVERTEX));" I''ll keep messing with it.

By the way, Can anyone tell me what the first parameter in that function does? The DX8 Documentation says it''s the "StreamNumber" and that it "Specifies the data stream, in the range from 0 to the maximum number of streams - 1.". This makes no sense to me and whenever I change the number I get crazy results on the screen.

This topic is closed to new replies.

Advertisement