PDA

View Full Version : Getting values out of a vector Array.


PerfectLine
02-01-2011, 08:47 PM
So I stored a vector array of all the distances of vertices from an initial origin point.

vector $averageDist[] = {<<0,0,0>>};

It starts out with only one value in the array [0] being 0,0,0.

As I run my "for loop" I add each vector, which is the x,y,z in distance from the origin point, to the vector array. I end up with one vector for each point I have selected.

So the list ends up being this when I print it.


-0.31992 0.616774 1.341836
-0.319918 0.616774 -1.341836
-0.532443 0.616774 -0
0.060095 -0.035267 1.218362
0.060098 -0.035267 -1.218362
0.532441 -0.616774 1.064887
0.532443 -0.616774 -1.064887
0.363782 -0.616774 -0

Now, how I can get an individual value out of this array?

When I try to do

print $averageDist[3];

I do get the proper result

0.060095 -0.035267 1.218362

But if I want to single out say the Y value only I can't seem to get it.

print $averageDist[3].y;

// Error: Syntax error //

Yet, if I did make a vector that wasn't an array I could get the y in this fashion.

What is the method used for getting a single value out of a vector array?

:D

Thanks.

NaughtyNathan
02-01-2011, 09:08 PM
this has come up before. and is in the docs ;) but you cannot get a component from an array element, you have to cast is as a temp vector first:

vector $temp = $averageDist[3];
print ($temp.y);
float $Y = ($temp.y);
// etc... :nathaN

PerfectLine
02-01-2011, 09:29 PM
Ah, ok. Sorry if I just newb'd up the forum. ;)

Thanks for the quick reply.

CGTalk Moderation
02-01-2011, 09:29 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.