Sign in to follow this  
Garra

Direct3D grid of spheres

Recommended Posts

Garra    103
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[i].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
Buckeye    10747
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[i].PM);
sphereMesh->DrawSubset(0); // either use a single spheremesh or P[i].Point
}

Share this post


Link to post
Share on other sites
Garra    103
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[i].PM, P[i].x, P[i].y, 0.0f);

}



Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this