PDA

View Full Version : how could i create a 2 dimensional vector array??


MegaManZZ
02-14-2008, 07:20 PM
I'm a little new to mel and im trying to figure out how to store a 2 dimensinal vector array??.
is it possible?

my goal is so create a bunch of locators in default positions.

example:

vector $locatorPositions[][3] = << 0,6.67,0.23; 0,6.67,0.23; 0,7.79,0.15>>;

int $size = size($locatorPositions);
for ($i = 0; $i < $size; $i++)
{
spaceLocator;
move($locatorPositions[$i][0]) ($locatorPositions[$i][1]) ($locatorPositions[$i][2]);
}


i know this is sloppy, but bear with me.. the result should be 3 locators created at the positions in the vector. Also the reason i made the first Dimension on the vector [blank] is to indicate that i should be able add additional vectors if i choose to. I'm also hoping to get the size of the first dimension on the vector.. I did look around the net for a while now with no luck. If im looking at things the wrong way let me know.. sorry if i caused any confusion:shrug:

meljunky
02-14-2008, 07:27 PM
A 2D array is a matrix in MEL. It entire size has to be delcared at the time of creation.

There is another thread discussing it right now:

http://forums.cgsociety.org/showthread.php?f=89&t=592781

I have written a method their that might help.

I am lacking coffee just notice you started that other thread. :)

-Brian
www.meljunky.com (http://www.meljunky.com/)

MegaManZZ
02-15-2008, 02:25 PM
in that case. How would be the best approach to pass the location of multiple locators to a spine chain? assuming that you don't know how many locators there will be?

meljunky
02-15-2008, 02:50 PM
Severel ways I can think of...

Three arrays that each of a float values where the index correspond to the different locators
float $locPosX[], $locPosY[], $locPosZ[] ;
string $locName[];
//Arrays stores name and XYZ positions
xform $locPosX[0], $locPosY[0], $locPosZ[0] $locName[0];
xform $locPosX[1], $locPosY[1], $locPosZ[1] $locName[1];

A single float array that store the XYZ values
float $locPos[];
//values stored as x1,y1,z1,x2,y2,z2,x3.y3.z3....
for ($i=0, $x=0,$y=1, $z=2; $i<size($locName); $i++, $x+3, $y+3, $z+3){
xform $locPos[$x], $locPos[$y], $locPos[$z] $locName[$i];
}

A string array that stores the xyz values seperated by spaces
string $locPosB[] = {"0.5 3.0 2.0", "3.5 2.7 2.7", "1.2 7.4 3.7"};
//token the string elements into three seperate values with tokenize and type cast to float

I like the last method I mention, personally.

-Brian
www.meljunky.com (http://www.meljunky.com)

MegaManZZ
02-15-2008, 10:12 PM
Very well said!

MegaManZZ
02-15-2008, 11:22 PM
hey meljunky, or other repliers

i tried your example
string $locPosB[] = {"0.5 3.0 2.0", "3.5 2.7 2.7", "1.2 7.4 3.7"};
and it worked like a charm.

how would i be able to do something like print the z value of the first element in the string.
(2.0) would be the result.

im assuming you where talking about it when you said.
//token the string elements into three seperate values with tokenize and type cast to float

unfortunatly im not educated enough to understand tokenize and type casting.. i hope someone can clarify things up. prefereably with an example for me to go by.

meljunky
02-15-2008, 11:37 PM
string $locPosB[] = {"0.5 3.0 2.0", "3.5 2.7 2.7", "1.2 7.4 3.7"};
string $tokenList[];
tokenizeList($locPosB[0], $tokenList);
float $locPos[3] = { float($tokenList[0]), float($tokenList[1]), float($tokenList[2]) };
print $locPos;
//Results:
0.5
3
2

-Brian
www.meljunky.com

CGTalk Moderation
02-15-2008, 11:37 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.