Skip to main content
GameDev.net gamedev.net
🔒 Locked

Draw Multiple Objects

Started by Ritti Sep 5, 2011 at 3:50 AM 1 replies 1.5k views
Original Post
Ritti
Ritti
Hi, 'm new to DirectX and following the DirectX SDK Tutorials.

For now I am able to draw cubes, pyramids and other shapes. I can turn a cube around an axis and let another cube bounce around.

But how can i draw two indipendent shapes and move them differently (i.e. a cube and a pyramid)?

I assume I need two Vertex Buffers and two Index Buffers but I wasn't able to write an executable code.

I've attached the Tutorials code, maybe somebody can point me to the right direction, because I wasn't able to find anything useful in the net.

Thanks, Ritti

[attachment=5261:Tutorial05.txt]





doug25
doug25
You could make a structure that defines a mesh such as


struct Mesh
{
ID3DXMesh* mesh;
std::vector<D3DMATERIAL9> Mtrls;
std::vector<IDirect3DTexture9*> Textures;
D3DXMATRIX mTranslation;
D3DXMATRIX mRotation;

void Release(); // make this function release the ID3DXMesh when done
};


This then contains the transformation matrices of the mesh,
the materials and associated textures.

To make a model you could then call
D3DXCreateMeshFVF where you specify the number of vertices and faces.

then to set the vertices

you'd do something like this

Mesh myfirstmodel;
Mesh mysecondmodel;

create a function that sets up the vertices of the model and faces


const D3DXCOLOR GREY(D3DCOLOR_XRGB(127,127,127)); // create a color for the vertices

void createTriangle(Mesh* resultMesh)
{
D3DXCreateMeshFVF(1, 3, D3DXMESH_DYNAMIC, D3DFVF_XYZ | D3DFVF_DIFFUSE, Device, &resultMesh->mesh);

VERTEX* vertices;
resultMesh->mesh->LockVertexBuffer(0, (void**)&vertices);

vertices[0] = VERTEX(0,0,0,GREY);
vertices[1] = VERTEX(1,0,0,GREY);
vertices[2] = VERTEX(1,1,0,GREY);

resultMesh->UnlockVertexBuffer();

// specify the vertices that make a face
WORD* indices = 0;
resultMesh->mesh->LockIndexBuffer(0, (void**)&indices);

indices[0] = 0;
indices[1] = 1;
indices[2] = 2;

resultMesh->UnlockIndexBuffer();
}



does this make enough sense for you ?
Doug
Ritti
Ritti
Hi, thank you for your reply.

I didn't think about using meshes since meshes are explained in the next chapters

I'll do it as you explained since it sounds more familiar than all other guides I've found on the net ^^

Thanks, best regards, Ritti

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.