Sign in to follow this  

Game board in 3D

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

Hello All, I am trying to program a game board in 3D space. The board is attached, for my needs, to a spherical object I have created under DirectX 9.0c Feb 2005. D3DXCreateSphere( pd3dDevice, fRadius, fSlices, fStacks, &pTempSunMesh, NULL ); A) I now want to attach pieces of the board to this sphere uniformly. I thought well I could use a bitmap, to represent the board pieces, and I got onto sprites and textures. -------a. Pieces are uniform in shape and size, for all pieces, and since it's DirectX that is on the order of 32x32 B) In order to use all of this, I need to create a structure to hold my pieces, as represented in 3d space, like where they are, in relation to other pieces. C) I thought, well I could use the normals or vectors of the sphere to accomplish this?? D) This is on the order of a 3d map editor in space, but luckily for now all I really want is for the program to decide what the pieces do. E) I have looked into Spherical maps, but that doesn't seem to be the uppht I need. I am pretty sure it has something to do with transformations. I have seen different things though; such as I can't attach a sprite surface to a sphere surface. I am pretty much stuck, and would like to throw this out to everyone and see if I can't get some braver people out there to tackle this one. MikHaven [Edited by - MikHaven on February 13, 2005 8:24:27 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by superpig
I don't quite understand. You're trying to wrap a game board around a sphere?


Yeah, basically that's exactly what I am trying to do. I will provide some links to get a general idea, of where I am headed.

http://www.mvps.org/directx/articles/spheremap.htm

OK guess that's it, sorry. If you look at the pictures, not the way he did it, because I want to make a game board itself, like the white backround with black boxes in the demo pictures.

I need to beable to sort and control which textures each of those squares are.

OK, due to lack of forum control, I am imaging a front half, of the right side of the sphere in 2d. WOOT I figured out how to show it in the forum.

Starter:

---0
--000
-00000
--000
---0

Like that, and then I can change the boxes however I want.

Round 1:

---1
--000
-01000
--001
---0

---0
--010
-10010
--100
---0

So you see it's more of a control and placement issue, I think. And how to store all the boxes, in 3d space, when I am done.

Share this post


Link to post
Share on other sites
So yah, one way of storing all the points was building from scratch.

Like in the last example, something like this

---A
--BCD
-EFGHI
--JKL
---M

Woot! I just raised my ascii skills, but 2 points.

Anyways you get the general idea, then I can loop through the elements and change them according to some logic.

Share this post


Link to post
Share on other sites
I'm not sure what exactly you want but to draw a 3d sphere produced from multiple boxes I would do the following.

Declare a 3d array of boxes which would give you a cuboid. You can then 'cut' that cuboid down to show a sphere by testing against a radius. If you set each box to have a mid-point, choose an arbitrary centre for your sphere and test the mid-point against the radius of the sphere from that central point. If the box is within the radius then flag it to be used, else set it to be ignored.

Share this post


Link to post
Share on other sites
If you have square tiles on a spherical surface, the easiest way is a geosphere.

Take a cube from (-1,-1,-1) to (1,1,1), and tesselate it. Then normalize all vertex positions, and multiply by the desired sphere radius.

Remember that for a sphere, the normal of a point is the same as the point itself normalized, so you can get orientation for your billboards or piece models instantly.

Hopefully you've got the graphics experience to take it the rest of the way. Good luck!

Share this post


Link to post
Share on other sites
Thanks for the suggestions, however I guess I really don't understand the math, or really what I am asking. I thought I could do it much more simply than I have been trying, however it's not even remotely doing anything I want to do.

Here is what I have so far..
Just imagine it's coded correctly : (


HRESULT InitGeometry( IDirect3DDevice9* pd3dDevice )
{
float fRadius = 0.25f;
UINT fSlices = 50;
UINT fStacks = 50;

D3DXCreateSphere( pd3dDevice, fRadius, fSlices, fStacks, &pTempSunMesh, NULL );
if( FAILED( D3DXComputeNormals( g_pSunMesh, NULL ) ) )
return E_FAIL;
if( SUCCEEDED( g_pSunMesh->GetVertexBuffer( &g_pVertexBuffer ) ) )
{
int nNumVerts = g_pSunMesh->GetNumVertices();
LifeVertex *pVertices = NULL;

g_pVertexBuffer->Lock( 0, 0, (void**)&pVertices, 0 );

for( int i = 0; i < nNumVerts; ++i )
{
pVertices[i].tu = asinf( pVertices[i].norm.x ) / D3DX_PI + 255.5f;
pVertices[i].tv = asinf( pVertices[i].norm.y ) / D3DX_PI + 255.5f; }
}
g_pVertexBuffer->Unlock();
pd3dDevice->SetStreamSource (0, NULL, 0, 0);
pVertices = NULL;
}
pTempSunMesh->Release();
return ( S_OK );
}



And in the Draw Sprites, I draw each square on the normal, or the vertice

g_pVertexBuffer->Lock( 0, 0, (void**)&pVertices, 0 );
{
for( int i = 0; i < nNumVerts; ++i )
{
vPosition.x = asinf( pVertices[i].norm.x ) / D3DX_PI + 255.5f;
vPosition.y = asinf( pVertices[i].norm.y ) / D3DX_PI + 255.5f;
vCenter = pVertices[i].norm;

mMatrix = mScale *
mSpinRotation

g_pTextureSprite->SetTransform( &mMatrix );
hr = g_pTextureSprite->Draw(g_pDeathTexture, &srcRect, &vCenter, &vPosition, COLORKEY );
}
}
g_pVertexBuffer->Unlock();



I am understanding now, maybe I should transform the sprites to orientate them around the sphere.

I have found several code snipets to do the sphere myself, but they mostly seem to be in opengl, and I have been having troubles converting them.

Thanks, for all your help...

Share this post


Link to post
Share on other sites

This topic is 4683 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.

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