# skydome problem

This topic is 4544 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 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: 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].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].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].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].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();
}



##### Share on other sites
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 &lt; numY; y++ ){      const float theta = (y * yStep);      for( uint32 x = 0; x &lt; numX; x++ )      {            const float phi = x * xStep;		// calculate the position		data-&gt;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 &lt; numY - 1; y++ ){	uint32 offset = y * numX;		for( uint32 x = 0; x &lt; 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++;	}}

##### Share on other sites

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]

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5
khawk
11

• 10
• 9
• 9
• 11
• 11
• ### Forum Statistics

• Total Topics
633679
• Total Posts
3013301
×