PDA

View Full Version : World position of an object


AlphaJoe
02-13-2005, 03:45 PM
I am writing an expression that requires me to retrieve the world position of an object. Where can I find that attribute?

1armedScissor
02-13-2005, 05:07 PM
xform -ws -q -t objectName would return objectName's x y z translation and could be stored in a float array.

AlphaJoe
02-13-2005, 05:37 PM
xform -ws -q -t objectName would return objectName's x y z translation and could be stored in a float array.

Well, that would work, but that returns translation, which, if transformations have been frozen on one of the objects, the values would be incorrect. I have tried -ws instead of -t, but I am still getting incorrect values.

GennadiyKorol
02-13-2005, 07:11 PM
For expression I would not suggest you using nondirect connetions like $Val = `command`;
To get the world position of an object, create a locator, name it something like worldPositionTaker, then pointConstrain that locator to your object. Now the xyz coordinates of locators transform will be the world position of your object. Now you can directly connect attributes with position of the locator.

seven6ty
02-13-2005, 09:04 PM
Hawk, any reason to avoid doing it the other way "$xVal = `command`"?

AlphaJoe
02-13-2005, 09:54 PM
OK, I got it to work. There was something wrong in my original scene file, so I created a new test scene and I got the script working correctly. Here is the script I am running now, for anyone else who has this question.

float $myPos[]=`xform -q -ws -rp Bumper01`;
float $ballPos[]=`xform -q -ws -rp Ball`;
float $myPosX = $myPos[0];
float $myPosY = $myPos[1];
float $myPosZ = $myPos[2];
float $ballPosX = $ballPos[0];
float $ballPosY = $ballPos[1];
float $ballPosZ = $ballPos[2];
float $distance=sqrt(pow(($ballPosX - $myPosX),2) + pow(($ballPosY - $myPosY),2));

This script is for a pinball machine bumper cylinder to be used with dynamics. This portion of the script checks the distance between the bumper and the ball. If the ball is within a certain range, another section of the script causes the bumper to kick and propel the ball in another direction.

john_homer
02-13-2005, 09:56 PM
Well, that would work, but that returns translation, which, if transformations have been frozen on one of the objects, the values would be incorrect. I have tried -ws instead of -t, but I am still getting incorrect values.

I'm not 100% on this.. but I think if you query the pivot, it will give you the world position even if its been frozen...
xform -q -ws -piv

.j

macaroniKazoo
02-13-2005, 10:41 PM
john homer is right, the `xform -q -ws -rp` or `xform -q -ws -piv` should work for ya. its strange how the `xform -q -ws -t` command doesn't work, but hey. thats alias for ya.

i use: xform -q -ws -rp

CGTalk Moderation
02-13-2006, 11:00 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.