Hi Mouloud,
The following code shows how to generate the vertices of a cylinder for example:
internal static void CreateCylinderY(GLDevice device, NSurface surface, int m, int n, float radiusX, float radiusZ, float minY, float maxY, float cx, float cz)
{
float angleStep = (float)(NMath.PI2 / (m - 1));
NVector3DF v3 = NVector3DF.Zero;
NVector4DF[] arrPrecomputedData = device.RequestPrecompData4F(m);
int vertexCount = m * n;
NVertex.P3N[] vertices = device.RequestBufferP3N(vertexCount);
int lastM = m - 1;
for (int i = 0; i < lastM; i++)
{
// calculate the current angle, its cos and sin
float alpha = i * angleStep;
double cosA = Math.Cos(alpha);
double sinA = Math.Sin(alpha);
// this is needed for the normal calculation
double nx = radiusZ * cosA;
double nz = radiusX * sinA;
double len = Math.Sqrt(nx * nx + nz * nz);
// calculate position
arrPrecomputedData[i].X = (float)(radiusX * cosA);
arrPrecomputedData[i].Y = (float)(radiusZ * sinA);
// normalize the normal vector
if (len > 0.00001)
{
arrPrecomputedData[i].Z = (float)(nx / len);
arrPrecomputedData[i].W = (float)(nz / len);
}
else
{
arrPrecomputedData[i].Z = (float)cosA;
arrPrecomputedData[i].W = (float)sinA;
}
}
arrPrecomputedData[lastM] = arrPrecomputedData[0];
float sizeY = maxY - minY;
float cellSizeY = sizeY / (n - 1);
int vertexIndex = 0;
for (int j = 0; j < n; j++)
{
float y = minY + j * cellSizeY;
for (int i = 0; i < m; i++)
{
// set normal
v3.X = arrPrecomputedData[i].Z;
v3.Y = 0;
v3.Z = arrPrecomputedData[i].W;
vertices[vertexIndex].N = v3;
// set position
v3.X = cx + arrPrecomputedData[i].X;
v3.Y = y;
v3.Z = cz + arrPrecomputedData[i].Y;
vertices[vertexIndex].P = v3;
vertexIndex++;
}
}
Best Regards,
Nevron Support Team