Jump to content
  • Advertisement
Sign in to follow this  
simotix

D3DXCreateMesh

This topic is 3760 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

I am trying to create a box D3DXCreateMesh out of verticies but I am not sure on some of the parameters. Could anyone tell me how to do this or show me where I can find this out?

Share this post


Link to post
Share on other sites
Advertisement
Hi, this is the vertex and index buffers for a cube from this you can set the rest up

buildVertexBuffer(void)
{
// Obtain a pointer to a new vertex buffer.
hr = (gd3dDevice->CreateVertexBuffer(8 * sizeof(VertexPos), D3DUSAGE_WRITEONLY,
0, D3DPOOL_MANAGED, &mVB, 0));
if(FAILED(hr))
do error


// Now lock it to obtain a pointer to its internal data, and write the
// cube's vertex data.

VertexPos* v = 0;
hr = (mVB->Lock(0, 0, (void**)&v, 0));
if(FAILED(hr))
do error


v[0] = VertexPos(-1.0f, -1.0f, -1.0f);
v[1] = VertexPos(-1.0f, 1.0f, -1.0f);
v[2] = VertexPos( 1.0f, 1.0f, -1.0f);
v[3] = VertexPos( 1.0f, -1.0f, -1.0f);
v[4] = VertexPos(-1.0f, -1.0f, 1.0f);
v[5] = VertexPos(-1.0f, 1.0f, 1.0f);
v[6] = VertexPos( 1.0f, 1.0f, 1.0f);
v[7] = VertexPos( 1.0f, -1.0f, 1.0f);

hr = (mVB->Unlock());
if(FAILED(hr))
do error
}

void buildIndexBuffer(void)
{
// Obtain a pointer to a new index buffer.
HRESULT hr = (gd3dDevice->CreateIndexBuffer(36 * sizeof(WORD), D3DUSAGE_WRITEONLY,
D3DFMT_INDEX16, D3DPOOL_MANAGED, &mIB, 0));

// Now lock it to obtain a pointer to its internal data, and write the
// cube's index data.

WORD* k = 0;

HR(mIB->Lock(0, 0, (void**)&k, 0));

// Front face.
k[0] = 0; k[1] = 1; k[2] = 2;
k[3] = 0; k[4] = 2; k[5] = 3;

// Back face.
k[6] = 4; k[7] = 6; k[8] = 5;
k[9] = 4; k[10] = 7; k[11] = 6;

// Left face.
k[12] = 4; k[13] = 5; k[14] = 1;
k[15] = 4; k[16] = 1; k[17] = 0;

// Right face.
k[18] = 3; k[19] = 2; k[20] = 6;
k[21] = 3; k[22] = 6; k[23] = 7;

// Top face.
k[24] = 1; k[25] = 5; k[26] = 6;
k[27] = 1; k[28] = 6; k[29] = 2;

// Bottom face.
k[30] = 4; k[31] = 0; k[32] = 3;
k[33] = 4; k[34] = 3; k[35] = 7;

hr = (mIB->Unlock());
if(FAILED(hr))
do error stuff


}


Share this post


Link to post
Share on other sites
The reason I do not want to use D3DXCreateMesh is because I want to be able to select the individual walls of the box. Although I do not know how to do that for creating the box either (I was going to use D3DXIntersect).

[Edited by - simotix on March 5, 2008 8:32:34 AM]

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!