View Full Version : components of vector array
tomViolet 03-16-2005, 12:49 PM Hello
Is there a way to get the x, y or z from an array of vectors?
for example
// this works
vector $vec = <<0.5, 1.5, 2.5>>;
print $vec.x;
// this doesn't work
vector $vec[2] = { <<0.5, 1.5, 2.5>>, <<3.5, 4.5, 6.5>> };
print $vec[1].x;
in the example above what is the syntax of the x component of the second element of the vector array $vec[2]?
ps. this is not about per particle attributes
thanx in andvace!
|
|
mhovland
03-16-2005, 03:18 PM
I think you need to declare your type as matrix:
matrix $mtx[3][2]; // A 3x2 matrix of floats
DezFX
03-16-2005, 03:58 PM
You do not have access to the vector components like you are thinking. You need to actually extract them out into floats in order to print and work on them as individual numbers.
This works:
vector $vec1[] = { <<0.5, 1.5, 2.5>>, <<3.5, 4.5, 6.5>> };
vector $vec2 = $vec1[0];
float $flt = $vec2.x;
print $flt;
tomViolet
03-16-2005, 06:02 PM
I hate the idea of using more two more variables to access another variable but it will do the job.
Thanx for your help guys!
mark_wilkins
03-16-2005, 06:35 PM
I hate the idea of using more two more variables to access another variable but it will do the job.
Thanx for your help guys!
You really only need one more variable:
vector $vec[2] = { <<0.5, 1.5, 2.5>>, <<3.5, 4.5, 6.5>> };
vector $currvec = $vec[1];
print ($currvec.x);
-- Mark
DezFX
03-16-2005, 08:30 PM
Ah-Ha! It's those damn parenthases. LoL I know I should get in the habit of using those all the time when printing something. Sometimes it works and sometimes it doesn't. I know that for concatination it is required, but it's hit-n-miss when dealing with straight variables. I guess Maya looks at accessing the components of an array as a suedo-concatination. Good deal...<mental note>.
CGTalk Moderation
03-16-2005, 08:30 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.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.