• Advertisement
Sign in to follow this  

Direct3D grid of spheres

This topic is 2684 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'm trying to figure out how to make a 10x10 grid of spheres with Direct3D. I have a structure called Points that includes the position and etc. of the spheres. This structure is shown below. The main problem i'm having is how to do the loops to draw the actual grid.


//Point structure to define the sphere grid
struct Points
{
ID3DXMesh* Point;
D3DXMATRIX PM;
float x;
float y;

};



then in my Setup function i go ahead and create all the spheres like so:


//create the spheres
for (i = 0; i < 100; i++)
{
D3DXCreateSphere(Device, 0.5, 20, 32, &P.Point, 0);

}



i'm not sure how to do the actual code in my main game loop to draw the grid. If someone could help, i would appreciate it.

Share this post


Link to post
Share on other sites
Advertisement
First, depending on your needs, you only need 1 mesh. Just draw it repeatedly at the various locations.

Anyway, something like:

for(int i=0; i<numPoints; i++)
{
device->SetTransform(D3DTS_WORLD,&P.PM);
sphereMesh->DrawSubset(0); // either use a single spheremesh or P.Point
}

Share this post


Link to post
Share on other sites
ok since your doing a set transform in the drawing loop, i'm assuming i need another for loop in my setup function that will translate each sphere in order to make the grid. Could i get a hand on how to do this. I'm just not sure how to do the translation to make them all in a 10x10 grid, I'm assuming it would be something like below... only i'm not sure how i would do the position to make it print right. Also would it need to be in a double for loop or something?

Also I'll fix the mesh so it is just one, just want to get it drawing first.


//set initial positions of spheres
for (i = 0; i < SIZE2; i++)
{
//change position

D3DXMatrixTranslation(&P.PM, P.x, P.y, 0.0f);

}



Share this post


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

  • Advertisement