Notifications
Clear all

[Closed] Vector for local z axis

I’ve been experimenting for a while trying to get a vector for the local z axis of an object as it rotates. So far I haven’t had any luck so far. Any suggestions would be very helpful. Thanks in advance.

3 Replies

never mind found it. It is just the .dir property of the object just in case any one else wants to know.

-bnvm

Having solved one problem I have come across another. I want to fire rays from the pivot of and object along its local x axis and varing angles. for example firing 10 rays from 0 to 180 degrees about the local x axis. Any suggestions on how to do this would be great.

-bnvm

1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

Take a look at the example “How do I rotate a vector around the Z axis?” in the MAXScript Reference 7.0. It rotates an arbitrary vector about the world Z axis.
In your case, you would define a vector [1,0,0] (X normal vector), do the same as in the example, then transform the stand-in object representing the ray into the local space of your object by multilpying with its .transform property.


theObj = $Teapot01 --assuming your object to define a local space is a teapot
theV = [1,0,0] 
for a = 0 to 180 by 10 do 
(
rm = rotateZMatrix a 
theRotV = theV * rm  
c = cylinder radius:1 height:100 
c.dir = theRotV 
c.transform *= theObj.transform
)
 

This creates 10 cylinders pointing from 0 to 180 degrees in Teapot01’s local space starting at X axis [1,0,0] and ending at -X axis [-1,0,0].

If you want to do this “virtually”, you would have to work with matrices all the way, creating a matrix from the X normal vector, rotating it about world Z from 0 to 180 degrees and then transforming it into the local space. Finally, build a Ray value out of the translation and the Z axis of the resulting matrix:


theObj = $Teapot01
theTM = matrixFromNormal [1,0,0]
for a = 0 to 180 by 10 do 
(
rm = rotateZMatrix a 
theRotTM = (theTM * rm) * theObj.transform
theRay = Ray theRotTM.row4 theRotTM.row3 --the ray points along the X to -X in local space
)