Skip to main content
gamedev.net
🔒 Locked

skydome problem

Started by TWild Jul 4, 2006 at 8:12 AM 1 replies 1k views
Original Post
TWild
TWild
I'm trying to rid of my ugly skybox and implement a skydome instead. I am going through the skydome paper at spheregames.com and haven't gotten the expected results. Here is a screenshot of what I'm getting: Free Image Hosting at www.ImageShack.us Vertex buffer creation:

m_pD3DDevice->CreateVertexBuffer(m_numVerts * sizeof(VertexPNT), D3DUSAGE_WRITEONLY, 0, D3DPOOL_MANAGED, &m_pVB, 0);

	VertexPNT *v;
	m_pVB->Lock(0, 0, (void**)&v, 0); 
	
	int n = 0;
	float dtor = D3DX_PI / 180.0f;
	
	for (int phi=0; phi <= 90 - m_dPhi; phi += (int)m_dPhi) {
		for (int theta=0; theta <= 360 - m_dTheta; theta += (int)m_dTheta) 
			
			v[n].pos.x = radius * ::sinf(phi*dtor) * ::cosf(dtor*theta);
			v[n].pos.y = radius * ::sinf(phi*dtor) * ::sinf(dtor*theta);
			v[n].pos.z = radius * ::cosf(phi*dtor);
			//v[n].color = D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f);
			n++;
			
			v[n].pos.x = radius * ::sinf((phi+m_dPhi)*dtor) * ::cosf(theta*dtor);
			v[n].pos.y = radius * ::sinf((phi+m_dPhi)*dtor) * ::sinf(theta*dtor);
			v[n].pos.z = radius * ::cosf((phi+m_dPhi)*dtor);
			//v[n].color = D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f);
			n++;

			v[n].pos.x = radius * ::sinf(dtor*phi) * ::cosf(dtor*(theta+m_dTheta));
			v[n].pos.y = radius * ::sinf(dtor*phi) * ::sinf(dtor*(theta+m_dTheta));
			v[n].pos.z = radius * ::cosf(dtor*phi);
			//v[n].color = D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f);
			n++;

			if (phi > -90 && phi < 90) {
				v[n].pos.x = radius * ::sinf((phi+m_dPhi)*dtor) * ::cosf(dtor*(theta+m_dTheta));
				v[n].pos.y = radius * ::sinf((phi+m_dPhi)*dtor) * ::sinf(dtor*(theta+m_dTheta));
				v[n].pos.z = radius * ::cosf((phi+m_dPhi)*dtor);
				//v[n].color = D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f);
				n++;
			}
		}

	m_pVB->Unlock();

I am using a dTheta of 15 and dPhi of 15 which gives me 576 vertices -

for(int i = 0; i < numPasses; i++)
	{
		m_tltEffect->BeginPass(i);
		m_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 574);
		m_tltEffect->EndPass();
	}

---------------------My specs (because I always forget to post them)Intel P4 2.4 GHz640 MB system memoryRadeon 9700 PROWindows XPDirectX 9DirectX 8.1 SDK
circlesoft
circlesoft
Hm, that looks a bit complicated. Here is how I do it:

const uint32 numX	      = 200;const uint32 numY	      = 100;const float  radius     = 200.0f;const float  xStep	= TWO_PI  / (float)(numX-1);const float  yStep	= HALF_PI / (float)(numY-1);	// Iterate over the hemisphere, initialize verticesfor( uint32 y = 0; y < numY; y++ ){      const float theta = (y * yStep);      for( uint32 x = 0; x < numX; x++ )      {            const float phi = x * xStep;		// calculate the position		data->pos = Vector3( radius * cosf( phi ) * sinf(theta),					   radius * cosf( theta ) * 1.15f,					   radius * sinf( phi ) * sinf(theta) );      }}


To generate a triangle list index buffer, just iterate over the x steps and reach down into the next step:

for( uint32 y = 0; y < numY - 1; y++ ){	uint32 offset = y * numX;		for( uint32 x = 0; x < numX; x++ )	{		// Vertex (2)		*data = offset + x;		 data++;				// Vertex (6)		*data = offset + x + numX;		 data++;				// Vertex (1)		*data = offset + x + 1;		 data++;				// Vertex (6)		*data = offset + x + numX;		 data++;				// Vertex (5)		*data = offset + x + numX + 1;		 data++;				// Vertex (1)		*data = offset + x + 1;		 data++;	}}
TWild
TWild


Thanks! The only problem I'm having is with the index buffer creation - It seems like my number of triangles calculation is wrong, because I'm blowing a subscript in my index buffer. I am using (numX - 1) * (numY - 1) * 2.

m_pD3DDevice->CreateIndexBuffer(3 * m_numTris * sizeof(WORD), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &m_pIB, 0); 




EDIT* Nevermind, I made a dumb mistake and left the parens off the tri calculation in the code.

[Edited by - TWild on July 4, 2006 12:06:36 PM]
---------------------My specs (because I always forget to post them)Intel P4 2.4 GHz640 MB system memoryRadeon 9700 PROWindows XPDirectX 9DirectX 8.1 SDK

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.