user13642292
user13642292

Reputation:

Convert 1d array into array of vectors

i have a 48 element in a double array that contains XYZ coordinates of 16 points, i need to extract every single point from this array into Vector3 (x,y,z) tried to loop over the array but somehow my loop is getting to the bounds of the array index like below

     {
        myVector = new Vector(myArray[i], myArray[i++], myArray[i+2]);
        Console.WriteLine(myVector);
     }

any ideas ?

Upvotes: 0

Views: 169

Answers (1)

Marco Salerno
Marco Salerno

Reputation: 5203

The solution is simple:

 {
    myVector = new Vector(myArray[i], myArray[i+1], myArray[i+2]);
    Console.WriteLine(myVector);
 }

Explanation:

i++ changes i value by adding 1 to it, i+1 doesn't.

Upvotes: 1

Related Questions