Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (
- --updated to handle groups
- --check if correct selection exists
- if (selection.count == 1) or (classof selection == ObjectSet) then
- (
- local obj = $
- if classof obj == ObjectSet do
- (
- for i in selection where isGroupHead i do obj = i
- )
- -- Create the variables
- local fromPivot
- local fromVector
- local toPivot
- local toVector
- -- Turn on snaps
- snapMode.active = true
- -- from object
- fromPivot = pickpoint snap:#3d
- print("from pivot is " + fromPivot as string)
- fromVector = pickpoint snap:#3d
- print("from vector is " + fromVector as string)
- print("and the unit vector is: " + (normalize(fromVector - fromPivot)) as string)
- -- To object
- toPivot = pickpoint snap:#3d
- print("to pivot is " + toPivot as string)
- toVector = pickpoint snap:#3d
- print("to vector is " + toVector as string)
- print("and the unit vector is: " + (normalize(toVector - toPivot)) as string)
- -- Set pivot for rotation
- obj.pivot = fromPivot
- -- Move object to the correct location
- moveAmount = (toPivot - fromPivot)
- move obj moveAmount
- -- The from vector has moved, updated it.
- updatedFromVector = (fromVector + moveAmount)
- print ("The updated from vector is: " + updatedFromVector as string)
- print ("As a unit vector it is: " + (normalize(updatedFromVector)) as string)
- -- Create the variables for the rotation math
- A = normalize(updatedFromVector - toPivot)
- B = normalize(toVector - toPivot)
- -- Calculate the cross product
- crossProduct = cross A B
- -- Calculate the length of the cross product vector
- crossProductLength = length crossProduct
- -- Calculate the dot product
- dotProduct = dot A B
- -- Calculate the angle using atan2
- rotationAngle = atan2 crossProductLength dotProduct
- print ("rotation angle is: " + rotationAngle as string)
- -- Find and apply the rotation Axis
- rotationAxis = normalize crossProduct
- print ("the rotation axis is " + rotationAxis as string)
- rotate obj (angleaxis rotationAngle rotationAxis)
- ) else
- (
- messageBox "You need to have the one object that you want to move selected!"
- )
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement