Notifications
Clear all

[Closed] Rotate problem

Hi MaxScripters, I have a small problem.
Let’s say that I have an object with its transform and a vector V. I have to rotate the object to make its Z local vector match the V vector. How to do it?

6 Replies

hopefully i haven’t forgot anything:

delete objects
--seed 0
s = point name:"source" pos:(random [10,10,10] [-10,-10,-10]) rotation:(eulerangles (random 0 180) (random 0 180) (random 0 180)) axistripod:on wirecolor:yellow
t = point name:"target" rotation:(eulerangles (random 0 180) (random 0 180) (random 0 180)) axistripod:on wirecolor:green
/*	
s.transform *= (inverse (quat (acos (dot s.transform[3] t.transform[3])) (normalize (cross s.transform[3] t.transform[3])))) as matrix3
*/

do you need a theory too?

Thanks a lot! I don’t need a theory now, I’m gonna analize it by myself later since I don’t suck at math, I just don’t know much about 3ds max transform matrix and also quat is a new thing for me.

1 Reply
(@denist)
Joined: 2 years ago

Posts: 0

does my code do what you want? the main problem of all these transforms is to take the right coordinate system…

I didn’t test it yet, will do it tomorrow.

Hi, it works great, but I can’t understand the math behind it so have a question. How to change the code to work with X axis? It works with local Z axis but when I simply change the transform[3] to transform[1] it doesn’t work.

Edit: solved, dir + swap did the job