Original Post
Hi everyone
?
Im newer of D3D11, and Im doing some simple work for practice.
My 1st question is : I use following code to generate sphere's vertices' position data.
I use Two-dimensional Array to save vertices, but I don't know whether following code vertexData.pSysMem = vertices; correct ?
And will the data in vertex-buffer correct ?
My 2nd question is : I don't know how to compute index of each triangle ?
Following code shows my way to create sphere's vertices' data.
Variable 'stack' like weft, and slice like warp, by them I create sphere with 2 step, each step create half-sphere.
for(int iStack = 0; iStack < stack; iStack++)
{
if( iStack == (stack / 2) )
{
tmp_radius = 0;
height = 0;
}
if( iStack < ((stack - 1) / 2) )
{
double angle = 0.0f;
height = pos.y - radius + tmp_radius;
for(int iSlice = 0; iSlice < (slices * 2); iSlice++)
{
vertices[iStack][iSlice].position.x = pos.x + (float)(cos(angle) * tmp_radius);
vertices[iStack][iSlice].position.y = (float)height;
vertices[iStack][iSlice].position.z = pos.z + (float)(sin(angle) * tmp_radius);
angle += phi;
}
tmp_radius += delta_of_radius;
continue;
}
else
{
double angle = 0;
height = pos.y + radius - tmp_radius;
for(int iSlice = 0; iSlice < (slices * 2); iSlice++)
{
vertices[iStack][iSlice].position.x = pos.x + (float)(cos(angle) * tmp_radius);
vertices[iStack][iSlice].position.y = (float)height;
vertices[iStack][iSlice].position.z = pos.z + (float)(sin(angle) * tmp_radius);
angle += phi;
}
tmp_radius += delta_of_radius;
continue;
}
}
Im newer of D3D11, and Im doing some simple work for practice.
My 1st question is : I use following code to generate sphere's vertices' position data.
I use Two-dimensional Array to save vertices, but I don't know whether following code vertexData.pSysMem = vertices; correct ?
And will the data in vertex-buffer correct ?
My 2nd question is : I don't know how to compute index of each triangle ?
Following code shows my way to create sphere's vertices' data.
Variable 'stack' like weft, and slice like warp, by them I create sphere with 2 step, each step create half-sphere.
for(int iStack = 0; iStack < stack; iStack++)
{
if( iStack == (stack / 2) )
{
tmp_radius = 0;
height = 0;
}
if( iStack < ((stack - 1) / 2) )
{
double angle = 0.0f;
height = pos.y - radius + tmp_radius;
for(int iSlice = 0; iSlice < (slices * 2); iSlice++)
{
vertices[iStack][iSlice].position.x = pos.x + (float)(cos(angle) * tmp_radius);
vertices[iStack][iSlice].position.y = (float)height;
vertices[iStack][iSlice].position.z = pos.z + (float)(sin(angle) * tmp_radius);
angle += phi;
}
tmp_radius += delta_of_radius;
continue;
}
else
{
double angle = 0;
height = pos.y + radius - tmp_radius;
for(int iSlice = 0; iSlice < (slices * 2); iSlice++)
{
vertices[iStack][iSlice].position.x = pos.x + (float)(cos(angle) * tmp_radius);
vertices[iStack][iSlice].position.y = (float)height;
vertices[iStack][iSlice].position.z = pos.z + (float)(sin(angle) * tmp_radius);
angle += phi;
}
tmp_radius += delta_of_radius;
continue;
}
}