ScriptSpot

Forum topic · General Scripting

ray help

By panaitsdv · 2009-03-08

Description

hello,

i have a ray created from two points.
i want the pivot of an object to be oriented as the ray.
(the z axis of the pivot to be oriented as the ray)

please help!

thanks,
mihai

Comments (1)

panaitsdv · 2009-03-08

OK, i think i found the answer myself:

---- rotate pivot only function

fn RotatePivotOnly obj rotation= (
local rotValInv=inverse (rotation as quat)
animate off in coordsys local obj.rotation*=RotValInv
obj.objectoffsetrot*=RotValInv
obj.objectoffsetpos*=RotValInv
)

---- new ray from 2 points

newpos1 = [0,0,0]
newpos2 = [20,20,20]
vector_dir = ray newpos1 newpos2

---- create a transformation matrix from the ray

rowZ = normalize vector_dir.dir
rowY = [0,0,1]
rowX = normalize (cross rowY rowZ)
rowY = cross rowZ rowX
trfm = matrix3 rowX rowY rowZ [1,1,1]

RotatePivotOnly obj (trfm)

----- end of script