配列を返さなければならない関数を書くなどの一般的なタスクを手伝ってください。この問題の解決に 2 時間費やしましたが、結果は得られませんでした。これが私のコードです:
VERTEX* ConstructVertices(float R, unsigned int Slices)
{
//const unsigned int n = static_cast<const unsigned int>(Slices);
VERTEX *__vertices = new VERTEX[100];
float dx = (2 * R) / Slices;
float dz = dx;
float x, y, z;
x = -R;
y = 0.5f;
z = 0;
int x_sign = 1;
int z_sign = -1;
__vertices[0].Color = D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f);
__vertices[0].Pos = D3DXVECTOR3(x, y, z);
for (int i=1; i<Slices * 4 + 1; i++)
{
__vertices[i].Color = D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f);
y = -y;
if (y < 0)
{
__vertices[i].Pos = D3DXVECTOR3(x, y, z);
continue;
}
x += x_sign * dx;
z += z_sign * dz;
x = round_up(x, 2);
z = round_up(z, 2);
if (abs(x) == abs(R))
{
x_sign = -x_sign;
}
if (abs(z) == abs(R))
{
z_sign = -z_sign;
}
__vertices[i].Pos = D3DXVECTOR3(x, y, z);
}
return __vertices;
}
配列にアクセスするためのコード:
VERTEX *vertices = new VERTEX[100];
vertices = ConstructVertices(1, 10);
Watchesウィンドウでは、頂点[0]、頂点[1]、..のような値を見ることができますが、配列として見ることはできません。メインはsizeof(頂点)が160ではなく4を返します!!
どうもありがとうございます!