Getting values out of a vector Array.

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
  02 February 2011
Getting values out of a vector Array.

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?

AKA KC / Intuition
  02 February 2011
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... 
  02 February 2011
Ah, ok. Sorry if I just newb'd up the forum.

Thanks for the quick reply.
AKA KC / Intuition
  02 February 2011
Thread automatically closed

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.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 02:39 PM.

Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.