Notifications
Clear all

[Closed] Pivot Questions

I’ve got two questions in regards to pivots and rotation.

  1. How do I rotate an object so it’s X is pointing towards a specified position value (point3) Similar to a look at constraint, but in this case using matrix math to actually calculate the rotation offset.

  2. I know how to position the pivot point3 wise, but how to I calculate the pivot only so it’s Z is aligned to the face normal and the Y is pointing to the corner point (position of corner vert)?
    As seen in the bottom of the image.

Thanks guys for your help on this! I’m excited to get this working.

Part one test script.


--Setup
delete objects
p = convertToPoly (teapot pos:[0,0,20] widthSegs:1 lengthSegs:1 radius:5)
trg = point size:5 pos:[40,30,0]

select p

Part two test script.


--Setup
delete objects
p = convertToPoly (plane pos:[0,0,50] widthSegs:1 lengthSegs:1)
rotate p (eulerangles 0 45 0)

--Pivot Changing
verts = #(2,4)
pts = for v in verts collect (polyop.getVert p v)
center = [0,0,0]
for p in pts do center += p
center /= pts.count


select p

2 Replies

You just have to get those 2 vert positions, and use that for a vector, then use the face normal as another vector, then you can calculate the last axis with those 2.


 verts = polyop.getVertSelection $ as BitArray
 vertPos = for vert in verts collect polyop.getVert $ vert 
 averageNormal = [0,-0.462054,0.886852]
 UpVector = normalize (vertPos[2] - vertPos[1])
 rightVector = normalize (cross  UpVector averageNormal ) 
 theMatrix = matrix3 rightVector upVector averageNormal  $.pos
 
 $Teapot03.transform = theMatrix
 

So I selected the bottom 2 verts on the plane, as you have in your example. Get those positions, and subtract one from the other to get the vector.

The AverageNormal is the FaceNormal, but you could get that however you want/use whatever other vector you want.

You may need to flip/flop the VertPositions when subtracting to get the proper direction, or also flip the UpVector/AverageNormal in the Matrix to get the right rotation as well.

But this should work.

Thank you Matt for the help. I’ll try this out and see what I get.