Game board in 3D

Started by
5 comments, last by MikHaven 19 years, 2 months ago
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]
Advertisement
I don't quite understand. You're trying to wrap a game board around a sphere?

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

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.
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.
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.
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!
RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.
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.tu = asinf( pVertices.norm.x ) / D3DX_PI + 255.5f;	pVertices.tv = asinf( pVertices.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.norm.x ) / D3DX_PI + 255.5f;		vPosition.y = asinf( pVertices.norm.y ) / D3DX_PI + 255.5f;		vCenter = pVertices.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...

This topic is closed to new replies.

Advertisement