Notifications
Clear all

[Closed] surface normal direction vector to quat?

Im trying to convert a surface normal direction vector that i get from IntersectRayEx() into a quaternion angle for an object. The objective is to place objects on geometry so that theyre aligned with the face thats hit with IntersectRayEx()
im still new to maxscript but this is how far i got:

auto is a car and $maasto is the geometry i want the car to be placed on
and the dummy is just for testing it actually does what i want.

for o in selection do
(
maa = $Maasto
auto = o.pivot
dum = dummy()
dum.pos = auto-[0,0,10]
r = ray auto (dum.pivot-auto)
arr= (intersectRayEx maa r)
o.pos=(arr[1]).pos

o.rotation = b.dir – how to convert this into quat rotation of o?[/b]

)

help is greatly appreciated and gets you extra karma points.

4 Replies

this may not do it for you, but just as an additional input:

max nodes also have a .dir property that you can set directly, so maybe the following is all you need

[b]o.dir = [/b][b](arr[1]).dir[/b]
 PEN

You are going to have to calculate the other two axes from the dir value, build a matrix and then get the quat value from that.

z=theRay.dir
tempX=[1,0,0]
y=normalize (cross z tempX)
x=normalize (cross y z)
tm=matrix3 x y z theRay.pos
tm.rotation

This is off the top of my head this morning over coffee so it needs to be tested but it should work.

 PEN

You should be able to do it with quat values as well but I’m not getting exactly what I expect. Here is what I have done.

theRay=tape as ray
hP=intersectRay ground theRay
quat hP.dir.x hP.dir.y hP.dir.z 1

This is in a script controller on the rotation of an object. It kind of works but isn’t completelty accurate.

thank very much kai and paul for your swift responses I´m looking into implementing your suggestions!