View Full Version : Object's direction
cppgraphics 10192011, 07:05 AM Hello folks,
How to find a object's direction in MEL? whether in it is in X direction or Z direction from current position? If any formula should be used or what?


NaughtyNathan
10192011, 11:34 AM
If you are refering to an objects direction as being the vector of it's local or world X, Y or Z axis, you could just extract the X, Y or Z axis from the objects local or world matrix. Assuming the matrix is got as 16 floats (i.e. via xform or getAttr) components [0:2] are the X axis vector, [4:6] are the Y axis vector and [8:10] are the Z axis vector.
:nathaN
cppgraphics
10202011, 05:03 AM
If you are refering to an objects direction as being the vector of it's local or world X, Y or Z axis, you could just extract the X, Y or Z axis from the objects local or world matrix. Assuming the matrix is got as 16 floats (i.e. via xform or getAttr) components [0:2] are the X axis vector, [4:6] are the Y axis vector and [8:10] are the Z axis vector.
:nathaN
Hi nathan,
I need to find the world position only. Fox example, Locator(A), plane(B) are the two objects I got.
A is at Orgin.
B will be in any(+x,x,+zz) direction from A. Based on the distance between two objects and the direction Im adding some lights on the plane.
To calulate distance my first component is Y and the second one is X or Z. So if I know the locator's position from the plane I can decide X or Y to pass it.
hope you got my problem.
NaughtyNathan
10202011, 09:56 AM
sorry dude, no. I have no idea what your are talking about here. :D :(
Maybe you need to describe your problem a little more clearly, or provide a diagram..? I have no idea whether you want direction or position:
How to find a object's direction in MEL?
...
I need to find the world position only.
:nathaN
cppgraphics
10212011, 05:28 AM
I have no idea whether you want direction or position:
Nathan,
I just need the direction, sorry for the confused edition :).
In the picture A is located in Z direction from B. Now I know the direction so I can calculate the distance by using Y and Z values of both object's position.
what if the A located in Z or X or X from B, Is there any way to find the direction easily rather than many calculations? Once I find the direction then I can find the distance between two objects.
heres the link of my example screen shot.
http://img94.imageshack.us/img94/1987/trussscreenshot.png
mlefevre
10212011, 09:43 PM
Once I find the direction then I can find the distance between two objects.
The distance tool under 'Create > Measure Tools > Distance Tool' can give you the distance between two objects.
There's also the distanceBetween node that uses two objects positions to determine distance.
You can find the world space positions of two objects, subtract one from the other to obtain the vector (doesn't matter which order you subtract) then use the mag command.
string $sel[] = `ls sl`;
vector $A = `xform q ws translation $sel[0]`;
vector $B = `xform q ws translation $sel[1]`;
float $dist = mag($A  $B);
WesHowe
10212011, 10:47 PM
You can also use the good old Pythagorean method. Square the differences between each component (X1  X2) * (X1  X2), sum all three dimensions, and extract the square root with sqrt().
<* Wes *>
NaughtyNathan
10222011, 09:58 AM
I'm not entirely sure he want's this simple kind of distance... I'm sure he's trying to do something related to facing direction, but I can't make head nor tail of his explanation...
Maybe if you simply explained what you were trying to achieve with this idea (e.g. a script that hides all objects that are not going to be hit by a given light source, or whatever) we could give you more specific help or pointers?
:nathaN
ah! maybe he does want the distance, but in terms of a LOCAL X and/or Y and/or Z offset? is that it cppgraphics?
cppgraphics
10222011, 12:09 PM
Thanks for your replies folks.
I used Pythagorean method, it seems like I used wrong formula. I have taken 2D distance formula and thought one point is Y and other point I should use either X or Z.
From WesHowe (http://forums.cgsociety.org/member.php?u=374368)'s reply I got the right formula.
@ Nathan,
This is a script to create truss light setup, the colorful focus lights we will see in stage shows.
Actually I need the distance between those two objects, to setup the length of the light's fog.
Heres the rendered output of the script.
http://vimeo.com/30890084
CGTalk Moderation
10222011, 12:09 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 ©20002014, Jelsoft Enterprises Ltd.