3D chart with Mesh surface


Author
Message
mouloud djamah
mouloud djamah
Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)
Group: Forum Members
Posts: 5, Visits: 48
Using 3d chart with mesh surface, can I generate graphics like these : https://www.nevron.com/forum/uploads/images/a0caf7c0-b798-484f-8ac7-e7f1.png 
Reply
Nevron Support
Nevron Support
Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)
Group: Administrators
Posts: 3.1K, Visits: 4.2K
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


GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search