Please, help me with such common task as to write function that must return array. I spent 2 hours with solving this problem, but no results. Here is my code:
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;
}
Code for accessing the array:
VERTEX *vertices = new VERTEX[100];
vertices = ConstructVertices(1, 10);
With Watches window i can see values like vertices[0], vertices[1],.. But i can't see it as an array & the main is sizeof(vertices) returns 4 instead of 160!!
Thank a lot!