[Closed] Place'n Rotate mousetool
Hello All,
So I am trying to script a tool that merges some objects and lets the user place and rotate them – just like inserting rpc’s. I just cant figure out how to do the rotate part…
This is what i got right now, it works but the rotatepart i not very userfriendly :shrug:
tool placeit prompt:"place and rotate objs on screen"
(
on freeMove do
(
global wldp = worldpoint
new_ass.pos = wldp --new_ass is the name of the merged objects (assembly)
)
on mouseMove clickno do
(
case clickno of
(
2:
(
-- I guess this is the part that causes my headache :-(
vctr = wldp - worldpoint
dir = atan2 vctr.y vctr.x
rotquat = quat 0 0 1 dir
print (rotquat)
new_ass.rotation = (inverse rotquat)
)
3:
(
(#stop)
)
)
)
)
- Sorry the bad formatting, it looks great in editpad…
Any ideas are welcome…
Might help, might not:
A similar tool I made to replace RPC spray at my work, when the mouse has been clicked, but not released, I made a tape dummy, with the base at the downpoint, and the target wherever I move the mouse. When I release, I build my vectors based on a ray of the tape into a matrix3, put the matrix into the transform of my new object, and now the object is pointed in the right direction, and its Z-axis is aligned with the normal of the face I clicked on (and the tape is deleted at this point too)
Hey skywisenight,
That’s a very nice workaround you’ve made, still I think im going for the ‘math way’ (if its there)
Finally cracked it.
Ended up doing something like this:
tool foo
(
local b
on mousePoint clickno do
(
if clickno == 1 then ( b = box width:50 pos:worldPoint ) else(#stop)
)
on mouseMove clickno do
(
targetrotation = - gridangle[3]
currentrotation = b.rotation as eulerangles
diff = targetrotation - currentrotation.z
in coordsys local
(
b.rotation = eulerangles 0 0 diff
)
)
)
starttool foo