On 16/07/2014 at 23:48, xxxxxxxx wrote:
Could some one please help me with why the object keeps flipping around to -180 when finding the mean rotation between two objects and how I could prevent it?
import c4d
from c4d import utils
def SetGlobalRotation(obj, rot) :
m = obj.GetMg()
pos = m.off
scale = c4d.Vector( m.v1.GetLength(),
m.v2.GetLength(),
m.v3.GetLength())
m = utils.HPBToMatrix(rot)
m.off = pos
m.v1 = m.v1.GetNormalized() * scale.x
m.v2 = m.v2.GetNormalized() * scale.y
m.v3 = m.v3.GetNormalized() * scale.z
obj.SetMg(m)
def main() :
a = op[c4d.ID_USERDATA,1]
b = op[c4d.ID_USERDATA,2]
c = op[c4d.ID_USERDATA,3]
aRot = utils.MatrixToHPB(a.GetMg())
bRot = utils.MatrixToHPB(b.GetMg())
cRot = utils.MatrixToHPB(c.GetMg())
x = [aRot,bRot]
mean_rot = sum(x)/2
SetGlobalRotation(c, mean_rot)
https://dl.dropboxusercontent.com/u/2802779/mean_rotation.c4d