Mr Jox Mr Jox - 2 months ago 19
C# Question

Write 3 arrays to 1

I have 3 arrays: x, y and z. How can I write all three to one in one-after-one mode?
For example: I have X=1,2 Y=3,4 Z=5,6
I need an array W = X[1],Y[1],Z[1],X[2],Y[2],Z[2] ... X[n],Y[n],Z[n]

float[] posX = new float[rmv2.lod[0].VerticesCount[0]];
float[] posY = new float[rmv2.lod[0].VerticesCount[0]];
float[] posZ = new float[rmv2.lod[0].VerticesCount[0]];
for (int i = 0; i < 1; i += 3)
{
posX[i] = rmv2.lod[0].Mesh[0].Vertex[i].X;
posY[i + 1] = rmv2.lod[0].Mesh[0].Vertex[i].Y;
posZ[i + 2] = rmv2.lod[0].Mesh[0].Vertex[i].Z;
}

Answer

I don't see the w array you're trying to write the output to. Are you looking for something like this?

    int n = rmv2.lod[0].VerticesCount[0];

    float[] posX = new float[n];
    float[] posY = new float[n];
    float[] posZ = new float[n];
    float[] w = new float[n * 3];
    for (int i = 0; i < n; i++)
    {
        posX[i] = rmv2.lod[0].Mesh[0].Vertex[i].X;
        posY[i] = rmv2.lod[0].Mesh[0].Vertex[i].Y;
        posZ[i] = rmv2.lod[0].Mesh[0].Vertex[i].Z;
        w[i * 3 + 0] = rmv2.lod[0].Mesh[0].Vertex[i].X;
        w[i * 3 + 1] = rmv2.lod[0].Mesh[0].Vertex[i].Y;
        w[i * 3 + 2] = rmv2.lod[0].Mesh[0].Vertex[i].Z;
    }
Comments