Public Group

# Direct3D grid of spheres

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

## 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 gridstruct 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 spheresfor (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 on other sites
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 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 spheresfor (i = 0; i < SIZE2; i++){        //change position	D3DXMatrixTranslation(&P.PM, P.x, P.y, 0.0f);		}

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5

• 11
• 37
• 12
• 12
• 11
• ### Forum Statistics

• Total Topics
631413
• Total Posts
2999945
×